Skip to content

Commit 7c6edf4

Browse files
authored
[Offload] Implement olGetQueueInfo, olGetEventInfo (#142947)
Add info queries for queues and events. `olGetQueueInfo` only supports getting the associated device. We were already tracking this so we can implement this for free. We will likely add other queries to it in the future (whether the queue is empty, what flags it was created with, etc) `olGetEventInfo` only supports getting the associated queue. This is another thing we were already storing in the handle. We'll be able to add other queries in future (the event type, status, etc)
1 parent d59d265 commit 7c6edf4

File tree

9 files changed

+366
-2
lines changed

9 files changed

+366
-2
lines changed

offload/liboffload/API/Event.td

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,51 @@ def : Function {
2929
];
3030
let returns = [];
3131
}
32+
33+
def : Enum {
34+
let name = "ol_event_info_t";
35+
let desc = "Supported event info.";
36+
let is_typed = 1;
37+
let etors = [
38+
TaggedEtor<"QUEUE", "ol_queue_handle_t", "The handle of the queue associated with the device.">
39+
];
40+
}
41+
42+
def : Function {
43+
let name = "olGetEventInfo";
44+
let desc = "Queries the given property of the event.";
45+
let details = [
46+
"`olGetEventInfoSize` can be used to query the storage size "
47+
"required for the given query."
48+
];
49+
let params = [
50+
Param<"ol_event_handle_t", "Event", "handle of the event", PARAM_IN>,
51+
Param<"ol_event_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,
52+
Param<"size_t", "PropSize", "the number of bytes pointed to by PropValue.", PARAM_IN>,
53+
TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. "
54+
"If PropSize is not equal to or greater to the real number of bytes needed to return the info "
55+
"then the OL_ERRC_INVALID_SIZE error is returned and PropValue is not used.", PARAM_OUT,
56+
TypeInfo<"PropName" , "PropSize">>
57+
];
58+
let returns = [
59+
Return<"OL_ERRC_INVALID_SIZE", [
60+
"`PropSize == 0`",
61+
"If `PropSize` is less than the real number of bytes needed to return the info."
62+
]>,
63+
Return<"OL_ERRC_INVALID_EVENT">
64+
];
65+
}
66+
67+
def : Function {
68+
let name = "olGetEventInfoSize";
69+
let desc = "Returns the storage size of the given event query.";
70+
let details = [];
71+
let params = [
72+
Param<"ol_event_handle_t", "Event", "handle of the event", PARAM_IN>,
73+
Param<"ol_event_info_t", "PropName", "type of the info to query", PARAM_IN>,
74+
Param<"size_t*", "PropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
75+
];
76+
let returns = [
77+
Return<"OL_ERRC_INVALID_EVENT">
78+
];
79+
}

offload/liboffload/API/Queue.td

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,51 @@ def : Function {
4040
];
4141
let returns = [];
4242
}
43+
44+
def : Enum {
45+
let name = "ol_queue_info_t";
46+
let desc = "Supported queue info.";
47+
let is_typed = 1;
48+
let etors = [
49+
TaggedEtor<"DEVICE", "ol_device_handle_t", "The handle of the device associated with the queue.">
50+
];
51+
}
52+
53+
def : Function {
54+
let name = "olGetQueueInfo";
55+
let desc = "Queries the given property of the queue.";
56+
let details = [
57+
"`olGetQueueInfoSize` can be used to query the storage size "
58+
"required for the given query."
59+
];
60+
let params = [
61+
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN>,
62+
Param<"ol_queue_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,
63+
Param<"size_t", "PropSize", "the number of bytes pointed to by PropValue.", PARAM_IN>,
64+
TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. "
65+
"If Size is not equal to or greater to the real number of bytes needed to return the info "
66+
"then the OL_ERRC_INVALID_SIZE error is returned and pPlatformInfo is not used.", PARAM_OUT,
67+
TypeInfo<"PropName" , "PropSize">>
68+
];
69+
let returns = [
70+
Return<"OL_ERRC_INVALID_SIZE", [
71+
"`PropSize == 0`",
72+
"If `PropSize` is less than the real number of bytes needed to return the info."
73+
]>,
74+
Return<"OL_ERRC_INVALID_QUEUE">
75+
];
76+
}
77+
78+
def : Function {
79+
let name = "olGetQueueInfoSize";
80+
let desc = "Returns the storage size of the given queue query.";
81+
let details = [];
82+
let params = [
83+
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN>,
84+
Param<"ol_queue_info_t", "PropName", "type of the info to query", PARAM_IN>,
85+
Param<"size_t*", "PropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
86+
];
87+
let returns = [
88+
Return<"OL_ERRC_INVALID_QUEUE">
89+
];
90+
}

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,33 @@ Error olWaitQueue_impl(ol_queue_handle_t Queue) {
487487
return Error::success();
488488
}
489489

