Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
torch::data::detail::DataShuttle< Job, Result > Class Template Reference

Encapsulates the full life cycle of DataLoader jobs. More...

#include <data_shuttle.h>

Public Member Functions

void push_job (Job job)
 Pushes a new job. Called by the main thread.
 
void push_result (Result result)
 Pushes the result of a job. Called by worker threads.
 
Job pop_job ()
 Returns the next job, blocking until there is one available. More...
 
optional< Result > pop_result (optional< std::chrono::milliseconds > timeout=nullopt)
 Returns the result of a job, or nullopt if all jobs were exhausted. More...
 
void drain ()
 Discards any jobs that are not yet in flight, and waits for all in-flight jobs to finish, discarding their result. More...
 
size_t in_flight_jobs () const noexcept
 Returns the number of jobs that are still in progress. More...
 

Detailed Description

template<typename Job, typename Result>
class torch::data::detail::DataShuttle< Job, Result >

Encapsulates the full life cycle of DataLoader jobs.

When a new job is enqueued to the DataShuttle, a counter for in-flight jobs is bumped. This job is said to be "in-flight" until its result is popped. Worker threads dequeue jobs as soon as they are available. When a worker finishes a job, it enqueues the result. Only when the main thread dequeues a result is the count of in-flight jobs decremented. When the main thread attempts to dequeue a job but no jobs are in-flight, that means the epoch is complete and pop_result returns an empty optional.

Definition at line 26 of file data_shuttle.h.

Member Function Documentation

template<typename Job, typename Result>
void torch::data::detail::DataShuttle< Job, Result >::drain ( )
inline

Discards any jobs that are not yet in flight, and waits for all in-flight jobs to finish, discarding their result.

Definition at line 59 of file data_shuttle.h.

template<typename Job, typename Result>
size_t torch::data::detail::DataShuttle< Job, Result >::in_flight_jobs ( ) const
inlinenoexcept

Returns the number of jobs that are still in progress.

When this number is zero, an epoch is finished.

Definition at line 71 of file data_shuttle.h.

template<typename Job, typename Result>
Job torch::data::detail::DataShuttle< Job, Result >::pop_job ( )
inline

Returns the next job, blocking until there is one available.

Called by worker threads.

Definition at line 41 of file data_shuttle.h.

template<typename Job, typename Result>
optional<Result> torch::data::detail::DataShuttle< Job, Result >::pop_result ( optional< std::chrono::milliseconds >  timeout = nullopt)
inline

Returns the result of a job, or nullopt if all jobs were exhausted.

Called by the main thread.

Definition at line 47 of file data_shuttle.h.


The documentation for this class was generated from the following file: