Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions offload/liboffload/API/Device.td
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,27 @@ def olGetDeviceInfoSize : Function {
Return<"OL_ERRC_INVALID_DEVICE">
];
}

def olElfIsCompatibleWithDevice : Function {
let desc = "Checks if the given ELF binary is compatible with the specified device.";
let details = [
"This function determines whether an ELF image can be executed on the specified device."
];
let params = [
Param<"ol_device_handle_t", "Device", "handle of the device to check against", PARAM_IN>,
Param<"const void*", "ElfData", "pointer to the ELF image data in memory", PARAM_IN>,
Param<"size_t", "ElfSize", "size in bytes of the ELF image", PARAM_IN>,
Param<"bool*", "IsCompatible", "set to true if the ELF is compatible, false otherwise", PARAM_OUT>
];
let returns = [
Return<"OL_ERRC_INVALID_DEVICE", [
"If the provided device handle is invalid."
]>,
Return<"OL_ERRC_INVALID_ARGUMENT", [
"If `ElfData` is null or `ElfSize` is zero."
]>,
Return<"OL_ERRC_NULL_POINTER", [
"If `IsCompatible` is null."
]>
];
}
21 changes: 21 additions & 0 deletions offload/liboffload/src/OffloadImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,27 @@ Error olGetDeviceInfoSize_impl(ol_device_handle_t Device,
return olGetDeviceInfoImplDetail(Device, PropName, 0, nullptr, PropSizeRet);
}

Error olElfIsCompatibleWithDevice_impl(ol_device_handle_t Device,
const void *ElfData, size_t ElfSize,
bool *IsCompatible) {
GenericDeviceTy *DeviceTy = Device->Device;
int32_t DeviceId = DeviceTy->getDeviceId();
GenericPluginTy &DevicePlugin = DeviceTy->Plugin;

StringRef Image(reinterpret_cast<const char *>(ElfData), ElfSize);

Expected<bool> ResultOrErr = DevicePlugin.isELFCompatible(DeviceId, Image);
if (!ResultOrErr) {
consumeError(ResultOrErr.takeError());
return createOffloadError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createOffloadError has an overload which allows it to accept another error.

ErrorCode::INVALID_ARGUMENT,
"elf compatibility can not be checked for device");
}

*IsCompatible = *ResultOrErr;
return Error::success();
}

Error olIterateDevices_impl(ol_device_iterate_cb_t Callback, void *UserData) {
for (auto &Platform : OffloadContext::get().Platforms) {
for (auto &Device : Platform.Devices) {
Expand Down
Loading