Peano
Loading...
Searching...
No Matches
tarch::multicore::orchestration::Hardcoded Class Reference

A hard coded strategy how to handle tasks and task fusion. More...

#include <Hardcoded.h>

Inheritance diagram for tarch::multicore::orchestration::Hardcoded:
Collaboration diagram for tarch::multicore::orchestration::Hardcoded:

Public Member Functions

 Hardcoded (int minTasksToFuse, int maxTasksToFuse, int deviceForFusedTasks, int maxNestedConcurrency, FusionImplementation fusionImplementation)
 Construct hardcoded scheme.
 
virtual ~Hardcoded ()=default
 
virtual void startBSPSection (int nestedParallelismLevel) override
 Notifies the strategy that we enter a BSP section.
 
virtual void endBSPSection (int nestedParallelismLevel) override
 Notifies the strategy that we leave a BSP (fork-join) section.
 
virtual FuseInstruction fuse (int taskType) override
 How many tasks to fuse and to which device to deploy.
 
virtual ExecutionPolicy paralleliseForkJoinSection (int nestedParallelismLevel, int numberOfTasks, int taskType) override
 Determine how to handle/realise parallelisation within fork/join region.
 
virtual void updateFuseStatistics (int taskType, int queueSize, double averageNumberOfPendingReadyTasksPerProcessTaskExecution, double probabilityThatTaskIsCompleted) override
 Update task fusion status.
 
virtual FusionImplementation getFusionImplementation () const override
 Determine how the implementation handles fusable tasks.
 
- Public Member Functions inherited from tarch::multicore::orchestration::Strategy
virtual ~Strategy ()=default
 

Static Public Member Functions

static HardcodedcreateBSP ()
 If you want to use sole BSP, you effectively switch off the tasking.
 
static HardcodedcreateNative ()
 Fall back to native tasking.
 
static HardcodedcreateFuseAll (int numberOfTasksToFuse, int targetDevice)
 Always fuse all tasks possible.
 

Static Public Attributes

static constexpr int NoNestedParallelism = 1
 
- Static Public Attributes inherited from tarch::multicore::orchestration::Strategy
static constexpr int EndOfBSPSection = -1
 

Private Attributes

int _minTasksToFuse
 
int _maxTasksToFuse
 
int _deviceForFusedTasks
 
int _maxNestedConcurrency
 
FusionImplementation _fusionImplementation
 

Additional Inherited Members

- Public Types inherited from tarch::multicore::orchestration::Strategy
enum class  ExecutionPolicy { RunSerially , RunParallel }
 Provide hint of execution policy. More...
 

Detailed Description

A hard coded strategy how to handle tasks and task fusion.

This hardcoded variant can be used to realise a few standard tasking patterns. As trivial example, it allows us to switch off all tasking, to map all tasks immediately onto one GPU device, or to fix the number of tasks that are to be fused.

Definition at line 25 of file Hardcoded.h.

Constructor & Destructor Documentation

◆ Hardcoded()

tarch::multicore::orchestration::Hardcoded::Hardcoded ( int minTasksToFuse,
int maxTasksToFuse,
int deviceForFusedTasks,
int maxNestedConcurrency,
FusionImplementation fusionImplementation )

Construct hardcoded scheme.

Please read through Task fusion strategies for some hints and remarks on the strategies.

Parameters
deviceForFusedTasksUse tarch::multicore::Task::Host if you do not intend to use GPUs
maxNestedConcurrencyPass in NoNestedParallelism if you don't want nested parallelism.

◆ ~Hardcoded()

virtual tarch::multicore::orchestration::Hardcoded::~Hardcoded ( )
virtualdefault

Member Function Documentation

◆ createBSP()

static Hardcoded * tarch::multicore::orchestration::Hardcoded::createBSP ( )
static

If you want to use sole BSP, you effectively switch off the tasking.

Technically, this is realised by a strategy which enqueues all tasks that are spawned into the pending task queue. No tasks are handed over to the actual back-end. Therefore, the tasks will be done lazily upon demand within processPendingTasks().

◆ createFuseAll()

static Hardcoded * tarch::multicore::orchestration::Hardcoded::createFuseAll ( int numberOfTasksToFuse,
int targetDevice )
static

Always fuse all tasks possible.

Create a strategy where tasks are always fused if possible given the configuration constraints. This variant is very similar to AllOnGPU, but it ties the fusion to one device rather than trying to keep all devices busy in a round-robin fashion.

Parameters
numberOfTasksToFuseThe remaining tasks(<numberOfTasksToFuse) will remain stuck in the background queue and will stay there until processed lazily.
targetDeviceNon-negative number or tarch::multicore::Task::Host.

◆ createNative()

static Hardcoded * tarch::multicore::orchestration::Hardcoded::createNative ( )
static

Fall back to native tasking.

Native tasking means simply that we do not hold back any tasks but immediately map them onto native tasks.

