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
21
22namespace sham {
23
24 namespace details {
25 // forward declare BufferEventHandler
27 } // namespace details
28
32 class EventList {
33 public:
50 inline void apply_dependency(sycl::handler &h) { h.depends_on(events); }
51
58 inline void wait() {
59 StackEntry __s{};
60 for (auto &e : events) {
61 e.wait();
62 }
63 consumed = true;
64 }
65
73 inline void wait_and_throw() {
74 StackEntry __s{};
75 for (auto &e : events) {
76 e.wait_and_throw();
77 }
78 consumed = true;
79 }
80
88 inline void add_event(sycl::event e) {
89 events.push_back(e);
90 consumed = false;
91 }
92
101 inline void add_events(std::vector<sycl::event> &e) {
102 events.insert(events.end(), e.begin(), e.end());
103 consumed = false;
104 }
105
115 inline void add_events(sham::EventList &e) {
116 events.insert(events.end(), e.events.begin(), e.events.end());
117 consumed = false;
118 e.consumed = true;
119 }
120
130 inline std::string get_state() {
131 return sham::format("events : {}, consumed : {}", events.size(), consumed);
132 }
133
135 EventList(SourceLocation loc = SourceLocation{}) : loc_build(loc) {}
136
138 EventList(std::initializer_list<sycl::event> e, SourceLocation loc = SourceLocation{})
139 : events(e), loc_build(loc) {}
140
148 ~EventList() noexcept(false);
149
151 inline std::vector<sycl::event> &get_events() { return events; }
152
154 inline const std::vector<sycl::event> &get_events() const { return events; }
155
157 inline void set_consumed(bool consumed) { this->consumed = consumed; }
158
159 private:
160 std::vector<sycl::event> events = {};
161 bool consumed = false;
162 SourceLocation loc_build;
163
164 friend class DeviceQueue;
165 friend class details::BufferEventHandler;
166 };
167} // namespace sham
Class to manage a list of SYCL events.
Definition EventList.hpp:32
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:88
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:73
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:58
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:50
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.
Core formatting functions: format, vformat, and format_printf.
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