@@ -17,19 +17,44 @@ __SYCL_INLINE_NAMESPACE(cl) {
17
17
namespace sycl {
18
18
namespace detail {
19
19
20
+ std::vector<std::string> tokenize (const std::string &Filter,
21
+ const std::string &Delim) {
22
+ std::vector<std::string> Tokens;
23
+ size_t Pos = 0 ;
24
+ std::string Input = Filter;
25
+ std::string Tok;
26
+
27
+ while ((Pos = Input.find (Delim)) != std::string::npos) {
28
+ Tok = Input.substr (0 , Pos);
29
+ Input.erase (0 , Pos + Delim.length ());
30
+
31
+ if (!Tok.empty ()) {
32
+ Tokens.push_back (std::move (Tok));
33
+ }
34
+ }
35
+
36
+ // Add remainder
37
+ if (!Input.empty ())
38
+ Tokens.push_back (std::move (Input));
39
+
40
+ return Tokens;
41
+ }
42
+
20
43
device_filter::device_filter (const std::string &FilterString) {
21
- size_t Cursor = 0 ;
22
- size_t ColonPos = 0 ;
44
+ std::string SubString ;
45
+
23
46
auto findElement = [&](auto Element) {
24
- size_t Found = FilterString .find (Element.first , Cursor );
47
+ size_t Found = SubString .find (Element.first );
25
48
if (Found == std::string::npos)
26
49
return false ;
27
- Cursor = Found;
28
50
return true ;
29
51
};
30
52
31
53
// Handle the optional 1st field of the filter, backend
32
54
// Check if the first entry matches with a known backend type
55
+ std::vector<std::string> Tokens = tokenize (FilterString, " :" );
56
+ size_t i = 0 ;
57
+ SubString = Tokens[i];
33
58
auto It =
34
59
std::find_if (std::begin (SyclBeMap), std::end (SyclBeMap), findElement);
35
60
// If no match is found, set the backend type backend::all
@@ -38,15 +63,14 @@ device_filter::device_filter(const std::string &FilterString) {
38
63
Backend = backend::all;
39
64
else {
40
65
Backend = It->second ;
41
- ColonPos = FilterString.find (" :" , Cursor);
42
- if (ColonPos != std::string::npos)
43
- Cursor = ColonPos + 1 ;
44
- else
45
- Cursor = Cursor + It->first .size ();
66
+ i++;
67
+ if (i < Tokens.size ())
68
+ SubString = Tokens[i];
46
69
}
70
+
47
71
// Handle the optional 2nd field of the filter - device type.
48
72
// Check if the 2nd entry matches with any known device type.
49
- if (Cursor >= FilterString .size ()) {
73
+ if (i >= Tokens .size ()) {
50
74
DeviceType = info::device_type::all;
51
75
} else {
52
76
auto Iter = std::find_if (std::begin (SyclDeviceTypeMap),
@@ -57,20 +81,18 @@ device_filter::device_filter(const std::string &FilterString) {
57
81
DeviceType = info::device_type::all;
58
82
else {
59
83
DeviceType = Iter->second ;
60
- ColonPos = FilterString.find (" :" , Cursor);
61
- if (ColonPos != std::string::npos)
62
- Cursor = ColonPos + 1 ;
63
- else
64
- Cursor = Cursor + Iter->first .size ();
84
+ i++;
85
+ if (i < Tokens.size ())
86
+ SubString = Tokens[i];
65
87
}
66
88
}
67
89
68
90
// Handle the optional 3rd field of the filter, device number
69
91
// Try to convert the remaining string to an integer.
70
92
// If succeessful, the converted integer is the desired device num.
71
- if (Cursor < FilterString .size ()) {
93
+ if (i < Tokens .size ()) {
72
94
try {
73
- DeviceNum = stoi (FilterString. substr (Cursor) );
95
+ DeviceNum = stoi (SubString );
74
96
HasDeviceNum = true ;
75
97
} catch (...) {
76
98
std::string Message =
0 commit comments