Skip to content

Commit ebe6141

Browse files
[SYCL] Remove outdated & invalid device score boost (#5349)
Every device that satisfies filter options receives 1000 as starting score. A device that doesn't satisfy filter settings is filtered out on get_devices step. So no need to do an extra boost for devices whose DeviceNum is equal to the one specified in the filter.
1 parent ac7c9ac commit ebe6141

File tree

1 file changed

+12
-68
lines changed

1 file changed

+12
-68
lines changed

sycl/source/device_selector.cpp

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,6 @@ static bool isDeviceOfPreferredSyclBe(const device &Device) {
3737
backend::ext_oneapi_level_zero;
3838
}
3939

40-
// Return true if the given device 'Dev' matches with any filter
41-
static bool isForcedDevice(const device &Dev, int Index = -1) {
42-
detail::device_filter_list *FilterList =
43-
detail::SYCLConfig<detail::SYCL_DEVICE_FILTER>::get();
44-
45-
if (!FilterList)
46-
return false;
47-
info::device_type Type = Dev.get_info<info::device::device_type>();
48-
backend Backend;
49-
if (Type == info::device_type::host)
50-
Backend = backend::host;
51-
else
52-
Backend = detail::getSyclObjImpl(Dev)->getPlugin().getBackend();
53-
54-
for (const detail::device_filter &Filter : FilterList->get()) {
55-
if ((Filter.Backend == Backend || Filter.Backend == backend::all) &&
56-
(Filter.DeviceType == Type ||
57-
Filter.DeviceType == info::device_type::all)) {
58-
if (Index < 0 || (Filter.HasDeviceNum && Filter.DeviceNum == Index))
59-
return true;
60-
}
61-
}
62-
return false;
63-
}
64-
6540
device device_selector::select_device() const {
6641
std::vector<device> devices = device::get_devices();
6742
int score = REJECT_DEVICE_SCORE;
@@ -87,13 +62,6 @@ device device_selector::select_device() const {
8762
if (dev_score < 0)
8863
continue;
8964

90-
// If SYCL_DEVICE_FILTER is set, give a bonus point for the device
91-
// whose index matches with desired device number.
92-
int index = &dev - &devices[0];
93-
if (isForcedDevice(dev, index)) {
94-
dev_score += 1000;
95-
}
96-
9765
// SYCL spec says: "If more than one device receives the high score then
9866
// one of those tied devices will be returned, but which of the devices
9967
// from the tied set is to be returned is not defined". Here we give a
@@ -141,12 +109,10 @@ int default_selector::operator()(const device &dev) const {
141109
// All unmatched devices should never be selected.
142110
detail::device_filter_list *FilterList =
143111
detail::SYCLConfig<detail::SYCL_DEVICE_FILTER>::get();
144-
if (FilterList) {
145-
if (isForcedDevice(dev))
146-
Score = 1000;
147-
else
148-
return REJECT_DEVICE_SCORE;
149-
}
112+
// device::get_devices returns filtered list of devices.
113+
// Keep 1000 for default score when filters were applied.
114+
if (FilterList)
115+
Score = 1000;
150116

151117
if (dev.get_info<info::device::device_type>() == detail::get_forced_type())
152118
Score += 1000;
@@ -173,16 +139,8 @@ int gpu_selector::operator()(const device &dev) const {
173139
int Score = REJECT_DEVICE_SCORE;
174140

175141
if (dev.is_gpu()) {
176-
detail::device_filter_list *FilterList =
177-
detail::SYCLConfig<detail::SYCL_DEVICE_FILTER>::get();
178-
if (FilterList) {
179-
if (isForcedDevice(dev))
180-
Score = 1000;
181-
else
182-
return Score;
183-
} else {
184-
Score = 1000;
185-
}
142+
// device::get_devices returns filtered list of devices.
143+
Score = 1000;
186144
// Give preference to device of SYCL BE.
187145
if (isDeviceOfPreferredSyclBe(dev))
188146
Score += 50;
@@ -194,16 +152,9 @@ int cpu_selector::operator()(const device &dev) const {
194152
int Score = REJECT_DEVICE_SCORE;
195153

196154
if (dev.is_cpu()) {
197-
detail::device_filter_list *FilterList =
198-
detail::SYCLConfig<detail::SYCL_DEVICE_FILTER>::get();
199-
if (FilterList) {
200-
if (isForcedDevice(dev))
201-
Score = 1000;
202-
else
203-
return Score;
204-
} else {
205-
Score = 1000;
206-
}
155+
// device::get_devices returns filtered list of devices.
156+
Score = 1000;
157+
207158
// Give preference to device of SYCL BE.
208159
if (isDeviceOfPreferredSyclBe(dev))
209160
Score += 50;
@@ -215,16 +166,9 @@ int accelerator_selector::operator()(const device &dev) const {
215166
int Score = REJECT_DEVICE_SCORE;
216167

217168
if (dev.is_accelerator()) {
218-
detail::device_filter_list *FilterList =
219-
detail::SYCLConfig<detail::SYCL_DEVICE_FILTER>::get();
220-
if (FilterList) {
221-
if (isForcedDevice(dev))
222-
Score = 1000;
223-
else
224-
return Score;
225-
} else {
226-
Score = 1000;
227-
}
169+
// device::get_devices returns filtered list of devices.
170+
Score = 1000;
171+
228172
// Give preference to device of SYCL BE.
229173
if (isDeviceOfPreferredSyclBe(dev))
230174
Score += 50;

0 commit comments

Comments
 (0)