Skip to content

[Offload] Add specifier for the host type #141635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged

[Offload] Add specifier for the host type #141635

merged 1 commit into from
May 28, 2025

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented May 27, 2025

Summary:
We use this sepcial type to indicate a host value, this will be refined
later but for now it's used as a stand-in device for transfers and
queues. It needs a special kind because it is not a device target as the
other ones so we need to differentiate it between a CPU and GPU type.

Fixes: #141436

Summary:
We use this sepcial type to indicate a host value, this will be refined
later but for now it's used as a stand-in device for transfers and
queues. It needs a special kind because it is not a device target as the
other ones so we need to differentiate it between a CPU and GPU type.

Fixes: llvm#141436
@jhuber6
Copy link
Contributor Author

jhuber6 commented May 27, 2025

@callumfare you should apply for access.

@llvmbot
Copy link
Member

llvmbot commented May 27, 2025

@llvm/pr-subscribers-offload

Author: Joseph Huber (jhuber6)

Changes

Summary:
We use this sepcial type to indicate a host value, this will be refined
later but for now it's used as a stand-in device for transfers and
queues. It needs a special kind because it is not a device target as the
other ones so we need to differentiate it between a CPU and GPU type.

Fixes: #141436


Full diff: https://github.com/llvm/llvm-project/pull/141635.diff

5 Files Affected:

  • (modified) offload/liboffload/API/Device.td (+1)
  • (modified) offload/liboffload/include/generated/OffloadAPI.h (+2)
  • (modified) offload/liboffload/include/generated/OffloadPrint.hpp (+3)
  • (modified) offload/liboffload/src/OffloadImpl.cpp (+2-1)
  • (modified) offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp (+7)
diff --git a/offload/liboffload/API/Device.td b/offload/liboffload/API/Device.td
index 28c96bb5d2910..4abc24f3ba27f 100644
--- a/offload/liboffload/API/Device.td
+++ b/offload/liboffload/API/Device.td
@@ -18,6 +18,7 @@ def : Enum {
     Etor<"ALL", "Devices of all types">,
     Etor<"GPU", "GPU device type">,
     Etor<"CPU", "CPU device type">,
+    Etor<"Host", "Host device type">,
   ];
 }
 
diff --git a/offload/liboffload/include/generated/OffloadAPI.h b/offload/liboffload/include/generated/OffloadAPI.h
index f7ec749f6efa3..a1d7540519e32 100644
--- a/offload/liboffload/include/generated/OffloadAPI.h
+++ b/offload/liboffload/include/generated/OffloadAPI.h
@@ -320,6 +320,8 @@ typedef enum ol_device_type_t {
   OL_DEVICE_TYPE_GPU = 2,
   /// CPU device type
   OL_DEVICE_TYPE_CPU = 3,
+  /// Host device type
+  OL_DEVICE_TYPE_HOST = 4,
   /// @cond
   OL_DEVICE_TYPE_FORCE_UINT32 = 0x7fffffff
   /// @endcond
diff --git a/offload/liboffload/include/generated/OffloadPrint.hpp b/offload/liboffload/include/generated/OffloadPrint.hpp
index 9b916543eec0d..3aad6223d4dea 100644
--- a/offload/liboffload/include/generated/OffloadPrint.hpp
+++ b/offload/liboffload/include/generated/OffloadPrint.hpp
@@ -224,6 +224,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
   case OL_DEVICE_TYPE_CPU:
     os << "OL_DEVICE_TYPE_CPU";
     break;
+  case OL_DEVICE_TYPE_HOST:
+    os << "OL_DEVICE_TYPE_HOST";
+    break;
   default:
     os << "unknown enumerator";
     break;
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index ea65282e3ba52..d311251ee088f 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -252,7 +252,8 @@ ol_impl_result_t olGetDeviceInfoImplDetail(ol_device_handle_t Device,
   case OL_DEVICE_INFO_PLATFORM:
     return ReturnValue(Device->Platform);
   case OL_DEVICE_INFO_TYPE:
-    return ReturnValue(OL_DEVICE_TYPE_GPU);
+    return Device == HostDevice() ? ReturnValue(OL_DEVICE_TYPE_HOST)
+                                  : ReturnValue(OL_DEVICE_TYPE_GPU);
   case OL_DEVICE_INFO_NAME:
     return ReturnValue(GetInfo({"Device Name"}).c_str());
   case OL_DEVICE_INFO_VENDOR:
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
index 46ed622fa8b81..243bedddea6fe 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -19,6 +19,13 @@ TEST_P(olGetDeviceInfoTest, SuccessType) {
                                  sizeof(ol_device_type_t), &DeviceType));
 }
 
+TEST_P(olGetDeviceInfoTest, HostSuccessType) {
+  ol_device_type_t DeviceType;
+  ASSERT_SUCCESS(olGetDeviceInfo(Host, OL_DEVICE_INFO_TYPE,
+                                 sizeof(ol_device_type_t), &DeviceType));
+  ASSERT_EQ(DeviceType, OL_DEVICE_TYPE_HOST);
+}
+
 TEST_P(olGetDeviceInfoTest, SuccessPlatform) {
   ol_platform_handle_t Platform = nullptr;
   ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_PLATFORM,

@callumfare
Copy link
Contributor

Thanks, LGTM

@callumfare you should apply for access.

I've just applied - #141729

@jhuber6 jhuber6 merged commit 0ebe555 into llvm:main May 28, 2025
11 checks passed
@jhuber6 jhuber6 deleted the HostType branch May 28, 2025 13:51
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
Summary:
We use this sepcial type to indicate a host value, this will be refined
later but for now it's used as a stand-in device for transfers and
queues. It needs a special kind because it is not a device target as the
other ones so we need to differentiate it between a CPU and GPU type.

Fixes: llvm#141436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Offload] olGetDeviceInfo with OL_DEVICE_INFO_TYPE always returns OL_DEVICE_TYPE_GPU
4 participants