mirror of
https://github.com/ml-explore/mlx.git
synced 2025-12-16 01:49:05 +08:00
24
mlx/event.h
24
mlx/event.h
@@ -10,46 +10,46 @@ namespace mlx::core {
|
||||
|
||||
class Event {
|
||||
public:
|
||||
Event() {};
|
||||
Event() = default;
|
||||
|
||||
Event(const Stream& steam);
|
||||
|
||||
// Wait for the event to be signaled at its curent value
|
||||
// Wait for the event to be signaled at its current value
|
||||
void wait();
|
||||
|
||||
// Signal the event at its current value
|
||||
void signal();
|
||||
|
||||
// Check if the event is valid
|
||||
bool valid() {
|
||||
bool valid() const {
|
||||
return event_ != nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
uint64_t value() {
|
||||
uint64_t value() const {
|
||||
return value_;
|
||||
};
|
||||
}
|
||||
|
||||
void set_value(uint64_t v) {
|
||||
value_ = v;
|
||||
};
|
||||
}
|
||||
|
||||
const Stream& stream() {
|
||||
const Stream& stream() const {
|
||||
if (!valid()) {
|
||||
throw std::runtime_error(
|
||||
"[Event::stream] Cannot access stream on invalid event.");
|
||||
}
|
||||
return stream_;
|
||||
};
|
||||
}
|
||||
|
||||
const std::shared_ptr<void>& raw_event() {
|
||||
const std::shared_ptr<void>& raw_event() const {
|
||||
return event_;
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
// Default constructed stream should never be used
|
||||
// since the event is not yet valid
|
||||
Stream stream_{0, Device::cpu};
|
||||
std::shared_ptr<void> event_{nullptr};
|
||||
std::shared_ptr<void> event_;
|
||||
uint64_t value_{0};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user