NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
WorkScheduler Class Referenceabstract

Scheduler for work dispatching. More...

Detailed Description

Scheduler for work dispatching.

The scheduler is responsible for determining

  1. The amount (number of batches) of work to be dispatched next
  2. Where (e.g., to which device) the next batch of work should be dispatched

The scheduler is also responsible for updating its internal state when work is dispatched.

See also
WorkGenerator, WorkDispatcher

#include <WorkScheduler.h>

Inheritance diagram for WorkScheduler:

Public Member Functions

 WorkScheduler (const OptionSet &options)
 Construct a new WorkScheduler object.
 
void schedule_work (Device &, std::size_t &)
 Determine the device and batch size for the next dispatch.
 
void dispatched_work (Device, std::size_t)
 Update the scheduler with the dispatch of the last batch.
 
void completed_work (Device, std::size_t)
 Update the scheduler with the completion of the last batch.
 
void wait_for_completion ()
 Wait for all work to complete.
 
virtual std::vector< Devicedevices () const
 Device options.
 
- Public Member Functions inherited from NEML2Object
 NEML2Object ()=delete
 
 NEML2Object (NEML2Object &&)=delete
 
 NEML2Object (const NEML2Object &)=delete
 
NEML2Objectoperator= (NEML2Object &&)=delete
 
NEML2Objectoperator= (const NEML2Object &)=delete
 
virtual ~NEML2Object ()=default
 
 NEML2Object (const OptionSet &options)
 Construct a new NEML2Object object.
 
const OptionSetinput_options () const
 
virtual void setup ()
 Setup this object.
 
const std::string & name () const
 A readonly reference to the object's name.
 
const std::string & type () const
 A readonly reference to the object's type.
 
const std::string & path () const
 A readonly reference to the object's path.
 
const std::string & doc () const
 A readonly reference to the object's docstring.
 
template<typename T = NEML2Object>
const T * host () const
 Get a readonly pointer to the host.
 
template<typename T = NEML2Object>
T * host ()
 Get a writable pointer to the host.
 

Static Public Member Functions

static OptionSet expected_options ()
 Options for the scheduler.
 
- Static Public Member Functions inherited from NEML2Object
static OptionSet expected_options ()
 

Protected Member Functions

virtual bool schedule_work_impl (Device &, std::size_t &) const =0
 Implementation of the work scheduling.
 
virtual void dispatched_work_impl (Device, std::size_t)=0
 Update the scheduler with the dispatch of the last batch.
 
virtual void completed_work_impl (Device, std::size_t)=0
 Update the scheduler with the completion of the last batch.
 
virtual bool all_work_completed () const =0
 Check if all work has been completed.
 

Protected Attributes

std::condition_variable _condition
 Condition variable for the scheduling thread.
 

Constructor & Destructor Documentation

◆ WorkScheduler()

WorkScheduler ( const OptionSet & options)

Construct a new WorkScheduler object.

Parameters
optionsOptions for the scheduler

Member Function Documentation

◆ all_work_completed()

virtual bool all_work_completed ( ) const
protectedpure virtual

Check if all work has been completed.

Implemented in SimpleMPIScheduler, SimpleScheduler, and StaticHybridScheduler.

◆ completed_work()

void completed_work ( Device device,
std::size_t m )

Update the scheduler with the completion of the last batch.

◆ completed_work_impl()

virtual void completed_work_impl ( Device ,
std::size_t  )
protectedpure virtual

Update the scheduler with the completion of the last batch.

Implemented in SimpleMPIScheduler, SimpleScheduler, and StaticHybridScheduler.

◆ devices()

virtual std::vector< Device > devices ( ) const
inlinevirtual

◆ dispatched_work()

void dispatched_work ( Device device,
std::size_t m )

Update the scheduler with the dispatch of the last batch.

◆ dispatched_work_impl()

virtual void dispatched_work_impl ( Device ,
std::size_t  )
protectedpure virtual

Update the scheduler with the dispatch of the last batch.

Implemented in SimpleMPIScheduler, SimpleScheduler, and StaticHybridScheduler.

◆ expected_options()

OptionSet expected_options ( )
static

Options for the scheduler.

◆ schedule_work()

void schedule_work ( Device & device,
std::size_t & batch_size )

Determine the device and batch size for the next dispatch.

This is blocking until work can be scheduled.

◆ schedule_work_impl()

virtual bool schedule_work_impl ( Device & ,
std::size_t &  ) const
protectedpure virtual

Implementation of the work scheduling.

Implemented in SimpleMPIScheduler, SimpleScheduler, and StaticHybridScheduler.

◆ wait_for_completion()

void wait_for_completion ( )

Wait for all work to complete.

Member Data Documentation

◆ _condition

std::condition_variable _condition
protected

Condition variable for the scheduling thread.