[llvm] [Liboffload] Add function for checking ELF file device compatibility (PR #156259)
Jonas Greifenhain via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 31 10:52:03 PDT 2025
https://github.com/cadivus updated https://github.com/llvm/llvm-project/pull/156259
>From 6b4653b4edc941720ec078dbb801a0824f1ac5f5 Mon Sep 17 00:00:00 2001
From: Jonas Greifenhain <cadivus at daverkomp.de>
Date: Mon, 4 Aug 2025 13:30:18 -0700
Subject: [PATCH] [Liboffload] Add function for checking device compatibility
---
offload/liboffload/API/Device.td | 24 ++++++++++++++++++++++++
offload/liboffload/src/OffloadImpl.cpp | 21 +++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/offload/liboffload/API/Device.td b/offload/liboffload/API/Device.td
index 5b54c79d83f9d..10931fa1ca807 100644
--- a/offload/liboffload/API/Device.td
+++ b/offload/liboffload/API/Device.td
@@ -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."
+ ]>
+ ];
+}
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index 7e8e297831f45..a93dc064e839c 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -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(
+ 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) {
More information about the llvm-commits
mailing list