[llvm] [Offload] Add specifier for the host type (PR #141635)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Tue May 27 10:16:27 PDT 2025
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/141635
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: https://github.com/llvm/llvm-project/issues/141436
>From 0be9fbffc03bda6562a6e4d5c14e8f8d410d28de Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 27 May 2025 12:14:44 -0500
Subject: [PATCH] [Offload] Add specifier for the host type
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: https://github.com/llvm/llvm-project/issues/141436
---
offload/liboffload/API/Device.td | 1 +
offload/liboffload/include/generated/OffloadAPI.h | 2 ++
offload/liboffload/include/generated/OffloadPrint.hpp | 3 +++
offload/liboffload/src/OffloadImpl.cpp | 3 ++-
offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp | 7 +++++++
5 files changed, 15 insertions(+), 1 deletion(-)
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,
More information about the llvm-commits
mailing list