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() = default;
14
15 Event(const Stream& steam);
16
17 // Wait for the event to be signaled at its current value
18 void wait();
19
20 // Signal the event at its current value
21 void signal();
22
23 // Check if the event has been signaled at its current value
24 bool is_signaled() const;
25
26 // Check if the event is valid
27 bool valid() const {
28 return event_ != nullptr;
29 }
30
31 uint64_t value() const {
32 return value_;
33 }
34
35 void set_value(uint64_t v) {
36 value_ = v;
37 }
38
39 const Stream& stream() const {
40 if (!valid()) {
41 throw std::runtime_error(
42 "[Event::stream] Cannot access stream on invalid event.");
43 }
44 return stream_;
45 }
46
47 const std::shared_ptr<void>& raw_event() const {
48 return event_;
49 }
50
51 private:
52 // Default constructed stream should never be used
53 // since the event is not yet valid
54 Stream stream_{0, Device::cpu};
55 std::shared_ptr<void> event_;
56 uint64_t value_{0};
57};
58
59} // namespace mlx::core
bool is_signaled() const
void set_value(uint64_t v)
Definition event.h:35
Event(const Stream &steam)
const Stream & stream() const
Definition event.h:39
bool valid() const
Definition event.h:27
uint64_t value() const
Definition event.h:31
const std::shared_ptr< void > & raw_event() const
Definition event.h:47
Definition allocator.h:7
static constexpr DeviceType cpu
Definition device.h:13
Definition stream.h:9