MLX
 
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1// Copyright © 2024 Apple Inc.
2#pragma once
3
4#include <memory>
5#include <stdexcept>
6
7#include "mlx/stream.h"
8
9namespace mlx::core {
10
11class Event {
12 public:
13 Event() {};
14 explicit Event(Stream stream);
15
16 // Wait for the event to be signaled at its current value
17 void wait();
18
19 // Signal the event at its current value
20 void signal();
21
22 // Wait in the given stream for the event to be signaled at its current value
24
25 // Signal the event at its current value in the given stream
27
28 // Check if the event has been signaled at its current value
29 bool is_signaled() const;
30
31 // Check if the event is valid
32 bool valid() const {
33 return event_ != nullptr;
34 }
35
36 uint64_t value() const {
37 return value_;
38 }
39
40 void set_value(uint64_t v) {
41 value_ = v;
42 }
43
44 const Stream& stream() const {
45 if (!valid()) {
46 throw std::runtime_error(
47 "[Event::stream] Cannot access stream on invalid event.");
48 }
49 return stream_;
50 }
51
52 private:
53 // Default constructed stream should never be used
54 // since the event is not yet valid
55 Stream stream_{0, Device::cpu};
56 std::shared_ptr<void> event_{nullptr};
57 uint64_t value_{0};
58};
59
60} // namespace mlx::core
bool is_signaled() const
void set_value(uint64_t v)
Definition event.h:40
const Stream & stream() const
Definition event.h:44
Event()
Definition event.h:13
bool valid() const
Definition event.h:32
void signal(Stream stream)
uint64_t value() const
Definition event.h:36
void wait(Stream stream)
Event(Stream stream)
Definition allocator.h:7
static constexpr DeviceType cpu
Definition device.h:13
Definition stream.h:9