Template Struct OrderedSequencer¶
Defined in File sequencers.h
OrderedSequencer: public torch::data::detail::sequencers::Sequencer<Result>¶
Sequencerthat buffers results and returns them in order of their sequence number.
OrderedSequencermaintains 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
OrderedSequenceris implemented with a fixed-size buffer. Let
mbe the maximum number of jobs in the data loader’s queue and
sbe the current sequence number. Assume
mjobs are scheduled in the
DataLoader. Any new result is stored at index
job.sqn mod min the
OrderedSequencer. Why are we sure sequence numbers of new jobs will not collide with sequence numbers of buffered jobs? The
OrderedSequencerwill not return from
next()until it receives the result with sqn
s. This means no new jobs can be scheduled in the
DataLoaderin the meantime, which enforces that as long as sqn
shas not been received,
s + m(which would cause a collision in the fixed-size buffer) will not yet be scheduled.
OrderedSequencerwith the maximum number of results it will ever hold at one point in time.
next(ResultProducer next_result) override¶
Buffers results until the next one in the expected order is received.