Skip to content

Commit 197d1c1

Browse files
authored
[Offload] OL_QUEUE_INFO_EMPTY (#152473)
Add a queue query that (if possible) reports whether the queue is empty
1 parent 81f3ddf commit 197d1c1

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

offload/liboffload/API/Queue.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def : Enum {
6565
let desc = "Supported queue info.";
6666
let is_typed = 1;
6767
let etors = [
68-
TaggedEtor<"DEVICE", "ol_device_handle_t", "The handle of the device associated with the queue.">
68+
TaggedEtor<"DEVICE", "ol_device_handle_t", "The handle of the device associated with the queue.">,
69+
TaggedEtor<"EMPTY", "bool", "True if the queue is known to be empty. May be unconditionally false if the device does not support status queries.">,
6970
];
7071
}
7172

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ Error olGetQueueInfoImplDetail(ol_queue_handle_t Queue,
530530
switch (PropName) {
531531
case OL_QUEUE_INFO_DEVICE:
532532
return Info.write<ol_device_handle_t>(Queue->Device);
533+
case OL_QUEUE_INFO_EMPTY: {
534+
auto Pending = Queue->Device->Device->hasPendingWork(Queue->AsyncInfo);
535+
if (auto Err = Pending.takeError())
536+
return Err;
537+
return Info.write<bool>(!*Pending);
538+
}
533539
default:
534540
return createOffloadError(ErrorCode::INVALID_ENUMERATION,
535541
"olGetQueueInfo enum '%i' is invalid", PropName);

offload/unittests/OffloadAPI/queue/olGetQueueInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ TEST_P(olGetQueueInfoTest, SuccessDevice) {
2020
ASSERT_EQ(Device, RetrievedDevice);
2121
}
2222

23+
TEST_P(olGetQueueInfoTest, SuccessEmpty) {
24+
bool Empty;
25+
ASSERT_SUCCESS(
26+
olGetQueueInfo(Queue, OL_QUEUE_INFO_EMPTY, sizeof(Empty), &Empty));
27+
}
28+
2329
TEST_P(olGetQueueInfoTest, InvalidNullHandle) {
2430
ol_device_handle_t RetrievedDevice;
2531
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,

offload/unittests/OffloadAPI/queue/olGetQueueInfoSize.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ TEST_P(olGetQueueInfoSizeTest, SuccessDevice) {
1919
ASSERT_EQ(Size, sizeof(ol_device_handle_t));
2020
}
2121

22+
TEST_P(olGetQueueInfoSizeTest, SuccessEmpty) {
23+
size_t Size = 0;
24+
ASSERT_SUCCESS(olGetQueueInfoSize(Queue, OL_QUEUE_INFO_EMPTY, &Size));
25+
ASSERT_EQ(Size, sizeof(bool));
26+
}
27+
2228
TEST_P(olGetQueueInfoSizeTest, InvalidNullHandle) {
2329
size_t Size = 0;
2430
ASSERT_ERROR(OL_ERRC_INVALID_NULL_HANDLE,

0 commit comments

Comments
 (0)