|
| 1 | += sycl_ext_intel_event_mode |
| 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_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 | +== Overview |
| 63 | + |
| 64 | +On some backends, calling `wait()` on an `event` will synchronize using a |
| 65 | +busy-waiting implementation. Though this comes at a low latency for the |
| 66 | +synchronization of the event, it has the downside of consuming high amounts of |
| 67 | +CPU time for no meaningful work. This extension introduces a new property for |
| 68 | +SYCL commands that allow users to pick modes for the associated events, one of |
| 69 | +these modes being a "low-power" event. These new low-power events will, if |
| 70 | +possible, yield the thread that the `wait()` member function is called on and |
| 71 | +only wake up occasionally to check if the event has finished. This reduces the |
| 72 | +time the CPU spends checking finish condition of the wait, at the cost of |
| 73 | +latency. |
| 74 | + |
| 75 | + |
| 76 | +== Specification |
| 77 | + |
| 78 | +=== Feature test macro |
| 79 | + |
| 80 | +This extension provides a feature-test macro as described in the core SYCL |
| 81 | +specification. An implementation supporting this extension must predefine the |
| 82 | +macro `SYCL_EXT_INTEL_EVENT_MODE` to one of the values defined in the table |
| 83 | +below. Applications can test for the existence of this macro to determine if |
| 84 | +the implementation supports this feature, or applications can test the macro's |
| 85 | +value to determine which of the extension's features the implementation |
| 86 | +supports. |
| 87 | + |
| 88 | +[%header,cols="1,5"] |
| 89 | +|=== |
| 90 | +|Value |
| 91 | +|Description |
| 92 | + |
| 93 | +|1 |
| 94 | +|The APIs of this experimental extension are not versioned, so the |
| 95 | + feature-test macro always has this value. |
| 96 | +|=== |
| 97 | + |
| 98 | + |
| 99 | +=== Event mode property |
| 100 | + |
| 101 | +This extension adds a new property `event_mode` which can be used with the |
| 102 | +`submit_with_event` free function from |
| 103 | +link:../experimental/sycl_ext_oneapi_enqueue_functions.asciidoc[sycl_ext_oneapi_enqueue_functions], |
| 104 | +allowing the user some control over how the resulting event is created and |
| 105 | +managed. |
| 106 | + |
| 107 | +``` |
| 108 | +namespace sycl::ext::intel::experimental { |
| 109 | + |
| 110 | +enum class event_mode_enum { none, low_power }; |
| 111 | + |
| 112 | +struct event_mode { |
| 113 | + event_mode(event_mode_enum mode); |
| 114 | + |
| 115 | + event_mode_enum value; |
| 116 | +}; |
| 117 | + |
| 118 | +using event_mode_key = event_mode; |
| 119 | + |
| 120 | +} // namespace sycl::ext::intel::experimental |
| 121 | +``` |
| 122 | + |
| 123 | + |
| 124 | +=== Low power event mode |
| 125 | + |
| 126 | +Passing the `event_mode` property with `event_mode_enum::low_power` to |
| 127 | +`submit_with_event` will act as a hint to the `event` created from the |
| 128 | +corresponding commands to do low-power synchronization. If the backend is able |
| 129 | +to handle low-power events, calling `event::wait()` or `event::wait_and_throw()` |
| 130 | +will cause the thread to yield and only do occasional wake-ups to check the |
| 131 | +event progress. |
| 132 | + |
| 133 | +[_Note:_ The low-power event mode currently only has an effect on `barrier` and |
| 134 | +`partial_barrier` commands enqueued on queues that return |
| 135 | +`backend::ext_oneapi_level_zero` from `queue::get_backend()`. |
| 136 | +_{endnote}_] |
| 137 | + |
| 138 | + |
| 139 | +=== New property usage example |
| 140 | + |
| 141 | +As an example of how to use the new `event_mode` property using the |
| 142 | +`event_mode_enum::low_power` mode, see the following code: |
| 143 | + |
| 144 | +``` |
| 145 | +#include <sycl/sycl.hpp> |
| 146 | + |
| 147 | +namespace oneapiex = sycl::ext::oneapi::experimental; |
| 148 | +namespace intelex = sycl::ext::intel::experimental; |
| 149 | + |
| 150 | +int main() { |
| 151 | + sycl::queue Q; |
| 152 | + |
| 153 | + // Submit some work to the queue. |
| 154 | + oneapiex::submit(Q, [&](sycl::handler &CGH) {...}); |
| 155 | + |
| 156 | + // Submit a command with the low-power event mode. |
| 157 | + oneapiex::properties Props{intelex::event_mode{intelex::event_mode_enum::low_power}}; |
| 158 | + sycl::event E = oneapiex::submit_with_event(Q, Props, [&](sycl::handler &CGH) { |
| 159 | + ... |
| 160 | + }); |
| 161 | + |
| 162 | + // Waiting for the resulting event will use low-power waiting if possible. |
| 163 | + E.wait(); |
| 164 | +} |
| 165 | +``` |
0 commit comments