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 " +
203 ValueStart += Prefix.length();
205 ValueEnd = ValueStart;
206 const std::string Postfix(
"}}");
207 for (; ValueEnd < AllowListRaw.length() - Postfix.length() + 1;
209 if (Postfix == AllowListRaw.substr(ValueEnd, Postfix.length()))
213 if (ValueEnd == AllowListRaw.length() - Postfix.length())
217 " of SYCL_DEVICE_ALLOWLIST should have "
218 "value which ends with " +
222 size_t NextExpectedDelimiterPos = ValueEnd + Postfix.length();
225 if ((AllowListRaw.length() != NextExpectedDelimiterPos) &&
226 (AllowListRaw[NextExpectedDelimiterPos] !=
227 DelimiterBtwItemsInDeviceDesc) &&
228 (AllowListRaw[NextExpectedDelimiterPos] != DelimiterBtwDeviceDescs))
231 "Unexpected symbol on position " +
232 std::to_string(NextExpectedDelimiterPos) +
": " +
233 AllowListRaw[NextExpectedDelimiterPos] +
234 ". Should be either " + DelimiterBtwItemsInDeviceDesc +
235 " or " + DelimiterBtwDeviceDescs +
238 if (AllowListRaw[NextExpectedDelimiterPos] == DelimiterBtwDeviceDescs)
239 ShouldAllocateNewDeviceDescMap =
true;
241 Value = AllowListRaw.substr(ValueStart, ValueEnd - ValueStart);
243 ValueEnd += Postfix.length();
246 "Key should be either in SupportedKeyNamesHaveFixedValue "
247 "or SupportedKeyNamesRequireRegexValue");
250 DeviceDescMap.emplace(Key, Value);
253 "Re-definition of key " + Key +
254 " is not allowed in "
255 "SYCL_DEVICE_ALLOWLIST " +
259 if (KeyStart != std::string::npos)
261 if (ShouldAllocateNewDeviceDescMap) {
263 AllowListParsed.emplace_back();
267 if (IsDeprecatedKeyNameDeviceNameWasUsed &&
268 IsDeprecatedKeyNamePlatformNameWasUsed) {
269 std::cout <<
"\nWARNING: " << DeprecatedKeyNameDeviceName <<
" and "
270 << DeprecatedKeyNamePlatformName
271 <<
" in SYCL_DEVICE_ALLOWLIST are deprecated. ";
272 }
else if (IsDeprecatedKeyNameDeviceNameWasUsed) {
273 std::cout <<
"\nWARNING: " << DeprecatedKeyNameDeviceName
274 <<
" in SYCL_DEVICE_ALLOWLIST is deprecated. ";
275 }
else if (IsDeprecatedKeyNamePlatformNameWasUsed) {
276 std::cout <<
"\nWARNING: " << DeprecatedKeyNamePlatformName
277 <<
" in SYCL_DEVICE_ALLOWLIST is deprecated. ";
279 if (IsDeprecatedKeyNameDeviceNameWasUsed ||
280 IsDeprecatedKeyNamePlatformNameWasUsed) {
283 <<
" instead. For details, please refer to "
284 "https://github.com/intel/llvm/blob/sycl/sycl/doc/"
285 "EnvironmentVariables.md\n\n";
288 return AllowListParsed;
296 [&DeviceDesc](
const auto &SupportedKeyName) {
297 return DeviceDesc.find(SupportedKeyName) !=
300 "DeviceDesc map should have all supported keys for "
301 "SYCL_DEVICE_ALLOWLIST.");
302 auto EqualityComp = [&](
const std::string &KeyName,
305 if (AllowListDeviceDesc.find(KeyName) != AllowListDeviceDesc.end())
306 if (AllowListDeviceDesc.at(KeyName) != DeviceDesc.at(KeyName))
310 auto RegexComp = [&](
const std::string &KeyName,
312 if (AllowListDeviceDesc.find(KeyName) != AllowListDeviceDesc.end())
313 if (!std::regex_match(DeviceDesc.at(KeyName),
314 std::regex(AllowListDeviceDesc.at(KeyName))))
319 bool ShouldDeviceBeAllowed =
false;
321 for (
const auto &AllowListDeviceDesc : AllowListParsed) {
339 ShouldDeviceBeAllowed =
true;
343 return ShouldDeviceBeAllowed;
352 if (AllowListParsed.empty())
358 backend Backend = PlatformImpl->getBackend();
361 if (SyclBe.second == Backend) {
368 sycl::detail::get_platform_info<info::platform::version>(
372 sycl::detail::get_platform_info<info::platform::name>(
377 auto DeviceImpl = PlatformImpl->getOrMakeDeviceImpl(Device, PlatformImpl);
382 &PiDevType,
nullptr);
384 for (
const auto &SyclDeviceType :
385 getSyclDeviceTypeMap<true /*Enable 'acc'*/>()) {
386 if (SyclDeviceType.second == DeviceType) {
387 const auto &DeviceTypeValue = SyclDeviceType.first;
393 uint32_t DeviceVendorIdUInt =
394 sycl::detail::get_device_info<info::device::vendor_id>(DeviceImpl);
395 std::stringstream DeviceVendorIdHexStringStream;
396 DeviceVendorIdHexStringStream <<
"0x" << std::hex << DeviceVendorIdUInt;
397 const auto &DeviceVendorIdValue = DeviceVendorIdHexStringStream.str();
400 const std::string &DriverVersionValue =
401 sycl::detail::get_device_info<info::device::driver_version>(DeviceImpl);
404 const std::string &DeviceNameValue =
405 sycl::detail::get_device_info<info::device::name>(DeviceImpl);
410 PiDevices[InsertIDx++] = Device;
413 PiDevices.resize(InsertIDx);
__SYCL_EXTERN_STREAM_ATTRS ostream cout
Linked to standard output.
::pi_device_type PiDeviceType
const std::array< std::pair< std::string, backend >, 8 > & getSyclBeMap()
constexpr char DeviceNameKeyName[]
constexpr char BackendNameKeyName[]
std::map< std::string, std::string > DeviceDescT
std::string codeToString(pi_int32 code)
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[]
constexpr char DeviceTypeKeyName[]
constexpr char DriverVersionKeyName[]
void applyAllowList(std::vector< sycl::detail::pi::PiDevice > &PiDevices, sycl::detail::pi::PiPlatform PiPlatform, const PluginPtr &Plugin)
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()
pi_result piDeviceGetInfo(pi_device device, pi_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
Returns requested info for provided native device Return PI_DEVICE_INFO_EXTENSION_DEVICELIB_ASSERT fo...
bool all_of(const simd_mask< _Tp, _Abi > &) noexcept