Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
EventList.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
17
20
21namespace sham {
22
23 namespace details {
24 // forward declare BufferEventHandler
26 } // namespace details
27
31 class EventList {
32 public:
49 inline void apply_dependency(sycl::handler &h) { h.depends_on(events); }
50
57 inline void wait() {
58 StackEntry __s{};
59 for (auto &e : events) {
60 e.wait();
61 }
62 consumed = true;
63 }
64
72 inline void wait_and_throw() {
73 StackEntry __s{};
74 for (auto &e : events) {
75 e.wait_and_throw();
76 }
77 consumed = true;
78 }
79
87 inline void add_event(sycl::event e) {
88 events.push_back(e);
89 consumed = false;
90 }
91
100 inline void add_events(std::vector<sycl::event> &e) {
101 events.insert(events.end(), e.begin(), e.end());
102 consumed = false;
103 }
104
114 inline void add_events(sham::EventList &e) {
115 events.insert(events.end(), e.events.begin(), e.events.end());
116 consumed = false;
117 e.consumed = true;
118 }
119
129 inline std::string get_state() {
130 return shambase::format("events : {}, consumed : {}", events.size(), consumed);
131 }
132
134 EventList(SourceLocation loc = SourceLocation{}) : loc_build(loc) {}
135
137 EventList(std::initializer_list<sycl::event> e, SourceLocation loc = SourceLocation{})
138 : events(e), loc_build(loc) {}
139
147 ~EventList() noexcept(false);
148
150 inline std::vector<sycl::event> &get_events() { return events; }
151
153 inline const std::vector<sycl::event> &get_events() const { return events; }
154
156 inline void set_consumed(bool consumed) { this->consumed = consumed; }
157
158 private:
159 std::vector<sycl::event> events = {};
160 bool consumed = false;
161 SourceLocation loc_build;
162
163 friend class DeviceQueue;
164 friend class details::BufferEventHandler;
165 };
166} // namespace sham
Class to manage a list of SYCL events.
Definition EventList.hpp:31
EventList(SourceLocation loc=SourceLocation{})
Default constructor for EventList with source location.
void add_event(sycl::event e)
Add an event to the list of events.
Definition EventList.hpp:87
void add_events(sham::EventList &e)
Add all events from another EventList to this one.
void wait_and_throw()
Wait for all events in the list to be finished and throw an exception if one has occurred.
Definition EventList.hpp:72
EventList(std::initializer_list< sycl::event > e, SourceLocation loc=SourceLocation{})
same constructor but with initializer list
const std::vector< sycl::event > & get_events() const
Get the list of events (const).
void set_consumed(bool consumed)
Set the consumed state of the EventList (to be used with interop).
std::string get_state()
Get a string representation of the EventList's state.
~EventList() noexcept(false)
Destructor for EventList.
Definition EventList.cpp:19
void wait()
Wait for all events in the list to be finished.
Definition EventList.hpp:57
std::vector< sycl::event > & get_events()
Get the list of events.
void apply_dependency(sycl::handler &h)
Apply all events in the list as dependancies to a SYCL command group.
Definition EventList.hpp:49
void add_events(std::vector< sycl::event > &e)
Add multiple events to the list of events.
Class that manages the event state of a SYCL USM buffer.
namespace for backends this one is named only sham since shambackends is too long to write
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
provide information about the source location