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
9
namespace
mlx::core
{
10
11
class
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
23
void
wait
(
Stream
stream
);
24
25
// Signal the event at its current value in the given stream
26
void
signal
(
Stream
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
mlx::core::Event::is_signaled
bool is_signaled() const
mlx::core::Event::set_value
void set_value(uint64_t v)
Definition
event.h:40
mlx::core::Event::stream
const Stream & stream() const
Definition
event.h:44
mlx::core::Event::wait
void wait()
mlx::core::Event::signal
void signal()
mlx::core::Event::Event
Event()
Definition
event.h:13
mlx::core::Event::valid
bool valid() const
Definition
event.h:32
mlx::core::Event::signal
void signal(Stream stream)
mlx::core::Event::value
uint64_t value() const
Definition
event.h:36
mlx::core::Event::wait
void wait(Stream stream)
mlx::core::Event::Event
Event(Stream stream)
mlx::core
Definition
allocator.h:7
stream.h
mlx::core::Device::cpu
static constexpr DeviceType cpu
Definition
device.h:13
mlx::core::Stream
Definition
stream.h:9
mlx
event.h
Generated by
1.13.2