45 TRACE_MODULE(ASYNC,
"EpochQueue::create_read_context",
this);
56 TRACE_MODULE(ASYNC,
"EpochQueue::create_write_context",
this);
57 if (current_->has_writer())
59 std::shared_ptr<EpochContext> next = std::make_shared<EpochContext>();
60 current_->set_next_epoch(next);
68 [[nodiscard]] std::shared_ptr<EpochContext>
latest() const noexcept {
return current_; }
72 [[nodiscard]]
bool has_pending_writers() const noexcept {
return current_ && current_->has_writer(); }
85 [[nodiscard]] NodeInfo
const* debug_node()
const {
return current_ ? current_->node() :
nullptr; }
89 std::shared_ptr<EpochContext> current_;
101 TRACE(
"Constructing ReverseEpochQueue EpochContext", first_.get());
120 TRACE_MODULE(ASYNC,
"ReverseEpochQueue Constructor",
this);
130 TRACE_MODULE(ASYNC,
"ReverseEpochQueue::create_read_context",
this);
142 TRACE_MODULE(ASYNC,
"ReverseEpochQueue::create_write_context",
this);
159 first_->writer_acquire();
160 first_->writer_cancel();
170 std::shared_ptr<EpochContext> first_;
RAII handle representing the writer of a value in an EpochContext.
Definition epoch_context.hpp:874
RAII-scoped representation of a writer’s participation in an epoch.
Definition epoch_context.hpp:1048
Definition epoch_context.hpp:169
static std::shared_ptr< EpochContext > make_previous(std::shared_ptr< EpochContext > next)
Helper factory to construct the previous epoch in a reverse-mode chain.
Definition epoch_context.hpp:214
Coordinates multiple epochs of read/write gates.
Definition epoch_queue.hpp:22
bool has_pending_writers() const noexcept
Reports whether the latest epoch already has a writer.
Definition epoch_queue.hpp:72
std::shared_ptr< EpochContext > latest() const noexcept
Returns the latest epoch context.
Definition epoch_queue.hpp:68
EpochQueue & operator=(EpochQueue &&)=delete
Queue identity is stable and is not move-assigned by value.
EpochContextWriter< T > create_write_context(shared_storage< T > storage)
Create a write context, advancing to a new epoch when needed.
Definition epoch_queue.hpp:54
EpochQueue & operator=(EpochQueue const &)=delete
Queue identity is shared by handle, never copy-assigned.
EpochQueue(EpochQueue &&)=delete
Queue identity is stable and is not transferred by value.
EpochContextReader< T > create_read_context(shared_storage< T > storage) const
Create a read context bound to the current epoch.
Definition epoch_queue.hpp:43
~EpochQueue()
Destroy the epoch queue.
Definition epoch_queue.hpp:37
EpochQueue()
Construct a queue with one initial epoch.
Definition epoch_queue.hpp:25
EpochQueue(EpochQueue const &)=delete
Queue identity is shared by handle, never copied.
static NodeInfo const * create(T const *value)
Returns the stacktrace of where the node was created.
Definition async_node.hpp:263
Reverse-order epoch queue used by reverse-mode gradient accumulation.
Definition epoch_queue.hpp:96
void start()
Start running the reverse queue.
Definition epoch_queue.hpp:151
EpochContextReader< T > create_read_context(shared_storage< T > storage)
Create a read context from the earliest active reverse epoch.
Definition epoch_queue.hpp:128
ReverseEpochQueue & operator=(ReverseEpochQueue &&)=default
Move assignment.
ReverseEpochQueue & operator=(ReverseEpochQueue &)=delete
Non-copyable.
ReverseEpochQueue(ReverseEpochQueue &&)=default
Move constructor.
ReverseEpochQueue()
Construct a reverse queue with one initial epoch.
Definition epoch_queue.hpp:99
ReverseEpochQueue(ReverseEpochQueue &)=delete
Non-copyable.
ReverseEpochQueue(std::shared_ptr< EpochContext > first)
Construct a ReverseEpochQueue from a given EpochContext.
Definition epoch_queue.hpp:118
EpochContextWriter< T > create_write_context(shared_storage< T > storage)
Create a write context from the earliest active reverse epoch.
Definition epoch_queue.hpp:140
~ReverseEpochQueue()=default
Destructor.
bool is_started() const
Reports whether the reverse queue has already started.
Definition epoch_queue.hpp:167
A lightweight, thread-safe, reference-counted storage for a single object.
Definition shared_storage.hpp:94
Manages one “generation” of write/read ordering in an Async<T>
This represents the reverse-mode adjoint for functions of complex variables, assuming a real-valued s...
Definition async/async.hpp:26
#define DEBUG_CHECK(cond,...)
Definition trace.hpp:608
#define TRACE_MODULE(m,...)
Definition trace.hpp:149
#define TRACE(...)
Definition trace.hpp:89