Skip to content

Commit 855d214

Browse files
authored
[SYCL] Do not select device with a negative score (#1751)
According to the SYCL specification, if a device has a negative score for a given selector it should not be selected.
1 parent 1b8b26a commit 855d214

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

sycl/source/device_selector.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ device device_selector::select_device() const {
4242
string_class DeviceName = dev.get_info<info::device::name>();
4343
std::cout << "SYCL_PI_TRACE[all]: "
4444
<< "select_device(): -> score = " << score
45-
<< ((score == REJECT_DEVICE_SCORE) ? "(REJECTED)" : " ")
46-
<< std::endl
45+
<< ((score < 0) ? "(REJECTED)" : " ") << std::endl
4746
<< "SYCL_PI_TRACE[all]: "
4847
<< " platform: " << PlatformVersion << std::endl
4948
<< "SYCL_PI_TRACE[all]: "
5049
<< " device: " << DeviceName << std::endl;
5150
}
5251

53-
// Device is discarded if is marked with REJECT_DEVICE_SCORE
54-
if (dev_score == REJECT_DEVICE_SCORE)
52+
// A negative score means that a device must not be selected.
53+
if (dev_score < 0)
5554
continue;
5655

5756
// SYCL spec says: "If more than one device receives the high score then
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: env SYCL_BE=%sycl_be %t.out
3+
//
4+
// Checks that no device is selected when no device of desired type is
5+
// available.
6+
7+
#include <CL/sycl.hpp>
8+
9+
#include <iostream>
10+
11+
class RejectEverything : public sycl::device_selector {
12+
public:
13+
int operator()(const sycl::device &Device) const final {
14+
// Negative value means that a device must not be selected
15+
return -1;
16+
}
17+
};
18+
19+
int main() {
20+
RejectEverything Selector;
21+
try {
22+
sycl::device Device(Selector);
23+
} catch (sycl::runtime_error &E) {
24+
return 0;
25+
}
26+
std::cerr << "Error. A device is found." << std::endl;
27+
return 1;
28+
}

0 commit comments

Comments
 (0)