Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,16 @@ piextDeviceSelectBinary(pi_device Device, // TODO: does this need to be context?
pi_device_binary *Binaries, pi_uint32 NumBinaries,
pi_uint32 *SelectedBinaryInd) {

// TODO dummy implementation.
assert(Device);
assert(SelectedBinaryInd);
assert(NumBinaries == 0 || Binaries);

// TODO: this is a bare-bones implementation for choosing a device image
// that would be compatible with the targeted device. An AOT-compiled
// image is preferred over SPIR-V for known devices (i.e. Intel devices)
// The implementation makes no effort to differentiate between multiple images
// for the given device, and simply picks the first one compatible.
//
// Real implementation will use the same mechanism OpenCL ICD dispatcher
// uses. Something like:
// PI_VALIDATE_HANDLE_RETURN_HANDLE(ctx, PI_INVALID_CONTEXT);
Expand All @@ -1450,9 +1459,28 @@ piextDeviceSelectBinary(pi_device Device, // TODO: does this need to be context?
// where context->dispatch is set to the dispatch table provided by PI
// plugin for platform/device the ctx was created for.

// Look for GEN binary, which we known can only be handled by Level-Zero now.
const char *BinaryTarget = PI_DEVICE_BINARY_TARGET_SPIRV64_GEN;

// Find the appropriate device image, fallback to spirv if not found
constexpr pi_uint32 InvalidInd = std::numeric_limits<pi_uint32>::max();
*SelectedBinaryInd = NumBinaries > 0 ? 0 : InvalidInd;
return PI_SUCCESS;
pi_uint32 Spirv = InvalidInd;

for (pi_uint32 i = 0; i < NumBinaries; ++i) {
if (strcmp(Binaries[i]->DeviceTargetSpec, BinaryTarget) == 0) {
*SelectedBinaryInd = i;
return PI_SUCCESS;
}
if (strcmp(Binaries[i]->DeviceTargetSpec,
PI_DEVICE_BINARY_TARGET_SPIRV64) == 0)
Spirv = i;
}
// Points to a spirv image, if such indeed was found
if ((*SelectedBinaryInd = Spirv) != InvalidInd)
return PI_SUCCESS;

// No image can be loaded for the given device
return PI_INVALID_BINARY;
}

pi_result piextDeviceGetNativeHandle(pi_device Device,
Expand Down