Skip to content

Commit ccdf847

Browse files
authored
[SYCL] Fixed filter parsing error. (#2643)
Signed-off-by: Byoungro So <[email protected]>
1 parent ce29b77 commit ccdf847

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

sycl/source/detail/device_filter.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,23 @@ device_filter::device_filter(const std::string &FilterString) {
4040
Cursor = Found;
4141
return true;
4242
};
43-
auto selectElement = [&](auto It, auto Map, auto EltIfNotFound) {
44-
if (It == Map.end())
45-
return EltIfNotFound;
46-
ColonPos = FilterString.find(":", Cursor);
47-
if (ColonPos != std::string::npos)
48-
Cursor = ColonPos + 1;
49-
else
50-
Cursor = Cursor + It->first.size();
51-
return It->second;
52-
};
5343

5444
// Handle the optional 1st field of the filter, backend
5545
// Check if the first entry matches with a known backend type
5646
auto It =
5747
std::find_if(std::begin(SyclBeMap), std::end(SyclBeMap), findElement);
5848
// If no match is found, set the backend type backend::all
5949
// which actually means 'any backend' will be a match.
60-
Backend = selectElement(It, SyclBeMap, backend::all);
61-
50+
if (It == SyclBeMap.end())
51+
Backend = backend::all;
52+
else {
53+
Backend = It->second;
54+
ColonPos = FilterString.find(":", Cursor);
55+
if (ColonPos != std::string::npos)
56+
Cursor = ColonPos + 1;
57+
else
58+
Cursor = Cursor + It->first.size();
59+
}
6260
// Handle the optional 2nd field of the filter - device type.
6361
// Check if the 2nd entry matches with any known device type.
6462
if (Cursor >= FilterString.size()) {
@@ -68,15 +66,24 @@ device_filter::device_filter(const std::string &FilterString) {
6866
std::end(SyclDeviceTypeMap), findElement);
6967
// If no match is found, set device_type 'all',
7068
// which actually means 'any device_type' will be a match.
71-
DeviceType = selectElement(Iter, SyclDeviceTypeMap, info::device_type::all);
69+
if (Iter == SyclDeviceTypeMap.end())
70+
DeviceType = info::device_type::all;
71+
else {
72+
DeviceType = Iter->second;
73+
ColonPos = FilterString.find(":", Cursor);
74+
if (ColonPos != std::string::npos)
75+
Cursor = ColonPos + 1;
76+
else
77+
Cursor = Cursor + Iter->first.size();
78+
}
7279
}
7380

7481
// Handle the optional 3rd field of the filter, device number
7582
// Try to convert the remaining string to an integer.
7683
// If succeessful, the converted integer is the desired device num.
7784
if (Cursor < FilterString.size()) {
7885
try {
79-
DeviceNum = stoi(FilterString.substr(ColonPos + 1));
86+
DeviceNum = stoi(FilterString.substr(Cursor));
8087
HasDeviceNum = true;
8188
} catch (...) {
8289
std::string Message =

sycl/test/filter_selector/select_device_acc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
// RU: env SYCL_DEVICE_FILTER=acc %t.out
2+
// RUN: env SYCL_DEVICE_FILTER=acc %t.out
33
//
44
// Checks if only specified device types can be acquired from select_device
55
// when SYCL_DEVICE_FILTER is set

sycl/test/filter_selector/select_device_cpu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
// RU: env SYCL_DEVICE_FILTER=cpu %t.out
2+
// RUN: env SYCL_DEVICE_FILTER=cpu %t.out
33
//
44
// Checks if only specified device types can be acquired from select_device
55
// when SYCL_DEVICE_FILTER is set

0 commit comments

Comments
 (0)