[llvm] [Offload] Refactor device/platform info queries (PR #146345)

Ross Brunton via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 30 06:00:38 PDT 2025


================
@@ -315,14 +322,45 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
   return Error::success();
 }
 
+Error olGetDeviceInfoImplDetailHost(ol_device_handle_t Device,
+                                    ol_device_info_t PropName, size_t PropSize,
+                                    void *PropValue, size_t *PropSizeRet) {
+  assert(Device == OffloadContext::get().HostDevice());
+  InfoWriter Info(PropSize, PropValue, PropSizeRet);
+
+  switch (PropName) {
+  case OL_DEVICE_INFO_PLATFORM:
+    return Info.Write<void *>(Device->Platform);
+  case OL_DEVICE_INFO_TYPE:
+    return Info.Write<ol_device_type_t>(OL_DEVICE_TYPE_HOST);
+  case OL_DEVICE_INFO_NAME:
+    return Info.WriteString("Virtual Host Device");
+  case OL_DEVICE_INFO_VENDOR:
+    return Info.WriteString("Liboffload");
+  case OL_DEVICE_INFO_DRIVER_VERSION:
+    return Info.WriteString(LLVM_VERSION_STRING);
+  default:
+    return createOffloadError(ErrorCode::INVALID_ENUMERATION,
+                              "getDeviceInfo enum '%i' is invalid", PropName);
+  }
+
+  return Error::success();
+}
+
 Error olGetDeviceInfo_impl(ol_device_handle_t Device, ol_device_info_t PropName,
                            size_t PropSize, void *PropValue) {
+  if (Device == OffloadContext::get().HostDevice())
+    return olGetDeviceInfoImplDetailHost(Device, PropName, PropSize, PropValue,
+                                         nullptr);
----------------
RossBrunton wrote:

Since the device info is now stored in the device handle itself, I wonder if the host device can just create its own tree and use that with the regular methods. It would mean it can go down the same code path as "real" devices, but on the other hand, that's a lot of pointer gymnastics.

https://github.com/llvm/llvm-project/pull/146345


More information about the llvm-commits mailing list