Skip to content

Commit f483158

Browse files
committed
Implement olGetEventInfo(Size)
1 parent 6bfcf72 commit f483158

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
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/src/OffloadImpl.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,34 @@ Error olDestroyEvent_impl(ol_event_handle_t Event) {
409409
return olDestroy(Event);
410410
}
411411

412+
Error olGetEventInfoImplDetail(ol_event_handle_t Event,
413+
ol_event_info_t PropName, size_t PropSize,
414+
void *PropValue, size_t *PropSizeRet) {
415+
ReturnHelper ReturnValue(PropSize, PropValue, PropSizeRet);
416+
417+
switch (PropName) {
418+
case OL_EVENT_INFO_QUEUE:
419+
return ReturnValue(Event->Queue);
420+
default:
421+
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
422+
"olGetEventInfo enum '%i' is invalid", PropName);
423+
}
424+
425+
return Error::success();
426+
}
427+
428+
Error olGetEventInfo_impl(ol_event_handle_t Event, ol_event_info_t PropName,
429+
size_t PropSize, void *PropValue) {
430+
431+
return olGetEventInfoImplDetail(Event, PropName, PropSize, PropValue,
432+
nullptr);
433+
}
434+
435+
Error olGetEventInfoSize_impl(ol_event_handle_t Event, ol_event_info_t PropName,
436+
size_t *PropSizeRet) {
437+
return olGetEventInfoImplDetail(Event, PropName, 0, nullptr, PropSizeRet);
438+
}
439+
412440
ol_event_handle_t makeEvent(ol_queue_handle_t Queue) {
413441
auto EventImpl = std::make_unique<ol_event_impl_t>(nullptr, Queue);
414442
if (auto Res = Queue->Device->Device->createEvent(&EventImpl->EventInfo)) {

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
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("kernel"
1618
kernel/olGetKernel.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()), \

0 commit comments

Comments
 (0)