Skip to content

Commit 9110431

Browse files
committed
[SYCL][Docs] Add proposed low-power event extension
This commit adds the sycl_ext_intel_low_power_event extension as proposed. To support this extension, the barriers in the sycl_ext_oneapi_enqueue_functions extension are given property arguments without any current consumers. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 48a75f4 commit 9110431

File tree

3 files changed

+180
-10
lines changed

3 files changed

+180
-10
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_enqueue_functions.asciidoc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,11 @@ a!
670670
----
671671
namespace sycl::ext::oneapi::experimental {
672672
673-
void barrier(sycl::queue q);
673+
template <typename Properties = empty_properties_t>
674+
void barrier(sycl::queue q, Properties properties = {});
674675
675-
void barrier(sycl::handler h);
676+
template <typename Properties = empty_properties_t>
677+
void barrier(sycl::handler h, Properties properties = {});
676678
677679
}
678680
----
@@ -690,9 +692,13 @@ a!
690692
----
691693
namespace sycl::ext::oneapi::experimental {
692694
693-
void partial_barrier(sycl::queue q, const std::vector<sycl::event>& events);
695+
template <typename Properties = empty_properties_t>
696+
void partial_barrier(sycl::queue q, const std::vector<sycl::event>& events,
697+
Properties properties = {});
694698
695-
void partial_barrier(sycl::handler h, const std::vector<sycl::event>& events);
699+
template <typename Properties = empty_properties_t>
700+
void partial_barrier(sycl::handler h, const std::vector<sycl::event>& events,
701+
Properties properties = {});
696702
697703
}
698704
----
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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: &#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_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+
```

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,34 @@ __SYCL_EXPORT void mem_advise(queue Q, void *Ptr, size_t NumBytes, int Advice,
349349
const sycl::detail::code_location &CodeLoc =
350350
sycl::detail::code_location::current());
351351

352-
inline void barrier(handler &CGH) { CGH.ext_oneapi_barrier(); }
352+
template <typename PropertiesT = empty_properties_t>
353+
inline void barrier(handler &CGH, PropertiesT Properties = {}) {
354+
std::ignore = Properties;
355+
CGH.ext_oneapi_barrier();
356+
}
353357

354-
inline void barrier(queue Q, const sycl::detail::code_location &CodeLoc =
355-
sycl::detail::code_location::current()) {
356-
submit(Q, [&](handler &CGH) { barrier(CGH); }, CodeLoc);
358+
template <typename PropertiesT = empty_properties_t>
359+
inline void barrier(queue Q, PropertiesT Properties = {},
360+
const sycl::detail::code_location &CodeLoc =
361+
sycl::detail::code_location::current()) {
362+
submit(Q, [&](handler &CGH) { barrier(CGH, Properties); }, CodeLoc);
357363
}
358364

359-
inline void partial_barrier(handler &CGH, const std::vector<event> &Events) {
365+
template <typename PropertiesT = empty_properties_t>
366+
inline void partial_barrier(handler &CGH, const std::vector<event> &Events,
367+
PropertiesT Properties = {}) {
368+
std::ignore = Properties;
360369
CGH.ext_oneapi_barrier(Events);
361370
}
362371

372+
template <typename PropertiesT = empty_properties_t>
363373
inline void partial_barrier(queue Q, const std::vector<event> &Events,
374+
PropertiesT Properties = {},
364375
const sycl::detail::code_location &CodeLoc =
365376
sycl::detail::code_location::current()) {
366-
submit(Q, [&](handler &CGH) { partial_barrier(CGH, Events); }, CodeLoc);
377+
submit(
378+
Q, [&](handler &CGH) { partial_barrier(CGH, Events, Properties); },
379+
CodeLoc);
367380
}
368381

369382
} // namespace ext::oneapi::experimental

0 commit comments

Comments
 (0)