Skip to content

Commit 48ec257

Browse files
committed
Merge pull request #700 from KhronosGroup/khr-queue-size-queries
[KHR] add sycl_khr_queue_empty_query (cherry picked from commit c90cf7b)
1 parent 0f36049 commit 48ec257

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

adoc/extensions/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ specification, but their design is subject to change.
1111
// include::sycl_khr_extension_name.adoc[leveloffset=2]
1212

1313
include::sycl_khr_default_context.adoc[leveloffset=2]
14+
include::sycl_khr_queue_empty_query.adoc[leveloffset=2]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
[[sec:khr-queue-empty-query]]
2+
= sycl_khr_queue_empty_query
3+
4+
This extension allows developers to query the queue's emptiness, meaning if all
5+
commands submitted to a queue have been completed.
6+
7+
[[sec:khr-queue-empty-query-dependencies]]
8+
== Dependencies
9+
10+
This extension has no dependencies on other extensions.
11+
12+
[[sec:khr-queue-empty-query-feature-test]]
13+
== Feature test macro
14+
15+
An implementation supporting this extension must predefine the macro
16+
[code]#SYCL_KHR_QUEUE_EMPTY_QUERY# to one of the values defined in the table
17+
below.
18+
19+
[%header,cols="1,5"]
20+
|===
21+
|Value
22+
|Description
23+
24+
|1
25+
|Initial version of this extension.
26+
|===
27+
28+
29+
[[sec:khr-queue-empty-query-funct]]
30+
== New Queue Function to Query Emptiness
31+
32+
This extension adds the following function to the [code]#sycl::queue# class,
33+
which provides information about the emptiness of the queue.
34+
35+
{node} This khr is more usefull when used in conjuction with
36+
[code]#queue::khr_flush()#.
37+
{endnode}
38+
39+
'''
40+
41+
.[apidef]#queue::khr_empty#
42+
[source,role=synopsis,id=api:queue-khr-empty]
43+
----
44+
bool khr_empty() const
45+
----
46+
47+
_Synchronization_: When this function returns [code]#true#, equivalent to
48+
[code]#queue::wait()#.
49+
50+
_Returns:_ [code]#true# if all <<command,commands>> enqueued on this queue have
51+
completed, [code]#false# otherwise.
52+
53+
{note} Since the implementation executes commands asynchronously, the returned
54+
value is a snapshot in time.
55+
{endnote}
56+
57+
'''
58+
59+
[[sec:khr-queue-empty-query-example]]
60+
== Example
61+
62+
The example below demonstrates the usage of this extension.
63+
64+
[source,,linenums]
65+
----
66+
#include <algorithm>
67+
#include <iostream>
68+
#include <sycl/sycl.hpp>
69+
int main() {
70+
// Pool of queues, one per device
71+
std::vector<sycl::queue> Qs;
72+
for (sycl::device& d : sycl::device::get_devices())
73+
Qs.push_back(sycl::queue(d));
74+
75+
// Useful recipe for load-balancing
76+
auto it = std::find_if(Qs.begin(), Qs.end(),
77+
[](const sycl::queue& q) { return q.khr_empty(); });
78+
79+
if (it != Qs.end()) {
80+
std::cout << "Empty queue present" << std::endl;
81+
} else {
82+
std::cout << "No empty queue" << std::endl;
83+
}
84+
}
85+
----

0 commit comments

Comments
 (0)