From 4b4ab1430b1f512aa52b65af8d978332423af419 Mon Sep 17 00:00:00 2001 From: Udit Agarwal <16324601+uditagarwal97@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:17:50 -0800 Subject: [PATCH] [SYCL] Make ONEAPI_DEVICE_SELECTOR reject an empty string (#12851) ```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. --- sycl/source/detail/config.hpp | 7 +++++++ sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp | 1 + sycl/test/basic_tests/device-selectors-exception.cpp | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index 1fdf229860022..633a8227873ad 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -270,6 +270,13 @@ template <> class SYCLConfig { } 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); } diff --git a/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp b/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp index 59129cf820abe..e21915ad9b23f 100644 --- a/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp +++ b/sycl/test-e2e/OneapiDeviceSelector/illegal_input.cpp @@ -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 diff --git a/sycl/test/basic_tests/device-selectors-exception.cpp b/sycl/test/basic_tests/device-selectors-exception.cpp index 5bddf0ed43454..2256b7f4745b8 100644 --- a/sycl/test/basic_tests/device-selectors-exception.cpp +++ b/sycl/test/basic_tests/device-selectors-exception.cpp @@ -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 using namespace sycl;