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

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 10 13:51:05 PST 2025


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

>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 1/2] 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

>From dc8f4748025bfd68c5bc7886f772b80e60c69a7d Mon Sep 17 00:00:00 2001
From: "Fine, Gregory" <gregory.fine at intel.com>
Date: Wed, 10 Dec 2025 13:50:55 -0800
Subject: [PATCH 2/2] Fix formatting issues

---
 offload/liboffload/src/OffloadImpl.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index 0765949280b04..0766b235e1451 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -278,9 +278,9 @@ Error initPlugins(OffloadContext &Context) {
   // Attempt to create an instance of each supported plugin.
 #define PLUGIN_TARGET(Name)                                                    \
   do {                                                                         \
-      Context.Platforms.emplace_back(std::make_unique<ol_platform_impl_t>(     \
-          std::unique_ptr<GenericPluginTy>(createPlugin_##Name()),             \
-          pluginNameToBackend(#Name)));                                        \
+    Context.Platforms.emplace_back(std::make_unique<ol_platform_impl_t>(       \
+        std::unique_ptr<GenericPluginTy>(createPlugin_##Name()),               \
+        pluginNameToBackend(#Name)));                                          \
   } while (false);
 #include "Shared/Targets.def"
 



More information about the llvm-commits mailing list