From 0ebe5557d9688f7397d45facb26efcd3f2c3bc8c Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 28 May 2025 08:51:14 -0500 Subject: [PATCH] [Offload] Add specifier for the host type (#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 --- 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 28c96bb5d291..4abc24f3ba27 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 f7ec749f6efa..a1d7540519e3 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 9b916543eec0..3aad6223d4de 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 f2a02d1cff94..a5935a7e5b31 100644 --- a/offload/liboffload/src/OffloadImpl.cpp +++ b/offload/liboffload/src/OffloadImpl.cpp @@ -258,7 +258,8 @@ Error 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 1240f219813e..0247744911ea 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,