@@ -121,173 +121,147 @@ vector_class<platform> platform_impl::get_platforms() {
121
121
return Platforms;
122
122
}
123
123
124
+ std::string getValue (/* const*/ std::string &AllowList, size_t &Pos,
125
+ unsigned long int Size) {
126
+ size_t Prev = Pos;
127
+ if ((Pos = AllowList.find (" {{" , Pos)) == std::string::npos) {
128
+ throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
129
+ PI_INVALID_VALUE);
130
+ }
131
+ if (Pos > Prev + Size) {
132
+ throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
133
+ PI_INVALID_VALUE);
134
+ }
135
+
136
+ Pos = Pos + 2 ;
137
+ size_t Start = Pos;
138
+ if ((Pos = AllowList.find (" }}" , Pos)) == std::string::npos) {
139
+ throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
140
+ PI_INVALID_VALUE);
141
+ }
142
+ std::string Value = AllowList.substr (Start, Pos - Start);
143
+ Pos = Pos + 2 ;
144
+ return Value;
145
+ }
146
+
124
147
struct DevDescT {
125
- std::string devName ;
126
- std::string devDriverVer ;
127
- std::string platName ;
128
- std::string platVer ;
148
+ std::string DevName ;
149
+ std::string DevDriverVer ;
150
+ std::string PlatName ;
151
+ std::string PlatVer ;
129
152
};
130
153
131
154
static std::vector<DevDescT> getAllowListDesc () {
132
- std::string allowList (SYCLConfig<SYCL_DEVICE_ALLOWLIST>::get ());
133
- if (allowList .empty ())
155
+ std::string AllowList (SYCLConfig<SYCL_DEVICE_ALLOWLIST>::get ());
156
+ if (AllowList .empty ())
134
157
return {};
135
158
136
- std::string deviceName (" DeviceName:" );
137
- std::string driverVersion (" DriverVersion:" );
138
- std::string platformName (" PlatformName:" );
139
- std::string platformVersion (" PlatformVersion:" );
140
- std::vector<DevDescT> decDescs;
141
- decDescs.emplace_back ();
142
-
143
- size_t pos = 0 ;
144
- size_t prev = pos;
145
- while (pos < allowList.size ()) {
146
- if ((allowList.compare (pos, deviceName.size (), deviceName)) == 0 ) {
147
- prev = pos;
148
- if ((pos = allowList.find (" {{" , pos)) == std::string::npos) {
149
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
150
- PI_INVALID_VALUE);
151
- }
152
- if (pos > prev + deviceName.size ()) {
153
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
154
- PI_INVALID_VALUE);
155
- }
156
-
157
- pos = pos + 2 ;
158
- size_t start = pos;
159
- if ((pos = allowList.find (" }}" , pos)) == std::string::npos) {
160
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
161
- PI_INVALID_VALUE);
162
- }
163
- decDescs.back ().devName = allowList.substr (start, pos - start);
164
- pos = pos + 2 ;
165
-
166
- if (allowList[pos] == ' ,' ) {
167
- pos++;
159
+ std::string DeviceName (" DeviceName:" );
160
+ std::string DriverVersion (" DriverVersion:" );
161
+ std::string PlatformName (" PlatformName:" );
162
+ std::string PlatformVersion (" PlatformVersion:" );
163
+ std::vector<DevDescT> DecDescs;
164
+ DecDescs.emplace_back ();
165
+
166
+ size_t Pos = 0 ;
167
+ while (Pos < AllowList.size ()) {
168
+ if ((AllowList.compare (Pos, DeviceName.size (), DeviceName)) == 0 ) {
169
+ DecDescs.back ().DevName = getValue (AllowList, Pos, DeviceName.size ());
170
+ if (AllowList[Pos] == ' ,' ) {
171
+ Pos++;
168
172
}
169
173
}
170
174
171
- else if ((allowList .compare (pos, driverVersion .size (), driverVersion )) ==
175
+ else if ((AllowList .compare (Pos, DriverVersion .size (), DriverVersion )) ==
172
176
0 ) {
173
- prev = pos;
174
- if ((pos = allowList.find (" {{" , pos)) == std::string::npos) {
175
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
176
- PI_INVALID_VALUE);
177
- }
178
- if (pos > prev + driverVersion.size ()) {
179
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
180
- PI_INVALID_VALUE);
181
- }
182
-
183
- size_t start = pos + 2 ;
184
- if ((pos = allowList.find (" }}" , pos)) == std::string::npos) {
185
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
186
- PI_INVALID_VALUE);
187
- }
188
- decDescs.back ().devDriverVer = allowList.substr (start, pos - start);
189
- pos = pos + 2 ;
190
-
191
- if (allowList[pos] == ' ,' ) {
192
- pos++;
193
- }
194
- }
195
-
196
- else if ((allowList.compare (pos, platformName.size (), platformName)) == 0 ) {
197
- prev = pos;
198
- if ((pos = allowList.find (" {{" , pos)) == std::string::npos) {
199
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
200
- PI_INVALID_VALUE);
177
+ DecDescs.back ().DevDriverVer =
178
+ getValue (AllowList, Pos, DriverVersion.size ());
179
+ if (AllowList[Pos] == ' ,' ) {
180
+ Pos++;
201
181
}
202
- if (pos > prev + platformName.size ()) {
203
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
204
- PI_INVALID_VALUE);
205
- }
206
-
207
- size_t start = pos + 2 ;
208
- if ((pos = allowList.find (" }}" , pos)) == std::string::npos) {
209
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
210
- PI_INVALID_VALUE);
211
- }
212
- decDescs.back ().platName = allowList.substr (start, pos - start);
213
- pos = pos + 2 ;
214
-
215
- if (allowList[pos] == ' ,' ) {
216
- pos++;
217
- }
218
-
219
182
}
220
183
221
- else if ((allowList.compare (pos, platformVersion.size (),
222
- platformVersion)) == 0 ) {
223
- prev = pos;
224
- if ((pos = allowList.find (" {{" , pos)) == std::string::npos) {
225
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
226
- PI_INVALID_VALUE);
184
+ else if ((AllowList.compare (Pos, PlatformName.size (), PlatformName)) == 0 ) {
185
+ DecDescs.back ().PlatName = getValue (AllowList, Pos, PlatformName.size ());
186
+ if (AllowList[Pos] == ' ,' ) {
187
+ Pos++;
227
188
}
228
- if (pos > prev + platformVersion.size ()) {
229
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
230
- PI_INVALID_VALUE);
231
- }
232
-
233
- size_t start = pos + 2 ;
234
- if ((pos = allowList.find (" }}" , pos)) == std::string::npos) {
235
- throw sycl::runtime_error (" Malformed syntax in SYCL_DEVICE_ALLOWLIST" ,
236
- PI_INVALID_VALUE);
237
- }
238
- decDescs.back ().platVer = allowList.substr (start, pos - start);
239
- pos = pos + 2 ;
240
189
}
241
190
242
- else if (allowList.find (' |' , pos) != std::string::npos) {
243
- pos = allowList.find (' |' ) + 1 ;
244
- while (allowList[pos] == ' ' ) {
245
- pos++;
191
+ else if ((AllowList.compare (Pos, PlatformVersion.size (),
192
+ PlatformVersion)) == 0 ) {
193
+ DecDescs.back ().PlatVer =
194
+ getValue (AllowList, Pos, PlatformVersion.size ());
195
+ } else if (AllowList.find (' |' , Pos) != std::string::npos) {
196
+ Pos = AllowList.find (' |' ) + 1 ;
197
+ while (AllowList[Pos] == ' ' ) {
198
+ Pos++;
246
199
}
247
- decDescs .emplace_back ();
200
+ DecDescs .emplace_back ();
248
201
}
249
202
250
203
else {
251
204
throw sycl::runtime_error (" Unrecognized key in device allowlist" ,
252
205
PI_INVALID_VALUE);
253
206
}
254
- } // while (pos <= allowList .size())
255
- return decDescs ;
207
+ } // while (Pos <= AllowList .size())
208
+ return DecDescs ;
256
209
}
257
210
258
- std::vector<int > convertVersionString (std::string version ) {
259
- // version string format is xx.yy.zzzzz
260
- std::vector<int > values ;
261
- size_t pos = 0 ;
262
- size_t start = pos ;
263
- if ((pos = version .find (" ." , pos )) == std::string::npos) {
211
+ std::vector<int > convertVersionString (std::string Version ) {
212
+ // version string format is xx.yy.zzzzz.ww WW is optional
213
+ std::vector<int > Values ;
214
+ size_t Pos = 0 ;
215
+ size_t Start = Pos ;
216
+ if ((Pos = Version .find (" ." , Pos )) == std::string::npos) {
264
217
throw sycl::runtime_error (" Malformed syntax in version string" ,
265
218
PI_INVALID_VALUE);
266
219
}
267
- values .push_back (std::stoi (version .substr (start, pos )));
268
- pos ++;
269
- start = pos ;
270
- if ((pos = version .find (" ." , pos )) == std::string::npos) {
220
+ Values .push_back (std::stoi (Version .substr (Start, Pos - Start )));
221
+ Pos ++;
222
+ Start = Pos ;
223
+ if ((Pos = Version .find (" ." , Pos )) == std::string::npos) {
271
224
throw sycl::runtime_error (" Malformed syntax in version string" ,
272
225
PI_INVALID_VALUE);
273
226
}
274
- values.push_back (std::stoi (version.substr (start, pos)));
275
- pos++;
276
- values.push_back (std::stoi (version.substr (pos)));
277
-
278
- return values;
227
+ Values.push_back (std::stoi (Version.substr (Start, Pos - Start)));
228
+ Pos++;
229
+ size_t Prev = Pos;
230
+ if ((Pos = Version.find (" ." , Pos)) == std::string::npos) {
231
+ Values.push_back (std::stoi (Version.substr (Prev)));
232
+ } else {
233
+ Values.push_back (std::stoi (Version.substr (Start, Pos - Start)));
234
+ Pos++;
235
+ Values.push_back (std::stoi (Version.substr (Pos)));
236
+ }
237
+ return Values;
279
238
}
280
239
281
240
enum MatchState { UNKNOWN, MATCH, NOMATCH };
282
241
283
- MatchState matchVersions (std::string version1, std::string version2) {
284
- std::vector<int > v1 = convertVersionString (version1);
285
- std::vector<int > v2 = convertVersionString (version2);
286
- if (v1[0 ] >= v2[0 ] && v1[1 ] >= v2[1 ] && v1[2 ] >= v2[2 ]) {
287
- return MatchState::MATCH;
288
- } else {
242
+ MatchState matchVersions (std::string Version1, std::string Version2) {
243
+ std::vector<int > V1 = convertVersionString (Version1);
244
+ std::vector<int > V2 = convertVersionString (Version2);
245
+
246
+ if (V1.size () != V2.size ()) {
289
247
return MatchState::NOMATCH;
290
248
}
249
+ if (V1[0 ] > V2[0 ]) {
250
+ return MatchState::MATCH;
251
+ }
252
+ if ((V1[0 ] == V2[0 ]) && (V1[1 ] >= V2[1 ])) {
253
+ return MatchState::MATCH;
254
+ }
255
+ if ((V1[0 ] == V2[0 ]) && (V1[1 ] == V2[1 ]) && (V1[2 ] >= V2[2 ])) {
256
+ return MatchState::MATCH;
257
+ }
258
+ if (V1.size () == 4 ) {
259
+ if ((V1[0 ] == V2[0 ]) && (V1[1 ] == V2[1 ]) && (V1[2 ] == V2[2 ]) &&
260
+ (V1[3 ] >= V2[3 ])) {
261
+ return MatchState::MATCH;
262
+ }
263
+ }
264
+ return MatchState::NOMATCH;
291
265
}
292
266
293
267
static void filterAllowList (vector_class<RT::PiDevice> &PiDevices,
@@ -296,10 +270,10 @@ static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
296
270
if (AllowList.empty ())
297
271
return ;
298
272
299
- MatchState devNameState = UNKNOWN;
300
- MatchState devVerState = UNKNOWN;
301
- MatchState platNameState = UNKNOWN;
302
- MatchState platVerState = UNKNOWN;
273
+ MatchState DevNameState = UNKNOWN;
274
+ MatchState DevVerState = UNKNOWN;
275
+ MatchState PlatNameState = UNKNOWN;
276
+ MatchState PlatVerState = UNKNOWN;
303
277
304
278
const string_class PlatformName =
305
279
sycl::detail::get_platform_info<string_class, info::platform::name>::get (
@@ -320,54 +294,54 @@ static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
320
294
string_class, info::device::driver_version>::get (Device, Plugin);
321
295
322
296
for (const DevDescT &Desc : AllowList) {
323
- if (!Desc.platName .empty ()) {
324
- if (!std::regex_match (PlatformName, std::regex (Desc.platName ))) {
325
- platNameState = MatchState::NOMATCH;
297
+ if (!Desc.PlatName .empty ()) {
298
+ if (!std::regex_match (PlatformName, std::regex (Desc.PlatName ))) {
299
+ PlatNameState = MatchState::NOMATCH;
326
300
continue ;
327
301
} else {
328
- platNameState = MatchState::MATCH;
302
+ PlatNameState = MatchState::MATCH;
329
303
}
330
304
}
331
305
332
- if (!Desc.platVer .empty ()) {
333
- if (!std::regex_match (PlatformVer, std::regex (Desc.platVer ))) {
334
- platVerState = MatchState::NOMATCH;
306
+ if (!Desc.PlatVer .empty ()) {
307
+ if (!std::regex_match (PlatformVer, std::regex (Desc.PlatVer ))) {
308
+ PlatVerState = MatchState::NOMATCH;
335
309
continue ;
336
310
} else {
337
- platVerState = MatchState::MATCH;
311
+ PlatVerState = MatchState::MATCH;
338
312
}
339
313
}
340
314
341
- if (!Desc.devName .empty ()) {
342
- if (!std::regex_match (DeviceName, std::regex (Desc.devName ))) {
343
- devNameState = MatchState::NOMATCH;
315
+ if (!Desc.DevName .empty ()) {
316
+ if (!std::regex_match (DeviceName, std::regex (Desc.DevName ))) {
317
+ DevNameState = MatchState::NOMATCH;
344
318
continue ;
345
319
} else {
346
- devNameState = MatchState::MATCH;
320
+ DevNameState = MatchState::MATCH;
347
321
}
348
322
}
349
323
350
- if (!Desc.devDriverVer .empty ()) {
351
- if (!std::regex_match (DeviceDriverVer, std::regex (Desc.devDriverVer ))) {
352
- devVerState = matchVersions (DeviceDriverVer, Desc.devDriverVer );
353
- if (devVerState == MatchState::NOMATCH) {
324
+ if (!Desc.DevDriverVer .empty ()) {
325
+ if (!std::regex_match (DeviceDriverVer, std::regex (Desc.DevDriverVer ))) {
326
+ DevVerState = matchVersions (DeviceDriverVer, Desc.DevDriverVer );
327
+ if (DevVerState == MatchState::NOMATCH) {
354
328
continue ;
355
329
}
356
330
} else {
357
- devVerState = MatchState::MATCH;
331
+ DevVerState = MatchState::MATCH;
358
332
}
359
333
}
360
334
361
335
PiDevices[InsertIDx++] = Device;
362
336
break ;
363
337
}
364
338
}
365
- if (devNameState == MatchState::MATCH && devVerState == MatchState::NOMATCH) {
339
+ if (DevNameState == MatchState::MATCH && DevVerState == MatchState::NOMATCH) {
366
340
throw sycl::runtime_error (" Requested SYCL device not found" ,
367
341
PI_DEVICE_NOT_FOUND);
368
342
}
369
- if (platNameState == MatchState::MATCH &&
370
- platVerState == MatchState::NOMATCH) {
343
+ if (PlatNameState == MatchState::MATCH &&
344
+ PlatVerState == MatchState::NOMATCH) {
371
345
throw sycl::runtime_error (" Requested SYCL platform not found" ,
372
346
PI_DEVICE_NOT_FOUND);
373
347
}
0 commit comments