pub struct WorkerPool<D, C>where
D: Dataset + Clone + Send + Sync + 'static,
C: Collate<D::Item> + Clone + Send + Sync + 'static,
D::Item: Send + 'static,
C::Output: Send + 'static,{ /* private fields */ }Expand description
Worker process manager for multi-process data loading
This struct manages a pool of worker threads that process batches in parallel, allowing for efficient utilization of multiple CPU cores during data loading.
§Type Parameters
D- Dataset type implementing the Dataset traitC- Collate function type implementing the Collate trait
§Examples
ⓘ
use std::sync::Arc;
use torsh_data::dataloader::workers::WorkerPool;
use torsh_data::dataset::TensorDataset;
use torsh_data::collate::DefaultCollate;
let dataset = Arc::new(TensorDataset::new(vec![1, 2, 3, 4, 5]));
let collate_fn = Arc::new(DefaultCollate);
let worker_pool = WorkerPool::new(dataset, collate_fn, 4);
// Submit tasks and collect results
worker_pool.submit_task(0, vec![0, 1]).unwrap();
let result = worker_pool.get_result().unwrap();Implementations§
Source§impl<D, C> WorkerPool<D, C>
impl<D, C> WorkerPool<D, C>
Sourcepub fn get_result(&self) -> Result<WorkerResult<C::Output>>
pub fn get_result(&self) -> Result<WorkerResult<C::Output>>
Get a result from the worker pool
This method blocks until a result is available from any worker.
§Returns
The next available worker result
Sourcepub fn try_get_result(&self) -> Option<WorkerResult<C::Output>>
pub fn try_get_result(&self) -> Option<WorkerResult<C::Output>>
Sourcepub fn num_workers(&self) -> usize
pub fn num_workers(&self) -> usize
Auto Trait Implementations§
impl<D, C> !RefUnwindSafe for WorkerPool<D, C>
impl<D, C> !Sync for WorkerPool<D, C>
impl<D, C> !UnwindSafe for WorkerPool<D, C>
impl<D, C> Freeze for WorkerPool<D, C>
impl<D, C> Send for WorkerPool<D, C>
impl<D, C> Unpin for WorkerPool<D, C>
impl<D, C> UnsafeUnpin for WorkerPool<D, C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.