Skip to content

Commit

Permalink
[SYCL] Drop 'acc' in favor of 'fpga' from ONEAPI_DEVICE_SELECTOR (#12614
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
uditagarwal97 authored Feb 8, 2024
1 parent 170be1f commit 698417a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
6 changes: 4 additions & 2 deletions sycl/source/detail/allowlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -380,7 +381,8 @@ void applyAllowList(std::vector<sycl::detail::pi::PiDevice> &PiDevices,
Device, PI_DEVICE_INFO_TYPE, sizeof(sycl::detail::pi::PiDeviceType),
&PiDevType, nullptr);
sycl::info::device_type DeviceType = pi::cast<info::device_type>(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;
Expand Down
16 changes: 9 additions & 7 deletions sycl/source/detail/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,16 @@ void dumpConfig() {
// TODO: host device type will be removed once sycl_ext_oneapi_filter_selector
// is removed.
const std::array<std::pair<std::string, info::device_type>, 6> &
getSyclDeviceTypeMap() {
getSyclDeviceTypeMap(bool supportAcc) {
static const std::array<std::pair<std::string, info::device_type>, 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;
}

Expand Down
6 changes: 4 additions & 2 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ template <> class SYCLConfig<SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS> {
};

// 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<std::pair<std::string, info::device_type>, 6> &
getSyclDeviceTypeMap();
getSyclDeviceTypeMap(bool supportAcc = false);

// Array is used by SYCL_DEVICE_FILTER and SYCL_DEVICE_ALLOWLIST and
// ONEAPI_DEVICE_SELECTOR
Expand Down Expand Up @@ -514,7 +516,7 @@ template <> class SYCLConfig<SYCL_REDUCTION_PREFERRED_WORKGROUP_SIZE> {
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;
Expand Down
23 changes: 16 additions & 7 deletions sycl/source/detail/device_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<std::string,
// info::device::type>>
auto DeviceTypeMap = getSyclDeviceTypeMap(
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
true /*Enable 'acc'*/
#endif
); // <-- std::array<std::pair<std::string,
// info::device::type>>

auto It =
std::find_if(std::begin(DeviceTypeMap), std::end(DeviceTypeMap),
[&](auto DtPair) { return TopDeviceStr == DtPair.first; });
Expand Down Expand Up @@ -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); });
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion sycl/unittests/allowlist/ParseAllowList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 698417a

Please sign in to comment.