Skip to content

Commit 77b6f34

Browse files
raaiq1bader
andauthored
[SYCL] Deprecate SYCL_DEVICE_FILTER environment variable (#7207)
- This patch prints an error warning when the environment variable SYCL_DEVICE_FILTER is set. - In-tree tests now use ONEAPI_DEVICE_SELECTOR instead of SYCL_DEVICE_FILTER. - The function SYCLConfig<SYCL_DEVICE_FILTER> which retrieves the value of the deprecated environment variable is also deprecated. - A switch is added to pi::findPlugins() to use ONEAPI_DEVICE_SELECTOR if possible Signed-off-by: Rauf, Rana <[email protected]> Co-authored-by: Alexey Bader <[email protected]>
1 parent b4ce7c0 commit 77b6f34

File tree

11 files changed

+136
-5
lines changed

11 files changed

+136
-5
lines changed

sycl/doc/EnvironmentVariables.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ compiler and runtime.
1010
| `ONEAPI_DEVICE_SELECTOR` | [See below.](#oneapi_device_selector) | This device selection environment variable can be used to limit the choice of devices available when the SYCL-using application is run. Useful for limiting devices to a certain type (like GPUs or accelerators) or backends (like Level Zero or OpenCL). This device selection mechanism is replacing `SYCL_DEVICE_FILTER` . The `ONEAPI_DEVICE_SELECTOR` syntax is shared with OpenMP and also allows sub-devices to be chosen. [See below.](#oneapi_device_selector) for a full description. |
1111
| `SYCL_BE` (deprecated) | `PI_OPENCL`, `PI_LEVEL_ZERO`, `PI_CUDA` | Force SYCL RT to consider only devices of the specified backend during the device selection. The `SYCL_BE` environment variable is deprecated and will be removed soon. Please use the new env var `ONEAPI_DEVICE_SELECTOR` instead. |
1212
| `SYCL_DEVICE_TYPE` (deprecated) | CPU, GPU, ACC, HOST | Force SYCL to use the specified device type. If unset, default selection rules are applied. If set to any unlisted value, this control has no effect. If the requested device type is not found, a `sycl::runtime_error` exception is thrown. If a non-default device selector is used, a device must satisfy both the selector and this control to be chosen. This control only has effect on devices created with a selector. The `SYCL_DEVICE_TYPE` environment variable is deprecated and will be removed soon. Please use the new env var `ONEAPI_DEVICE_SELECTOR` instead. |
13-
| `SYCL_DEVICE_FILTER` | `backend:device_type:device_num` | See Section [`SYCL_DEVICE_FILTER`](#sycl_device_filter) below. |
13+
| `SYCL_DEVICE_FILTER` (deprecated) | `backend:device_type:device_num` | Please use `ONEAPI_DEVICE_SELECTOR` environment variable instead. See section [`SYCL_DEVICE_FILTER`](#sycl_device_filter) below for `SYCL_DEVICE_FILTER` description. |
1414
| `SYCL_DEVICE_ALLOWLIST` | See [below](#sycl_device_allowlist) | Filter out devices that do not match the pattern specified. `BackendName` accepts `host`, `opencl`, `level_zero` or `cuda`. `DeviceType` accepts `host`, `cpu`, `gpu` or `acc`. `DeviceVendorId` accepts uint32_t in hex form (`0xXYZW`). `DriverVersion`, `PlatformVersion`, `DeviceName` and `PlatformName` accept regular expression. Special characters, such as parenthesis, must be escaped. DPC++ runtime will select only those devices which satisfy provided values above and regex. More than one device can be specified using the piping symbol "\|".|
1515
| `SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING` | Any(\*) | Disables automatic rounding-up of `parallel_for` invocation ranges. |
1616
| `SYCL_CACHE_DIR` | Path | Path to persistent cache root directory. Default values are `%AppData%\libsycl_cache` for Windows and `$XDG_CACHE_HOME/libsycl_cache` on Linux, if `XDG_CACHE_HOME` is not set then `$HOME/.cache/libsycl_cache`. When none of the environment variables are set SYCL persistent cache is disabled. |

sycl/source/detail/config.hpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ template <> class SYCLConfig<ONEAPI_DEVICE_SELECTOR> {
307307
// ---------------------------------------
308308
// SYCL_DEVICE_FILTER support
309309

310-
template <> class SYCLConfig<SYCL_DEVICE_FILTER> {
310+
template <>
311+
class __SYCL2020_DEPRECATED("Use SYCLConfig<ONEAPI_DEVICE_SELECTOR> instead")
312+
SYCLConfig<SYCL_DEVICE_FILTER> {
311313
using BaseT = SYCLConfigBase<SYCL_DEVICE_FILTER>;
312314

313315
public:
@@ -323,6 +325,14 @@ template <> class SYCLConfig<SYCL_DEVICE_FILTER> {
323325

324326
const char *ValStr = BaseT::getRawValue();
325327
if (ValStr) {
328+
329+
std::cerr
330+
<< "\nWARNING: The enviroment variable SYCL_DEVICE_FITLER"
331+
" is deprecated. Please use ONEAPI_DEVICE_SELECTOR instead.\n"
332+
"For more details, please refer to:\n"
333+
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
334+
"EnvironmentVariables.md#oneapi_device_selector\n\n";
335+
326336
FilterList = &GlobalHandler::instance().getDeviceFilterList(ValStr);
327337
}
328338

sycl/source/detail/pi.cpp

+31-2
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,23 @@ std::vector<std::pair<std::string, backend>> findPlugins() {
276276
// search is done for libpi_opencl.so/pi_opencl.dll file in LD_LIBRARY_PATH
277277
// env only.
278278
//
279+
279280
device_filter_list *FilterList = SYCLConfig<SYCL_DEVICE_FILTER>::get();
280-
if (!FilterList) {
281+
ods_target_list *OdsTargetList = SYCLConfig<ONEAPI_DEVICE_SELECTOR>::get();
282+
283+
// Will we be filtering with SYCL_DEVICE_FILTER or ONEAPI_DEVICE_SELECTOR ?
284+
// We do NOT attempt to support both simultaneously.
285+
if (OdsTargetList && FilterList) {
286+
throw sycl::exception(sycl::make_error_code(errc::invalid),
287+
"ONEAPI_DEVICE_SELECTOR cannot be used in "
288+
"conjunction with SYCL_DEVICE_FILTER");
289+
} else if (!FilterList && !OdsTargetList) {
281290
PluginNames.emplace_back(__SYCL_OPENCL_PLUGIN_NAME, backend::opencl);
282291
PluginNames.emplace_back(__SYCL_LEVEL_ZERO_PLUGIN_NAME,
283292
backend::ext_oneapi_level_zero);
284293
PluginNames.emplace_back(__SYCL_CUDA_PLUGIN_NAME, backend::ext_oneapi_cuda);
285294
PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip);
286-
} else {
295+
} else if (FilterList) {
287296
std::vector<device_filter> Filters = FilterList->get();
288297
bool OpenCLFound = false;
289298
bool LevelZeroFound = false;
@@ -321,6 +330,26 @@ std::vector<std::pair<std::string, backend>> findPlugins() {
321330
HIPFound = true;
322331
}
323332
}
333+
} else {
334+
ods_target_list &list = *OdsTargetList;
335+
if (list.backendCompatible(backend::opencl)) {
336+
PluginNames.emplace_back(__SYCL_OPENCL_PLUGIN_NAME, backend::opencl);
337+
}
338+
if (list.backendCompatible(backend::ext_oneapi_level_zero)) {
339+
PluginNames.emplace_back(__SYCL_LEVEL_ZERO_PLUGIN_NAME,
340+
backend::ext_oneapi_level_zero);
341+
}
342+
if (list.backendCompatible(backend::ext_oneapi_cuda)) {
343+
PluginNames.emplace_back(__SYCL_CUDA_PLUGIN_NAME,
344+
backend::ext_oneapi_cuda);
345+
}
346+
if (list.backendCompatible(backend::ext_intel_esimd_emulator)) {
347+
PluginNames.emplace_back(__SYCL_ESIMD_EMULATOR_PLUGIN_NAME,
348+
backend::ext_intel_esimd_emulator);
349+
}
350+
if (list.backendCompatible(backend::ext_oneapi_hip)) {
351+
PluginNames.emplace_back(__SYCL_HIP_PLUGIN_NAME, backend::ext_oneapi_hip);
352+
}
324353
}
325354
return PluginNames;
326355
}

sycl/test/Unit/lit.cfg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def find_shlibpath_var():
7676
# The mock plugin currently appears as an opencl plugin, but could be changed in
7777
# the future. To avoid it being filtered out we set the filter to use the *
7878
# wildcard.
79-
config.environment['SYCL_DEVICE_FILTER'] = "*"
79+
config.environment['ONEAPI_DEVICE_SELECTOR'] = "'*:*'"
8080
lit_config.note("Using Mock Plugin.")
8181

8282
config.environment['SYCL_CACHE_DIR'] = config.llvm_obj_root + "/sycl_cache"

sycl/unittests/Extensions/FPGADeviceSelectors.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ static pi_result redefinedDeviceGetInfo(pi_device device,
6666
*param_value_size_ret = sizeof(MockDeviceName);
6767
return PI_SUCCESS;
6868
}
69+
// Mock FPGA has no sub-devices
70+
case PI_DEVICE_INFO_PARTITION_PROPERTIES: {
71+
if (param_value_size_ret) {
72+
*param_value_size_ret = 0;
73+
}
74+
return PI_SUCCESS;
75+
}
76+
case PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN: {
77+
assert(param_value_size == sizeof(pi_device_affinity_domain));
78+
if (param_value) {
79+
*static_cast<pi_device_affinity_domain *>(param_value) = 0;
80+
}
81+
return PI_SUCCESS;
82+
}
6983
default:
7084
return PI_SUCCESS;
7185
}

sycl/unittests/buffer/BufferLocation.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ static pi_result redefinedDeviceGetInfo(pi_device device,
6666
strcpy(dst, name.data());
6767
}
6868
}
69+
// This mock device has no sub-devices
70+
if (param_name == PI_DEVICE_INFO_PARTITION_PROPERTIES) {
71+
if (param_value_size_ret) {
72+
*param_value_size_ret = 0;
73+
}
74+
}
75+
if (param_name == PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN) {
76+
assert(param_value_size == sizeof(pi_device_affinity_domain));
77+
if (param_value) {
78+
*static_cast<pi_device_affinity_domain *>(param_value) = 0;
79+
}
80+
}
6981
return PI_SUCCESS;
7082
}
7183

sycl/unittests/helpers/PiMockPlugin.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ inline pi_result mock_piDeviceGetInfo(pi_device device,
154154
*param_value_size_ret = sizeof(PI_TRUE);
155155
return PI_SUCCESS;
156156
}
157+
// This mock GPU device has no sub-devices
158+
case PI_DEVICE_INFO_PARTITION_PROPERTIES: {
159+
if (param_value_size_ret) {
160+
*param_value_size_ret = 0;
161+
}
162+
return PI_SUCCESS;
163+
}
164+
case PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN: {
165+
assert(param_value_size == sizeof(pi_device_affinity_domain));
166+
if (param_value) {
167+
*static_cast<pi_device_affinity_domain *>(param_value) = 0;
168+
}
169+
return PI_SUCCESS;
170+
}
157171
default:
158172
return PI_SUCCESS;
159173
}

sycl/unittests/kernel-and-program/DeviceInfo.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ static pi_result redefinedDeviceGetInfo(pi_device device,
4545
TestContext->FreeMemoryInfoCalled = true;
4646
}
4747

48+
// This mock device has no sub-devices
49+
if (param_name == PI_DEVICE_INFO_PARTITION_PROPERTIES) {
50+
if (param_value_size_ret) {
51+
*param_value_size_ret = 0;
52+
}
53+
}
54+
if (param_name == PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN) {
55+
assert(param_value_size == sizeof(pi_device_affinity_domain));
56+
if (param_value) {
57+
*static_cast<pi_device_affinity_domain *>(param_value) = 0;
58+
}
59+
}
60+
4861
return PI_SUCCESS;
4962
}
5063

sycl/unittests/kernel-and-program/MultipleDevsCache.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ static pi_result redefinedDeviceGetInfo(pi_device device,
6464
auto *Result = reinterpret_cast<pi_bool *>(param_value);
6565
*Result = true;
6666
}
67+
68+
// This mock device has no sub-devices
69+
if (param_name == PI_DEVICE_INFO_PARTITION_PROPERTIES) {
70+
if (param_value_size_ret) {
71+
*param_value_size_ret = 0;
72+
}
73+
}
74+
if (param_name == PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN) {
75+
assert(param_value_size == sizeof(pi_device_affinity_domain));
76+
if (param_value) {
77+
*static_cast<pi_device_affinity_domain *>(param_value) = 0;
78+
}
79+
}
6780
return PI_SUCCESS;
6881
}
6982

sycl/unittests/scheduler/AllocaLinking.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ static pi_result redefinedDeviceGetInfo(pi_device Device,
2828
auto *Result = reinterpret_cast<_pi_device_type *>(ParamValue);
2929
*Result = PI_DEVICE_TYPE_CPU;
3030
}
31+
32+
// This mock device has no sub-devices
33+
if (ParamName == PI_DEVICE_INFO_PARTITION_PROPERTIES) {
34+
if (ParamValueSizeRet) {
35+
*ParamValueSizeRet = 0;
36+
}
37+
}
38+
if (ParamName == PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN) {
39+
assert(ParamValueSize == sizeof(pi_device_affinity_domain));
40+
if (ParamValue) {
41+
*static_cast<pi_device_affinity_domain *>(ParamValue) = 0;
42+
}
43+
}
3144
return PI_SUCCESS;
3245
}
3346

sycl/unittests/scheduler/NoHostUnifiedMemory.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ static pi_result redefinedDeviceGetInfo(pi_device Device,
2929
auto *Result = reinterpret_cast<_pi_device_type *>(ParamValue);
3030
*Result = PI_DEVICE_TYPE_CPU;
3131
}
32+
33+
// This mock device has no sub-devices
34+
if (ParamName == PI_DEVICE_INFO_PARTITION_PROPERTIES) {
35+
if (ParamValueSizeRet) {
36+
*ParamValueSizeRet = 0;
37+
}
38+
}
39+
if (ParamName == PI_DEVICE_INFO_PARTITION_AFFINITY_DOMAIN) {
40+
assert(ParamValueSize == sizeof(pi_device_affinity_domain));
41+
if (ParamValue) {
42+
*static_cast<pi_device_affinity_domain *>(ParamValue) = 0;
43+
}
44+
}
3245
return PI_SUCCESS;
3346
}
3447

0 commit comments

Comments
 (0)