Skip to content

Commit aff799f

Browse files
committed
Incorporated code review comments
Signed-off-by: Gail Lyons <[email protected]>
1 parent dc5c005 commit aff799f

File tree

3 files changed

+158
-163
lines changed

3 files changed

+158
-163
lines changed

sycl/doc/EnvironmentVariables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ subject to change. Do not rely on these variables in production code.
2222
| SYCL_DISABLE_EXECUTION_GRAPH_CLEANUP | Any(\*) | Disable cleanup of finished command nodes at host-device synchronization points. |
2323
| SYCL_THROW_ON_BLOCK | Any(\*) | Throw an exception on attempt to wait for a blocked command. |
2424
| SYCL_DEVICELIB_INHIBIT_NATIVE | String of device library extensions (separated by a whitespace) | Do not rely on device native support for devicelib extensions listed in this option. |
25-
| SYCL_DEVICE_ALLOWLIST | A list of devices and their minimum driver version following the pattern: DeviceName:{{XXX}},DriverVersion:{{X.Y.Z.W}}. Also may contain PlatformName and PlatformVersion | Filter out devices that do not match the pattern specified. Regular expression can be passed and the DPC++ runtime will select only those devices which satisfy the regex. Note that the device name, platform name and their respective versions are regular expression. Special characters, such as parenthesis, must be escaped. |
25+
| SYCL_DEVICE_ALLOWLIST | A list of devices and their minimum driver version following the pattern: DeviceName:{{XXX}},DriverVersion:{{X.Y.Z.W}}. Also may contain PlatformName and PlatformVersion | Filter out devices that do not match the pattern specified. Regular expression can be passed and the DPC++ runtime will select only those devices which satisfy the regex. Note that the device name, platform name and platform version are regular expressions. Special characters, such as parenthesis, must be escaped. The device driver version is treated as 4 regular expressions, separated by ".". More than one device can be specified using "|".|
2626
| SYCL_QUEUE_THREAD_POOL_SIZE | Positive integer | Number of threads in thread pool of queue. |
2727
| SYCL_DEVICELIB_NO_FALLBACK | Any(\*) | Disable loading and linking of device library images |
2828
| SYCL_PI_LEVEL0_MAX_COMMAND_LIST_CACHE | Positive integer | Maximum number of oneAPI Level Zero Command lists that can be allocated with no reuse before throwing an "out of resources" error. Default is 20000, threshold may be increased based on resource availabilty and workload demand. |

sycl/source/detail/platform_impl.cpp

Lines changed: 128 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -121,173 +121,147 @@ vector_class<platform> platform_impl::get_platforms() {
121121
return Platforms;
122122
}
123123

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+
124147
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;
129152
};
130153

131154
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())
134157
return {};
135158

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++;
168172
}
169173
}
170174

171-
else if ((allowList.compare(pos, driverVersion.size(), driverVersion)) ==
175+
else if ((AllowList.compare(Pos, DriverVersion.size(), DriverVersion)) ==
172176
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++;
201181
}
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-
219182
}
220183

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++;
227188
}
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;
240189
}
241190

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++;
246199
}
247-
decDescs.emplace_back();
200+
DecDescs.emplace_back();
248201
}
249202

250203
else {
251204
throw sycl::runtime_error("Unrecognized key in device allowlist",
252205
PI_INVALID_VALUE);
253206
}
254-
} // while (pos <= allowList.size())
255-
return decDescs;
207+
} // while (Pos <= AllowList.size())
208+
return DecDescs;
256209
}
257210

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) {
264217
throw sycl::runtime_error("Malformed syntax in version string",
265218
PI_INVALID_VALUE);
266219
}
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) {
271224
throw sycl::runtime_error("Malformed syntax in version string",
272225
PI_INVALID_VALUE);
273226
}
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;
279238
}
280239

281240
enum MatchState { UNKNOWN, MATCH, NOMATCH };
282241

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()) {
289247
return MatchState::NOMATCH;
290248
}
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;
291265
}
292266

293267
static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
@@ -296,10 +270,10 @@ static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
296270
if (AllowList.empty())
297271
return;
298272

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;
303277

304278
const string_class PlatformName =
305279
sycl::detail::get_platform_info<string_class, info::platform::name>::get(
@@ -320,54 +294,54 @@ static void filterAllowList(vector_class<RT::PiDevice> &PiDevices,
320294
string_class, info::device::driver_version>::get(Device, Plugin);
321295

322296
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;
326300
continue;
327301
} else {
328-
platNameState = MatchState::MATCH;
302+
PlatNameState = MatchState::MATCH;
329303
}
330304
}
331305

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;
335309
continue;
336310
} else {
337-
platVerState = MatchState::MATCH;
311+
PlatVerState = MatchState::MATCH;
338312
}
339313
}
340314

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;
344318
continue;
345319
} else {
346-
devNameState = MatchState::MATCH;
320+
DevNameState = MatchState::MATCH;
347321
}
348322
}
349323

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) {
354328
continue;
355329
}
356330
} else {
357-
devVerState = MatchState::MATCH;
331+
DevVerState = MatchState::MATCH;
358332
}
359333
}
360334

361335
PiDevices[InsertIDx++] = Device;
362336
break;
363337
}
364338
}
365-
if (devNameState == MatchState::MATCH && devVerState == MatchState::NOMATCH) {
339+
if (DevNameState == MatchState::MATCH && DevVerState == MatchState::NOMATCH) {
366340
throw sycl::runtime_error("Requested SYCL device not found",
367341
PI_DEVICE_NOT_FOUND);
368342
}
369-
if (platNameState == MatchState::MATCH &&
370-
platVerState == MatchState::NOMATCH) {
343+
if (PlatNameState == MatchState::MATCH &&
344+
PlatVerState == MatchState::NOMATCH) {
371345
throw sycl::runtime_error("Requested SYCL platform not found",
372346
PI_DEVICE_NOT_FOUND);
373347
}

0 commit comments

Comments
 (0)