19 inline namespace _V1 {
55 if (AllowListRaw.empty())
59 AllowListParsed.emplace_back();
61 constexpr std::array<const char *, 3> SupportedKeyNamesHaveFixedValue{
63 constexpr std::array<const char *, 4> SupportedKeyNamesRequireRegexValue{
67 size_t KeyStart = 0, KeyEnd = 0, ValueStart = 0, ValueEnd = 0,
70 const char DelimiterBtwKeyAndValue =
':';
71 const char DelimiterBtwItemsInDeviceDesc =
',';
72 const char DelimiterBtwDeviceDescs =
'|';
74 if (AllowListRaw.find(DelimiterBtwKeyAndValue, KeyStart) == std::string::npos)
76 "SYCL_DEVICE_ALLOWLIST has incorrect format. For "
77 "details, please refer to "
78 "https://github.com/intel/llvm/blob/sycl/sycl/"
79 "doc/EnvironmentVariables.md " +
85 bool IsDeprecatedKeyNameDeviceNameWasUsed =
false;
86 bool IsDeprecatedKeyNamePlatformNameWasUsed =
false;
88 while ((KeyEnd = AllowListRaw.find(DelimiterBtwKeyAndValue, KeyStart)) !=
90 if ((ValueStart = AllowListRaw.find_first_not_of(
91 DelimiterBtwKeyAndValue, KeyEnd)) == std::string::npos)
93 const std::string &Key = AllowListRaw.substr(KeyStart, KeyEnd - KeyStart);
101 "Unrecognized key in SYCL_DEVICE_ALLOWLIST. For details, please "
103 "https://github.com/intel/llvm/blob/sycl/sycl/doc/"
104 "EnvironmentVariables.md " +
108 if (Key == DeprecatedKeyNameDeviceName) {
109 IsDeprecatedKeyNameDeviceNameWasUsed =
true;
111 if (Key == DeprecatedKeyNamePlatformName) {
112 IsDeprecatedKeyNamePlatformNameWasUsed =
true;
115 bool ShouldAllocateNewDeviceDescMap =
false;
119 auto &DeviceDescMap = AllowListParsed[DeviceDescIndex];
123 if (DeviceDescMap.find(Key) == DeviceDescMap.end()) {
125 if (std::find(SupportedKeyNamesHaveFixedValue.begin(),
126 SupportedKeyNamesHaveFixedValue.end(),
127 Key) != SupportedKeyNamesHaveFixedValue.end()) {
128 ValueEnd = AllowListRaw.find(DelimiterBtwItemsInDeviceDesc, ValueStart);
131 if (
size_t ValueEndCand =
132 AllowListRaw.find(DelimiterBtwDeviceDescs, ValueStart);
133 (ValueEndCand != std::string::npos) && (ValueEndCand < ValueEnd)) {
134 ValueEnd = ValueEndCand;
135 ShouldAllocateNewDeviceDescMap =
true;
137 if (ValueEnd == std::string::npos)
138 ValueEnd = AllowListRaw.length();
140 Value = AllowListRaw.substr(ValueStart, ValueEnd - ValueStart);
144 auto ValidateEnumValues = [&](std::string CheckingKeyName,
145 auto SourceOfSupportedValues) {
146 if (Key == CheckingKeyName) {
147 bool ValueIsValid =
false;
148 for (
const auto &Item : SourceOfSupportedValues)
149 if (Value == Item.first) {
156 "Value " + Value +
" for key " + Key +
158 "SYCL_DEVICE_ALLOWLIST. For details, please refer to "
159 "https://github.com/intel/llvm/blob/sycl/sycl/doc/"
160 "EnvironmentVariables.md " +
170 getSyclDeviceTypeMap<true /*Enable 'acc'*/>());
174 if (!std::regex_match(Value, std::regex(
"0[xX][0-9a-fA-F]+"))) {
177 "Value " + Value +
" for key " + Key +
179 "SYCL_DEVICE_ALLOWLIST. It should have the hex format. For "
180 "details, please refer to "
181 "https://github.com/intel/llvm/blob/sycl/sycl/doc/"
182 "EnvironmentVariables.md " +
188 else if (std::find(SupportedKeyNamesRequireRegexValue.begin(),
189 SupportedKeyNamesRequireRegexValue.end(),
190 Key) != SupportedKeyNamesRequireRegexValue.end()) {
191 const std::string Prefix(
"{{");
194 if (Prefix != AllowListRaw.substr(ValueStart, Prefix.length())) {
198 " of SYCL_DEVICE_ALLOWLIST should have "
199 "value which starts with " +
204 ValueStart += Prefix.length();
206 ValueEnd = ValueStart;
207 const std::string Postfix(
"}}");
208 for (; ValueEnd < AllowListRaw.length() - Postfix.length() + 1;
210 if (Postfix == AllowListRaw.substr(ValueEnd, Postfix.length()))
214 if (ValueEnd == AllowListRaw.length() - Postfix.length())
218 " of SYCL_DEVICE_ALLOWLIST should have "
219 "value which ends with " +
223 size_t NextExpectedDelimiterPos = ValueEnd + Postfix.length();
226 if ((AllowListRaw.length() != NextExpectedDelimiterPos) &&
227 (AllowListRaw[NextExpectedDelimiterPos] !=
228 DelimiterBtwItemsInDeviceDesc) &&
229 (AllowListRaw[NextExpectedDelimiterPos] != DelimiterBtwDeviceDescs))
232 "Unexpected symbol on position " +
233 std::to_string(NextExpectedDelimiterPos) +
": " +
234 AllowListRaw[NextExpectedDelimiterPos] +
235 ". Should be either " + DelimiterBtwItemsInDeviceDesc +
236 " or " + DelimiterBtwDeviceDescs +
239 if (AllowListRaw[NextExpectedDelimiterPos] == DelimiterBtwDeviceDescs)
240 ShouldAllocateNewDeviceDescMap =
true;
242 Value = AllowListRaw.substr(ValueStart, ValueEnd - ValueStart);
244 ValueEnd += Postfix.length();
247 "Key should be either in SupportedKeyNamesHaveFixedValue "
248 "or SupportedKeyNamesRequireRegexValue");
251 DeviceDescMap.emplace(Key, Value);
254 "Re-definition of key " + Key +
255 " is not allowed in "
256 "SYCL_DEVICE_ALLOWLIST " +
260 if (KeyStart != std::string::npos)
262 if (ShouldAllocateNewDeviceDescMap) {
264 AllowListParsed.emplace_back();
268 if (IsDeprecatedKeyNameDeviceNameWasUsed &&
269 IsDeprecatedKeyNamePlatformNameWasUsed) {
270 std::cout <<
"\nWARNING: " << DeprecatedKeyNameDeviceName <<
" and "
271 << DeprecatedKeyNamePlatformName
272 <<
" in SYCL_DEVICE_ALLOWLIST are deprecated. ";
273 }
else if (IsDeprecatedKeyNameDeviceNameWasUsed) {
274 std::cout <<
"\nWARNING: " << DeprecatedKeyNameDeviceName
275 <<
" in SYCL_DEVICE_ALLOWLIST is deprecated. ";
276 }
else if (IsDeprecatedKeyNamePlatformNameWasUsed) {
277 std::cout <<
"\nWARNING: " << DeprecatedKeyNamePlatformName
278 <<
" in SYCL_DEVICE_ALLOWLIST is deprecated. ";
280 if (IsDeprecatedKeyNameDeviceNameWasUsed ||
281 IsDeprecatedKeyNamePlatformNameWasUsed) {
284 <<
" instead. For details, please refer to "
285 "https://github.com/intel/llvm/blob/sycl/sycl/doc/"
286 "EnvironmentVariables.md\n\n";
289 return AllowListParsed;
297 [&DeviceDesc](
const auto &SupportedKeyName) {
298 return DeviceDesc.find(SupportedKeyName) !=
301 "DeviceDesc map should have all supported keys for "
302 "SYCL_DEVICE_ALLOWLIST.");
303 auto EqualityComp = [&](
const std::string &KeyName,
306 if (AllowListDeviceDesc.find(KeyName) != AllowListDeviceDesc.end())
307 if (AllowListDeviceDesc.at(KeyName) != DeviceDesc.at(KeyName))
311 auto RegexComp = [&](
const std::string &KeyName,
313 if (AllowListDeviceDesc.find(KeyName) != AllowListDeviceDesc.end())
314 if (!std::regex_match(DeviceDesc.at(KeyName),
315 std::regex(AllowListDeviceDesc.at(KeyName))))
320 bool ShouldDeviceBeAllowed =
false;
322 for (
const auto &AllowListDeviceDesc : AllowListParsed) {
340 ShouldDeviceBeAllowed =
true;
344 return ShouldDeviceBeAllowed;
348 ur_platform_handle_t UrPlatform,
const PluginPtr &Plugin) {
352 if (AllowListParsed.empty())
358 backend Backend = PlatformImpl->getBackend();
361 if (SyclBe.second == Backend) {
368 sycl::detail::get_platform_info<info::platform::version>(
369 UrPlatform, Plugin));
372 sycl::detail::get_platform_info<info::platform::name>(
373 UrPlatform, Plugin));
376 for (ur_device_handle_t Device : UrDevices) {
377 auto DeviceImpl = PlatformImpl->getOrMakeDeviceImpl(Device, PlatformImpl);
379 ur_device_type_t UrDevType = UR_DEVICE_TYPE_ALL;
380 Plugin->call<UrApiKind::urDeviceGetInfo>(
381 Device, UR_DEVICE_INFO_TYPE,
sizeof(UrDevType), &UrDevType,
nullptr);
387 case UR_DEVICE_TYPE_ALL:
390 case UR_DEVICE_TYPE_GPU:
393 case UR_DEVICE_TYPE_CPU:
396 case UR_DEVICE_TYPE_FPGA:
400 for (
const auto &SyclDeviceType :
401 getSyclDeviceTypeMap<true /*Enable 'acc'*/>()) {
402 if (SyclDeviceType.second == DeviceType) {
403 const auto &DeviceTypeValue = SyclDeviceType.first;
409 uint32_t DeviceVendorIdUInt =
410 sycl::detail::get_device_info<info::device::vendor_id>(DeviceImpl);
411 std::stringstream DeviceVendorIdHexStringStream;
412 DeviceVendorIdHexStringStream <<
"0x" << std::hex << DeviceVendorIdUInt;
413 const auto &DeviceVendorIdValue = DeviceVendorIdHexStringStream.str();
416 const std::string &DriverVersionValue =
417 sycl::detail::get_device_info<info::device::driver_version>(DeviceImpl);
420 const std::string &DeviceNameValue =
421 sycl::detail::get_device_info<info::device::name>(DeviceImpl);
426 UrDevices[InsertIDx++] = Device;
429 UrDevices.resize(InsertIDx);
__SYCL_EXTERN_STREAM_ATTRS ostream cout
Linked to standard output.
void applyAllowList(std::vector< ur_device_handle_t > &UrDevices, ur_platform_handle_t UrPlatform, const PluginPtr &Plugin)
std::string codeToString(int32_t code)
constexpr char DeviceNameKeyName[]
constexpr char BackendNameKeyName[]
std::map< std::string, std::string > DeviceDescT
AllowListParsedT parseAllowList(const std::string &AllowListRaw)
bool deviceIsAllowed(const DeviceDescT &DeviceDesc, const AllowListParsedT &AllowListParsed)
constexpr char DeviceVendorIdKeyName[]
std::shared_ptr< plugin > PluginPtr
constexpr std::array< const char *, 7 > SupportedAllowListKeyNames
constexpr char PlatformVersionKeyName[]
const std::array< std::pair< std::string, backend >, 7 > & getSyclBeMap()
constexpr char DeviceTypeKeyName[]
constexpr char DriverVersionKeyName[]
std::vector< DeviceDescT > AllowListParsedT
constexpr char PlatformNameKeyName[]
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
bool all_of(const simd_mask< _Tp, _Abi > &) noexcept