Peano
Loading...
Searching...
No Matches
exahype2::EnclaveTask Class Reference

Base class for all enclave tasks. More...

#include <EnclaveTask.h>

Inheritance diagram for exahype2::EnclaveTask:
Collaboration diagram for exahype2::EnclaveTask:

Public Types

typedef std::function< void()> Functor
 

Public Member Functions

 EnclaveTask (int enclaveTaskTypeId, const ::peano4::datamanagement::CellMarker &marker, double t, double dt, double *__restrict__ inputValues, double *__restrict__ outputValues, int numberOfInputValues, int numberOfResultValues, Functor functor)
 Create plain enclave task.
 
 EnclaveTask (const EnclaveTask &other)=delete
 
 EnclaveTask (const EnclaveTask &&other)=delete
 
virtual ~EnclaveTask ()=default
 
virtual bool run () override
 Computes a task and bookmarks the outcome.
 
void computeTask ()
 Compute the task.
 
int getTaskId () const
 Return _taskNumber.
 
- Public Member Functions inherited from tarch::multicore::Task
 Task (int taskType, int priority)
 Construct task.
 
virtual ~Task ()
 
int getTaskType () const
 
int getPriority () const
 
void setPriority (int priority)
 Set priority.
 
virtual bool canFuse () const
 
virtual bool fuse (const std::list< Task * > &otherTasks, int targetDevice=Host)
 Fuse multiple tasks.
 

Static Public Member Functions

static int getNumberOfActiveTasks ()
 
static void releaseTaskNumber (int number)
 
static int reserveTaskNumber ()
 Reserve a new enclave task number.
 

Protected Attributes

const int _taskNumber
 Each task needs a unique number, so we can look up its output.
 
const ::peano4::datamanagement::CellMarker _marker
 
const double _t
 These are the reconstructed values in the Finite Volume sense and the linear combination in the DG solver.
 
const double _dt
 
double *__restrict__ _inputValues
 
double *__restrict__ _outputValues
 
int _numberOfInputValues
 
int _numberOfResultValues
 
Functor _functor
 
double _maxEigenvalue
 
- Protected Attributes inherited from tarch::multicore::Task
const int _taskType
 
int _priority
 

Static Protected Attributes

static tarch::logging::Log _log
 

Static Private Attributes

static tarch::Enumerator _enumerator
 

Friends

class EnclaveBookkeeping
 

Additional Inherited Members

- Static Public Attributes inherited from tarch::multicore::Task
static constexpr int DefaultPriority = 1024
 
static constexpr int Host = -1
 
static constexpr int DontFuse = -1
 

Detailed Description

Base class for all enclave tasks.

Please study the enclave task in tandem with the EnclaveBookkeeping. Enclave tasks use the bookkeeping to register themselves (obtain a task number). The bookkeeping thus is aware which enclave tasks are outstanding still. Once an enclave task terminates, it registers itself again with the bookkeeping - this time as finished, so anybody can grab the outcome.

Enclave tasks per se are application-generic. They are given an array of values, they are told how big the output data has to be, and they are also given a functor which tells them what to run on the outcome. They don't know anything about the functor's semantics.

Tasks are automatically destroyed when we make their run() method return false. Enclave tasks however are slightly different: They create their outcome array on the heap. This has to be the CPU heap - not a stack, not an accelerator. When they have computed their stuff, they have to hand over this heap (and the responsibility to destroy it) to the bookkeeping and then can be deleted themselves.

Usage:

Every ExaHyPE solver category defines its own enclave tasks being subclasses of the present, generic type. Enclave tasks are always to be spawned with their task number, so we can efficiently wait for them:

auto newEnclaveTask = new tasks::{{SOLVER_NAME}}EnclaveTask(
...
);
...
tarch::multicore::spawnTask(newEnclaveTask, tarch::multicore::NoInDependencies, newEnclaveTask->getTaskId() );
EnclaveTask(int enclaveTaskTypeId, const ::peano4::datamanagement::CellMarker &marker, double t, double dt, double *__restrict__ inputValues, double *__restrict__ outputValues, int numberOfInputValues, int numberOfResultValues, Functor functor)
Create plain enclave task.
const std::set< TaskNumber > NoInDependencies
Definition multicore.h:161

Data ownership

  • The run() operation allocates the output data and then invokes the functor.
  • I assume that the functor frees the input data.
  • The task allocated the output value within _outputValues itself before it invokes the actual task functor. This happens in computeTask(). We have the following sequence: run() calls computeTask() calls the user's functor. The size of the output field is specified in the constructor argument. The output will be on the heap and is eventually passed over to the enclave bookkeeping. See exahype2::EnclaveBookkeeping::waitForTaskToTerminateAndCopyResultOver().

SmartMPI

If you enable SmartMPI, then all enclave tasks are SmartMPI tasks, too. I could realise this through multiple inheritance, but I have to know excactly how big the memory footprint behind an enclave task is, so I decided against this. Instead, subclasses of the enclave task do specialise w.r.t. SmartMPI.

Definition at line 76 of file EnclaveTask.h.

Member Typedef Documentation

◆ Functor

typedef std::function<void()> exahype2::EnclaveTask::Functor

Definition at line 78 of file EnclaveTask.h.

Constructor & Destructor Documentation

◆ EnclaveTask() [1/3]

exahype2::EnclaveTask::EnclaveTask ( int enclaveTaskTypeId,
const ::peano4::datamanagement::CellMarker & marker,
double t,
double dt,
double *__restrict__ inputValues,
double *__restrict__ outputValues,
int numberOfInputValues,
int numberOfResultValues,
Functor functor )

