Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// events/barriers for Realm
19
20#ifndef REALM_EVENT_H
21#define REALM_EVENT_H
22
23#include "realm/realm_c.h"
24#include "realm/utils.h"
25#include "realm/memory.h"
26
27#include <vector>
28#include <set>
29#include <iostream>
30
36namespace Realm {
37
39
51 public:
53
55
56 Event() = default;
57 constexpr explicit Event(id_t id)
58 : id(id)
59 {}
60
61 constexpr operator id_t() const { return id; }
62
63 bool operator<(const Event &rhs) const;
64 bool operator==(const Event &rhs) const;
65 bool operator!=(const Event &rhs) const;
66
71 static const Event NO_EVENT;
72
77 bool exists(void) const;
78
83 bool has_triggered(void) const;
84
88 void wait(void) const;
89
93 void external_wait(void) const;
94
101 bool external_timedwait(long long max_ns) const;
102
109 bool has_triggered_faultaware(bool &poisoned) const;
110
116 void wait_faultaware(bool &poisoned) const;
117
123 void external_wait_faultaware(bool &poisoned) const;
124
131 bool external_timedwait_faultaware(bool &poisoned, long long max_ns) const;
132
138 void subscribe(void) const;
139
145 void cancel_operation(const void *reason_data, size_t reason_size) const;
146
152 void set_operation_priority(int new_priority) const;
153
155
162 static Event merge_events(const Event *wait_for, size_t num_events);
163 static Event merge_events(Event ev1, Event ev2, Event ev3 = NO_EVENT,
164 Event ev4 = NO_EVENT, Event ev5 = NO_EVENT,
165 Event ev6 = NO_EVENT);
166 static Event merge_events(const std::set<Event> &wait_for);
167 static Event merge_events(const span<const Event> &wait_for);
169
177 static Event merge_events_ignorefaults(const Event *wait_for, size_t num_events);
179 static Event merge_events_ignorefaults(const std::set<Event> &wait_for);
180 static Event ignorefaults(Event wait_for);
181
190 static void advise_event_ordering(Event happens_before, Event happens_after);
191 static void advise_event_ordering(const Event *happens_before, size_t num_events,
192 Event happens_after, bool all_must_trigger = true);
193 static void advise_event_ordering(const span<Event> &happens_before,
194 Event happens_after, bool all_must_trigger = true);
195 };
196
206 public:
207 UserEvent() = default;
208 constexpr UserEvent(id_t id)
209 : Event(id)
210 {}
211
217
225 void trigger(Event wait_on = Event::NO_EVENT, bool ignore_faults = false) const;
226
227 /*
228 * Attempt to cancell all the operations waiting on this user
229 * event.
230 */
231 void cancel(void) const;
232
234 };
235
243 public:
245 timestamp_t; // used to avoid race conditions with arrival adjustments
246
248
249 static const Barrier NO_BARRIER;
250
251 static Barrier create_barrier(unsigned expected_arrivals, ReductionOpID redop_id = 0,
252 const void *initial_value = 0,
253 size_t initial_value_size = 0);
254
259
269 static Barrier create_barrier(const Barrier::ParticipantInfo *expected_arrivals,
270 size_t num_participants, ReductionOpID redop_id = 0,
271 const void *initial_value = 0,
272 size_t initial_value_size = 0);
273
281 size_t num_participants);
282
283 void destroy_barrier(void);
284
285 static const ::realm_event_gen_t MAX_PHASES;
286
287 /*
288 * Advance a barrier to the next phase, returning a new barrier
289 * handle. Attemps to advance beyond the last phase return NO_BARRIER
290 * instead.
291 * \return the new barrier handle.
292 */
294
295 /*
296 * Alter the arrival count of a barrier.
297 * \param delta the amount to adjust the arrival count by
298 * \return the new barrier handle.
299 */
300 Barrier alter_arrival_count(int delta) const;
301
302 /*
303 * Get the previous phase of a barrier.
304 * \return the previous phase of the barrier
305 */
307
308 /*
309 * Adjust the arrival count of a barrier.
310 * \param count the amount to adjust the arrival count by
311 * \param wait_on an event that must trigger before the arrival count
312 * can be adjusted.
313 * \param ignore_faults if true, the arrival count will be adjusted even
314 * if the event it is waiting on is poisoned.
315 * \param reduce_value if non-null, the value will be used to update the
316 * reduction value associated with the barrier.
317 * \param reduce_value_size the size of the reduction value
318 */
319 void arrive(unsigned count = 1, Event wait_on = Event::NO_EVENT,
320 const void *reduce_value = 0, size_t reduce_value_size = 0) const;
321
322 /*
323 * Get the resulting barrier value.
324 * \param value the resulting value
325 * \param value_size the size of the resulting value
326 * \return true if the value was successfully retrieved,
327 * generation hasn't triggered yet.
328 */
329 bool get_result(void *value, size_t value_size) const;
330 };
331
339 public:
341
343 bool operator<(const CompletionQueue &rhs) const;
344 bool operator==(const CompletionQueue &rhs) const;
345 bool operator!=(const CompletionQueue &rhs) const;
346
348
349 bool exists(void) const;
350
360
366 void destroy(Event wait_on = Event::NO_EVENT);
367
369
375 void add_event(Event event);
378
392 size_t pop_events(Event *events, size_t max_events);
393
410 };
411
412}; // namespace Realm
413
414#include "realm/event.inl"
415
416#endif // ifndef REALM_EVENT_H
Definition event.h:242
Barrier alter_arrival_count(int delta) const
void destroy_barrier(void)
Barrier advance_barrier(void) const
static const Barrier NO_BARRIER
Definition event.h:249
void arrive(unsigned count=1, Event wait_on=Event::NO_EVENT, const void *reduce_value=0, size_t reduce_value_size=0) const
static Barrier create_barrier(const Barrier::ParticipantInfo *expected_arrivals, size_t num_participants, ReductionOpID redop_id=0, const void *initial_value=0, size_t initial_value_size=0)
timestamp_t timestamp
Definition event.h:247
static Barrier create_barrier(unsigned expected_arrivals, ReductionOpID redop_id=0, const void *initial_value=0, size_t initial_value_size=0)
Barrier get_previous_phase(void) const
Barrier set_arrival_pattern(const Barrier::ParticipantInfo *expected_arrivals, size_t num_participants)
bool get_result(void *value, size_t value_size) const
::realm_barrier_timestamp_t timestamp_t
Definition event.h:245
static const ::realm_event_gen_t MAX_PHASES
Definition event.h:285
Definition event.h:338
::realm_id_t id_t
Definition event.h:340
bool operator!=(const CompletionQueue &rhs) const
id_t id
Definition event.h:342
bool exists(void) const
bool operator<(const CompletionQueue &rhs) const
size_t pop_events(Event *events, size_t max_events)
bool operator==(const CompletionQueue &rhs) const
void add_event(Event event)
void add_event_faultaware(Event event)
static const CompletionQueue NO_QUEUE
Definition event.h:347
static CompletionQueue create_completion_queue(size_t max_size)
Event get_nonempty_event(void)
void destroy(Event wait_on=Event::NO_EVENT)
Definition event.h:50
bool has_triggered(void) const
static const Event NO_EVENT
The value should be usued to initialize an event handle. NO_EVENT is always in has triggered state .
Definition event.h:71
void set_operation_priority(int new_priority) const
Event()=default
bool has_triggered_faultaware(bool &poisoned) const
static Event merge_events_ignorefaults(const span< const Event > &wait_for)
static void advise_event_ordering(const Event *happens_before, size_t num_events, Event happens_after, bool all_must_trigger=true)
bool operator!=(const Event &rhs) const
bool operator==(const Event &rhs) const
::realm_id_t id_t
Definition event.h:52
void external_wait(void) const
constexpr Event(id_t id)
Definition event.h:57
static void advise_event_ordering(Event happens_before, Event happens_after)
void subscribe(void) const
static Event ignorefaults(Event wait_for)
static Event merge_events(const std::set< Event > &wait_for)
bool operator<(const Event &rhs) const
bool external_timedwait(long long max_ns) const
void external_wait_faultaware(bool &poisoned) const
void wait(void) const
bool external_timedwait_faultaware(bool &poisoned, long long max_ns) const
static Event merge_events_ignorefaults(const Event *wait_for, size_t num_events)
bool exists(void) const
static Event merge_events_ignorefaults(const std::set< Event > &wait_for)
static Event merge_events(const span< const Event > &wait_for)
void cancel_operation(const void *reason_data, size_t reason_size) const
static void advise_event_ordering(const span< Event > &happens_before, Event happens_after, bool all_must_trigger=true)
static Event merge_events(Event ev1, Event ev2, Event ev3=NO_EVENT, Event ev4=NO_EVENT, Event ev5=NO_EVENT, Event ev6=NO_EVENT)
static Event merge_events(const Event *wait_for, size_t num_events)
void wait_faultaware(bool &poisoned) const
Definition event.h:205
void trigger(Event wait_on=Event::NO_EVENT, bool ignore_faults=false) const
UserEvent()=default
static const UserEvent NO_USER_EVENT
Definition event.h:233
constexpr UserEvent(id_t id)
Definition event.h:208
void cancel(void) const
static UserEvent create_user_event(void)
Definition utils.h:84
#define REALM_PUBLIC_API
Definition compiler_support.h:217
Definition activemsg.h:38
::realm_address_space_t AddressSpace
Definition memory.h:31
::realm_reduction_op_id_t ReductionOpID
Definition event.h:38
unsigned long long realm_id_t
Definition realm_c.h:64
unsigned long long realm_barrier_timestamp_t
Definition realm_c.h:78
int realm_reduction_op_id_t
Definition realm_c.h:74
#define REALM_NO_EVENT
Definition realm_c.h:167
Definition event.h:255
unsigned count
Definition event.h:257
AddressSpace address_space
Definition event.h:256