A Sequencer
that buffers results and returns them in order of their sequence number.
More...
#include <sequencers.h>
Public Member Functions | |
OrderedSequencer (size_t max_jobs) | |
Constructs the OrderedSequencer with the maximum number of results it will ever hold at one point in time. More... | |
optional< Result > | next (ResultProducer next_result) override |
Buffers results until the next one in the expected order is received. | |
optional< Result > & | buffer (size_t index) |
Accesses the buffer at the index modulo the buffer size. | |
Data Fields | |
size_t | next_sequence_number_ = 0 |
The monotonically increasing sequence number we expect. | |
std::vector< optional< Result > > | buffer_ |
A fixed-size buffer (after construction). | |
Additional Inherited Members | |
Public Types inherited from torch::data::detail::sequencers::Sequencer< Result > | |
using | ResultProducer = std::function< optional< Result >()> |
A Sequencer
that buffers results and returns them in order of their sequence number.
The OrderedSequencer
maintains an internal, monotonically incrementing counter for the next sequence number it expects. If it receives a result with a higher sequence number, it will buffer it for later (when the sequence number reaches that of this result). Otherwise, if the sequence numbers match, the result is returned.
Implementation note: The OrderedSequencer
is implemented with a fixed-size buffer. Let m
be the maximum number of jobs in the data loader's queue and s
be the current sequence number. Assume m
jobs are scheduled in the DataLoader
. Any new result is stored at index job.sqn mod m
in the OrderedSequencer
. Why are we sure sequence numbers of new jobs will not collide with sequence numbers of buffered jobs? The OrderedSequencer
will not return from next()
until it receives the result with sqn s
. This means no new jobs can be scheduled in the DataLoader
in the meantime, which enforces that as long as sqn s
has not been received, s + m
(which would cause a collision in the fixed-size buffer) will not yet be scheduled.
Definition at line 63 of file sequencers.h.
|
inlineexplicit |
Constructs the OrderedSequencer
with the maximum number of results it will ever hold at one point in time.
Definition at line 68 of file sequencers.h.