|
| 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 | +''' |
| 36 | + |
| 37 | +.[apidef]#queue::khr_empty# |
| 38 | +[source,role=synopsis,id=api:queue-khr-empty] |
| 39 | +---- |
| 40 | +bool khr_empty() const |
| 41 | +---- |
| 42 | + |
| 43 | +_Synchronization_: When this function returns [code]#true#, equivalent to |
| 44 | +[api]#queue::wait#. |
| 45 | + |
| 46 | +_Returns:_ [code]#true# if all <<command,commands>> enqueued on this queue have |
| 47 | +completed, [code]#false# otherwise. |
| 48 | + |
| 49 | +{note} Since the implementation executes commands asynchronously, the returned |
| 50 | +value is a snapshot in time. |
| 51 | +{endnote} |
| 52 | + |
| 53 | +''' |
| 54 | + |
| 55 | +[[sec:khr-queue-empty-query-example]] |
| 56 | +== Example |
| 57 | + |
| 58 | +The example below demonstrates the usage of this extension. |
| 59 | + |
| 60 | +[source,,linenums] |
| 61 | +---- |
| 62 | +#include <algorithm> |
| 63 | +#include <iostream> |
| 64 | +#include <sycl/sycl.hpp> |
| 65 | +int main() { |
| 66 | + // Pool of queues, one per device |
| 67 | + std::vector<sycl::queue> Qs; |
| 68 | + for (sycl::device& d : sycl::device::get_devices()) |
| 69 | + Qs.push_back(sycl::queue(d)); |
| 70 | +
|
| 71 | + // Useful recipe for load-balancing |
| 72 | + auto it = std::find_if(Qs.begin(), Qs.end(), |
| 73 | + [](const sycl::queue& q) { return q.khr_empty(); }); |
| 74 | +
|
| 75 | + if (it != Qs.end()) { |
| 76 | + std::cout << "Empty queue present" << std::endl; |
| 77 | + } else { |
| 78 | + std::cout << "No empty queue" << std::endl; |
| 79 | + } |
| 80 | +} |
| 81 | +---- |
0 commit comments