Skip to content

Commit 6bfcf72

Browse files
committed
Implement olGetQueueInfo(Size)
1 parent 5e21f2b commit 6bfcf72

File tree

5 files changed

+170
-1
lines changed

5 files changed

+170
-1
lines changed

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,33 @@ Error olWaitQueue_impl(ol_queue_handle_t Queue) {
368368
return Error::success();
369369
}
370370

371+
Error olGetQueueInfoImplDetail(ol_queue_handle_t Queue,
372+
ol_queue_info_t PropName, size_t PropSize,
373+
void *PropValue, size_t *PropSizeRet) {
374+
ReturnHelper ReturnValue(PropSize, PropValue, PropSizeRet);
375+
376+
switch (PropName) {
377+
case OL_QUEUE_INFO_DEVICE:
378+
return ReturnValue(Queue->Device);
379+
default:
380+
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
381+
"olGetQueueInfo enum '%i' is invalid", PropName);
382+
}
383+
384+
return Error::success();
385+
}
386+
387+
Error olGetQueueInfo_impl(ol_queue_handle_t Queue, ol_queue_info_t PropName,
388+
size_t PropSize, void *PropValue) {
389+
return olGetQueueInfoImplDetail(Queue, PropName, PropSize, PropValue,
390+
nullptr);
391+
}
392+
393+
Error olGetQueueInfoSize_impl(ol_queue_handle_t Queue, ol_queue_info_t PropName,
394+
size_t *PropSizeRet) {
395+
return olGetQueueInfoImplDetail(Queue, PropName, 0, nullptr, PropSizeRet);
396+
}
397+
371398
Error olWaitEvent_impl(ol_event_handle_t Event) {
372399
if (auto Res = Event->Queue->Device->Device->syncEvent(Event->EventInfo))
373400
return Res;

offload/unittests/OffloadAPI/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ add_offload_unittest("program"
3232
add_offload_unittest("queue"
3333
queue/olCreateQueue.cpp
3434
queue/olWaitQueue.cpp
35-
queue/olDestroyQueue.cpp)
35+
queue/olDestroyQueue.cpp
36+
queue/olGetQueueInfo.cpp
37+
queue/olGetQueueInfoSize.cpp)
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+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===------- Offload API tests - olGetQueueInfoSize -----------------------===//
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 olGetQueueInfoSizeTest = OffloadQueueTest;
14+
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE(olGetQueueInfoSizeTest);
15+
16+
TEST_P(olGetQueueInfoSizeTest, SuccessDevice) {
17+
size_t Size = 0;
18+
ASSERT_SUCCESS(olGetQueueInfoSize(Queue, OL_QUEUE_INFO_DEVICE, &Size));
19+
ASSERT_EQ(Size, sizeof(ol_device_handle_t));
20+
}
21+
22+
TEST_P(olGetQueueInfoSizeTest, InvalidNullHandle) {
23+
size_t Size = 0;
24+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,
25+
olGetQueueInfoSize(nullptr, OL_QUEUE_INFO_DEVICE, &Size));
26+
}
27+
28+
TEST_P(olGetQueueInfoSizeTest, InvalidQueueInfoEnumeration) {
29+
size_t Size = 0;
30+
ASSERT_ERROR(OL_ERRC_INVALID_ENUMERATION,
31+
olGetQueueInfoSize(Queue, OL_QUEUE_INFO_FORCE_UINT32, &Size));
32+
}
33+
34+
TEST_P(olGetQueueInfoSizeTest, InvalidNullPointer) {
35+
ASSERT_ERROR(OL_ERRC_INVALID_NULL_POINTER,
36+
olGetQueueInfoSize(Queue, OL_QUEUE_INFO_DEVICE, nullptr));
37+
}

0 commit comments

Comments
 (0)