@@ -1441,7 +1441,16 @@ piextDeviceSelectBinary(pi_device Device, // TODO: does this need to be context?
1441
1441
pi_device_binary *Binaries, pi_uint32 NumBinaries,
1442
1442
pi_uint32 *SelectedBinaryInd) {
1443
1443
1444
- // TODO dummy implementation.
1444
+ assert (Device);
1445
+ assert (SelectedBinaryInd);
1446
+ assert (NumBinaries == 0 || Binaries);
1447
+
1448
+ // TODO: this is a bare-bones implementation for choosing a device image
1449
+ // that would be compatible with the targeted device. An AOT-compiled
1450
+ // image is preferred over SPIR-V for known devices (i.e. Intel devices)
1451
+ // The implementation makes no effort to differentiate between multiple images
1452
+ // for the given device, and simply picks the first one compatible.
1453
+ //
1445
1454
// Real implementation will use the same mechanism OpenCL ICD dispatcher
1446
1455
// uses. Something like:
1447
1456
// PI_VALIDATE_HANDLE_RETURN_HANDLE(ctx, PI_INVALID_CONTEXT);
@@ -1450,9 +1459,28 @@ piextDeviceSelectBinary(pi_device Device, // TODO: does this need to be context?
1450
1459
// where context->dispatch is set to the dispatch table provided by PI
1451
1460
// plugin for platform/device the ctx was created for.
1452
1461
1462
+ // Look for GEN binary, which we known can only be handled by Level-Zero now.
1463
+ const char *BinaryTarget = PI_DEVICE_BINARY_TARGET_SPIRV64_GEN;
1464
+
1465
+ // Find the appropriate device image, fallback to spirv if not found
1453
1466
constexpr pi_uint32 InvalidInd = std::numeric_limits<pi_uint32>::max ();
1454
- *SelectedBinaryInd = NumBinaries > 0 ? 0 : InvalidInd;
1455
- return PI_SUCCESS;
1467
+ pi_uint32 Spirv = InvalidInd;
1468
+
1469
+ for (pi_uint32 i = 0 ; i < NumBinaries; ++i) {
1470
+ if (strcmp (Binaries[i]->DeviceTargetSpec , BinaryTarget) == 0 ) {
1471
+ *SelectedBinaryInd = i;
1472
+ return PI_SUCCESS;
1473
+ }
1474
+ if (strcmp (Binaries[i]->DeviceTargetSpec ,
1475
+ PI_DEVICE_BINARY_TARGET_SPIRV64) == 0 )
1476
+ Spirv = i;
1477
+ }
1478
+ // Points to a spirv image, if such indeed was found
1479
+ if ((*SelectedBinaryInd = Spirv) != InvalidInd)
1480
+ return PI_SUCCESS;
1481
+
1482
+ // No image can be loaded for the given device
1483
+ return PI_INVALID_BINARY;
1456
1484
}
1457
1485
1458
1486
pi_result piextDeviceGetNativeHandle (pi_device Device,
0 commit comments