Skip to content

Commit f3edec3

Browse files
Error handling specific for system with no devices
Setting environment variable `ONEAPI_DEVICE_SELECTOR=cpu` effectively disables all devices. This PR wraps some calls to DPC++ RT routines in try/catch to properly handle exceptions that would arise from a call should the said environment variable be set.
1 parent e01e270 commit f3edec3

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

libsyclinterface/source/dpctl_sycl_device_manager.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ DPCTLDeviceMgr_GetDevices(int device_identifier)
208208
if (!device_identifier)
209209
return wrap<vecTy>(Devices);
210210

211-
const auto &root_devices = device::get_devices();
211+
std::vector<device> root_devices;
212+
try {
213+
root_devices = device::get_devices();
214+
} catch (std::exception const &e) {
215+
delete Devices;
216+
error_handler(e, __FILE__, __func__, __LINE__);
217+
return nullptr;
218+
}
212219
dpctl_default_selector mRanker;
213220

214221
for (const auto &root_device : root_devices) {

libsyclinterface/source/dpctl_sycl_platform_interface.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,13 @@ __dpctl_give DPCTLPlatformVectorRef DPCTLPlatform_GetPlatforms()
194194
using vecTy = std::vector<DPCTLSyclPlatformRef>;
195195
vecTy *Platforms = nullptr;
196196

197-
auto platforms = platform::get_platforms();
197+
std::vector<platform> platforms;
198+
try {
199+
platforms = platform::get_platforms();
200+
} catch (std::exception const &e) {
201+
error_handler(e, __FILE__, __func__, __LINE__);
202+
return nullptr;
203+
}
198204

199205
try {
200206
Platforms = new vecTy();

0 commit comments

Comments
 (0)