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_t * | getCallbackMap () |
__INLINE__ HiCR::tasking::Task * | getCurrentTask () |
__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
◆ state_t
Complete state set that a worker can be in
Constructor & Destructor Documentation
◆ Worker()
|
inline |
Constructor for the worker class.
- Parameters
-
[in] executionStateComputeManager A backend's compute manager to initialize and run the task's execution states. [in] processingUnitComputeManager A backend's compute manager to initialize and run processing units [in] pullFunction A callback for the worker to get a new task to execute [in] callbackMap Pointer to the callback map to be called by the worker
Member Function Documentation
◆ addProcessingUnit()
|
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] pu Processing unit to assign to the worker
◆ await()
|
inline |
A function that will suspend the execution of the caller until the worker has stopped
◆ 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 |
Gets the task's callback map.
- Returns
- A pointer to the worker's an callback map. nullptr, if not defined.
◆ 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 |
Gets a reference to the workers assigned processing units.
- Returns
- A container with the worker's resources
◆ getState()
|
inline |
Queries the worker's internal state.
- Returns
- The worker's internal state
◆ initialize()
|
inline |
Initializes the worker and its resources
◆ 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 |
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] callbackMap A pointer to an callback map
◆ setSuspendInterval()
|
inline |
This function sets the sleep intervals for a worker after it has been suspended, and in between checks for resuming
- Parameters
-
[in] suspendIntervalMs The interval (milliseconds) a worker sleeps for before checking for suspension conditions again
◆ start()
|
inline |
Initializes the worker's task execution loop
◆ 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 |
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
Generated by