@@ -30,6 +30,50 @@ static cl_int mapURPlatformInfoToCL(ur_platform_info_t URPropName) {
3030 }
3131}
3232
33+ static bool isBannedOpenCLPlatform (cl_platform_id platform) {
34+ size_t nameSize = 0 ;
35+ cl_int res =
36+ clGetPlatformInfo (platform, CL_PLATFORM_NAME, 0 , nullptr , &nameSize);
37+ if (res != CL_SUCCESS || nameSize == 0 ) {
38+ return false ;
39+ }
40+
41+ std::string name (nameSize, ' \0 ' );
42+ res = clGetPlatformInfo (platform, CL_PLATFORM_NAME, nameSize, name.data (),
43+ nullptr );
44+ if (res != CL_SUCCESS) {
45+ return false ;
46+ }
47+
48+ // The NVIDIA OpenCL platform is currently not compatible with DPC++
49+ // since it is only 1.2 but gets selected by default in many systems.
50+ // There is also no support on the PTX backend for OpenCL consumption.
51+ //
52+ // There is also no support for the AMD HSA backend for OpenCL consumption,
53+ // as well as reported problems with device queries, so AMD OpenCL support
54+ // is disabled as well.
55+ bool isBanned =
56+ name.find (" NVIDIA CUDA" ) != std::string::npos ||
57+ name.find (" AMD Accelerated Parallel Processing" ) != std::string::npos;
58+
59+ return isBanned;
60+ }
61+
62+ static bool isBannedOpenCLDevice (cl_device_id device) {
63+ cl_device_type deviceType = 0 ;
64+ cl_int res = clGetDeviceInfo (device, CL_DEVICE_TYPE, sizeof (cl_device_type),
65+ &deviceType, nullptr );
66+ if (res != CL_SUCCESS) {
67+ return false ;
68+ }
69+
70+ // Filter out FPGA accelerator devices as their usage with OpenCL adapter is
71+ // deprecated
72+ bool isBanned = (deviceType & CL_DEVICE_TYPE_ACCELERATOR) != 0 ;
73+
74+ return isBanned;
75+ }
76+
3377UR_DLLEXPORT ur_result_t UR_APICALL
3478urPlatformGetInfo (ur_platform_handle_t hPlatform, ur_platform_info_t propName,
3579 size_t propSize, void *pPropValue, size_t *pSizeRet) {
@@ -102,14 +146,26 @@ urPlatformGet(ur_adapter_handle_t, uint32_t NumEntries,
102146 CLPlatforms.data (), nullptr );
103147 CL_RETURN_ON_FAILURE (Res);
104148
149+ // Filter out banned platforms
150+ std::vector<cl_platform_id> FilteredPlatforms;
151+ for (uint32_t i = 0 ; i < NumPlatforms; i++) {
152+ if (!isBannedOpenCLPlatform (CLPlatforms[i])) {
153+ FilteredPlatforms.push_back (CLPlatforms[i]);
154+ }
155+ }
156+
105157 try {
106- for (uint32_t i = 0 ; i < NumPlatforms; i++) {
107- auto URPlatform =
108- std::make_unique<ur_platform_handle_t_>(CLPlatforms[i]);
158+ for (auto &Platform : FilteredPlatforms) {
159+ auto URPlatform = std::make_unique<ur_platform_handle_t_>(Platform);
109160 UR_RETURN_ON_FAILURE (URPlatform->InitDevices ());
110- Adapter->URPlatforms .emplace_back (URPlatform.release ());
161+ // Only add platforms that have devices, especially in case all
162+ // devices are banned
163+ if (!URPlatform->Devices .empty ()) {
164+ Adapter->URPlatforms .emplace_back (URPlatform.release ());
165+ }
111166 }
112- Adapter->NumPlatforms = NumPlatforms;
167+ Adapter->NumPlatforms =
168+ static_cast <uint32_t >(Adapter->URPlatforms .size ());
113169 } catch (std::bad_alloc &) {
114170 return UR_RESULT_ERROR_OUT_OF_RESOURCES;
115171 } catch (...) {
@@ -217,11 +273,19 @@ ur_result_t ur_platform_handle_t_::InitDevices() {
217273
218274 CL_RETURN_ON_FAILURE (Res);
219275
276+ // Filter out banned devices
277+ std::vector<cl_device_id> FilteredDevices;
278+ for (uint32_t i = 0 ; i < DeviceNum; i++) {
279+ if (!isBannedOpenCLDevice (CLDevices[i])) {
280+ FilteredDevices.push_back (CLDevices[i]);
281+ }
282+ }
283+
220284 try {
221- Devices.resize (DeviceNum );
222- for (size_t i = 0 ; i < DeviceNum ; i++) {
223- Devices[i] =
224- std::make_unique<ur_device_handle_t_>(CLDevices[i], this , nullptr );
285+ Devices.resize (FilteredDevices. size () );
286+ for (size_t i = 0 ; i < FilteredDevices. size () ; i++) {
287+ Devices[i] = std::make_unique<ur_device_handle_t_>(FilteredDevices[i],
288+ this , nullptr );
225289 }
226290 } catch (std::bad_alloc &) {
227291 return UR_RESULT_ERROR_OUT_OF_RESOURCES;
0 commit comments