490+
Error olGetQueueInfoImplDetail(ol_queue_handle_t Queue,
491+
ol_queue_info_t PropName, size_t PropSize,
492+
void *PropValue, size_t *PropSizeRet) {
493+
InfoWriter Info(PropSize, PropValue, PropSizeRet);
494+
495+
switch (PropName) {
496+
case OL_QUEUE_INFO_DEVICE:
497+
return Info.write<ol_device_handle_t>(Queue->Device);
498+
default:
499+
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
500+
"olGetQueueInfo enum '%i' is invalid", PropName);
501+
}
502+
503+
return Error::success();
504+
}
505+
506+
Error olGetQueueInfo_impl(ol_queue_handle_t Queue, ol_queue_info_t PropName,
507+
size_t PropSize, void *PropValue) {
508+
return olGetQueueInfoImplDetail(Queue, PropName, PropSize, PropValue,
509+
nullptr);
510+
}
511+
512+
Error olGetQueueInfoSize_impl(ol_queue_handle_t Queue, ol_queue_info_t PropName,
513+
size_t *PropSizeRet) {
514+
return olGetQueueInfoImplDetail(Queue, PropName, 0, nullptr, PropSizeRet);
515+
}
516+
490517
Error olWaitEvent_impl(ol_event_handle_t Event) {
491518
if (auto Res = Event->Queue->Device->Device->syncEvent(Event->EventInfo))
492519
return Res;
@@ -501,6 +528,34 @@ Error olDestroyEvent_impl(ol_event_handle_t Event) {
501528
return olDestroy(Event);
502529
}
503530

531+
Error olGetEventInfoImplDetail(ol_event_handle_t Event,
532+
ol_event_info_t PropName, size_t PropSize,
533+
void *PropValue, size_t *PropSizeRet) {
534+
InfoWriter Info(PropSize, PropValue, PropSizeRet);
535+
536+
switch (PropName) {
537+
case OL_EVENT_INFO_QUEUE:
538+
return Info.write<ol_queue_handle_t>(Event->Queue);
539+
default:
540+
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
541+
"olGetEventInfo enum '%i' is invalid", PropName);
542+
}
543+
544+
return Error::success();
545+
}
546+
547+
Error olGetEventInfo_impl(ol_event_handle_t Event, ol_event_info_t PropName,
548+
size_t PropSize, void *PropValue) {
549+
550+
return olGetEventInfoImplDetail(Event, PropName, PropSize, PropValue,
551+
nullptr);
552+
}
553+
554+
Error olGetEventInfoSize_impl(ol_event_handle_t Event, ol_event_info_t PropName,
555+
size_t *PropSizeRet) {
556+
return olGetEventInfoImplDetail(Event, PropName, 0, nullptr, PropSizeRet);
557+
}
558+
504559
ol_event_handle_t makeEvent(ol_queue_handle_t Queue) {
505560
auto EventImpl = std::make_unique<ol_event_impl_t>(nullptr, Queue);
506561
if (auto Res = Queue->Device->Device->createEvent(&EventImpl->EventInfo)) {

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ add_offload_unittest("device"
1010

1111
add_offload_unittest("event"
1212
event/olDestroyEvent.cpp
13-
event/olWaitEvent.cpp)
13+
event/olWaitEvent.cpp
14+
event/olGetEventInfo.cpp
15+
event/olGetEventInfoSize.cpp)
1416

1517
add_offload_unittest("init"
1618
init/olInit.cpp)
@@ -36,4 +38,6 @@ add_offload_unittest("program"
3638
add_offload_unittest("queue"
3739
queue/olCreateQueue.cpp
3840
queue/olWaitQueue.cpp
39-
queue/olDestroyQueue.cpp)
41+
queue/olDestroyQueue.cpp
42+
queue/olGetQueueInfo.cpp
43+
queue/olGetQueueInfoSize.cpp)

offload/unittests/OffloadAPI/common/Fixtures.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ struct OffloadQueueTest : OffloadDeviceTest {
139139
ol_queue_handle_t Queue = nullptr;
140140
};
141141

142+
struct OffloadEventTest : OffloadQueueTest {
143+
void SetUp() override {
144+
RETURN_ON_FATAL_FAILURE(OffloadQueueTest::SetUp());
145+
146+
// Get an event from a memcpy. We can still use it in olGetEventInfo etc
147+
// after it has been waited on.
148+
void *Alloc;
149+
uint32_t Value = 42;
150+
ASSERT_SUCCESS(
151+
olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(Value), &Alloc));
152+
ASSERT_SUCCESS(
153+
olMemcpy(Queue, Alloc, Device, &Value, Host, sizeof(Value), &Event));
154+
ASSERT_SUCCESS(olWaitEvent(Event));
155+
ASSERT_SUCCESS(olMemFree(Alloc));
156+
}
157+
158+
void TearDown() override {
159+
if (Event)
160+
olDestroyEvent(Event);
161+
RETURN_ON_FATAL_FAILURE(OffloadQueueTest::TearDown());
162+
}
163+
164+
ol_event_handle_t Event = nullptr;
165+
};
166+
142167
#define OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(FIXTURE) \
143168
INSTANTIATE_TEST_SUITE_P( \
144169
, FIXTURE, ::testing::ValuesIn(TestEnvironment::getDevices()), \
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===------- Offload API tests - olGetEventInfo ---------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <OffloadAPI.h>
10+
11+
#include "../common/Fixtures.hpp"
12+
13+
using olGetEventInfoTest = OffloadEventTest;
14+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetEventInfoTest);
15+
16+
TEST_P(olGetEventInfoTest, SuccessDevice) {
17+
ol_queue_handle_t RetrievedQueue;
18+
ASSERT_SUCCESS(olGetEventInfo(Event, OL_EVENT_INFO_QUEUE,
19+
sizeof(ol_queue_handle_t), &RetrievedQueue));
20+
ASSERT_EQ(Queue, RetrievedQueue);
21+
}
22+
23+
TEST_P(olGetEventInfoTest, InvalidNullHandle) {
24+
ol_queue_handle_t RetrievedQueue;
25+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
26+
olGetEventInfo(nullptr, OL_EVENT_INFO_QUEUE,
27+
sizeof(RetrievedQueue), &RetrievedQueue));
28+
}
29+
30+
TEST_P(olGetEventInfoTest, InvalidEventInfoEnumeration) {
31+
ol_queue_handle_t RetrievedQueue;
32+
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
33+
olGetEventInfo(Event, OL_EVENT_INFO_FORCE_UINT32,
34+
sizeof(RetrievedQueue), &RetrievedQueue));
35+
}
36+
37+
TEST_P(olGetEventInfoTest, InvalidSizeZero) {
38+
ol_queue_handle_t RetrievedQueue;
39+
ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
40+
olGetEventInfo(Event, OL_EVENT_INFO_QUEUE, 0, &RetrievedQueue));
41+
}
42+
43+
TEST_P(olGetEventInfoTest, InvalidSizeSmall) {
44+
ol_queue_handle_t RetrievedQueue;
45+
ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
46+
olGetEventInfo(Event, OL_EVENT_INFO_QUEUE,
47+
sizeof(RetrievedQueue) - 1, &RetrievedQueue));
48+
}
49+
50+
TEST_P(olGetEventInfoTest, InvalidNullPointerPropValue) {
51+
ol_queue_handle_t RetrievedQueue;
52+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
53+
olGetEventInfo(Event, OL_EVENT_INFO_QUEUE,
54+
sizeof(RetrievedQueue), nullptr));
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===------- Offload API tests - olGetEventInfoSize -----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <OffloadAPI.h>
10+
11+
#include "../common/Fixtures.hpp"
12+
13+
using olGetEventInfoSizeTest = OffloadEventTest;
14+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetEventInfoSizeTest);
15+
16+
TEST_P(olGetEventInfoSizeTest, SuccessQueue) {
17+
size_t Size = 0;
18+
ASSERT_SUCCESS(olGetEventInfoSize(Event, OL_EVENT_INFO_QUEUE, &Size));
19+
ASSERT_EQ(Size, sizeof(ol_queue_handle_t));
20+
}
21+
22+
TEST_P(olGetEventInfoSizeTest, InvalidNullHandle) {
23+
size_t Size = 0;
24+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
25+
olGetEventInfoSize(nullptr, OL_EVENT_INFO_QUEUE, &Size));
26+
}
27+
28+
TEST_P(olGetEventInfoSizeTest, InvalidEventInfoEnumeration) {
29+
size_t Size = 0;
30+
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
31+
olGetEventInfoSize(Event, OL_EVENT_INFO_FORCE_UINT32, &Size));
32+
}
33+
34+
TEST_P(olGetEventInfoSizeTest, InvalidNullPointer) {
35+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
36+
olGetEventInfoSize(Event, OL_EVENT_INFO_QUEUE, nullptr));
37+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===------- Offload API tests - olGetQueueInfo ---------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <OffloadAPI.h>
10+
11+
#include "../common/Fixtures.hpp"
12+
13+
using olGetQueueInfoTest = OffloadQueueTest;
14+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetQueueInfoTest);
15+
16+
TEST_P(olGetQueueInfoTest, SuccessDevice) {
17+
ol_device_handle_t RetrievedDevice;
18+
ASSERT_SUCCESS(olGetQueueInfo(Queue, OL_QUEUE_INFO_DEVICE,
19+
sizeof(ol_device_handle_t), &RetrievedDevice));
20+
ASSERT_EQ(Device, RetrievedDevice);
21+
}
22+
23+
TEST_P(olGetQueueInfoTest, InvalidNullHandle) {
24+
ol_device_handle_t RetrievedDevice;
25+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
26+
olGetQueueInfo(nullptr, OL_QUEUE_INFO_DEVICE,
27+
sizeof(RetrievedDevice), &RetrievedDevice));
28+
}
29+
30+
TEST_P(olGetQueueInfoTest, InvalidQueueInfoEnumeration) {
31+
ol_device_handle_t RetrievedDevice;
32+
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
33+
olGetQueueInfo(Queue, OL_QUEUE_INFO_FORCE_UINT32,
34+
sizeof(RetrievedDevice), &RetrievedDevice));
35+
}
36+
37+
TEST_P(olGetQueueInfoTest, InvalidSizeZero) {
38+
ol_device_handle_t RetrievedDevice;
39+
ASSERT_ERROR(OL_ERRC_INVALID_SIZE, olGetQueueInfo(Queue, OL_QUEUE_INFO_DEVICE,
40+
0, &RetrievedDevice));
41+
}
42+
43+
TEST_P(olGetQueueInfoTest, InvalidSizeSmall) {
44+
ol_device_handle_t RetrievedDevice;
45+
ASSERT_ERROR(OL_ERRC_INVALID_SIZE,
46+
olGetQueueInfo(Queue, OL_QUEUE_INFO_DEVICE,
47+
sizeof(RetrievedDevice) - 1, &RetrievedDevice));
48+
}
49+
50+
TEST_P(olGetQueueInfoTest, InvalidNullPointerPropValue) {
51+
ol_device_handle_t RetrievedDevice;
52+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
53+
olGetQueueInfo(Queue, OL_QUEUE_INFO_DEVICE,
54+
sizeof(RetrievedDevice), nullptr));
55+
}

0 commit comments

Comments
 (0)