◆ endBSPSection()

virtual void tarch::multicore::orchestration::Hardcoded::endBSPSection ( int nestedParallelismLevel)
overridevirtual

Notifies the strategy that we leave a BSP (fork-join) section.

Implements tarch::multicore::orchestration::Strategy.

◆ fuse()

virtual FuseInstruction tarch::multicore::orchestration::Hardcoded::fuse ( int taskType)
overridevirtual

How many tasks to fuse and to which device to deploy.

See also
Consult the page Task fusion strategies for recommendations and hints on task fusion strategies.
Consult the namespace documentation of tarch::multicore::taskfusion for details on the realisation of the task fusion.
Parameters
taskTypeTask type for which we want to know if to fuse or not.

Implements tarch::multicore::orchestration::Strategy.

◆ getFusionImplementation()

virtual FusionImplementation tarch::multicore::orchestration::Hardcoded::getFusionImplementation ( ) const
overridevirtual

Determine how the implementation handles fusable tasks.

In theory, you can change the strategy at runtime. However, such a switching is not well-defined and might lead to errors.

Implements tarch::multicore::orchestration::Strategy.

◆ paralleliseForkJoinSection()

virtual ExecutionPolicy tarch::multicore::orchestration::Hardcoded::paralleliseForkJoinSection ( int nestedParallelismLevel,
int numberOfTasks,
int taskType )
overridevirtual

Determine how to handle/realise parallelisation within fork/join region.

Peano models its execution with multiple parallel, nested fork/join sections. You could also think of these as mini-BSP sections. This routine guides the orchestration how to map those BSP sections onto tasks.

The decision can be guided by basically arbitrary contextual factors. The most important one for me is the nesting factor. As we work mainly with OpenMP, where tasks are tied to one core, it makes limited sense to have nested parallel fors. Notably, it makes stuff slower. So usually, I return ExecutionPolicy::RunSerially with anything with a nesting level greater than 1.

Parameters
nestedParallelismLevelPlease compare with tarch::multicore::spawnAndWait() which ensures that this flag equals 1 on the top level. A parameter of 0 would mean that no fork/join region has been opened. For such a parameter, the code would not query this function.
taskTypeIf we enter a fork-join section, this section logically spawns a set of tasks, which are all of the same type. So the task type here is given implicitly by the code location. But each BSP section has a unique identifier.

Implements tarch::multicore::orchestration::Strategy.

◆ startBSPSection()

virtual void tarch::multicore::orchestration::Hardcoded::startBSPSection ( int nestedParallelismLevel)
overridevirtual

Notifies the strategy that we enter a BSP section.

Implements tarch::multicore::orchestration::Strategy.

◆ updateFuseStatistics()

virtual void tarch::multicore::orchestration::Hardcoded::updateFuseStatistics ( int taskType,
int queueSize,
double averageNumberOfReadyTasksPerProcessTaskExecution,
double probabilityThatTaskIsCompleted )
overridevirtual

Update task fusion status.

Feed orchestration with some stats around the task queue of interest. This routine is not called every time a process read tasks kicks off, but only every now and then. Furthermore, please note that this routine is invoked iff the orchestration beforehand had decided to fuse tasks.

Parameters
taskTypeNumber of the task that we are studying
queueSizeSize of the queue at this observation point
averageNumberOfReadyTasksPerProcessTaskExecutionaverage over number of tasks in the queue whenever a process task has kicked off and the underlying real task has not completed yet.
probabilityThatTaskIsCompletedProbability that task result has been there already when the corresponding instance of ProcessReadyTask fires up. This is a biased value: If we try to look up if a task is already completed and the underlying dictionary is locked, then this counts as a "no hit" as well.

Implements tarch::multicore::orchestration::Strategy.

Field Documentation

◆ _deviceForFusedTasks

int tarch::multicore::orchestration::Hardcoded::_deviceForFusedTasks
private

Definition at line 29 of file Hardcoded.h.

◆ _fusionImplementation

FusionImplementation tarch::multicore::orchestration::Hardcoded::_fusionImplementation
private

Definition at line 31 of file Hardcoded.h.

◆ _maxNestedConcurrency

int tarch::multicore::orchestration::Hardcoded::_maxNestedConcurrency
private

Definition at line 30 of file Hardcoded.h.

◆ _maxTasksToFuse

int tarch::multicore::orchestration::Hardcoded::_maxTasksToFuse
private

Definition at line 28 of file Hardcoded.h.

◆ _minTasksToFuse

int tarch::multicore::orchestration::Hardcoded::_minTasksToFuse
private

Definition at line 27 of file Hardcoded.h.

◆ NoNestedParallelism

constexpr int tarch::multicore::orchestration::Hardcoded::NoNestedParallelism = 1
staticconstexpr

Definition at line 68 of file Hardcoded.h.


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