Skip to content

Commit 3b48a46

Browse files
[SYCL] Implement sycl_ext_oneapi_event_mode extension (#16108)
This commit implements the sycl_ext_oneapi_event_mode extension. Of particular focus is the low-power event mode. --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 3524739 commit 3b48a46

26 files changed

+396
-85
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,27 @@ template <typename LCRangeT, typename LCPropertiesT> struct LaunchConfigAccess {
8989
}
9090
};
9191

92-
template <typename CommandGroupFunc>
93-
void submit_impl(queue &Q, CommandGroupFunc &&CGF,
92+
template <typename CommandGroupFunc, typename PropertiesT>
93+
void submit_impl(queue &Q, PropertiesT Props, CommandGroupFunc &&CGF,
9494
const sycl::detail::code_location &CodeLoc) {
95-
Q.submit_without_event(std::forward<CommandGroupFunc>(CGF), CodeLoc);
95+
Q.submit_without_event(Props, std::forward<CommandGroupFunc>(CGF), CodeLoc);
96+
}
97+
98+
template <typename CommandGroupFunc, typename PropertiesT>
99+
event submit_with_event_impl(queue &Q, PropertiesT Props,
100+
CommandGroupFunc &&CGF,
101+
const sycl::detail::code_location &CodeLoc) {
102+
return Q.submit_with_event(Props, std::forward<CommandGroupFunc>(CGF),
103+
nullptr, CodeLoc);
96104
}
97105
} // namespace detail
98106

99107
template <typename CommandGroupFunc, typename PropertiesT>
100108
void submit(queue Q, PropertiesT Props, CommandGroupFunc &&CGF,
101109
const sycl::detail::code_location &CodeLoc =
102110
sycl::detail::code_location::current()) {
103-
std::ignore = Props;
104111
sycl::ext::oneapi::experimental::detail::submit_impl(
105-
Q, std::forward<CommandGroupFunc>(CGF), CodeLoc);
112+
Q, Props, std::forward<CommandGroupFunc>(CGF), CodeLoc);
106113
}
107114

108115
template <typename CommandGroupFunc>
@@ -116,8 +123,8 @@ template <typename CommandGroupFunc, typename PropertiesT>
116123
event submit_with_event(queue Q, PropertiesT Props, CommandGroupFunc &&CGF,
117124
const sycl::detail::code_location &CodeLoc =
118125
sycl::detail::code_location::current()) {
119-
std::ignore = Props;
120-
return Q.submit(std::forward<CommandGroupFunc>(CGF), CodeLoc);
126+
return sycl::ext::oneapi::experimental::detail::submit_with_event_impl(
127+
Q, Props, std::forward<CommandGroupFunc>(CGF), CodeLoc);
121128
}
122129

123130
template <typename CommandGroupFunc>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//==-- cluster_group_prop.hpp --- SYCL extension for event mode property ---==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/ext/oneapi/properties/property.hpp>
12+
13+
namespace sycl {
14+
inline namespace _V1 {
15+
namespace ext::oneapi::experimental {
16+
17+
enum class event_mode_enum { none, low_power };
18+
19+
struct event_mode
20+
: detail::run_time_property_key<event_mode, detail::PropKind::EventMode> {
21+
event_mode(event_mode_enum mode) : value(mode) {}
22+
23+
event_mode_enum value;
24+
};
25+
26+
using event_mode_key = event_mode;
27+
28+
inline bool operator==(const event_mode &lhs, const event_mode &rhs) {
29+
return lhs.value == rhs.value;
30+
}
31+
inline bool operator!=(const event_mode &lhs, const event_mode &rhs) {
32+
return !(lhs == rhs);
33+
}
34+
35+
} // namespace ext::oneapi::experimental
36+
} // namespace _V1
37+
} // namespace sycl

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ enum PropKind : uint32_t {
223223
InitializeToIdentity = 78,
224224
WorkGroupScratchSize = 79,
225225
Restrict = 80,
226+
EventMode = 81,
226227
// PropKindSize must always be the last value.
227-
PropKindSize = 81,
228+
PropKindSize = 82,
228229
};
229230

