Skip to content

[SYCL] Fixed filter parsing error. #2643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions sycl/source/detail/device_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,23 @@ device_filter::device_filter(const std::string &FilterString) {
Cursor = Found;
return true;
};
auto selectElement = [&](auto It, auto Map, auto EltIfNotFound) {
if (It == Map.end())
return EltIfNotFound;
ColonPos = FilterString.find(":", Cursor);
if (ColonPos != std::string::npos)
Cursor = ColonPos + 1;
else
Cursor = Cursor + It->first.size();
return It->second;
};

// Handle the optional 1st field of the filter, backend
// Check if the first entry matches with a known backend type
auto It =
std::find_if(std::begin(SyclBeMap), std::end(SyclBeMap), findElement);
// If no match is found, set the backend type backend::all
// which actually means 'any backend' will be a match.
Backend = selectElement(It, SyclBeMap, backend::all);

if (It == SyclBeMap.end())
Backend = backend::all;
else {
Backend = It->second;
ColonPos = FilterString.find(":", Cursor);
if (ColonPos != std::string::npos)
Cursor = ColonPos + 1;
else
Cursor = Cursor + It->first.size();
}
// Handle the optional 2nd field of the filter - device type.
// Check if the 2nd entry matches with any known device type.
if (Cursor >= FilterString.size()) {
Expand All @@ -68,15 +66,24 @@ device_filter::device_filter(const std::string &FilterString) {
std::end(SyclDeviceTypeMap), findElement);
// If no match is found, set device_type 'all',
// which actually means 'any device_type' will be a match.
DeviceType = selectElement(Iter, SyclDeviceTypeMap, info::device_type::all);
if (Iter == SyclDeviceTypeMap.end())
DeviceType = info::device_type::all;
else {
DeviceType = Iter->second;
ColonPos = FilterString.find(":", Cursor);
if (ColonPos != std::string::npos)
Cursor = ColonPos + 1;
else
Cursor = Cursor + Iter->first.size();
}
}

// Handle the optional 3rd field of the filter, device number
// Try to convert the remaining string to an integer.
// If succeessful, the converted integer is the desired device num.
if (Cursor < FilterString.size()) {
try {
DeviceNum = stoi(FilterString.substr(ColonPos + 1));
DeviceNum = stoi(FilterString.substr(Cursor));
HasDeviceNum = true;
} catch (...) {
std::string Message =
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/filter_selector/select_device_acc.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RU: env SYCL_DEVICE_FILTER=acc %t.out
// RUN: env SYCL_DEVICE_FILTER=acc %t.out
//
// Checks if only specified device types can be acquired from select_device
// when SYCL_DEVICE_FILTER is set
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/filter_selector/select_device_cpu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RU: env SYCL_DEVICE_FILTER=cpu %t.out
// RUN: env SYCL_DEVICE_FILTER=cpu %t.out
//
// Checks if only specified device types can be acquired from select_device
// when SYCL_DEVICE_FILTER is set
Expand Down