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
15 Event(const Stream& steam);
16
17 // Wait for the event to be signaled at its curent 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() {
25 return event_ != nullptr;
26 };
27
28 uint64_t value() {
29 return value_;
30 };
31
32 void set_value(uint64_t v) {
33 value_ = v;
34 };
35
36 const Stream& stream() {
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() {
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_{nullptr};
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()
Definition event.h:36
bool valid()
Definition event.h:24
const std::shared_ptr< void > & raw_event()
Definition event.h:44
Event()
Definition event.h:13
uint64_t value()
Definition event.h:28
Definition allocator.h:7
static constexpr DeviceType cpu
Definition device.h:13
Definition stream.h:9