230231
template <typename PropertyT> struct PropertyToKind {

sycl/include/sycl/queue.hpp

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030
#include <sycl/exception_list.hpp> // for defaultAsyncHa...
3131
#include <sycl/ext/oneapi/device_global/device_global.hpp> // for device_global
3232
#include <sycl/ext/oneapi/device_global/properties.hpp> // for device_image_s...
33-
#include <sycl/ext/oneapi/experimental/graph.hpp> // for command_graph...
34-
#include <sycl/ext/oneapi/properties/properties.hpp> // for empty_properti...
35-
#include <sycl/handler.hpp> // for handler, isDev...
36-
#include <sycl/id.hpp> // for id
37-
#include <sycl/kernel.hpp> // for auto_name
38-
#include <sycl/kernel_handler.hpp> // for kernel_handler
39-
#include <sycl/nd_range.hpp> // for nd_range
40-
#include <sycl/property_list.hpp> // for property_list
41-
#include <sycl/range.hpp> // for range
33+
#include <sycl/ext/oneapi/experimental/event_mode_property.hpp>
34+
#include <sycl/ext/oneapi/experimental/graph.hpp> // for command_graph...
35+
#include <sycl/ext/oneapi/properties/properties.hpp> // for empty_properti...
36+
#include <sycl/handler.hpp> // for handler, isDev...
37+
#include <sycl/id.hpp> // for id
38+
#include <sycl/kernel.hpp> // for auto_name
39+
#include <sycl/kernel_handler.hpp> // for kernel_handler
40+
#include <sycl/nd_range.hpp> // for nd_range
41+
#include <sycl/property_list.hpp> // for property_list
42+
#include <sycl/range.hpp> // for range
4243

4344
#include <cstddef> // for size_t
4445
#include <functional> // for function
@@ -99,6 +100,9 @@ class __SYCL_EXPORT SubmissionInfo {
99100
std::shared_ptr<detail::queue_impl> &SecondaryQueue();
100101
const std::shared_ptr<detail::queue_impl> &SecondaryQueue() const;
101102

103+
ext::oneapi::experimental::event_mode_enum &EventMode();
104+
const ext::oneapi::experimental::event_mode_enum &EventMode() const;
105+
102106
private:
103107
std::shared_ptr<SubmissionInfoImpl> impl = nullptr;
104108
};
@@ -111,9 +115,14 @@ enum class queue_state { executing, recording };
111115
struct image_descriptor;
112116

113117
namespace detail {
114-
template <typename CommandGroupFunc>
115-
void submit_impl(queue &Q, CommandGroupFunc &&CGF,
118+
template <typename CommandGroupFunc, typename PropertiesT>
119+
void submit_impl(queue &Q, PropertiesT Props, CommandGroupFunc &&CGF,
116120
const sycl::detail::code_location &CodeLoc);
121+
122+
template <typename CommandGroupFunc, typename PropertiesT>
123+
event submit_with_event_impl(queue &Q, PropertiesT Props,
124+
CommandGroupFunc &&CGF,
125+
const sycl::detail::code_location &CodeLoc);
117126
} // namespace detail
118127
} // namespace ext::oneapi::experimental
119128

@@ -366,7 +375,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
366375
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit(
367376
T CGF,
368377
const detail::code_location &CodeLoc = detail::code_location::current()) {
369-
return submit_with_event(CGF, /*SecondaryQueuePtr=*/nullptr, CodeLoc);
378+
return submit_with_event(
379+
sycl::ext::oneapi::experimental::empty_properties_t{}, CGF,
380+
/*SecondaryQueuePtr=*/nullptr, CodeLoc);
370381
}
371382

372383
/// Submits a command group function object to the queue, in order to be
@@ -384,7 +395,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
384395
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit(
385396
T CGF, queue &SecondaryQueue,
386397
const detail::code_location &CodeLoc = detail::code_location::current()) {
387-
return submit_with_event(CGF, &SecondaryQueue, CodeLoc);
398+
return submit_with_event(
399+
sycl::ext::oneapi::experimental::empty_properties_t{}, CGF,
400+
&SecondaryQueue, CodeLoc);
388401
}
389402

390403
/// Prevents any commands submitted afterward to this queue from executing
@@ -2747,11 +2760,28 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
27472760
const detail::code_location &);
27482761
#endif
27492762

2750-
template <typename CommandGroupFunc>
2763+
template <typename CommandGroupFunc, typename PropertiesT>
27512764
friend void ext::oneapi::experimental::detail::submit_impl(
2752-
queue &Q, CommandGroupFunc &&CGF,
2765+
queue &Q, PropertiesT Props, CommandGroupFunc &&CGF,
27532766
const sycl::detail::code_location &CodeLoc);
27542767

