Skip to content

Commit 19608d6

Browse files
[SYCL][Docs] Add proposed event mode extension (#15704)
This commit adds the sycl_ext_intel_event_mode extension as proposed. To support this extension, the submission functions in the sycl_ext_oneapi_enqueue_functions extension are given property arguments without any current consumers. --------- Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com> Co-authored-by: John Pennycook <john.pennycook@intel.com>
1 parent b7bb745 commit 19608d6

File tree

3 files changed

+192
-3
lines changed

3 files changed

+192
-3
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_enqueue_functions.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ namespace sycl::ext::oneapi::experimental {
233233
template <typename CommandGroupFunc>
234234
void submit(sycl::queue q, CommandGroupFunc&& cgf);
235235
236+
template <typename CommandGroupFunc, typename Properties>
237+
void submit(sycl::queue q, Properties properties, CommandGroupFunc&& cgf);
238+
236239
}
237240
----
238241
!====
@@ -250,6 +253,10 @@ namespace sycl::ext::oneapi::experimental {
250253
template <typename CommandGroupFunc>
251254
sycl::event submit_with_event(sycl::queue q, CommandGroupFunc&& cgf);
252255
256+
template <typename CommandGroupFunc, typename Properties>
257+
sycl::event submit_with_event(sycl::queue q, Properties properties,
258+
CommandGroupFunc&& cgf);
259+
253260
}
254261
----
255262
!====
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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: &#8212;{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+
```

sycl/include/sycl/ext/oneapi/experimental/enqueue_functions.hpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,38 @@ void submit_impl(queue &Q, CommandGroupFunc &&CGF,
9595
}
9696
} // namespace detail
9797

98-
template <typename CommandGroupFunc>
99-
void submit(queue Q, CommandGroupFunc &&CGF,
98+
template <typename CommandGroupFunc, typename PropertiesT>
99+
void submit(queue Q, PropertiesT Props, CommandGroupFunc &&CGF,
100100
const sycl::detail::code_location &CodeLoc =
101101
sycl::detail::code_location::current()) {
102+
std::ignore = Props;
102103
sycl::ext::oneapi::experimental::detail::submit_impl(
103104
Q, std::forward<CommandGroupFunc>(CGF), CodeLoc);
104105
}
105106

106107
template <typename CommandGroupFunc>
107-
event submit_with_event(queue Q, CommandGroupFunc &&CGF,
108+
void submit(queue Q, CommandGroupFunc &&CGF,
109+
const sycl::detail::code_location &CodeLoc =
110+
sycl::detail::code_location::current()) {
111+
submit(Q, empty_properties_t{}, std::forward<CommandGroupFunc>(CGF), CodeLoc);
112+
}
113+
114+
template <typename CommandGroupFunc, typename PropertiesT>
115+
event submit_with_event(queue Q, PropertiesT Props, CommandGroupFunc &&CGF,
108116
const sycl::detail::code_location &CodeLoc =
109117
sycl::detail::code_location::current()) {
118+
std::ignore = Props;
110119
return Q.submit(std::forward<CommandGroupFunc>(CGF), CodeLoc);
111120
}
112121

122+
template <typename CommandGroupFunc>
123+
event submit_with_event(queue Q, CommandGroupFunc &&CGF,
124+
const sycl::detail::code_location &CodeLoc =
125+
sycl::detail::code_location::current()) {
126+
return submit_with_event(Q, empty_properties_t{},
127+
std::forward<CommandGroupFunc>(CGF), CodeLoc);
128+
}
129+
113130
template <typename KernelName = sycl::detail::auto_name, typename KernelType>
114131
void single_task(handler &CGH, const KernelType &KernelObj) {
115132
CGH.single_task<KernelName>(KernelObj);

0 commit comments

Comments
 (0)