[llvm] [OFFLOAD] Add support for host offloading device (PR #171010)

via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 6 20:19:30 PST 2025


https://github.com/fineg74 created https://github.com/llvm/llvm-project/pull/171010

Add missing host liboffload API for libomptarget migration

OpenMP supports host as an offloading target and therefore liboffload should also support offloading to host
This PR adds host API that needed to make libomptarget to use liboffload

>From 8fb7fb823baa1f07b59fdd35256248eeafb19196 Mon Sep 17 00:00:00 2001
From: "Fine, Gregory" <gregory.fine at intel.com>
Date: Fri, 21 Nov 2025 18:35:24 -0800
Subject: [PATCH] Add support for host offloading device

---
 offload/liboffload/API/Device.td       |  9 +++++++++
 offload/liboffload/src/OffloadImpl.cpp | 10 ++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/offload/liboffload/API/Device.td b/offload/liboffload/API/Device.td
index 6ada191089674..79ad077b945e2 100644
--- a/offload/liboffload/API/Device.td
+++ b/offload/liboffload/API/Device.td
@@ -131,3 +131,12 @@ def olGetDeviceInfoSize : Function {
     Return<"OL_ERRC_INVALID_DEVICE">
   ];
 }
+
+def olGetHostDevice : Function {
+  let desc = "Returns the host device.";
+  let details = [];
+  let params = [
+    Param<"ol_device_handle_t*", "Device", "handle of the device instance", PARAM_OUT>,
+  ];
+  let returns = [];
+}
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index eab9627217ca8..0765949280b04 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -263,6 +263,8 @@ constexpr ol_platform_backend_t pluginNameToBackend(StringRef Name) {
     return OL_PLATFORM_BACKEND_AMDGPU;
   } else if (Name == "cuda") {
     return OL_PLATFORM_BACKEND_CUDA;
+  } else if (Name == "host") {
+    return OL_PLATFORM_BACKEND_HOST;
   } else {
     return OL_PLATFORM_BACKEND_UNKNOWN;
   }
@@ -276,7 +278,6 @@ Error initPlugins(OffloadContext &Context) {
   // Attempt to create an instance of each supported plugin.
 #define PLUGIN_TARGET(Name)                                                    \
   do {                                                                         \
-    if (StringRef(#Name) != "host")                                            \
       Context.Platforms.emplace_back(std::make_unique<ol_platform_impl_t>(     \
           std::unique_ptr<GenericPluginTy>(createPlugin_##Name()),             \
           pluginNameToBackend(#Name)));                                        \
@@ -349,7 +350,7 @@ Error olGetPlatformInfoImplDetail(ol_platform_handle_t Platform,
                                   ol_platform_info_t PropName, size_t PropSize,
                                   void *PropValue, size_t *PropSizeRet) {
   InfoWriter Info(PropSize, PropValue, PropSizeRet);
-  bool IsHost = Platform->BackendType == OL_PLATFORM_BACKEND_HOST;
+  bool IsHost = Platform->Plugin == nullptr;
 
   // Note that the plugin is potentially uninitialized here. It will need to be
   // initialized once info is added that requires it to be initialized.
@@ -1214,5 +1215,10 @@ Error olLaunchHostFunction_impl(ol_queue_handle_t Queue,
                                                 Queue->AsyncInfo);
 }
 
+Error olGetHostDevice_impl(ol_device_handle_t *Device) {
+  *Device = OffloadContext::get().HostDevice;
+  return Error::success();
+}
+
 } // namespace offload
 } // namespace llvm



More information about the llvm-commits mailing list