Skip to content

Commit 7d52b09

Browse files
authored
[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.
1 parent ab42c4a commit 7d52b09

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

offload/liboffload/API/Device.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def : Enum {
3131
TaggedEtor<"PLATFORM", "ol_platform_handle_t", "the platform associated with the device">,
3232
TaggedEtor<"NAME", "char[]", "Device name">,
3333
TaggedEtor<"VENDOR", "char[]", "Device vendor">,
34-
TaggedEtor<"DRIVER_VERSION", "char[]", "Driver version">
34+
TaggedEtor<"DRIVER_VERSION", "char[]", "Driver version">,
35+
TaggedEtor<"MAX_WORK_GROUP_SIZE", "ol_dimensions_t", "Maximum work group size in each dimension">,
3536
];
3637
}
3738

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,41 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
302302
"plugin did not provide a response for this information");
303303
};
304304

305+
auto getInfoXyz =
306+
[&](std::vector<std::string> Names) -> llvm::Expected<ol_dimensions_t> {
307+
for (auto &Name : Names) {
308+
if (auto Entry = Device->Info.get(Name)) {
309+
auto Node = *Entry;
310+
ol_dimensions_t Out{0, 0, 0};
311+
312+
auto getField = [&](StringRef Name, uint32_t &Dest) {
313+
if (auto F = Node->get(Name)) {
314+
if (!std::holds_alternative<size_t>((*F)->Value))
315+
return makeError(
316+
ErrorCode::BACKEND_FAILURE,
317+
"plugin returned incorrect type for dimensions element");
318+
Dest = std::get<size_t>((*F)->Value);
319+
} else
320+
return makeError(ErrorCode::BACKEND_FAILURE,
321+
"plugin didn't provide all values for dimensions");
322+
return Plugin::success();
323+
};
324+
325+
if (auto Res = getField("x", Out.x))
326+
return Res;
327+
if (auto Res = getField("y", Out.y))
328+
return Res;
329+
if (auto Res = getField("z", Out.z))
330+
return Res;
331+
332+
return Out;
333+
}
334+
}
335+
336+
return makeError(ErrorCode::UNIMPLEMENTED,
337+
"plugin did not provide a response for this information");
338+
};
339+
305340
switch (PropName) {
306341
case OL_DEVICE_INFO_PLATFORM:
307342
return Info.write<void *>(Device->Platform);
@@ -314,6 +349,9 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
314349
case OL_DEVICE_INFO_DRIVER_VERSION:
315350
return Info.writeString(
316351
getInfoString({"CUDA Driver Version", "HSA Runtime Version"}));
352+
case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE:
353+
return Info.write(getInfoXyz({"Workgroup Max Size per Dimension" /*AMD*/,
354+
"Maximum Block Dimensions" /*CUDA*/}));
317355
default:
318356
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
319357
"getDeviceInfo enum '%i' is invalid", PropName);
@@ -339,6 +377,8 @@ Error olGetDeviceInfoImplDetailHost(ol_device_handle_t Device,
339377
return Info.writeString("Liboffload");
340378
case OL_DEVICE_INFO_DRIVER_VERSION:
341379
return Info.writeString(LLVM_VERSION_STRING);
380+
case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE:
381+
return Info.write<ol_dimensions_t>(ol_dimensions_t{1, 1, 1});
342382
default:
343383
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
344384
"getDeviceInfo enum '%i' is invalid", PropName);

offload/tools/offload-tblgen/PrintGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ template <typename T> inline void printTagged(llvm::raw_ostream &os, const void
213213
"enum {0} value);\n",
214214
EnumRec{R}.getName());
215215
}
216+
for (auto *R : Records.getAllDerivedDefinitions("Struct")) {
217+
OS << formatv("inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os, "
218+
"const struct {0} param);\n",
219+
StructRec{R}.getName());
220+
}
216221
OS << "\n";
217222

218223
// Create definitions

offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ TEST_P(olGetDeviceInfoTest, SuccessDriverVersion) {
7777
ASSERT_EQ(std::strlen(DriverVersion.data()), Size - 1);
7878
}
7979

80+
TEST_P(olGetDeviceInfoTest, SuccessMaxWorkGroupSize) {
81+
ol_dimensions_t Value{0, 0, 0};
82+
ASSERT_SUCCESS(olGetDeviceInfo(Device, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE,
83+
sizeof(Value), &Value));
84+
ASSERT_GT(Value.x, 0u);
85+
ASSERT_GT(Value.y, 0u);
86+
ASSERT_GT(Value.z, 0u);
87+
}
88+
8089
TEST_P(olGetDeviceInfoTest, InvalidNullHandleDevice) {
8190
ol_device_type_t DeviceType;
8291
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,

offload/unittests/OffloadAPI/device/olGetDeviceInfoSize.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ TEST_P(olGetDeviceInfoSizeTest, SuccessDriverVersion) {
4444
ASSERT_NE(Size, 0ul);
4545
}
4646

47+
TEST_P(olGetDeviceInfoSizeTest, SuccessMaxWorkGroupSize) {
48+
size_t Size = 0;
49+
ASSERT_SUCCESS(
50+
olGetDeviceInfoSize(Device, OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE, &Size));
51+
ASSERT_EQ(Size, sizeof(ol_dimensions_t));
52+
ASSERT_EQ(Size, sizeof(uint32_t) * 3);
53+
}
54+
4755
TEST_P(olGetDeviceInfoSizeTest, InvalidNullHandle) {
4856
size_t Size = 0;
4957
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,

0 commit comments

Comments
 (0)