Skip to content

Commit 614943f

Browse files
committed
[Liboffload] Add function for checking device compatibility
1 parent b1d2c62 commit 614943f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

offload/liboffload/API/Device.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,27 @@ def olGetDeviceInfoSize : Function {
129129
Return<"OL_ERRC_INVALID_DEVICE">
130130
];
131131
}
132+
133+
def olElfIsCompatibleWithDevice : Function {
134+
let desc = "Checks if the given ELF binary is compatible with the specified device.";
135+
let details = [
136+
"This function determines whether an ELF image can be executed on the specified device."
137+
];
138+
let params = [
139+
Param<"ol_device_handle_t", "Device", "handle of the device to check against", PARAM_IN>,
140+
Param<"const void*", "ElfData", "pointer to the ELF image data in memory", PARAM_IN>,
141+
Param<"size_t", "ElfSize", "size in bytes of the ELF image", PARAM_IN>,
142+
Param<"bool*", "IsCompatible", "set to true if the ELF is compatible, false otherwise", PARAM_OUT>
143+
];
144+
let returns = [
145+
Return<"OL_ERRC_INVALID_DEVICE", [
146+
"If the provided device handle is invalid."
147+
]>,
148+
Return<"OL_ERRC_INVALID_ARGUMENT", [
149+
"If `ElfData` is null or `ElfSize` is zero."
150+
]>,
151+
Return<"OL_ERRC_NULL_POINTER", [
152+
"If `IsCompatible` is null."
153+
]>
154+
];
155+
}

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,27 @@ Error olGetDeviceInfoSize_impl(ol_device_handle_t Device,
592592
return olGetDeviceInfoImplDetail(Device, PropName, 0, nullptr, PropSizeRet);
593593
}
594594

595+
Error olElfIsCompatibleWithDevice_impl(ol_device_handle_t Device,
596+
const void *ElfData, size_t ElfSize,
597+
bool *IsCompatible) {
598+
GenericDeviceTy *DeviceTy = Device->Device;
599+
int32_t DeviceId = DeviceTy->getDeviceId();
600+
GenericPluginTy &DevicePlugin = DeviceTy->Plugin;
601+
602+
StringRef Image(reinterpret_cast<const char *>(ElfData), ElfSize);
603+
604+
Expected<bool> ResultOrErr = DevicePlugin.isELFCompatible(DeviceId, Image);
605+
if (!ResultOrErr) {
606+
consumeError(ResultOrErr.takeError());
607+
return createOffloadError(
608+
ErrorCode::INVALID_ARGUMENT,
609+
"elf compatibility can not be checked for device");
610+
}
611+
612+
*IsCompatible = *ResultOrErr;
613+
return Error::success();
614+
}
615+
595616
Error olIterateDevices_impl(ol_device_iterate_cb_t Callback, void *UserData) {
596617
for (auto &Platform : OffloadContext::get().Platforms) {
597618
for (auto &Device : Platform.Devices) {

0 commit comments

Comments
 (0)