@@ -201,6 +201,8 @@ Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envString) {
201
201
std::vector<std::string_view> Pair =
202
202
tokenize (Entry, " :" , true /* ProhibitEmptyTokens */ );
203
203
204
+ // Error handling. ONEAPI_DEVICE_SELECTOR terms should be in the
205
+ // format: <backend>:<devices>.
204
206
if (Pair.empty ()) {
205
207
std::stringstream ss;
206
208
ss << " Incomplete selector! Backend and device must be specified." ;
@@ -210,8 +212,24 @@ Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envString) {
210
212
ss << " Incomplete selector! Try '" << Pair[0 ]
211
213
<< " :*' if all devices under the backend was original intention." ;
212
214
throw sycl::exception (sycl::make_error_code (errc::invalid), ss.str ());
213
- } else if (Pair.size () == 2 ) {
214
- backend be = Parse_ODS_Backend (Pair[0 ], Entry); // Pair[0] is backend.
215
+ } else if (Pair.size () > 2 ) {
216
+ std::stringstream ss;
217
+ ss << " Error parsing selector string \" " << Entry
218
+ << " \" Too many colons (:)" ;
219
+ throw sycl::exception (sycl::make_error_code (errc::invalid), ss.str ());
220
+ }
221
+
222
+ // Parse ONEAPI_DEVICE_SELECTOR terms for Pair.size() == 2.
223
+ else {
224
+
225
+ // Remove `!` from input backend string if it is present.
226
+ std::string_view input_be = Pair[0 ];
227
+ if (Pair[0 ][0 ] == ' !' )
228
+ input_be = Pair[0 ].substr (1 );
229
+
230
+ backend be = Parse_ODS_Backend (input_be, Entry);
231
+
232
+ // For each backend, we can have multiple targets, seperated by ','.
215
233
std::vector<std::string_view> Targets = tokenize (Pair[1 ], " ," );
216
234
for (auto TargetStr : Targets) {
217
235
ods_target DeviceTarget (be);
@@ -233,11 +251,6 @@ Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envString) {
233
251
Parse_ODS_Device (DeviceTarget, TargetStr);
234
252
Result.push_back (DeviceTarget);
235
253
}
236
- } else if (Pair.size () > 2 ) {
237
- std::stringstream ss;
238
- ss << " Error parsing selector string \" " << Entry
239
- << " \" Too many colons (:)" ;
240
- throw sycl::exception (sycl::make_error_code (errc::invalid), ss.str ());
241
254
}
242
255
}
243
256
0 commit comments