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 void 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 void fuse (const std::vector< Task * > &otherTasks, int targetDevice=Host)
 Fuse multiple tasks.
virtual std::string toString () const

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::multicore::TaskEnumerator _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:103

You should try to release the enclave task numbers eventually. Otherwise, you will get huge enclave task maps and an overflow if you are unlucky.

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 79 of file EnclaveTask.h.

Member Typedef Documentation

◆ Functor

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

Definition at line 81 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:13
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 30 of file EnclaveTask.cpp.

References _dt, _functor, _inputValues, _marker, _maxEigenvalue, _numberOfInputValues, _numberOfResultValues, _outputValues, _t, _taskNumber, assertion1, tarch::multicore::Task::DefaultPriority, exahype2::EnclaveBookkeeping::getInstance(), logTraceIn, logTraceOut, exahype2::EnclaveBookkeeping::registerTask(), reserveTaskNumber(), tarch::multicore::Task::Task(), and tarch::multicore::Task::toString().

Referenced by EnclaveTask(), and EnclaveTask().

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

◆ EnclaveTask() [2/3]

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

References EnclaveTask().

Here is the call graph for this function:

◆ EnclaveTask() [3/3]

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

References EnclaveTask().

Here is the call graph for this function:

◆ ~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 69 of file EnclaveTask.cpp.

References _functor, _inputValues, _maxEigenvalue, _numberOfResultValues, _outputValues, _taskNumber, tarch::allocateMemory(), assertion, logDebug, and tarch::ManagedSharedAcceleratorDeviceMemory.

Referenced by run().

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

◆ getNumberOfActiveTasks()

int exahype2::EnclaveTask::getNumberOfActiveTasks ( )
static

Definition at line 16 of file EnclaveTask.cpp.

References _enumerator.

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

Here is the caller graph for this function:

◆ getTaskId()

int exahype2::EnclaveTask::getTaskId ( ) const

Return _taskNumber.

Definition at line 85 of file EnclaveTask.cpp.

References _taskNumber.

Referenced by run().

Here is the caller graph for this function:

◆ releaseTaskNumber()

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

Definition at line 19 of file EnclaveTask.cpp.

References _enumerator, and logDebug.

Referenced by exahype2::EnclaveBookkeeping::finishedTask(), and exahype2::EnclaveBookkeeping::waitForTaskToTerminateAndReturnResult().

Here is the caller graph for this function:

◆ 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 25 of file EnclaveTask.cpp.

References _enumerator.

Referenced by EnclaveTask().

Here is the caller graph for this function:

◆ run()

void exahype2::EnclaveTask::run ( )
overridevirtual

Computes a task and bookmarks the outcome.

Implements tarch::multicore::Task.

Definition at line 61 of file EnclaveTask.cpp.

References _marker, _maxEigenvalue, _numberOfResultValues, _outputValues, computeTask(), exahype2::EnclaveBookkeeping::finishedTask(), exahype2::EnclaveBookkeeping::getInstance(), getTaskId(), logTraceInWith1Argument, and logTraceOut.

Here is the call graph for this function:

◆ EnclaveBookkeeping

friend class EnclaveBookkeeping
friend

Definition at line 84 of file EnclaveTask.h.

References EnclaveBookkeeping.

Referenced by EnclaveBookkeeping.

Field Documentation

◆ _dt

const double exahype2::EnclaveTask::_dt
protected

Definition at line 101 of file EnclaveTask.h.

Referenced by EnclaveTask().

◆ _enumerator

tarch::multicore::TaskEnumerator exahype2::EnclaveTask::_enumerator
staticprivate

Definition at line 187 of file EnclaveTask.h.

Referenced by getNumberOfActiveTasks(), releaseTaskNumber(), and reserveTaskNumber().

◆ _functor

Functor exahype2::EnclaveTask::_functor
protected

Definition at line 106 of file EnclaveTask.h.

Referenced by computeTask(), and EnclaveTask().

◆ _inputValues

double* __restrict__ exahype2::EnclaveTask::_inputValues
protected

Definition at line 102 of file EnclaveTask.h.

Referenced by computeTask(), and EnclaveTask().

◆ _log

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

Definition at line 86 of file EnclaveTask.h.

◆ _marker

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

Definition at line 92 of file EnclaveTask.h.

Referenced by EnclaveTask(), and run().

◆ _maxEigenvalue

double exahype2::EnclaveTask::_maxEigenvalue
protected

Definition at line 107 of file EnclaveTask.h.

Referenced by computeTask(), EnclaveTask(), and run().

◆ _numberOfInputValues

int exahype2::EnclaveTask::_numberOfInputValues
protected

Definition at line 104 of file EnclaveTask.h.

Referenced by EnclaveTask().

◆ _numberOfResultValues

int exahype2::EnclaveTask::_numberOfResultValues
protected

Definition at line 105 of file EnclaveTask.h.

Referenced by computeTask(), EnclaveTask(), and run().

◆ _outputValues

double* __restrict__ exahype2::EnclaveTask::_outputValues
protected

Definition at line 103 of file EnclaveTask.h.

Referenced by computeTask(), EnclaveTask(), and run().

◆ _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 100 of file EnclaveTask.h.

Referenced by EnclaveTask().

◆ _taskNumber

const int exahype2::EnclaveTask::_taskNumber
protected

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

Definition at line 91 of file EnclaveTask.h.

Referenced by computeTask(), EnclaveTask(), and getTaskId().


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