@@ -228,16 +228,13 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
228
228
ReturnHelper ReturnValue (PropSize, PropValue, PropSizeRet);
229
229
230
230
// Find the info if it exists under any of the given names
231
- auto GetInfo = [&](std::vector<std::string> Names) {
232
- InfoQueueTy DevInfo;
233
- if (Device == HostDevice ())
234
- return std::string (" Host" );
235
-
231
+ auto FindInfo = [&](InfoQueueTy &DevInfo, std::vector<std::string> &Names)
232
+ -> std::optional<decltype (DevInfo.getQueue ().begin ())> {
236
233
if (!Device->Device )
237
- return std::string ( " " ) ;
234
+ return std::nullopt ;
238
235
239
236
if (auto Err = Device->Device ->obtainInfoImpl (DevInfo))
240
- return std::string ( " " ) ;
237
+ return std::nullopt ;
241
238
242
239
for (auto Name : Names) {
243
240
auto InfoKeyMatches = [&](const InfoQueueTy::InfoQueueEntryTy &Info) {
@@ -247,11 +244,50 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
247
244
DevInfo.getQueue ().end (), InfoKeyMatches);
248
245
249
246
if (Item != std::end (DevInfo.getQueue ())) {
250
- return Item-> Value ;
247
+ return Item;
251
248
}
252
249
}
253
250
254
- return std::string (" " );
251
+ return std::nullopt;
252
+ };
253
+ auto GetInfoString = [&](std::vector<std::string> Names) {
254
+ InfoQueueTy DevInfo;
255
+
256
+ if (auto Item = FindInfo (DevInfo, Names)) {
257
+ return (*Item)->Value .c_str ();
258
+ } else {
259
+ return " " ;
260
+ }
261
+ };
262
+ auto GetInfoXyz = [&](std::vector<std::string> Names) {
263
+ InfoQueueTy DevInfo;
264
+
265
+ if (auto Item = FindInfo (DevInfo, Names)) {
266
+ auto Iter = *Item;
267
+ ol_dimensions_t Out{0 , 0 , 0 };
268
+ auto Level = Iter->Level + 1 ;
269
+
270
+ while ((++Iter)->Level == Level) {
271
+ switch (Iter->Key [0 ]) {
272
+ case ' x' :
273
+ Out.x = std::stoi (Iter->Value );
274
+ break ;
275
+ case ' y' :
276
+ Out.y = std::stoi (Iter->Value );
277
+ break ;
278
+ case ' z' :
279
+ Out.z = std::stoi (Iter->Value );
280
+ break ;
281
+ default :
282
+ // Ignore any extra values
283
+ (void )0 ;
284
+ }
285
+ }
286
+
287
+ return Out;
288
+ } else {
289
+ return ol_dimensions_t {0 , 0 , 0 };
290
+ }
255
291
};
256
292
257
293
switch (PropName) {
@@ -261,12 +297,21 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
261
297
return Device == HostDevice () ? ReturnValue (OL_DEVICE_TYPE_HOST)
262
298
: ReturnValue (OL_DEVICE_TYPE_GPU);
263
299
case OL_DEVICE_INFO_NAME:
264
- return ReturnValue (GetInfo ({" Device Name" }).c_str ());
300
+ if (Device == HostDevice ())
301
+ return ReturnValue (" Host" );
302
+ return ReturnValue (GetInfoString ({" Device Name" }));
265
303
case OL_DEVICE_INFO_VENDOR:
266
- return ReturnValue (GetInfo ({" Vendor Name" }).c_str ());
304
+ if (Device == HostDevice ())
305
+ return ReturnValue (" Host" );
306
+ return ReturnValue (GetInfoString ({" Vendor Name" }));
267
307
case OL_DEVICE_INFO_DRIVER_VERSION:
308
+ if (Device == HostDevice ())
309
+ return ReturnValue (" Host" );
268
310
return ReturnValue (
269
- GetInfo ({" CUDA Driver Version" , " HSA Runtime Version" }).c_str ());
311
+ GetInfoString ({" CUDA Driver Version" , " HSA Runtime Version" }));
312
+ case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE:
313
+ return ReturnValue (GetInfoXyz ({" Workgroup Max Size per Dimension" /* AMD*/ ,
314
+ " Maximum Block Dimensions" /* CUDA*/ }));
270
315
default :
271
316
return createOffloadError (ErrorCode::INVALID_ENUMERATION,
272
317
" getDeviceInfo enum '%i' is invalid" , PropName);
0 commit comments