Skip to content

Commit 17480e0

Browse files
author
Ruyman Reyes
committed
[SYCL][CUDA] CUDA OpenCL platform ignored in get_devices
CUDA OpenCL platform is ignored on get_devices as suggested by feedback Signed-off-by: Ruyman Reyes <ruyman@codeplay.com>
1 parent a659354 commit 17480e0

File tree

2 files changed

+41
-50
lines changed

2 files changed

+41
-50
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,41 @@ static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
196196
PiDevices.resize(InsertIDx);
197197
}
198198

199+
200+
// @return True if the device is invalid for the current backend preferences
201+
static bool isDeviceInvalidForBe(const device &Device) {
202+
203+
if (Device.is_host())
204+
return false;
205+
206+
// Taking the version information from the platform gives us more useful
207+
// information than the driver_version of the device.
208+
const platform platform = Device.get_info<info::device::platform>();
209+
const std::string platformVersion =
210+
platform.get_info<info::platform::version>();
211+
212+
backend *BackendPref = detail::SYCLConfig<detail::SYCL_BE>::get();
213+
auto BackendType = detail::getSyclObjImpl(Device)->getPlugin().getBackend();
214+
static_assert(std::is_same<backend, decltype(BackendType)>(),
215+
"Type is not the same");
216+
217+
// If no preference, assume OpenCL and reject CUDA backend
218+
if (BackendType == backend::cuda && !BackendPref) {
219+
return true;
220+
} else if (!BackendPref)
221+
return false;
222+
223+
// If using PI_CUDA, don't accept a non-CUDA device
224+
if (BackendType == backend::opencl && *BackendPref == backend::cuda)
225+
return true;
226+
227+
// If using PI_OPENCL, don't accept a non-OpenCL device
228+
if (BackendType == backend::cuda && *BackendPref == backend::opencl)
229+
return true;
230+
231+
return false;
232+
}
233+
199234
vector_class<device>
200235
platform_impl::get_devices(info::device_type DeviceType) const {
201236
vector_class<device> Res;
@@ -236,6 +271,9 @@ platform_impl::get_devices(info::device_type DeviceType) const {
236271
PiDevice, std::make_shared<platform_impl>(*this)));
237272
});
238273

274+
Res.erase(std::remove_if(Res.begin(), Res.end(), isDeviceInvalidForBe),
275+
Res.end());
276+
239277
return Res;
240278
}
241279

sycl/source/device_selector.cpp

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,6 @@ static bool isDeviceOfPreferredSyclBe(const device &Device) {
2929
backend::opencl;
3030
}
3131

32-
// @return True if the device is invalid for the current backend preferences
33-
static bool isDeviceInvalidForBe(const device &Device) {
34-
35-
if (Device.is_host())
36-
return false;
37-
38-
// Taking the version information from the platform gives us more useful
39-
// information than the driver_version of the device.
40-
const platform platform = Device.get_info<info::device::platform>();
41-
const std::string platformVersion =
42-
platform.get_info<info::platform::version>();
43-
44-
backend *BackendPref = detail::SYCLConfig<detail::SYCL_BE>::get();
45-
auto BackendType = detail::getSyclObjImpl(Device)->getPlugin().getBackend();
46-
static_assert(std::is_same<backend, decltype(BackendType)>(),
47-
"Type is not the same");
48-
49-
// If no preference, assume OpenCL and reject CUDA backend
50-
if (BackendType == backend::cuda && !BackendPref) {
51-
return true;
52-
} else if (!BackendPref)
53-
return false;
54-
55-
// If using PI_CUDA, don't accept a non-CUDA device
56-
if (BackendType == backend::opencl && *BackendPref == backend::cuda)
57-
return true;
58-
59-
// If using PI_OPENCL, don't accept a non-OpenCL device
60-
if (BackendType == backend::cuda && *BackendPref == backend::opencl)
61-
return true;
62-
63-
return false;
64-
}
65-
6632
device device_selector::select_device() const {
6733
vector_class<device> devices = device::get_devices();
6834
int score = -1;
@@ -102,7 +68,8 @@ device device_selector::select_device() const {
10268
// preference to the device of the preferred BE.
10369
//
10470
if (score < dev_score ||
105-
(score == dev_score && isDeviceOfPreferredSyclBe(dev))) {
71+
(score == dev_score && isDeviceOfPreferredSyclBe(dev)
72+
&& dev_score != -1)) {
10673
res = &dev;
10774
score = dev_score;
10875
}
@@ -131,9 +98,6 @@ int default_selector::operator()(const device &dev) const {
13198

13299
int Score = -1;
133100

134-
if (isDeviceInvalidForBe(dev))
135-
return -1;
136-
137101
// Give preference to device of SYCL BE.
138102
if (isDeviceOfPreferredSyclBe(dev))
139103
Score = 50;
@@ -157,9 +121,6 @@ int default_selector::operator()(const device &dev) const {
157121
int gpu_selector::operator()(const device &dev) const {
158122
int Score = -1;
159123

160-
if (isDeviceInvalidForBe(dev))
161-
return -1;
162-
163124
if (dev.is_gpu()) {
164125
Score = 1000;
165126
// Give preference to device of SYCL BE.
@@ -172,9 +133,6 @@ int gpu_selector::operator()(const device &dev) const {
172133
int cpu_selector::operator()(const device &dev) const {
173134
int Score = -1;
174135

175-
if (isDeviceInvalidForBe(dev))
176-
return -1;
177-
178136
if (dev.is_cpu()) {
179137
Score = 1000;
180138

@@ -188,9 +146,6 @@ int cpu_selector::operator()(const device &dev) const {
188146
int accelerator_selector::operator()(const device &dev) const {
189147
int Score = -1;
190148

191-
if (isDeviceInvalidForBe(dev))
192-
return -1;
193-
194149
if (dev.is_accelerator()) {
195150
Score = 1000;
196151
// Give preference to device of SYCL BE.
@@ -205,10 +160,8 @@ int host_selector::operator()(const device &dev) const {
205160
if (dev.is_host()) {
206161
Score = 1000;
207162
// Give preference to device of SYCL BE.
208-
if (isDeviceOfPreferredSyclBe(dev)) {
163+
if (isDeviceOfPreferredSyclBe(dev))
209164
Score += 50;
210-
} else if (isDeviceInvalidForBe(dev))
211-
return -1;
212165
}
213166
return Score;
214167
}

0 commit comments

Comments
 (0)