Skip to content

Commit 235cfdd

Browse files
author
Alexander Johnston
committed
[SYCL] Have default_selector consider SYCL_BE
Have the default_selector consider the env var SYCL_BE when rating device scores to make choosing a backend easier. Signed-off-by: Alexander Johnston <[email protected]>
1 parent 88c1355 commit 235cfdd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

sycl/source/device_selector.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ device device_selector::select_device() const {
3131
}
3232

3333
int default_selector::operator()(const device &dev) const {
34+
35+
// Take note of the SYCL_BE environment variable when doing default selection
36+
const char *SYCL_BE = std::getenv("SYCL_BE");
37+
std::string backend = (SYCL_BE ? SYCL_BE : "");
38+
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") {
42+
return -1;
43+
}
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") {
48+
return -1;
49+
}
50+
}
51+
3452
if (dev.is_gpu())
3553
return 500;
3654

0 commit comments

Comments
 (0)