diff options
| author | Ross Brunton <ross@codeplay.com> | 2025-07-02 16:33:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-02 16:33:54 +0100 |
| commit | 7d52b0983e0bee3c1d5dbe04ae2adfd33f0265e5 (patch) | |
| tree | 1939f550b4b9baefe6b59548c7fb847016bcbec3 | |
| parent | ab42c4abe86c454a6812d837a7f2a8d5b9671fdf (diff) | |
[Offload] Add `MAX_WORK_GROUP_SIZE` device info query (#143718)
This adds a new device info query for the maximum workgroup/block size
for each dimension.
| -rw-r--r-- | offload/liboffload/API/Device.td | 3 | ||||
| -rw-r--r-- | offload/liboffload/src/OffloadImpl.cpp | 40 | ||||
| -rw-r--r-- | offload/tools/offload-tblgen/PrintGen.cpp | 5 | ||||
| -rw-r--r-- | offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp | 9 | ||||
| -rw-r--r-- | offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp | 8 |
5 files changed, 64 insertions, 1 deletions
diff --git a/offload/liboffload/API/Device.td b/offload/liboffload/API/Device.td index 4abc24f3ba27..94bd6cbf0e5b 100644 --- a/offload/liboffload/API/Device.td +++ b/offload/liboffload/API/Device.td @@ -31,7 +31,8 @@ def : Enum { TaggedEtor<"PLATFORM", "ol_platform_handle_t", "the platform associated with the device">, TaggedEtor<"NAME", "char[]", "Device name">, TaggedEtor<"VENDOR", "char[]", "Device vendor">, - TaggedEtor<"DRIVER_VERSION", "char[]", "Driver version"> + TaggedEtor<"DRIVER_VERSION", "char[]", "Driver version">, + TaggedEtor<"MAX_WORK_GROUP_SIZE", "ol_dimensions_t", "Maximum work group size in each dimension">, ]; } diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp index e7da4eddce54..f9da63843670 100644 --- a/offload/liboffload/src/OffloadImpl.cpp +++ b/offload/liboffload/src/OffloadImpl.cpp @@ -302,6 +302,41 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device, "plugin did not provide a response for this information"); }; + auto getInfoXyz = + [&](std::vector<std::string> Names) -> llvm::Expected<ol_dimensions_t> { + for (auto &Name : Names) { + if (auto Entry = Device->Info.get(Name)) { + auto Node = *Entry; + ol_dimensions_t Out{0, 0, 0}; + + auto getField = [&](StringRef Name, uint32_t &Dest) { + if (auto F = Node->get(Name)) { + if (!std::holds_alternative<size_t>((*F)->Value)) + return makeError( + ErrorCode::BACKEND_FAILURE, + "plugin returned incorrect type for dimensions element"); + Dest = std::get<size_t>((*F)->Value); + } else + return makeError(ErrorCode::BACKEND_FAILURE, + "plugin didn't provide all values for dimensions"); + return Plugin::success(); + }; + + if (auto Res = getField("x", Out.x)) + return Res; + if (auto Res = getField("y", Out.y)) + return Res; + if (auto Res = getField("z", Out.z)) + return Res; + + return Out; + } + } + + return makeError(ErrorCode::UNIMPLEMENTED, + "plugin did not provide a response for this information"); + }; + switch (PropName) { case OL_DEVICE_INFO_PLATFORM: return Info.write<void *>(Device->Platform); @@ -314,6 +349,9 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device, case OL_DEVICE_INFO_DRIVER_VERSION: return Info.writeString( getInfoString({"CUDA Driver Version", "HSA Runtime Version"})); + case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE: + return Info.write(getInfoXyz({"Workgroup Max Size per Dimension" /*AMD*/, + "Maximum Block Dimensions" /*CUDA*/})); default: return createOffloadError(ErrorCode::INVALID_ENUMERATION, "getDeviceInfo enum '%i' is invalid", PropName); @@ -339,6 +377,8 @@ Error olGetDeviceInfoImplDetailHost(ol_device_handle_t Device, return Info.writeString("Liboffload"); case OL_DEVICE_INFO_DRIVER_VERSION: return Info.writeString(LLVM_VERSION_STRING); + case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE: + return Info.write<ol_dimensions_t>(ol_dimensions_t{1, 1, 1}); default: return createOffloadError(ErrorCode::INVALID_ENUMERATION, "getDeviceInfo enum '%i' is invalid", PropName); diff --git a/offload/tools/offload-tblgen/PrintGen.cpp b/offload/tools/offload-tblgen/PrintGen.cpp index a964ff09d0f6..d1189688a90a 100644 --- a/offload/tools/offload-tblgen/PrintGen.cpp +++ b/offload/tools/offload-tblgen/PrintGen.cpp @@ -213,6 +213,11 @@ template <typename T> inline void printTagged(llvm::raw_ostream &os, const void "enum {0} value);\n", EnumRec{R}.getName()); } + for (auto *R : Records.getAllDerivedDefinitions("Struct")) { + OS << formatv("inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, " + "const struct {0} param);\n", + StructRec{R}.getName()); + } OS << "\n"; // Create definitions diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp index 0247744911ea..c534c4520599 100644 --- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp +++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp @@ -77,6 +77,15 @@ TEST_P(olGetDeviceInfoTest, SuccessDriverVersion) { ASSERT_EQ(std::strlen(DriverVersion.data()), Size - 1); } +TEST_P(olGetDeviceInfoTest, SuccessMaxWorkGroupSize) { + ol_dimensions_t Value{0, 0, 0}; + ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE, + sizeof(Value), &Value)); + ASSERT_GT(Value.x, 0u); + ASSERT_GT(Value.y, 0u); + ASSERT_GT(Value.z, 0u); +} + TEST_P(olGetDeviceInfoTest, InvalidNullHandleDevice) { ol_device_type_t DeviceType; ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp index edd2704a722d..a908078a2521 100644 --- a/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp +++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp @@ -44,6 +44,14 @@ TEST_P(olGetDeviceInfoSizeTest, SuccessDriverVersion) { ASSERT_NE(Size, 0ul); } +TEST_P(olGetDeviceInfoSizeTest, SuccessMaxWorkGroupSize) { + size_t Size = 0; + ASSERT_SUCCESS( + olGetDeviceInfoSize(Device, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE, &Size)); + ASSERT_EQ(Size, sizeof(ol_dimensions_t)); + ASSERT_EQ(Size, sizeof(uint32_t) * 3); +} + TEST_P(olGetDeviceInfoSizeTest, InvalidNullHandle) { size_t Size = 0; ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE, |
