Skip to content

Commit e876fd1

Browse files
committed
Apply most of the comments
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent 9d888a1 commit e876fd1

File tree

4 files changed

+51
-32
lines changed

4 files changed

+51
-32
lines changed

sycl/include/CL/sycl/detail/pi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ constexpr pi_map_flags PI_MAP_WRITE_INVALIDATE_REGION =
504504
// NOTE: this is made 64-bit to match the size of cl_mem_properties_intel to
505505
// make the translation to OpenCL transparent.
506506
using pi_mem_properties = pi_bitfield;
507-
constexpr pi_mem_properties PI_MEM_CHANNEL_INTEL = CL_MEM_CHANNEL_INTEL;
507+
constexpr pi_mem_properties PI_MEM_PROPERTIES_CHANNEL = CL_MEM_CHANNEL_INTEL;
508508

509509
// NOTE: queue properties are implemented this way to better support bit
510510
// manipulations

sycl/include/CL/sycl/info/info_desc.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ enum class device : cl_device_info {
132132
usm_restricted_shared_allocations = PI_USM_CROSS_SHARED_SUPPORT,
133133
usm_system_allocator = PI_USM_SYSTEM_SHARED_SUPPORT,
134134

135-
ext_intel_mem_channel = PI_MEM_CHANNEL_INTEL
135+
ext_intel_mem_channel = PI_MEM_PROPERTIES_CHANNEL
136136
};
137137

138138
enum class device_type : pi_uint64 {

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
#include <CL/sycl/detail/cl.h>
1818
#include <CL/sycl/detail/pi.h>
1919

20+
#include <algorithm>
2021
#include <cassert>
2122
#include <cstring>
2223
#include <iostream>
2324
#include <limits>
2425
#include <map>
26+
#include <set>
27+
#include <sstream>
2528
#include <string>
2629
#include <vector>
2730

@@ -33,6 +36,7 @@
3336
}
3437

3538
const char SupportedVersion[] = _PI_H_VERSION_STRING;
39+
std::set<std::string> SupportedExtensions;
3640

3741
// Want all the needed casts be explicit, do not define conversion operators.
3842
template <class To, class From> To cast(From value) {
@@ -66,6 +70,39 @@ CONSTFIX char clSetProgramSpecializationConstantName[] =
6670

6771
#undef CONSTFIX
6872

73+
// Helper to get extensions that are common for all devices within a context
74+
pi_result getSupportedExtensionsWithinContext(pi_context context) {
75+
size_t deviceCount;
76+
cl_int ret_err =
77+
clGetContextInfo(cast<cl_context>(context), CL_CONTEXT_DEVICES, 0,
78+
nullptr, &deviceCount);
79+
if (ret_err != CL_SUCCESS || deviceCount < 1)
80+
return PI_INVALID_CONTEXT;
81+
std::vector<cl_device_id> devicesInCtx(deviceCount);
82+
ret_err = clGetContextInfo(
83+
cast<cl_context>(context), CL_CONTEXT_DEVICES,
84+
deviceCount * sizeof(cl_device_id), devicesInCtx.data(), nullptr);
85+
86+
size_t retSize;
87+
for (size_t i = 0; i != deviceCount; ++i) {
88+
ret_err = clGetDeviceInfo(devicesInCtx[i], CL_DEVICE_EXTENSIONS, 0,
89+
nullptr, &retSize);
90+
if (ret_err != CL_SUCCESS)
91+
return PI_INVALID_DEVICE;
92+
std::string extensions(retSize, '\0');
93+
ret_err = clGetDeviceInfo(devicesInCtx[i], CL_DEVICE_EXTENSIONS,
94+
retSize, &extensions[0], nullptr);
95+
if (ret_err != CL_SUCCESS)
96+
return PI_INVALID_DEVICE;
97+
std::string extension;
98+
std::stringstream ss(extensions);
99+
while (getline(ss, extension, ' '))
100+
SupportedExtensions.insert(extension);
101+
}
102+
return cast<pi_result>(ret_err);
103+
}
104+
105+
69106
// USM helper function to get an extension function pointer
70107
template <const char *FuncName, typename T>
71108
static pi_result getExtFuncFromContext(pi_context context, T *fptr) {
@@ -535,36 +572,18 @@ pi_result piMemBufferCreate(pi_context context, pi_mem_flags flags, size_t size,
535572
properties + propSize);
536573
// Go through buffer properties. If there is one, that shall be propagated
537574
// to an OpenCL runtime - check if this property is being supported.
538-
for (auto prop = supported.begin(); prop != supported.end(); ++prop) {
539-
// Check if PI_MEM_CHANNEL_INTEL property is supported. If it's not -
540-
// just ignore it, as it's an optimization hint.
541-
if (*prop == PI_MEM_CHANNEL_INTEL) {
542-
size_t deviceCount;
543-
cl_int ret_err =
544-
clGetContextInfo(cast<cl_context>(context), CL_CONTEXT_DEVICES, 0,
545-
nullptr, &deviceCount);
546-
if (ret_err != CL_SUCCESS || deviceCount < 1)
547-
return PI_INVALID_CONTEXT;
548-
std::vector<cl_device_id> devicesInCtx(deviceCount);
549-
ret_err = clGetContextInfo(
550-
cast<cl_context>(context), CL_CONTEXT_DEVICES,
551-
deviceCount * sizeof(cl_device_id), devicesInCtx.data(), nullptr);
552-
553-
size_t retSize;
554-
ret_err = clGetDeviceInfo(devicesInCtx[0], CL_DEVICE_EXTENSIONS, 0,
555-
nullptr, &retSize);
556-
if (ret_err != CL_SUCCESS)
557-
return PI_INVALID_DEVICE;
558-
std::string extensions(retSize, '\0');
559-
ret_err = clGetDeviceInfo(devicesInCtx[0], CL_DEVICE_EXTENSIONS,
560-
retSize, &extensions[0], nullptr);
561-
if (ret_err != CL_SUCCESS)
562-
return PI_INVALID_DEVICE;
563-
564-
size_t pos = extensions.find("cl_intel_mem_channel_property");
565-
if (pos == std::string::npos)
575+
for (const auto &prop = supported.begin(); prop != supported.end();
576+
++(*prop)) {
577+
if (!SupportedExtensions.empty())
578+
ret_err = getSupportedExtensionsWithinContext(context);
579+
// Check if PI_MEM_PROPERTIES_CHANNEL property is supported. If it's
580+
// not - just ignore it, as it's an optimization hint.
581+
if (*prop == PI_MEM_PROPERTIES_CHANNEL) {
582+
if (SupportedExtensions.find("cl_intel_mem_channel_property") !=
583+
SupportedExtensions.end())
566584
supported.erase(prop);
567-
}
585+
} else
586+
assert("Unsupported property found");
568587
}
569588
if (!supported.empty()) {
570589
*ret_mem =

sycl/source/detail/device_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ template <> struct get_device_info<bool, info::device::ext_intel_mem_channel> {
10151015
pi_result Err = Plugin.call_nocheck<PiApiKind::piDeviceGetInfo>(
10161016
dev, pi::cast<RT::PiDeviceInfo>(info::device::ext_intel_mem_channel),
10171017
sizeof(pi_mem_properties), &caps, nullptr);
1018-
return (Err != PI_SUCCESS) ? false : (caps & PI_MEM_CHANNEL_INTEL);
1018+
return (Err != PI_SUCCESS) ? false : (caps & PI_MEM_PROPERTIES_CHANNEL);
10191019
}
10201020
};
10211021

0 commit comments

Comments
 (0)