|
| 1 | += sycl_ext_intel_low_power_event |
| 2 | + |
| 3 | +:source-highlighter: coderay |
| 4 | +:coderay-linenums-mode: table |
| 5 | + |
| 6 | +// This section needs to be after the document title. |
| 7 | +:doctype: book |
| 8 | +:toc2: |
| 9 | +:toc: left |
| 10 | +:encoding: utf-8 |
| 11 | +:lang: en |
| 12 | +:dpcpp: pass:[DPC++] |
| 13 | +:endnote: —{nbsp}end{nbsp}note |
| 14 | + |
| 15 | +// Set the default source code type in this document to C++, |
| 16 | +// for syntax highlighting purposes. This is needed because |
| 17 | +// docbook uses c++ and html5 uses cpp. |
| 18 | +:language: {basebackend@docbook:c++:cpp} |
| 19 | + |
| 20 | +:common_ref_sem: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:reference-semantics |
| 21 | + |
| 22 | +== Notice |
| 23 | + |
| 24 | +[%hardbreaks] |
| 25 | +Copyright (C) 2024 Intel Corporation. All rights reserved. |
| 26 | + |
| 27 | +Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks |
| 28 | +of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by |
| 29 | +permission by Khronos. |
| 30 | + |
| 31 | + |
| 32 | +== Contact |
| 33 | + |
| 34 | +To report problems with this extension, please open a new issue at: |
| 35 | + |
| 36 | +https://github.com/intel/llvm/issues |
| 37 | + |
| 38 | + |
| 39 | +== Dependencies |
| 40 | + |
| 41 | +This extension is written against the SYCL 2020 revision 9 specification. All |
| 42 | +references below to the "core SYCL specification" or to section numbers in the |
| 43 | +SYCL specification refer to that revision. |
| 44 | + |
| 45 | +This extension also depends on the following other SYCL extensions: |
| 46 | + |
| 47 | +* link:../experimental/sycl_ext_oneapi_enqueue_functions.asciidoc[ |
| 48 | + sycl_ext_oneapi_enqueue_functions] |
| 49 | +* link:../experimental/sycl_ext_oneapi_properties.asciidoc[ |
| 50 | + sycl_ext_oneapi_enqueue_properties] |
| 51 | + |
| 52 | + |
| 53 | +== Status |
| 54 | + |
| 55 | +This is a proposed extension specification, intended to gather community |
| 56 | +feedback. Interfaces defined in this specification may not be implemented yet |
| 57 | +or may be in a preliminary state. The specification itself may also change in |
| 58 | +incompatible ways before it is finalized. *Shipping software products should |
| 59 | +not rely on APIs defined in this specification.* |
| 60 | + |
| 61 | + |
| 62 | +== Backend support status |
| 63 | + |
| 64 | +This extension is currently implemented in {dpcpp} only for all device targets. |
| 65 | + |
| 66 | +== Overview |
| 67 | + |
| 68 | +On some backends, calling `wait()` on a `event` will synchronize using a |
| 69 | +busy-waiting implementation. Though this comes at a low latency for the |
| 70 | +synchronization of the event, it has the downside of consuming high amounts of |
| 71 | +CPU time for no meaningful work. This extension introduces a new property for |
| 72 | +`sycl::ext::oneapi::experimental::barrier()` that will produce a "low-power" |
| 73 | +event. These new low-power events will, if possible, yield the thread that the |
| 74 | +`wait()` member function is called on and only wake up occasionally to check if |
| 75 | +the event has finished. This reduces the time the CPU spends checking finish |
| 76 | +condition of the wait, at the cost of latency. |
| 77 | + |
| 78 | + |
| 79 | +== Specification |
| 80 | + |
| 81 | +=== Feature test macro |
| 82 | + |
| 83 | +This extension provides a feature-test macro as described in the core SYCL |
| 84 | +specification. An implementation supporting this extension must predefine the |
| 85 | +macro `SYCL_EXT_ONEAPI_LOW_POWER_EVENT` to one of the values defined in the table |
| 86 | +below. Applications can test for the existence of this macro to determine if |
| 87 | +the implementation supports this feature, or applications can test the macro's |
| 88 | +value to determine which of the extension's features the implementation |
| 89 | +supports. |
| 90 | + |
| 91 | +[%header,cols="1,5"] |
| 92 | +|=== |
| 93 | +|Value |
| 94 | +|Description |
| 95 | + |
| 96 | +|1 |
| 97 | +|The APIs of this experimental extension are not versioned, so the |
| 98 | + feature-test macro always has this value. |
| 99 | +|=== |
| 100 | + |
| 101 | + |
| 102 | +=== Low-power event property |
| 103 | + |
| 104 | +This extension also adds a new property which can be used with the `barrier` |
| 105 | +and `partial_barrier` enqueue free functions from |
| 106 | +link:../experimental/sycl_ext_oneapi_enqueue_functions.asciidoc[sycl_ext_oneapi_enqueue_functions]. |
| 107 | +Passing this property to either of these functions will act as a hint to the |
| 108 | +`event` created from the corresponding commands to do low-power synchronization. |
| 109 | +If the backend is able to handle low-power events, calling `event::wait()` or |
| 110 | +`event::wait_and_throw()` will cause the thread to yield and only do occasional |
| 111 | +wake-ups to check the event progress. |
| 112 | + |
| 113 | +``` |
| 114 | +namespace sycl::ext::intel::experimental { |
| 115 | + |
| 116 | +struct low_power_event_key { |
| 117 | + using value_t = |
| 118 | + oneapi::experimental::property_value<low_power_event_key>; |
| 119 | +}; |
| 120 | + |
| 121 | +inline constexpr low_power_event_key::value_t low_power_event; |
| 122 | + |
| 123 | +} // namespace sycl::ext::intel::experimental |
| 124 | +``` |
| 125 | + |
| 126 | +=== New property usage example |
| 127 | + |
| 128 | +As an example of how to use the new `low_power_event` property, see the |
| 129 | +following code: |
| 130 | + |
| 131 | +``` |
| 132 | +#include <sycl/sycl.hpp> |
| 133 | + |
| 134 | +namespace oneapiex = sycl::ext::oneapi::experimental; |
| 135 | +namespace intelex = sycl::ext::intel::experimental; |
| 136 | + |
| 137 | +int main() { |
| 138 | + sycl::queue Q; |
| 139 | + |
| 140 | + // Submit some work to the queue. |
| 141 | + oneapiex::submit(Q, [&](sycl::handler &CGH) {...}); |
| 142 | + |
| 143 | + // Submit a barrier with the low-power event property. |
| 144 | + sycl::event E = oneapiex::submit_with_event(Q, [&](sycl::handler &CGH) { |
| 145 | + oneapiex::barrier(CGH, oneapiex::properties{intelex::low_power_event}); |
| 146 | + }); |
| 147 | + |
| 148 | + // Waiting for the resulting event will use low-power waiting if possible. |
| 149 | + E.wait(); |
| 150 | +} |
| 151 | +``` |
0 commit comments