Skip to main content

PrefetchDataLoader

Struct PrefetchDataLoader 

Source
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

Source

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.

Source

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.

Source

pub fn next_batch_on(&mut self, runtime: &Runtime) -> Result<Option<Batch>>

Pop the next batch and upload it to runtime.

§Errors

Returns worker errors plus upload failures.

Source

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.

Source

pub fn num_batches(&self) -> i64

Number of batches in the current epoch.

Source

pub fn current_batch(&self) -> i64

Index of the next batch that will be returned.

Source

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.

Auto Trait Implementations§

§

impl !RefUnwindSafe for PrefetchDataLoader

§

impl !Sync for PrefetchDataLoader

§

impl !UnwindSafe for PrefetchDataLoader

§

impl Forget for PrefetchDataLoader

§

impl Freeze for PrefetchDataLoader
where *const ArcInner<dyn HostDataset> is !null: Freeze, PhantomData<ArcInner<dyn HostDataset>>: Freeze, *mut Counter<Channel<Result<HostBatch, Error>>>: Freeze, *mut Counter<Channel<Result<HostBatch, Error>>>: Freeze, *mut Counter<Channel<Result<HostBatch, Error>>>: Freeze, *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze, *const ArcInner<Packet<'static, ()>> is !null: Freeze, PhantomData<ArcInner<Packet<'static, ()>>>: Freeze,

§

impl Move for PrefetchDataLoader

§

impl Send for PrefetchDataLoader

§

impl Unpin for PrefetchDataLoader
where Arc<dyn HostDataset>: Unpin, *mut Counter<Channel<Result<HostBatch, Error>>>: Unpin, *mut Counter<Channel<Result<HostBatch, Error>>>: Unpin, *mut Counter<Channel<Result<HostBatch, Error>>>: Unpin, Arc<Inner, System>: Unpin, Arc<Packet<'static, ()>>: Unpin,

§

impl UnsafeUnpin for PrefetchDataLoader
where *const ArcInner<dyn HostDataset> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn HostDataset>>: UnsafeUnpin, *mut Counter<Channel<Result<HostBatch, Error>>>: UnsafeUnpin, *mut Counter<Channel<Result<HostBatch, Error>>>: UnsafeUnpin, *mut Counter<Channel<Result<HostBatch, Error>>>: UnsafeUnpin, *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin, *const ArcInner<Packet<'static, ()>> is !null: UnsafeUnpin, PhantomData<ArcInner<Packet<'static, ()>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.