From 958be5bd7721e26a424de8567f42314e5e3961f8 Mon Sep 17 00:00:00 2001 From: Dmitry Vodopyanov Date: Wed, 1 Sep 2021 19:35:18 +0300 Subject: [PATCH 1/2] [SYCL] Add deprecation warnings for unstable keys of SYCL_DEVICE_ALLOWLIST 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 --- sycl/source/detail/allowlist.cpp | 34 ++++++++++++++++ sycl/unittests/allowlist/ParseAllowList.cpp | 45 +++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/sycl/source/detail/allowlist.cpp b/sycl/source/detail/allowlist.cpp index fe8edecc5f2a4..5df45040bbecc 100644 --- a/sycl/source/detail/allowlist.cpp +++ b/sycl/source/detail/allowlist.cpp @@ -77,6 +77,12 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) { "doc/EnvironmentVariables.md", PI_INVALID_VALUE); + const std::string &DeprecatedKeyNameDeviceName = DeviceNameKeyName; + const std::string &DeprecatedKeyNamePlatformName = PlatformNameKeyName; + + bool IsDeprecatedKeyNameDeviceNameWasUsed = false; + bool IsDeprecatedKeyNamePlatformNameWasUsed = false; + while ((KeyEnd = AllowListRaw.find(DelimiterBtwKeyAndValue, KeyStart)) != std::string::npos) { if ((ValueStart = AllowListRaw.find_first_not_of( @@ -96,6 +102,13 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) { PI_INVALID_VALUE); } + if (Key == DeprecatedKeyNameDeviceName) { + IsDeprecatedKeyNameDeviceNameWasUsed = true; + } + if (Key == DeprecatedKeyNamePlatformName) { + IsDeprecatedKeyNamePlatformNameWasUsed = true; + } + bool ShouldAllocateNewDeviceDescMap = false; std::string Value; @@ -241,6 +254,27 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) { } } + if (IsDeprecatedKeyNameDeviceNameWasUsed && + IsDeprecatedKeyNamePlatformNameWasUsed) { + std::cerr << "\nWARNING: " << DeprecatedKeyNameDeviceName << " and " + << DeprecatedKeyNamePlatformName + << " in SYCL_DEVICE_ALLOWLIST are deprecated. "; + } else if (IsDeprecatedKeyNameDeviceNameWasUsed) { + std::cerr << "\nWARNING: " << DeprecatedKeyNameDeviceName + << " in SYCL_DEVICE_ALLOWLIST is deprecated. "; + } else if (IsDeprecatedKeyNamePlatformNameWasUsed) { + std::cerr << "\nWARNING: " << DeprecatedKeyNamePlatformName + << " in SYCL_DEVICE_ALLOWLIST is deprecated. "; + } + if (IsDeprecatedKeyNameDeviceNameWasUsed || + IsDeprecatedKeyNamePlatformNameWasUsed) { + std::cerr << "Please use " << BackendNameKeyName << ", " + << DeviceTypeKeyName << " and " << DeviceVendorIdKeyName + << " instead. For details, please refer to " + "https://github.com/intel/llvm/blob/sycl/sycl/doc/" + "EnvironmentVariables.md\n\n"; + } + return AllowListParsed; } diff --git a/sycl/unittests/allowlist/ParseAllowList.cpp b/sycl/unittests/allowlist/ParseAllowList.cpp index 4c417618c4a62..d5a11e8cdc301 100644 --- a/sycl/unittests/allowlist/ParseAllowList.cpp +++ b/sycl/unittests/allowlist/ParseAllowList.cpp @@ -267,3 +267,48 @@ TEST(ParseAllowListTests, CheckExceptionIsThrownForValueWOColonDelim) { FAIL() << "Expected sycl::runtime_error"; } } + +TEST(ParseAllowListTests, CheckDeviceNameDeprecationWarning) { + testing::internal::CaptureStderr(); + sycl::detail::parseAllowList("DeviceName:{{regex}}"); + std::string ActualOutput = testing::internal::GetCapturedStderr(); + EXPECT_EQ("\nWARNING: DeviceName in SYCL_DEVICE_ALLOWLIST is deprecated. " + "Please use BackendName, DeviceType and DeviceVendorId instead. " + "For details, please refer to " + "https://github.com/intel/llvm/blob/sycl/sycl/doc/" + "EnvironmentVariables.md\n\n", + ActualOutput); +} + +TEST(ParseAllowListTests, CheckPlatformNameDeprecationWarning) { + testing::internal::CaptureStderr(); + sycl::detail::parseAllowList("PlatformName:{{regex}}"); + std::string ActualOutput = testing::internal::GetCapturedStderr(); + EXPECT_EQ("\nWARNING: PlatformName in SYCL_DEVICE_ALLOWLIST is deprecated. " + "Please use BackendName, DeviceType and DeviceVendorId instead. " + "For details, please refer to " + "https://github.com/intel/llvm/blob/sycl/sycl/doc/" + "EnvironmentVariables.md\n\n", + ActualOutput); +} + +TEST(ParseAllowListTests, CheckDeviceNameAndPlatformNameDeprecationWarning) { + testing::internal::CaptureStderr(); + sycl::detail::parseAllowList("DeviceName:{{regex}},PlatformName:{{regex}}"); + std::string ActualOutput = testing::internal::GetCapturedStderr(); + EXPECT_EQ("\nWARNING: DeviceName and PlatformName in SYCL_DEVICE_ALLOWLIST " + "are deprecated. Please use BackendName, DeviceType and " + "DeviceVendorId instead. For details, please refer to " + "https://github.com/intel/llvm/blob/sycl/sycl/doc/" + "EnvironmentVariables.md\n\n", + ActualOutput); +} + +TEST(ParseAllowListTests, CheckNoDeprecationWarningForNotDeprecatedKeys) { + testing::internal::CaptureStderr(); + sycl::detail::parseAllowList( + "BackendName:level_zero,DeviceType:gpu,DeviceVendorId:0x0000," + "DriverVersion:{{regex1}},PlatformVersion:{{regex2}}"); + std::string ActualOutput = testing::internal::GetCapturedStderr(); + EXPECT_EQ("", ActualOutput); +} From d56f0fcf997515fb5c2ea5556e9c3edcc9edda86 Mon Sep 17 00:00:00 2001 From: Dmitry Vodopyanov Date: Fri, 3 Sep 2021 20:10:15 +0300 Subject: [PATCH 2/2] Change std::cerr to std::cout --- sycl/source/detail/allowlist.cpp | 8 ++++---- sycl/unittests/allowlist/ParseAllowList.cpp | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sycl/source/detail/allowlist.cpp b/sycl/source/detail/allowlist.cpp index 5df45040bbecc..49b210a69f5da 100644 --- a/sycl/source/detail/allowlist.cpp +++ b/sycl/source/detail/allowlist.cpp @@ -256,19 +256,19 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) { if (IsDeprecatedKeyNameDeviceNameWasUsed && IsDeprecatedKeyNamePlatformNameWasUsed) { - std::cerr << "\nWARNING: " << DeprecatedKeyNameDeviceName << " and " + std::cout << "\nWARNING: " << DeprecatedKeyNameDeviceName << " and " << DeprecatedKeyNamePlatformName << " in SYCL_DEVICE_ALLOWLIST are deprecated. "; } else if (IsDeprecatedKeyNameDeviceNameWasUsed) { - std::cerr << "\nWARNING: " << DeprecatedKeyNameDeviceName + std::cout << "\nWARNING: " << DeprecatedKeyNameDeviceName << " in SYCL_DEVICE_ALLOWLIST is deprecated. "; } else if (IsDeprecatedKeyNamePlatformNameWasUsed) { - std::cerr << "\nWARNING: " << DeprecatedKeyNamePlatformName + std::cout << "\nWARNING: " << DeprecatedKeyNamePlatformName << " in SYCL_DEVICE_ALLOWLIST is deprecated. "; } if (IsDeprecatedKeyNameDeviceNameWasUsed || IsDeprecatedKeyNamePlatformNameWasUsed) { - std::cerr << "Please use " << BackendNameKeyName << ", " + std::cout << "Please use " << BackendNameKeyName << ", " << DeviceTypeKeyName << " and " << DeviceVendorIdKeyName << " instead. For details, please refer to " "https://github.com/intel/llvm/blob/sycl/sycl/doc/" diff --git a/sycl/unittests/allowlist/ParseAllowList.cpp b/sycl/unittests/allowlist/ParseAllowList.cpp index d5a11e8cdc301..714c0f20fec7e 100644 --- a/sycl/unittests/allowlist/ParseAllowList.cpp +++ b/sycl/unittests/allowlist/ParseAllowList.cpp @@ -269,9 +269,9 @@ TEST(ParseAllowListTests, CheckExceptionIsThrownForValueWOColonDelim) { } TEST(ParseAllowListTests, CheckDeviceNameDeprecationWarning) { - testing::internal::CaptureStderr(); + testing::internal::CaptureStdout(); sycl::detail::parseAllowList("DeviceName:{{regex}}"); - std::string ActualOutput = testing::internal::GetCapturedStderr(); + std::string ActualOutput = testing::internal::GetCapturedStdout(); EXPECT_EQ("\nWARNING: DeviceName in SYCL_DEVICE_ALLOWLIST is deprecated. " "Please use BackendName, DeviceType and DeviceVendorId instead. " "For details, please refer to " @@ -281,9 +281,9 @@ TEST(ParseAllowListTests, CheckDeviceNameDeprecationWarning) { } TEST(ParseAllowListTests, CheckPlatformNameDeprecationWarning) { - testing::internal::CaptureStderr(); + testing::internal::CaptureStdout(); sycl::detail::parseAllowList("PlatformName:{{regex}}"); - std::string ActualOutput = testing::internal::GetCapturedStderr(); + std::string ActualOutput = testing::internal::GetCapturedStdout(); EXPECT_EQ("\nWARNING: PlatformName in SYCL_DEVICE_ALLOWLIST is deprecated. " "Please use BackendName, DeviceType and DeviceVendorId instead. " "For details, please refer to " @@ -293,9 +293,9 @@ TEST(ParseAllowListTests, CheckPlatformNameDeprecationWarning) { } TEST(ParseAllowListTests, CheckDeviceNameAndPlatformNameDeprecationWarning) { - testing::internal::CaptureStderr(); + testing::internal::CaptureStdout(); sycl::detail::parseAllowList("DeviceName:{{regex}},PlatformName:{{regex}}"); - std::string ActualOutput = testing::internal::GetCapturedStderr(); + std::string ActualOutput = testing::internal::GetCapturedStdout(); EXPECT_EQ("\nWARNING: DeviceName and PlatformName in SYCL_DEVICE_ALLOWLIST " "are deprecated. Please use BackendName, DeviceType and " "DeviceVendorId instead. For details, please refer to " @@ -305,10 +305,10 @@ TEST(ParseAllowListTests, CheckDeviceNameAndPlatformNameDeprecationWarning) { } TEST(ParseAllowListTests, CheckNoDeprecationWarningForNotDeprecatedKeys) { - testing::internal::CaptureStderr(); + testing::internal::CaptureStdout(); sycl::detail::parseAllowList( "BackendName:level_zero,DeviceType:gpu,DeviceVendorId:0x0000," "DriverVersion:{{regex1}},PlatformVersion:{{regex2}}"); - std::string ActualOutput = testing::internal::GetCapturedStderr(); + std::string ActualOutput = testing::internal::GetCapturedStdout(); EXPECT_EQ("", ActualOutput); }