2768+
template <typename CommandGroupFunc, typename PropertiesT>
2769+
friend event ext::oneapi::experimental::detail::submit_with_event_impl(
2770+
queue &Q, PropertiesT Props, CommandGroupFunc &&CGF,
2771+
const sycl::detail::code_location &CodeLoc);
2772+
2773+
template <typename PropertiesT>
2774+
void ProcessSubmitProperties(PropertiesT Props, detail::SubmissionInfo &SI) {
2775+
if constexpr (Props.template has_property<
2776+
ext::oneapi::experimental::event_mode_key>()) {
2777+
ext::oneapi::experimental::event_mode EventModeProp =
2778+
Props.template get_property<ext::oneapi::experimental::event_mode>();
2779+
if (EventModeProp.value !=
2780+
ext::oneapi::experimental::event_mode_enum::none)
2781+
SI.EventMode() = EventModeProp.value;
2782+
}
2783+
}
2784+
27552785
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
27562786
/// TODO: Unused. Remove these when ABI-break window is open.
27572787
event submit_impl(std::function<void(handler &)> CGH,
@@ -2800,16 +2830,18 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
28002830
/// Submits a command group function object to the queue, in order to be
28012831
/// scheduled for execution on the device.
28022832
///
2833+
/// \param Props is a property list with submission properties.
28032834
/// \param CGF is a function object containing command group.
28042835
/// \param CodeLoc is the code location of the submit call (default argument)
28052836
/// \return a SYCL event object for the submitted command group.
2806-
template <typename T>
2837+
template <typename T, typename PropertiesT>
28072838
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event>
28082839
submit_with_event(
2809-
T CGF, queue *SecondaryQueuePtr,
2840+
PropertiesT Props, T CGF, queue *SecondaryQueuePtr,
28102841
const detail::code_location &CodeLoc = detail::code_location::current()) {
28112842
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
28122843
detail::SubmissionInfo SI{};
2844+
ProcessSubmitProperties(Props, SI);
28132845
if (SecondaryQueuePtr)
28142846
SI.SecondaryQueue() = detail::getSyclObjImpl(*SecondaryQueuePtr);
28152847
#if __SYCL_USE_FALLBACK_ASSERT
@@ -2834,18 +2866,21 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
28342866
/// Submits a command group function object to the queue, in order to be
28352867
/// scheduled for execution on the device.
28362868
///
2869+
/// \param Props is a property list with submission properties.
28372870
/// \param CGF is a function object containing command group.
28382871
/// \param CodeLoc is the code location of the submit call (default argument)
2839-
template <typename T>
2872+
template <typename T, typename PropertiesT>
28402873
std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, void>
2841-
submit_without_event(T CGF, const detail::code_location &CodeLoc) {
2874+
submit_without_event(PropertiesT Props, T CGF,
2875+
const detail::code_location &CodeLoc) {
28422876
#if __SYCL_USE_FALLBACK_ASSERT
28432877
// If post-processing is needed, fall back to the regular submit.
28442878
// TODO: Revisit whether we can avoid this.
2845-
submit_with_event(CGF, nullptr, CodeLoc);
2879+
submit_with_event(Props, CGF, nullptr, CodeLoc);
28462880
#else
28472881
detail::tls_code_loc_t TlsCodeLocCapture(CodeLoc);
28482882
detail::SubmissionInfo SI{};
2883+
ProcessSubmitProperties(Props, SI);
28492884
submit_without_event_impl(CGF, SI, TlsCodeLocCapture.query(),
28502885
TlsCodeLocCapture.isToplevel());
28512886
#endif // __SYCL_USE_FALLBACK_ASSERT
@@ -3072,8 +3107,12 @@ event submitAssertCapture(queue &Self, event &Event, queue *SecondaryQueue,
30723107
});
30733108
};
30743109

3075-
CopierEv = Self.submit_with_event(CopierCGF, SecondaryQueue, CodeLoc);
3076-
CheckerEv = Self.submit_with_event(CheckerCGF, SecondaryQueue, CodeLoc);
3110+
CopierEv = Self.submit_with_event(
3111+
sycl::ext::oneapi::experimental::empty_properties_t{}, CopierCGF,
3112+
SecondaryQueue, CodeLoc);
3113+
CheckerEv = Self.submit_with_event(
3114+
sycl::ext::oneapi::experimental::empty_properties_t{}, CheckerCGF,
3115+
SecondaryQueue, CodeLoc);
30773116

30783117
return CheckerEv;
30793118
}

sycl/source/detail/cg.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#include <sycl/detail/ur.hpp> // for ur_rect_region_t, ur_rect_offset_t
1616
#include <sycl/event.hpp> // for event_impl
1717
#include <sycl/exception_list.hpp> // for queue_impl
18-
#include <sycl/kernel.hpp> // for kernel_impl
19-
#include <sycl/kernel_bundle.hpp> // for kernel_bundle_impl
18+
#include <sycl/ext/oneapi/experimental/event_mode_property.hpp>
19+
#include <sycl/kernel.hpp> // for kernel_impl
20+
#include <sycl/kernel_bundle.hpp> // for kernel_bundle_impl
2021

2122
#include <assert.h> // for assert
2223
#include <memory> // for shared_ptr, unique_ptr
@@ -425,12 +426,16 @@ class CGAdviseUSM : public CG {
425426
class CGBarrier : public CG {
426427
public:
427428
std::vector<detail::EventImplPtr> MEventsWaitWithBarrier;
429+
ext::oneapi::experimental::event_mode_enum MEventMode =
430+
ext::oneapi::experimental::event_mode_enum::none;
428431

429432
CGBarrier(std::vector<detail::EventImplPtr> EventsWaitWithBarrier,
433+
ext::oneapi::experimental::event_mode_enum EventMode,
430434
CG::StorageInitHelper CGData, CGType Type,
431435
detail::code_location loc = {})
432436
: CG(Type, std::move(CGData), std::move(loc)),
433-
MEventsWaitWithBarrier(std::move(EventsWaitWithBarrier)) {}
437+
MEventsWaitWithBarrier(std::move(EventsWaitWithBarrier)),
438+
MEventMode(EventMode) {}
434439
};
435440

436441
class CGProfilingTag : public CG {

sycl/source/detail/handler_impl.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ class handler_impl {
196196
bool MIsTopCodeLoc = true;
197197

198198
/// List of work group memory objects associated with this handler
199-
std::vector<std::shared_ptr<detail::work_group_memory_impl>> MWorkGroupMemoryObjects;
199+
std::vector<std::shared_ptr<detail::work_group_memory_impl>>
200+
MWorkGroupMemoryObjects;
201+
202+
/// Potential event mode for the result event of the command.
203+
ext::oneapi::experimental::event_mode_enum MEventMode =
204+
ext::oneapi::experimental::event_mode_enum::none;
200205
};
201206

202207
} // namespace detail

sycl/source/detail/queue_impl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ event queue_impl::submit_impl(const std::function<void(handler &)> &CGF,
358358
bool IsTopCodeLoc,
359359
const SubmissionInfo &SubmitInfo) {
360360
handler Handler(Self, PrimaryQueue, SecondaryQueue, CallerNeedsEvent);
361+
auto HandlerImpl = detail::getSyclObjImpl(Handler);
361362
Handler.saveCodeLoc(Loc, IsTopCodeLoc);
362363

363364
{
@@ -368,13 +369,15 @@ event queue_impl::submit_impl(const std::function<void(handler &)> &CGF,
368369
// Scheduler will later omit events, that are not required to execute tasks.
369370
// Host and interop tasks, however, are not submitted to low-level runtimes
370371
// and require separate dependency management.
371-
const CGType Type = detail::getSyclObjImpl(Handler)->MCGType;
372+
const CGType Type = HandlerImpl->MCGType;
372373
event Event = detail::createSyclObjFromImpl<event>(
373374
std::make_shared<detail::event_impl>());
374375
std::vector<StreamImplPtr> Streams;
375376
if (Type == CGType::Kernel)
376377
Streams = std::move(Handler.MStreamStorage);
377378

379+
HandlerImpl->MEventMode = SubmitInfo.EventMode();
380+
378381
if (SubmitInfo.PostProcessorFunc()) {
379382
auto &PostProcess = *SubmitInfo.PostProcessorFunc();
380383

sycl/source/detail/queue_impl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ enum QueueOrder { Ordered, OOO };
7171
struct SubmissionInfoImpl {
7272
optional<detail::SubmitPostProcessF> MPostProcessorFunc = std::nullopt;
7373
std::shared_ptr<detail::queue_impl> MSecondaryQueue = nullptr;
74+
ext::oneapi::experimental::event_mode_enum MEventMode =
75+
ext::oneapi::experimental::event_mode_enum::none;
7476
};
7577

7678
class queue_impl {

0 commit comments

Comments
 (0)