Skip to content

Commit b27c57c

Browse files
[SYCL] Add deprecation warnings for unstable keys of SYCL_DEVICE_ALLOWLIST (#4455)
This patch adds deprecation warnings for DeviceName and PlatformName keys of SYCL_DEVICE_ALLOWLIST and suggests using stable BackendName, DeviceType and DeviceVendorId keys instead of them
1 parent c696415 commit b27c57c

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

sycl/source/detail/allowlist.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
7777
"doc/EnvironmentVariables.md",
7878
PI_INVALID_VALUE);
7979

80+
const std::string &DeprecatedKeyNameDeviceName = DeviceNameKeyName;
81+
const std::string &DeprecatedKeyNamePlatformName = PlatformNameKeyName;
82+
83+
bool IsDeprecatedKeyNameDeviceNameWasUsed = false;
84+
bool IsDeprecatedKeyNamePlatformNameWasUsed = false;
85+
8086
while ((KeyEnd = AllowListRaw.find(DelimiterBtwKeyAndValue, KeyStart)) !=
8187
std::string::npos) {
8288
if ((ValueStart = AllowListRaw.find_first_not_of(
@@ -96,6 +102,13 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
96102
PI_INVALID_VALUE);
97103
}
98104

105+
if (Key == DeprecatedKeyNameDeviceName) {
106+
IsDeprecatedKeyNameDeviceNameWasUsed = true;
107+
}
108+
if (Key == DeprecatedKeyNamePlatformName) {
109+
IsDeprecatedKeyNamePlatformNameWasUsed = true;
110+
}
111+
99112
bool ShouldAllocateNewDeviceDescMap = false;
100113

101114
std::string Value;
@@ -241,6 +254,27 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
241254
}
242255
}
243256

257+
if (IsDeprecatedKeyNameDeviceNameWasUsed &&
258+
IsDeprecatedKeyNamePlatformNameWasUsed) {
259+
std::cout << "\nWARNING: " << DeprecatedKeyNameDeviceName << " and "
260+
<< DeprecatedKeyNamePlatformName
261+
<< " in SYCL_DEVICE_ALLOWLIST are deprecated. ";
262+
} else if (IsDeprecatedKeyNameDeviceNameWasUsed) {
263+
std::cout << "\nWARNING: " << DeprecatedKeyNameDeviceName
264+
<< " in SYCL_DEVICE_ALLOWLIST is deprecated. ";
265+
} else if (IsDeprecatedKeyNamePlatformNameWasUsed) {
266+
std::cout << "\nWARNING: " << DeprecatedKeyNamePlatformName
267+
<< " in SYCL_DEVICE_ALLOWLIST is deprecated. ";
268+
}
269+
if (IsDeprecatedKeyNameDeviceNameWasUsed ||
270+
IsDeprecatedKeyNamePlatformNameWasUsed) {
271+
std::cout << "Please use " << BackendNameKeyName << ", "
272+
<< DeviceTypeKeyName << " and " << DeviceVendorIdKeyName
273+
<< " instead. For details, please refer to "
274+
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
275+
"EnvironmentVariables.md\n\n";
276+
}
277+
244278
return AllowListParsed;
245279
}
246280

sycl/unittests/allowlist/ParseAllowList.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,48 @@ TEST(ParseAllowListTests, CheckExceptionIsThrownForValueWOColonDelim) {
267267
FAIL() << "Expected sycl::runtime_error";
268268
}
269269
}
270+
271+
TEST(ParseAllowListTests, CheckDeviceNameDeprecationWarning) {
272+
testing::internal::CaptureStdout();
273+
sycl::detail::parseAllowList("DeviceName:{{regex}}");
274+
std::string ActualOutput = testing::internal::GetCapturedStdout();
275+
EXPECT_EQ("\nWARNING: DeviceName in SYCL_DEVICE_ALLOWLIST is deprecated. "
276+
"Please use BackendName, DeviceType and DeviceVendorId instead. "
277+
"For details, please refer to "
278+
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
279+
"EnvironmentVariables.md\n\n",
280+
ActualOutput);
281+
}
282+
283+
TEST(ParseAllowListTests, CheckPlatformNameDeprecationWarning) {
284+
testing::internal::CaptureStdout();
285+
sycl::detail::parseAllowList("PlatformName:{{regex}}");
286+
std::string ActualOutput = testing::internal::GetCapturedStdout();
287+
EXPECT_EQ("\nWARNING: PlatformName in SYCL_DEVICE_ALLOWLIST is deprecated. "
288+
"Please use BackendName, DeviceType and DeviceVendorId instead. "
289+
"For details, please refer to "
290+
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
291+
"EnvironmentVariables.md\n\n",
292+
ActualOutput);
293+
}
294+
295+
TEST(ParseAllowListTests, CheckDeviceNameAndPlatformNameDeprecationWarning) {
296+
testing::internal::CaptureStdout();
297+
sycl::detail::parseAllowList("DeviceName:{{regex}},PlatformName:{{regex}}");
298+
std::string ActualOutput = testing::internal::GetCapturedStdout();
299+
EXPECT_EQ("\nWARNING: DeviceName and PlatformName in SYCL_DEVICE_ALLOWLIST "
300+
"are deprecated. Please use BackendName, DeviceType and "
301+
"DeviceVendorId instead. For details, please refer to "
302+
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
303+
"EnvironmentVariables.md\n\n",
304+
ActualOutput);
305+
}
306+
307+
TEST(ParseAllowListTests, CheckNoDeprecationWarningForNotDeprecatedKeys) {
308+
testing::internal::CaptureStdout();
309+
sycl::detail::parseAllowList(
310+
"BackendName:level_zero,DeviceType:gpu,DeviceVendorId:0x0000,"
311+
"DriverVersion:{{regex1}},PlatformVersion:{{regex2}}");
312+
std::string ActualOutput = testing::internal::GetCapturedStdout();
313+
EXPECT_EQ("", ActualOutput);
314+
}

0 commit comments

Comments
 (0)