Skip to content

Commit d81081f

Browse files
[SYCL] Fix wrong except. raising for ALLOWLIST (#2739)
This patch fixes the following situation: 1. User set * SYCL_DEVICE_ALLOWLIST=DeviceName:{{DEV_NAME}},DriverVersion:{{X.Y.Z}} * SYCL_DEVICE_TYPE=GPU * SYCL_BE=PI_OPENCL // no effect 2. Machine has * OpenCL GPU device with name DEV_NAME and driver version X.Y.Z * Level Zero device with name DEV_NAME and driver version A.B.C User expects that OpenCL GPU device will be selected but instead got cl::sycl::runtime_error Requested SYCL device not found -1 (CL_DEVICE_NOT_FOUND). Since GPU driver 20.43.18277, OpenCL GPU and Level Zero device names are the same. So, DPC++ RT checks OpenCL GPU device first - everything is ok, then checks Level Zero device, and throws the exception above. This patch changes behavior - instead of raising exception in case of device name == device name in SYCL_DEVICE_ALLOWLIST and driver version != driver version in SYCL_DEVICE_ALLOWLIST - now DPC++ raise an exception in case none devices were selected based on a value from SYCL_DEVICE_ALLOWLIST. Regression test: LIT test config/select_device.cpp with GPU driver 20.43.18277.
1 parent 4fabfd1 commit d81081f

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

sycl/source/detail/platform_impl.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,18 @@ static std::vector<DevDescT> getAllowListDesc() {
211211
return DecDescs;
212212
}
213213

214-
enum MatchState { UNKNOWN, MATCH, NOMATCH };
214+
enum class FilterState { DENIED, ALLOWED };
215215

216216
static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
217217
RT::PiPlatform PiPlatform, const plugin &Plugin) {
218218
const std::vector<DevDescT> AllowList(getAllowListDesc());
219219
if (AllowList.empty())
220220
return;
221221

222-
MatchState DevNameState = UNKNOWN;
223-
MatchState DevVerState = UNKNOWN;
224-
MatchState PlatNameState = UNKNOWN;
225-
MatchState PlatVerState = UNKNOWN;
222+
FilterState DevNameState = FilterState::ALLOWED;
223+
FilterState DevVerState = FilterState::ALLOWED;
224+
FilterState PlatNameState = FilterState::ALLOWED;
225+
FilterState PlatVerState = FilterState::ALLOWED;
226226

227227
const string_class PlatformName =
228228
sycl::detail::get_platform_info<string_class, info::platform::name>::get(
@@ -245,53 +245,40 @@ static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
245245
for (const DevDescT &Desc : AllowList) {
246246
if (!Desc.PlatName.empty()) {
247247
if (!std::regex_match(PlatformName, std::regex(Desc.PlatName))) {
248-
PlatNameState = MatchState::NOMATCH;
248+
PlatNameState = FilterState::DENIED;
249249
continue;
250-
} else {
251-
PlatNameState = MatchState::MATCH;
252250
}
253251
}
254252

255253
if (!Desc.PlatVer.empty()) {
256254
if (!std::regex_match(PlatformVer, std::regex(Desc.PlatVer))) {
257-
PlatVerState = MatchState::NOMATCH;
255+
PlatVerState = FilterState::DENIED;
258256
continue;
259-
} else {
260-
PlatVerState = MatchState::MATCH;
261257
}
262258
}
263259

264260
if (!Desc.DevName.empty()) {
265261
if (!std::regex_match(DeviceName, std::regex(Desc.DevName))) {
266-
DevNameState = MatchState::NOMATCH;
262+
DevNameState = FilterState::DENIED;
267263
continue;
268-
} else {
269-
DevNameState = MatchState::MATCH;
270264
}
271265
}
272266

273267
if (!Desc.DevDriverVer.empty()) {
274268
if (!std::regex_match(DeviceDriverVer, std::regex(Desc.DevDriverVer))) {
275-
DevVerState = MatchState::NOMATCH;
269+
DevVerState = FilterState::DENIED;
276270
continue;
277-
} else {
278-
DevVerState = MatchState::MATCH;
279271
}
280272
}
281273

282-
PiDevices[InsertIDx++] = Device;
274+
if (DevNameState == FilterState::ALLOWED &&
275+
DevVerState == FilterState::ALLOWED &&
276+
PlatNameState == FilterState::ALLOWED &&
277+
PlatVerState == FilterState::ALLOWED)
278+
PiDevices[InsertIDx++] = Device;
283279
break;
284280
}
285281
}
286-
if (DevNameState == MatchState::MATCH && DevVerState == MatchState::NOMATCH) {
287-
throw sycl::runtime_error("Requested SYCL device not found",
288-
PI_DEVICE_NOT_FOUND);
289-
}
290-
if (PlatNameState == MatchState::MATCH &&
291-
PlatVerState == MatchState::NOMATCH) {
292-
throw sycl::runtime_error("Requested SYCL platform not found",
293-
PI_DEVICE_NOT_FOUND);
294-
}
295282
PiDevices.resize(InsertIDx);
296283
}
297284

sycl/test/on-device/config/select_device.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ int main() {
337337
device dev = deviceQueue.get_device();
338338
const auto &plt = dev.get_platform();
339339
} catch (sycl::runtime_error &E) {
340-
const std::string expectedMsg("Requested SYCL device not found");
340+
const std::string expectedMsg(
341+
"No device of requested type available");
341342
const std::string gotMessage(E.what());
342343
if (gotMessage.find(expectedMsg) != std::string::npos) {
343344
passed = true;
@@ -394,7 +395,8 @@ int main() {
394395
device dev = deviceQueue.get_device();
395396
const auto &plt = dev.get_platform();
396397
} catch (sycl::runtime_error &E) {
397-
const std::string expectedMsg("Requested SYCL platform not found");
398+
const std::string expectedMsg(
399+
"No device of requested type available");
398400
const std::string gotMessage(E.what());
399401
if (gotMessage.find(expectedMsg) != std::string::npos) {
400402
passed = true;

0 commit comments

Comments
 (0)