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 is valid
24 bool valid() const {
25 return event_ != nullptr;
26 }
27
28 uint64_t value() const {
29 return value_;
30 }
31
32 void set_value(uint64_t v) {
33 value_ = v;
34 }
35
36 const Stream& stream() const {
37 if (!valid()) {
38 throw std::runtime_error(
39 "[Event::stream] Cannot access stream on invalid event.");
40 }
41 return stream_;
42 }
43
44 const std::shared_ptr<void>& raw_event() const {
45 return event_;
46 }
47
48 private:
49 // Default constructed stream should never be used
50 // since the event is not yet valid
51 Stream stream_{0, Device::cpu};
52 std::shared_ptr<void> event_;
53 uint64_t value_{0};
54};
55
56} // namespace mlx::core
Definition event.h:11
void set_value(uint64_t v)
Definition event.h:32
Event(const Stream &steam)
const Stream & stream() const
Definition event.h:36
bool valid() const
Definition event.h:24
uint64_t value() const
Definition event.h:28
const std::shared_ptr< void > & raw_event() const
Definition event.h:44
Definition allocator.h:7
static constexpr DeviceType cpu
Definition device.h:13
Definition stream.h:9