Skip to content

Commit 3a58432

Browse files
committed
[SYCL] Improve SYCL_DEVICE_ALLOWLIST
This patch adds more stability to SYCL_DEVICE_ALLOWLIST: 1. Introduce 3 new keys `BackendName`, `DeviceType` and `DeviceVendorId` which should be used instead of `DeviceName` and `PlatformName`. These 3 new keys are more stable. 2. Refactor the implementation of SYCL_DEVICE_ALLOWLIST to make it more stable, to fix std::bad_alloc crash, and to make the code testable 3. Add unit tests for parsing SYCL_DEVICE_ALLOWLIST value and for functionality which allows device to use or reject it.
1 parent 4dc23a2 commit 3a58432

File tree

9 files changed

+764
-145
lines changed

9 files changed

+764
-145
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ subject to change. Do not rely on these variables in production code.
2323
| SYCL_DISABLE_EXECUTION_GRAPH_CLEANUP | Any(\*) | Disable cleanup of finished command nodes at host-device synchronization points. |
2424
| SYCL_THROW_ON_BLOCK | Any(\*) | Throw an exception on attempt to wait for a blocked command. |
2525
| SYCL_DEVICELIB_INHIBIT_NATIVE | String of device library extensions (separated by a whitespace) | Do not rely on device native support for devicelib extensions listed in this option. |
26-
| SYCL_DEVICE_ALLOWLIST | A list of devices and their driver version following the pattern: DeviceName:{{XXX}},DriverVersion:{{X.Y.Z.W}}. Also may contain PlatformName and PlatformVersion | Filter out devices that do not match the pattern specified. Regular expression can be passed and the DPC++ runtime will select only those devices which satisfy the regex. Special characters, such as parenthesis, must be escaped. More than one device can be specified using the piping symbol "\|".|
26+
| SYCL_DEVICE_ALLOWLIST | A list of devices and their driver version following the pattern: BackendName:XXX,DeviceType:YYY,DeviceVendorId:ZZZ,DriverVersion:{{X.Y.Z.W}}. Also may contain PlatformVersion, DeviceName and PlatformName | 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 "\|".|
2727
| SYCL_QUEUE_THREAD_POOL_SIZE | Positive integer | Number of threads in thread pool of queue. |
2828
| SYCL_DEVICELIB_NO_FALLBACK | Any(\*) | Disable loading and linking of device library images |
2929
| SYCL_PI_LEVEL_ZERO_MAX_COMMAND_LIST_CACHE | Positive integer | Maximum number of oneAPI Level Zero Command lists that can be allocated with no reuse before throwing an "out of resources" error. Default is 20000, threshold may be increased based on resource availabilty and workload demand. |

sycl/source/detail/config.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//==---------------- config.hpp - SYCL context ------------------*- C++-*---==//
1+
//==---------------- config.hpp - SYCL config -------------------*- C++-*---==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -166,6 +166,22 @@ template <> class SYCLConfig<SYCL_PI_TRACE> {
166166
}
167167
};
168168

169+
// Array is used by SYCL_DEVICE_FILTER and SYCL_DEVICE_ALLOWLIST
170+
static const std::array<std::pair<std::string, info::device_type>, 5>
171+
SyclDeviceTypeMap = {{{"host", info::device_type::host},
172+
{"cpu", info::device_type::cpu},
173+
{"gpu", info::device_type::gpu},
174+
{"acc", info::device_type::accelerator},
175+
{"*", info::device_type::all}}};
176+
177+
// Array is used by SYCL_DEVICE_FILTER and SYCL_DEVICE_ALLOWLIST
178+
static const std::array<std::pair<std::string, backend>, 5> SyclBeMap = {
179+
{{"host", backend::host},
180+
{"opencl", backend::opencl},
181+
{"level_zero", backend::level_zero},
182+
{"cuda", backend::cuda},
183+
{"*", backend::all}}};
184+
169185
template <> class SYCLConfig<SYCL_DEVICE_FILTER> {
170186
using BaseT = SYCLConfigBase<SYCL_DEVICE_FILTER>;
171187

sycl/source/detail/device_filter.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ namespace sycl {
1818
namespace detail {
1919

2020
device_filter::device_filter(const std::string &FilterString) {
21-
const std::array<std::pair<std::string, info::device_type>, 5>
22-
SyclDeviceTypeMap = {{{"host", info::device_type::host},
23-
{"cpu", info::device_type::cpu},
24-
{"gpu", info::device_type::gpu},
25-
{"acc", info::device_type::accelerator},
26-
{"*", info::device_type::all}}};
27-
const std::array<std::pair<std::string, backend>, 5> SyclBeMap = {
28-
{{"host", backend::host},
29-
{"opencl", backend::opencl},
30-
{"level_zero", backend::level_zero},
31-
{"cuda", backend::cuda},
32-
{"*", backend::all}}};
33-
3421
size_t Cursor = 0;
3522
size_t ColonPos = 0;
3623
auto findElement = [&](auto Element) {

0 commit comments

Comments
 (0)