Skip to content

Commit 00ecbf0

Browse files
author
Alexander Johnston
committed
[SYCL] Improve default device selection checks
Better checks for CUDA and OpenCL devices to match with SYCL_BE in the default device selection, based on the platform version info. Signed-off-by: Alexander Johnston <[email protected]>
1 parent 243bf5d commit 00ecbf0

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

sycl/source/device_selector.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ int default_selector::operator()(const device &dev) const {
3636
const char *SYCL_BE = std::getenv("SYCL_BE");
3737
std::string backend = (SYCL_BE ? SYCL_BE : "");
3838
if (backend != "") {
39-
const std::string DriverVersion = dev.get_info<info::device::driver_version>();
40-
// If we have a cuda device but aren't using PI_CUDA, don't use this device
41-
if (DriverVersion.find("CUDA") == std::string::npos && backend == "PI_CUDA") {
39+
// Taking the version information from the platform gives us more useful
40+
// information than the driver_version of the device.
41+
const platform Platform = dev.get_info<info::device::platform>();
42+
const std::string PlatformVersion = Platform.get_info<info::platform::version>();
43+
// If using PI_CUDA, don't accept a non-CUDA device
44+
if (PlatformVersion.find("CUDA") == std::string::npos && backend == "PI_CUDA") {
4245
return -1;
4346
}
44-
// We can't easily check for an OpenCL device as there is no common string
45-
// to search for on all devices, so just guarantee we don't choose a cuda
46-
// device when PI_OPENCL is used
47-
if (DriverVersion.find("CUDA") != std::string::npos && backend == "PI_OPENCL") {
47+
// If using PI_OPENCL, don't accept a non-OpenCL device
48+
if (PlatformVersion.find("OpenCL") == std::string::npos && backend == "PI_OPENCL") {
4849
return -1;
4950
}
5051
}

0 commit comments

Comments
 (0)