From 698417a1571bb8f0d9c37487fa75f103ff8b1c37 Mon Sep 17 00:00:00 2001 From: Udit Agarwal <16324601+uditagarwal97@users.noreply.github.com> Date: Thu, 8 Feb 2024 07:37:50 -0800 Subject: [PATCH] [SYCL] Drop 'acc' in favor of 'fpga' from ONEAPI_DEVICE_SELECTOR (#12614) As per the ONEAPI_DEVICE_SELECTOR [documentation](https://github.com/intel/llvm/blob/sycl/sycl/doc/EnvironmentVariables.md#oneapi_device_selector), the device type can only be cpu, gpu, or fpga (or any combination of those). Currently, 'acc' is also accepted by ONEAPI_DEVICE_SELECTOR as a valid device type, which is incorrect. This PR modifies drops support of 'acc' in ONEAPI_DEVICE_SELECTOR in favor of 'fpga'. We have already updated existing test cases (#12551), testing scripts (#12596 ) to use 'fpga' with ONEAPI_DEVICE_SELECTOR. --- sycl/source/detail/allowlist.cpp | 6 ++++-- sycl/source/detail/config.cpp | 16 +++++++------- sycl/source/detail/config.hpp | 6 ++++-- sycl/source/detail/device_filter.cpp | 23 ++++++++++++++------- sycl/unittests/allowlist/ParseAllowList.cpp | 3 ++- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/sycl/source/detail/allowlist.cpp b/sycl/source/detail/allowlist.cpp index 881a014c4831f..83309ec9f2d92 100644 --- a/sycl/source/detail/allowlist.cpp +++ b/sycl/source/detail/allowlist.cpp @@ -166,7 +166,8 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) { // valid. E.g., for BackendName key, the allowed values are only ones // described in SyclBeMap ValidateEnumValues(BackendNameKeyName, getSyclBeMap()); - ValidateEnumValues(DeviceTypeKeyName, getSyclDeviceTypeMap()); + ValidateEnumValues(DeviceTypeKeyName, + getSyclDeviceTypeMap(true /*Enable 'acc'*/)); if (Key == DeviceVendorIdKeyName) { // DeviceVendorId should have hex format @@ -380,7 +381,8 @@ void applyAllowList(std::vector &PiDevices, Device, PI_DEVICE_INFO_TYPE, sizeof(sycl::detail::pi::PiDeviceType), &PiDevType, nullptr); sycl::info::device_type DeviceType = pi::cast(PiDevType); - for (const auto &SyclDeviceType : getSyclDeviceTypeMap()) { + for (const auto &SyclDeviceType : + getSyclDeviceTypeMap(true /*Enable 'acc'*/)) { if (SyclDeviceType.second == DeviceType) { const auto &DeviceTypeValue = SyclDeviceType.first; DeviceDesc[DeviceTypeKeyName] = DeviceTypeValue; diff --git a/sycl/source/detail/config.cpp b/sycl/source/detail/config.cpp index f7760aa227168..7ae96d42e220d 100644 --- a/sycl/source/detail/config.cpp +++ b/sycl/source/detail/config.cpp @@ -165,14 +165,16 @@ void dumpConfig() { // TODO: host device type will be removed once sycl_ext_oneapi_filter_selector // is removed. const std::array, 6> & -getSyclDeviceTypeMap() { +getSyclDeviceTypeMap(bool supportAcc) { static const std::array, 6> - SyclDeviceTypeMap = {{{"host", info::device_type::host}, - {"cpu", info::device_type::cpu}, - {"gpu", info::device_type::gpu}, - {"acc", info::device_type::accelerator}, - {"fpga", info::device_type::accelerator}, - {"*", info::device_type::all}}}; + SyclDeviceTypeMap = { + {{"host", info::device_type::host}, + {"cpu", info::device_type::cpu}, + {"gpu", info::device_type::gpu}, + /* Duplicate entries are fine as this map is one-directional.*/ + {supportAcc ? "acc" : "fpga", info::device_type::accelerator}, + {"fpga", info::device_type::accelerator}, + {"*", info::device_type::all}}}; return SyclDeviceTypeMap; } diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index 8f048e0f95f60..1079f32caa388 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -232,8 +232,10 @@ template <> class SYCLConfig { }; // Array is used by SYCL_DEVICE_ALLOWLIST and ONEAPI_DEVICE_SELECTOR. +// The 'supportAcc' parameter is used by SYCL_DEVICE_ALLOWLIST which, +// unlike ONEAPI_DEVICE_SELECTOR, also accepts 'acc' as a valid device type. const std::array, 6> & -getSyclDeviceTypeMap(); +getSyclDeviceTypeMap(bool supportAcc = false); // Array is used by SYCL_DEVICE_FILTER and SYCL_DEVICE_ALLOWLIST and // ONEAPI_DEVICE_SELECTOR @@ -514,7 +516,7 @@ template <> class SYCLConfig { return Result; std::string ValueStr{ValueRaw}; - auto DeviceTypeMap = getSyclDeviceTypeMap(); + auto DeviceTypeMap = getSyclDeviceTypeMap(true /*Enable 'acc'*/); // Iterate over all configurations. size_t Start = 0, End = 0; diff --git a/sycl/source/detail/device_filter.cpp b/sycl/source/detail/device_filter.cpp index 311ebeaa174b8..eb3d0f83ed26e 100644 --- a/sycl/source/detail/device_filter.cpp +++ b/sycl/source/detail/device_filter.cpp @@ -93,9 +93,13 @@ static void Parse_ODS_Device(ods_target &Target, std::string_view TopDeviceStr = DeviceSubTuple[0]; // Handle explicit device type (e.g. 'gpu'). - auto DeviceTypeMap = - getSyclDeviceTypeMap(); // <-- std::array> + auto DeviceTypeMap = getSyclDeviceTypeMap( +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES + true /*Enable 'acc'*/ +#endif + ); // <-- std::array> + auto It = std::find_if(std::begin(DeviceTypeMap), std::end(DeviceTypeMap), [&](auto DtPair) { return TopDeviceStr == DtPair.first; }); @@ -262,7 +266,11 @@ Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envString) { std::ostream &operator<<(std::ostream &Out, const ods_target &Target) { Out << Target.Backend; if (Target.DeviceType) { - auto DeviceTypeMap = getSyclDeviceTypeMap(); + auto DeviceTypeMap = getSyclDeviceTypeMap( +#ifndef __INTEL_PREVIEW_BREAKING_CHANGES + true /*Enable 'acc'*/ +#endif + ); auto Match = std::find_if( DeviceTypeMap.begin(), DeviceTypeMap.end(), [&](auto Pair) { return (Pair.second == Target.DeviceType); }); @@ -335,11 +343,12 @@ device_filter::device_filter(const std::string &FilterString) { if (TripleValueID >= Tokens.size()) { DeviceType = info::device_type::all; } else { - auto Iter = std::find_if(std::begin(getSyclDeviceTypeMap()), - std::end(getSyclDeviceTypeMap()), FindElement); + auto Iter = std::find_if( + std::begin(getSyclDeviceTypeMap(true /*Enable 'acc'*/)), + std::end(getSyclDeviceTypeMap(true /*Enable 'acc'*/)), FindElement); // If no match is found, set device_type 'all', // which actually means 'any device_type' will be a match. - if (Iter == getSyclDeviceTypeMap().end()) + if (Iter == getSyclDeviceTypeMap(true /*Enable 'acc'*/).end()) DeviceType = info::device_type::all; else { DeviceType = Iter->second; diff --git a/sycl/unittests/allowlist/ParseAllowList.cpp b/sycl/unittests/allowlist/ParseAllowList.cpp index faecab30aaeaf..40fbceb76616e 100644 --- a/sycl/unittests/allowlist/ParseAllowList.cpp +++ b/sycl/unittests/allowlist/ParseAllowList.cpp @@ -178,7 +178,8 @@ TEST(ParseAllowListTests, CheckAllValidBackendNameValuesAreProcessed) { TEST(ParseAllowListTests, CheckAllValidDeviceTypeValuesAreProcessed) { std::string AllowList; - for (const auto &SyclDeviceType : sycl::detail::getSyclDeviceTypeMap()) { + for (const auto &SyclDeviceType : + sycl::detail::getSyclDeviceTypeMap(true /*Enable 'acc'*/)) { if (!AllowList.empty()) AllowList += "|"; AllowList += "DeviceType:" + SyclDeviceType.first;