Worker Class Reference

HiCR: HiCR::tasking::Worker Class Reference
HiCR

#include <worker.hpp>

Public Types

enum  callback_t {
  onWorkerStart , onWorkerTaskPulled , onWorkerSuspend , onWorkerResume ,
  onWorkerTerminate
}
 
enum  state_t {
  uninitialized , ready , running , suspending ,
  suspended , resuming , terminating , terminated
}
 
using workerCallbackMap_t = HiCR::tasking::CallbackMap< Worker *, callback_t >
 

Public Member Functions

 Worker (HiCR::ComputeManager *executionStateComputeManager, HiCR::ComputeManager *processingUnitComputeManager, pullFunction_t pullFunction, workerCallbackMap_t *callbackMap=nullptr)
 
__INLINE__ const state_t getState ()
 
__INLINE__ void setCallbackMap (workerCallbackMap_t *callbackMap)
 
__INLINE__ workerCallbackMap_tgetCallbackMap ()
 
__INLINE__ HiCR::tasking::TaskgetCurrentTask ()
 
__INLINE__ void initialize ()
 
__INLINE__ void start ()
 
__INLINE__ bool suspend ()
 
__INLINE__ bool resume ()
 
__INLINE__ void terminate ()
 
__INLINE__ void await ()
 
__INLINE__ void addProcessingUnit (std::unique_ptr< HiCR::ProcessingUnit > pu)
 
__INLINE__ std::vector< std::unique_ptr< HiCR::ProcessingUnit > > & getProcessingUnits ()
 
__INLINE__ void setSuspendInterval (size_t suspendIntervalMs)
 

Protected Member Functions

virtual __INLINE__ bool checkResumeConditions ()
 

Detailed Description

Defines the worker class, which is in charge of executing tasks.

To receive pending tasks for execution, the worker needs a pull function. Upon execution, the worker will constantly check the pull function in search for new tasks for execution.

To execute a task, the worker needs to be assigned at least a computational resource capable to executing the type of task submitted.

Member Typedef Documentation

◆ workerCallbackMap_t

Type definition for the worker's callback map

Member Enumeration Documentation

◆ callback_t

Enumeration of possible task-related callbacks that can trigger a user-defined function callback

Enumerator
onWorkerStart 

Triggered as the task starts or resumes execution

onWorkerTaskPulled 

Triggered as the workers received a task pointer

onWorkerSuspend 

Triggered as the worker is preempted into suspension by an asynchronous callback

onWorkerResume 

Triggered as the worker is resumed from suspension

onWorkerTerminate 

Triggered as the worker terminates

◆ state_t

Complete state set that a worker can be in

Enumerator
uninitialized 

The worker object has been instantiated but not initialized

ready 

The worker has been ininitalized (or is back from executing) and can currently run

running 

The worker has started executing

suspending 

The worker is in the process of being suspended

suspended 

The worker has suspended

resuming 

The worker is in the process of being resumed

terminating 

The worker has been issued for termination (but still running)

terminated 

The worker has terminated

Constructor & Destructor Documentation

◆ Worker()

HiCR::tasking::Worker::Worker ( HiCR::ComputeManager executionStateComputeManager,
HiCR::ComputeManager processingUnitComputeManager,
pullFunction_t  pullFunction,
workerCallbackMap_t callbackMap = nullptr 
)
inline

Constructor for the worker class.

Parameters
[in]executionStateComputeManagerA backend's compute manager to initialize and run the task's execution states.
[in]processingUnitComputeManagerA backend's compute manager to initialize and run processing units
[in]pullFunctionA callback for the worker to get a new task to execute
[in]callbackMapPointer to the callback map to be called by the worker

Member Function Documentation

◆ addProcessingUnit()

__INLINE__ void HiCR::tasking::Worker::addProcessingUnit ( std::unique_ptr< HiCR::ProcessingUnit pu)
inline

Adds a processing unit to the worker. The worker will freely use this resource during execution. The worker may contain multiple resources and resource types.

Parameters
[in]puProcessing unit to assign to the worker

◆ await()

__INLINE__ void HiCR::tasking::Worker::await ( )
inline

A function that will suspend the execution of the caller until the worker has stopped

◆ checkResumeConditions()

virtual __INLINE__ bool HiCR::tasking::Worker::checkResumeConditions ( )
inlineprotectedvirtual

This function runs in in intervals defined by _suspendIntervalMs to check whether the suspension conditions remain true

Returns
True, if the worker must now resume; False, otherwise.

◆ getCallbackMap()

__INLINE__ workerCallbackMap_t * HiCR::tasking::Worker::getCallbackMap ( )
inline

Gets the task's callback map.

Returns
A pointer to the worker's an callback map. nullptr, if not defined.

◆ getCurrentTask()

__INLINE__ HiCR::tasking::Task * HiCR::tasking::Worker::getCurrentTask ( )
inline

Gets the current task being handled by the worker

Returns
A pointer to the task being handled by the worker. nullptr if none

◆ getProcessingUnits()

__INLINE__ std::vector< std::unique_ptr< HiCR::ProcessingUnit > > & HiCR::tasking::Worker::getProcessingUnits ( )
inline

Gets a reference to the workers assigned processing units.

Returns
A container with the worker's resources

◆ getState()

__INLINE__ const state_t HiCR::tasking::Worker::getState ( )
inline

Queries the worker's internal state.

Returns
The worker's internal state

◆ initialize()

__INLINE__ void HiCR::tasking::Worker::initialize ( )
inline

Initializes the worker and its resources

◆ resume()

__INLINE__ bool HiCR::tasking::Worker::resume ( )
inline

Resumes the execution of the underlying resource(s) after suspension

Returns
True, if the worker has been put to resume; False, otherwise. The latter is returned if the thread wasn't suspended in the first place

◆ setCallbackMap()

__INLINE__ void HiCR::tasking::Worker::setCallbackMap ( workerCallbackMap_t callbackMap)
inline

Sets the worker's callback map. This map will be queried whenever a state transition occurs, and if the map defines a callback for it, it will be executed.

Parameters
[in]callbackMapA pointer to an callback map

◆ setSuspendInterval()

__INLINE__ void HiCR::tasking::Worker::setSuspendInterval ( size_t  suspendIntervalMs)
inline

This function sets the sleep intervals for a worker after it has been suspended, and in between checks for resuming

Parameters
[in]suspendIntervalMsThe interval (milliseconds) a worker sleeps for before checking for suspension conditions again

◆ start()

__INLINE__ void HiCR::tasking::Worker::start ( )
inline

Initializes the worker's task execution loop

◆ suspend()

__INLINE__ bool HiCR::tasking::Worker::suspend ( )
inline

Suspends the execution of the underlying resource(s). The resources are guaranteed to be suspended after this function is called

Returns
True, if the worker has been put to suspended; False, otherwise. The latter is returned if the thread wasn't running in the first place

◆ terminate()

__INLINE__ void HiCR::tasking::Worker::terminate ( )
inline

Terminates the worker's task execution loop. After stopping it can be restarted later


The documentation for this class was generated from the following file:
  • /home/runner/work/HiCR/HiCR/include/hicr/frontends/tasking/worker.hpp