pub struct PrefetchDataLoader { /* private fields */ }Expand description
Asynchronous batch iterator over a shared HostDataset.
A single worker thread walks the epoch’s index order, calls
get_host_sample, collates, and pushes HostBatch values into a
queue bounded at prefetch_batches. next_batch pops on the caller
thread, so sample production overlaps consumption; next_batch_on
additionally uploads the collated batch to the runtime. Shuffle order,
drop_last, and epoch resets share the DataLoader seed contract.
One worker is the admitted contract: the queue depth already decouples production from consumption, and multi-worker partitioning would add index ownership without changing the device boundary.
Implementations§
Source§impl PrefetchDataLoader
impl PrefetchDataLoader
Sourcepub fn new(
dataset: Arc<dyn HostDataset>,
config: DataLoaderConfig,
prefetch_batches: usize,
) -> Result<Self>
pub fn new( dataset: Arc<dyn HostDataset>, config: DataLoaderConfig, prefetch_batches: usize, ) -> Result<Self>
Construct a prefetching loader and start the epoch-0 worker.
§Errors
Returns an error for a non-positive batch size, a zero prefetch depth, a negative dataset length, or index allocation failure.
Sourcepub fn next_batch(&mut self) -> Result<Option<HostBatch>>
pub fn next_batch(&mut self) -> Result<Option<HostBatch>>
Advance to the next host batch; None means the epoch is exhausted.
The call blocks only when the queue is empty and the worker is still producing; a worker-side failure is delivered once and ends the epoch.
§Errors
Returns the first worker-side sample or collation error.
Sourcepub fn reset_epoch(&mut self, epoch: u64) -> Result<()>
pub fn reset_epoch(&mut self, epoch: u64) -> Result<()>
Reset for a new data pass, deriving the shuffle order from the
configured seed mixed with the epoch number — matching
DataLoader::reset_epoch. A new worker replaces the old one;
queued batches from the previous epoch are discarded.
§Errors
Returns the index-building errors described by Self::new.
Sourcepub fn num_batches(&self) -> i64
pub fn num_batches(&self) -> i64
Number of batches in the current epoch.
Sourcepub fn current_batch(&self) -> i64
pub fn current_batch(&self) -> i64
Index of the next batch that will be returned.
Sourcepub fn seek(&mut self, epoch: u64, cursor: i64) -> Result<()>
pub fn seek(&mut self, epoch: u64, cursor: i64) -> Result<()>
Restore a recorded loader position (epoch, cursor), matching
DataLoader::seek.
§Errors
Returns index-building errors or an invalid-argument error when
cursor is outside 0..=num_batches(). A failed seek leaves the
existing worker and cursor unchanged.