Skip to content

Commit 91bfce2

Browse files
committed
[Offload] Add MAX_WORK_GROUP_SIZE device info query
This adds a new device info query for the maximum workgroup/block size for each dimension. Since this returns three values, a new `ol_range_t` type was added as an `{x, y, z}` triplet. Device info handling and struct printing was also updated to handle it.
1 parent 4359e55 commit 91bfce2

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,31 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
264264

265265
return "";
266266
};
267+
auto GetInfoXyz = [&](std::vector<std::string> Names) {
268+
if (!Device->Device)
269+
return ol_dimensions_t{0, 0, 0};
270+
271+
auto Info = Device->Device->obtainInfoImpl();
272+
if (auto Err = Info.takeError())
273+
return ol_dimensions_t{0, 0, 0};
274+
275+
for (auto Name : Names) {
276+
if (auto Entry = Info->get(Name)) {
277+
auto Node = *Entry;
278+
ol_dimensions_t Out{0, 0, 0};
279+
280+
if (auto X = Node->get("x"))
281+
Out.x = std::get<size_t>((*X)->Value);
282+
if (auto Y = Node->get("y"))
283+
Out.y = std::get<size_t>((*Y)->Value);
284+
if (auto Z = Node->get("z"))
285+
Out.z = std::get<size_t>((*Z)->Value);
286+
return Out;
287+
}
288+
}
289+
290+
return ol_dimensions_t{0, 0, 0};
291+
};
267292

268293
switch (PropName) {
269294
case OL_DEVICE_INFO_PLATFORM:
@@ -279,6 +304,9 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
279304
case OL_DEVICE_INFO_DRIVER_VERSION:
280305
return ReturnValue(
281306
GetInfoString({"CUDA Driver Version", "HSA Runtime Version"}));
307+
case OL_DEVICE_INFO_MAX_WORK_GROUP_SIZE:
308+
return ReturnValue(GetInfoXyz({"Workgroup Max Size per Dimension" /*AMD*/,
309+
"Maximum Block Dimensions" /*CUDA*/}));
282310
default:
283311
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
284312
"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, 0);
85+
ASSERT_GT(Value.y, 0);
86+
ASSERT_GT(Value.z, 0);
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)