Skip to content

Commit

Permalink
[SYCL] Make ONEAPI_DEVICE_SELECTOR reject an empty string (#12851)
Browse files Browse the repository at this point in the history
```ONEAPI_DEVICE_SELECTOR=""``` causes SYCL runtime to silently not select/initialize any device at all. This PR makes SYCL runtime to throw an error when input to ONEAPI_DEVICE_SELECTOR is null.
  • Loading branch information
uditagarwal97 authored Mar 4, 2024
1 parent 56e9067 commit 4b4ab14
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ template <> class SYCLConfig<ONEAPI_DEVICE_SELECTOR> {
}
const char *ValStr = BaseT::getRawValue();
if (ValStr) {
// Throw if the input string is empty.
if (ValStr[0] == '\0')
throw invalid_parameter_error(
"Invalid value for ONEAPI_DEVICE_SELECTOR environment "
"variable: value should not be null.",
PI_ERROR_INVALID_VALUE);

DeviceTargets =
&GlobalHandler::instance().getOneapiDeviceSelectorTargets(ValStr);
}
Expand Down
1 change: 1 addition & 0 deletions sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:" %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:::gpu" %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="level_zero:.1" %{run-unfiltered-devices} %t.out
// RUN: env ONEAPI_DEVICE_SELECTOR="" %{run-unfiltered-devices} %t.out
// XFAIL: *

// Calling ONEAPI_DEVICE_SELECTOR with an illegal input should result in an
Expand Down
4 changes: 3 additions & 1 deletion sycl/test/basic_tests/device-selectors-exception.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env SYCL_DEVICE_FILTER="" %t.out
// RUN: %if preview-breaking-changes-supported %{ %clangxx -fsycl -fsycl-targets=%sycl_triple -fpreview-breaking-changes %s -o %t.out %}
// RUN: %if preview-breaking-changes-supported %{ env ONEAPI_DEVICE_SELECTOR="" %t.out %}
// ONEAPI_DEVICE_SELECTOR="*:-1" causes this test to not select any device at
// all.
// RUN: %if preview-breaking-changes-supported %{ env ONEAPI_DEVICE_SELECTOR="*:-1" %t.out %}

#include <sycl/sycl.hpp>
using namespace sycl;
Expand Down

0 comments on commit 4b4ab14

Please sign in to comment.