Create plain enclave task.

Create an unique id for the task type

It is best to use the parallel factory mechanism within parallel:

static int enclaveTaskTypeId = peano4::parallel::getTaskType("{{SOLVER_INSTANCE}}");
int getTaskType(const std::string &className)
Get unique number (id) for task.
Definition parallel.cpp:7
Parameters
inputValuesHas to be created on heap via tarch::multicore::allocateMemory().
enclaveTaskTypeIdUnique id for this type. If you use task merging, only tasks of the same type will be merged.
outputValuesIf you pass in nullptr, then the enclave task will create a new array on the heap for the task output and then move this one over into the bookkeeping from where it eventually will be copied once more into the target data field.
See also
_inputValues for a discussion of const qualifiers

Definition at line 29 of file EnclaveTask.cpp.

References logTraceIn, and logTraceOut.

◆ EnclaveTask() [2/3]

exahype2::EnclaveTask::EnclaveTask ( const EnclaveTask & other)
delete

◆ EnclaveTask() [3/3]

exahype2::EnclaveTask::EnclaveTask ( const EnclaveTask && other)
delete

◆ ~EnclaveTask()

virtual exahype2::EnclaveTask::~EnclaveTask ( )
virtualdefault

Member Function Documentation

◆ computeTask()

void exahype2::EnclaveTask::computeTask ( )

Compute the task.

Typically invoked by run() - though it might also be called directly by smartMPI, e.g. The routine basically forwards the call to the functor stored within the task. Before that, it checks if the task is supposed to allocate the memory for the task outcomes itself. If so, we allocate in the shared GPU memory, as the task might be deployed there.

Definition at line 65 of file EnclaveTask.cpp.

References assertion, logDebug, and tarch::ManagedSharedAcceleratorDeviceMemory.

◆ getNumberOfActiveTasks()

int exahype2::EnclaveTask::getNumberOfActiveTasks ( )
static

Definition at line 16 of file EnclaveTask.cpp.

References _enumerator, and tarch::Enumerator::size().

Referenced by exahype2::EnclaveBookkeeping::dumpStatistics().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTaskId()

int exahype2::EnclaveTask::getTaskId ( ) const

Return _taskNumber.

Definition at line 81 of file EnclaveTask.cpp.

◆ releaseTaskNumber()

void exahype2::EnclaveTask::releaseTaskNumber ( int number)
static

◆ reserveTaskNumber()

int exahype2::EnclaveTask::reserveTaskNumber ( )
static

Reserve a new enclave task number.

This factory mechanism is implicitly used by the constructor of an enclave task. However, we make it public. Therefore, you can also hijack enclave task numbers. This comes in handy if you want to manually insert predecessor tasks to enclave tasks: You create "your own" enclave task, the enclave task creation will recognise that a task is already associated with a cell, and hence use this one as additional input constraint.

Definition at line 24 of file EnclaveTask.cpp.

◆ run()

bool exahype2::EnclaveTask::run ( )
overridevirtual

Computes a task and bookmarks the outcome.

Implements tarch::multicore::Task.

Definition at line 56 of file EnclaveTask.cpp.

References exahype2::EnclaveBookkeeping::finishedTask(), exahype2::EnclaveBookkeeping::getInstance(), logTraceInWith1Argument, and logTraceOut.

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ EnclaveBookkeeping

friend class EnclaveBookkeeping
friend

Definition at line 81 of file EnclaveTask.h.

Field Documentation

◆ _dt

const double exahype2::EnclaveTask::_dt
protected

Definition at line 98 of file EnclaveTask.h.

◆ _enumerator

tarch::Enumerator exahype2::EnclaveTask::_enumerator
staticprivate

Definition at line 184 of file EnclaveTask.h.

Referenced by getNumberOfActiveTasks().

◆ _functor

Functor exahype2::EnclaveTask::_functor
protected

◆ _inputValues

double* __restrict__ exahype2::EnclaveTask::_inputValues
protected

Definition at line 99 of file EnclaveTask.h.

◆ _log

tarch::logging::Log exahype2::EnclaveTask::_log
staticprotected

Definition at line 83 of file EnclaveTask.h.

◆ _marker

const ::peano4::datamanagement::CellMarker exahype2::EnclaveTask::_marker
protected

Definition at line 89 of file EnclaveTask.h.

◆ _maxEigenvalue

double exahype2::EnclaveTask::_maxEigenvalue
protected

Definition at line 104 of file EnclaveTask.h.

◆ _numberOfInputValues

int exahype2::EnclaveTask::_numberOfInputValues
protected

Definition at line 101 of file EnclaveTask.h.

◆ _numberOfResultValues

int exahype2::EnclaveTask::_numberOfResultValues
protected

Definition at line 102 of file EnclaveTask.h.

◆ _outputValues

double* __restrict__ exahype2::EnclaveTask::_outputValues
protected

Definition at line 100 of file EnclaveTask.h.

◆ _t

const double exahype2::EnclaveTask::_t
protected

These are the reconstructed values in the Finite Volume sense and the linear combination in the DG solver.

In both cases, the enclave task will free the memory once it has terminated, so the attribute may not be const here.

Definition at line 97 of file EnclaveTask.h.

◆ _taskNumber

const int exahype2::EnclaveTask::_taskNumber
protected

Each task needs a unique number, so we can look up its output.

Definition at line 88 of file EnclaveTask.h.


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