tfel
Loading...
Searching...
No Matches
mfront::generic_parallel Namespace Reference

Classes

struct  AbstractBackend
 base class of the backends of the generic-parallel interfaces. More...
struct  AbstractBackendExecutionPolicy
 base class of the execution policies of the backends of the generic-parallel interfaces. More...
struct  BackendExecutionCommonPolicy
 options common to the execution policies of most backends More...
struct  BackendExecutionPolicyBase
 base class of the execution policies of the backends using the common options More...
struct  CheckedBackendExecutionPolicy
 policy given to a generated function, once checked (see checkBackendExecutionPolicy) More...
struct  BackendFactory
 abstract factory for backends More...
struct  BatchStatistics
 statistics of the computations at one point or at a group of points of a batch, combined by parallel reductions. The keys are built by makeKey. More...
struct  CombineStatistics
 function object combining two statistics More...
struct  BatchExecution
 execution of the computations on a batch, as given by the calling code: the policy, checked by the backend against its own policy (see mfront::generic_parallel::checkBackendExecutionPolicy), and the statistics More...
struct  CountingIterator
 a random access iterator over a range of indices. More...
struct  CUDABackendExecutionOptions
 options of the execution policy of the cuda backend More...
struct  CUDABackendExecutionPolicy
 execution policy of the cuda backend More...
struct  GPUBackend
 base class of the CUDA and HIP backends: one thread per point. More...
struct  CUDABackend
 CUDA backend. More...
struct  HIPBackend
 HIP backend. More...
struct  HIPBackendExecutionOptions
 options of the execution policy of the hip backend More...
struct  HIPBackendExecutionPolicy
 execution policy of the hip backend More...
struct  ParallelSTLBackend
 backend based on the parallel algorithms of the C++ standard library. More...
struct  ParallelSTLBackendExecutionPolicy
 execution policy of the stlpar backend: the computations are performed synchronously, and only the common options are used More...
class  StatusBlockPool
 pool of blocks of memory holding the statuses or the statistics of synchronous computations performed on a device. More...
struct  SYCLBackend
 backend based on SYCL. The points are treated on the device associated with the queue given by the batch data. More...
struct  SyclBackendExecutionPolicy
 execution policy of the sycl backend. The sycl backend has no default policy: the arrays given by the caller belong to the context of a queue, so the queue is required. More...

Typedefs

using size_type = std::size_t
 type of the indices and of the numbers of points
using atomic_size_type = ::mfront_gp_atomic_size_type
 a simple alias

Functions

template<typename Policy>
const Policy * getBackendExecutionPolicy (const AbstractBackendExecutionPolicy &p) noexcept
template<typename Policy>
CheckedBackendExecutionPolicy< Policy > checkBackendExecutionPolicy (const AbstractBackendExecutionPolicy *const p, const bool has_statistics) noexcept
MFRONT_VISIBILITY_EXPORT void declareExecutionPolicyOption (tfel::utilities::DataMapValidator &)
 declare the execution_policy option of the backends based on the parallel algorithms of the standard library
MFRONT_VISIBILITY_EXPORT std::string getExecutionPolicy (const tfel::utilities::DataMap &)
MFRONT_VISIBILITY_EXPORT void declareDeviceStackSizeOption (tfel::utilities::DataMapValidator &)
 declare the device_stack_size option, which gives the minimal stack size, in bytes, of the threads of the device
MFRONT_VISIBILITY_EXPORT int getDeviceStackSize (const tfel::utilities::DataMap &)
MFRONT_VISIBILITY_EXPORT void declareDataTransferPolicyOption (tfel::utilities::DataMapValidator &)
 declare the data_transfer_policy option of the SYCL backends
MFRONT_VISIBILITY_EXPORT bool areDataTransfersAutomatic (const tfel::utilities::DataMap &)
TFEL_HOST_DEVICE constexpr atomic_size_type toOrderedKey (const double v) noexcept
template<typename Atomics, typename Statistics, typename real>
TFEL_HOST_DEVICE void updateStatistics (Statistics &s, const BatchStatistics< real > &r, const atomic_size_type rdt0)
 update the statistics shared by the threads with the statistics of a point or of a group of points, by atomic operations. The shared statistics are only accessed if an event occurred: a failure, an unreliable result, or a time step scaling factor lower than the initial one.
template<typename OutputStatus>
int report (OutputStatus &s, const int status, const std::string_view msg) noexcept
 set the status and the error message of an output status
template<typename OutputStatus, typename Initialize, typename Function>
int handleExceptions (OutputStatus *const s, const Initialize &initialize, Function &&f) noexcept
 call the body of a generated function of batches, so that no exception goes through its C interface: an exception is reported as an error of the backend (status -7). The output status is initialized before the call, and errno is restored on return: it may be modified by the runtimes of the backends and by the computations on the host.
CUDABackendExecutionPolicy makeCUDABackendExecutionPolicy (const CUDABackendExecutionOptions &opts={}) noexcept
std::mutex & getStackSizeMutex () noexcept
bool setMinimalCUDAStackSize (const std::size_t stack_size, const bool preserve=false) noexcept
 increase the stack size of the threads of the current CUDA device, if the CUDA runtime is loaded by the process. Otherwise, nothing is done. A loaded CUDA runtime does not mean that the computations are performed on an NVIDIA GPU: the primitives of the stlpar and sycl backends only call this function when the computations are offloaded to a GPU (nvc++ -stdpar=gpu, sycl queue running on a GPU).
HIPBackendExecutionPolicy makeHIPBackendExecutionPolicy (const HIPBackendExecutionOptions &opts={}) noexcept
constexpr const char * getNVHPCOffloadMemorySpace () noexcept
constexpr const char * getParallelSTLMemorySpace () noexcept
ParallelSTLBackendExecutionPolicy makeParallelSTLBackendExecutionPolicy (const BackendExecutionCommonPolicy &opts={}) noexcept
TFEL_HOST_DEVICE constexpr atomic_size_type makeKey (const atomic_size_type i, const atomic_size_type c) noexcept
TFEL_HOST_DEVICE constexpr atomic_size_type getPointIndex (const atomic_size_type k) noexcept
TFEL_HOST_DEVICE constexpr atomic_size_type getCheck (const atomic_size_type k) noexcept
SyclBackendExecutionPolicy makeSyclBackendExecutionPolicy (const ::sycl::queue &q, const BackendExecutionCommonPolicy &opts={})

Variables

template<typename Statistics>
constexpr bool hasTimeStepScalingFactor
 true if the statistics updated by the devices hold a time step scaling factor, false otherwise, which is the case of the statistics of the material properties
constexpr const char * stack_size_error_message
 error message associated with setMinimalCUDAStackSize
constexpr const char * host_memory_space = "host"
 the computations are performed on the host: the fields must be accessible by the host (ordinary or shared memory)
constexpr const char * device_memory_space = "device"
 the computations are performed on a device, which may not access the ordinary memory of the host: the fields must be accessible by the device (memory of the device or shared memory). The library can't assume that the device accesses the ordinary memory of the host, even if the device is a CPU (sycl backend without data transfers).
constexpr const char * any_memory_space = "any"
 the fields may be located anywhere (for instance, the fields which are not accessible by the device are copied)
constexpr atomic_size_type no_event = ~atomic_size_type{0}
 value of a key meaning that no event occurred
constexpr unsigned int check_bits = 16
 number of bits of the identifier of a check in a key. The other bits hold the index of the point.
constexpr atomic_size_type maximal_number_of_checks
 maximal number of checks
constexpr atomic_size_type maximal_number_of_points
 maximal number of points of a batch

Detailed Description

The primitives of the backends (apply, see for instance MFront/GenericParallel/ParallelSTL.hxx) apply a function at the points of a batch. This function returns the statistics of a point (BatchStatistics). The primitives combine them, by atomic operations or by reductions, and report the result through a handler of the statistics given by the interface (mfront::gpmp::StatisticsHandler for the material properties), which provides:

  • the type OutputStatus of the output status and the type Statistics of the statistics updated by the devices and given by the calling code (C structures of the interface);
  • initial(): the statistics of a batch without event, neutral element of the reductions;
  • hasEvents(): false if the function applied at the points never reports an event, in which case the statistics are neither combined nor reported;
  • initialize(Statistics&): initialization of the statistics updated by the devices;
  • report(OutputStatus&, const Statistics&): report of the statistics updated by the devices, once the computations are completed;
  • report(OutputStatus&, Statistics*, const BatchStatistics&): report of the statistics combined by a reduction, or accumulation of those statistics in the statistics given by the calling code, if any.

Function Documentation

◆ areDataTransfersAutomatic()

MFRONT_VISIBILITY_EXPORT bool mfront::generic_parallel::areDataTransfersAutomatic ( const tfel::utilities::DataMap & )
Returns
true if the data_transfer_policy option is automatic (or auto, default), false if it is none
Parameters
[in]optsoptions of a backend

◆ checkBackendExecutionPolicy()

template<typename Policy>
CheckedBackendExecutionPolicy< Policy > mfront::generic_parallel::checkBackendExecutionPolicy ( const AbstractBackendExecutionPolicy *const p,
const bool has_statistics )
noexcept
Returns
the policy given to a generated function, checked against the policy of its backend: a policy of another backend, or an asynchronous computation without statistics, are refused. The generated function copies what it needs from the policy, which does not have to outlive the call.
Template Parameters
Policypolicy of the backend
Parameters
[in]ppolicy given by the caller, or a null pointer for the default policy
[in]has_statisticstrue if the caller gave statistics

◆ declareDataTransferPolicyOption()

MFRONT_VISIBILITY_EXPORT void mfront::generic_parallel::declareDataTransferPolicyOption ( tfel::utilities::DataMapValidator & )

declare the data_transfer_policy option of the SYCL backends

Parameters
[in,out]vvalidator of the options of a backend

◆ declareDeviceStackSizeOption()

MFRONT_VISIBILITY_EXPORT void mfront::generic_parallel::declareDeviceStackSizeOption ( tfel::utilities::DataMapValidator & )

declare the device_stack_size option, which gives the minimal stack size, in bytes, of the threads of the device

Parameters
[in,out]vvalidator of the options of a backend

◆ declareExecutionPolicyOption()

MFRONT_VISIBILITY_EXPORT void mfront::generic_parallel::declareExecutionPolicyOption ( tfel::utilities::DataMapValidator & )

declare the execution_policy option of the backends based on the parallel algorithms of the standard library

Parameters
[in,out]vvalidator of the options of a backend

◆ getBackendExecutionPolicy()

template<typename Policy>
const Policy * mfront::generic_parallel::getBackendExecutionPolicy ( const AbstractBackendExecutionPolicy & p)
noexcept
Returns
the policy of the given type, or a null pointer if the identifier of the policy is not the one of this type
Template Parameters
Policyexpected policy, whose static member function identifier gives the identifier
Parameters
[in]ppolicy

◆ getCheck()

TFEL_HOST_DEVICE constexpr atomic_size_type mfront::generic_parallel::getCheck ( const atomic_size_type k)
nodiscardconstexprnoexcept
Returns
the identifier of the check of a key

◆ getDeviceStackSize()

MFRONT_VISIBILITY_EXPORT int mfront::generic_parallel::getDeviceStackSize ( const tfel::utilities::DataMap & )
Returns
the value of the device_stack_size option (null if the option is not given)
Parameters
[in]optsoptions of a backend

◆ getExecutionPolicy()

MFRONT_VISIBILITY_EXPORT std::string mfront::generic_parallel::getExecutionPolicy ( const tfel::utilities::DataMap & )
Returns
the execution policy given by the execution_policy option, as a C++ expression (std::execution::par_unseq by default)
Parameters
[in]optsoptions of a backend

◆ getNVHPCOffloadMemorySpace()

const char * mfront::generic_parallel::getNVHPCOffloadMemorySpace ( )
constexprnoexcept
Returns
the memory space of the computations offloaded by nvc++ (C++ parallel algorithms with -stdpar=gpu): with the unified memory mode, the device accesses the whole memory of the host.

◆ getParallelSTLMemorySpace()

const char * mfront::generic_parallel::getParallelSTLMemorySpace ( )
constexprnoexcept
Returns
the memory space of the C++ parallel algorithms

◆ getPointIndex()

TFEL_HOST_DEVICE constexpr atomic_size_type mfront::generic_parallel::getPointIndex ( const atomic_size_type k)
nodiscardconstexprnoexcept
Returns
the index of the point of a key

◆ getStackSizeMutex()

std::mutex & mfront::generic_parallel::getStackSizeMutex ( )
inlinenoexcept
Returns
a mutex protecting the modifications of the stack size of the threads of the device. The stack size is a property of the context of the device, shared by all the threads of the process: concurrent modifications by other libraries are not protected.

◆ handleExceptions()

template<typename OutputStatus, typename Initialize, typename Function>
int mfront::generic_parallel::handleExceptions ( OutputStatus *const s,
const Initialize & initialize,
Function && f )
noexcept

call the body of a generated function of batches, so that no exception goes through its C interface: an exception is reported as an error of the backend (status -7). The output status is initialized before the call, and errno is restored on return: it may be modified by the runtimes of the backends and by the computations on the host.

Returns
the status
Parameters
[out]soutput status
[in]initializefunction initializing the output status
[in]fbody of the function, returning the status

◆ makeCUDABackendExecutionPolicy()

CUDABackendExecutionPolicy mfront::generic_parallel::makeCUDABackendExecutionPolicy ( const CUDABackendExecutionOptions & opts = {})
inlinenoexcept
Returns
an execution policy of the cuda backend
Parameters
[in]optsoptions

◆ makeHIPBackendExecutionPolicy()

HIPBackendExecutionPolicy mfront::generic_parallel::makeHIPBackendExecutionPolicy ( const HIPBackendExecutionOptions & opts = {})
inlinenoexcept
Returns
an execution policy of the hip backend
Parameters
[in]optsoptions

◆ makeKey()

TFEL_HOST_DEVICE constexpr atomic_size_type mfront::generic_parallel::makeKey ( const atomic_size_type i,
const atomic_size_type c )
nodiscardconstexprnoexcept
Returns
the key of an event: the minimum of the keys gives the first point concerned, whatever the order of the computations
Parameters
[in]iindex of the point
[in]cidentifier of the check retained at this point

◆ makeParallelSTLBackendExecutionPolicy()

ParallelSTLBackendExecutionPolicy mfront::generic_parallel::makeParallelSTLBackendExecutionPolicy ( const BackendExecutionCommonPolicy & opts = {})
inlinenoexcept
Returns
an execution policy of the stlpar backend
Parameters
[in]optscommon options

◆ makeSyclBackendExecutionPolicy()

SyclBackendExecutionPolicy mfront::generic_parallel::makeSyclBackendExecutionPolicy ( const ::sycl::queue & q,
const BackendExecutionCommonPolicy & opts = {} )
inline
Returns
an execution policy of the sycl backend
Parameters
[in]qqueue on which the kernels are submitted (required)
[in]optscommon options

◆ report()

template<typename OutputStatus>
int mfront::generic_parallel::report ( OutputStatus & s,
const int status,
const std::string_view msg )
noexcept

set the status and the error message of an output status

Parameters
[out]soutput status
[in]statusstatus
[in]msgerror message
Returns
the status

◆ setMinimalCUDAStackSize()

bool mfront::generic_parallel::setMinimalCUDAStackSize ( const std::size_t stack_size,
const bool preserve = false )
inlinenoexcept

increase the stack size of the threads of the current CUDA device, if the CUDA runtime is loaded by the process. Otherwise, nothing is done. A loaded CUDA runtime does not mean that the computations are performed on an NVIDIA GPU: the primitives of the stlpar and sycl backends only call this function when the computations are offloaded to a GPU (nvc++ -stdpar=gpu, sycl queue running on a GPU).

Some parallel programming models execute the computations on NVIDIA GPUs through the CUDA runtime but give no access to the stack size of the threads: the C++ standard parallelism with nvc++ -stdpar=gpu and SYCL with AdaptiveCpp. The default stack size (1024 bytes) and the automatic increase performed by the CUDA driver at kernel launch, which does not take into account the internal routines of the compilers (such as the division of double precision numbers), are not sufficient for some kernels.

The CUDA runtime is looked up among the loaded libraries, whatever its version, so that this function does not require the CUDA headers nor the CUDA runtime. Nothing is done on systems other than Linux.

Returns
true on success, false if the stack size could not be set or is too small and must be preserved
Parameters
[in]stack_sizeminimal stack size, in bytes
[in]preserveif true, the stack size is only checked

◆ toOrderedKey()

TFEL_HOST_DEVICE constexpr atomic_size_type mfront::generic_parallel::toOrderedKey ( const double v)
constexprnoexcept
Returns
an unsigned integer whose ordering is the same as the ordering of the given floating point values. This allows to compute the minimum of floating point values with an integer atomic operation, which is how the devices update the time step scaling factor.

◆ updateStatistics()

template<typename Atomics, typename Statistics, typename real>
TFEL_HOST_DEVICE void mfront::generic_parallel::updateStatistics ( Statistics & s,
const BatchStatistics< real > & r,
const atomic_size_type rdt0 )

update the statistics shared by the threads with the statistics of a point or of a group of points, by atomic operations. The shared statistics are only accessed if an event occurred: a failure, an unreliable result, or a time step scaling factor lower than the initial one.

Template Parameters
Atomicsatomic operations of the backend, given by the static functions add and min on values of type atomic_size_type
Parameters
[in,out]sshared statistics
[in]rstatistics of a point or of a group of points
[in]rdt0ordered key of the initial time step scaling factor (see toOrderedKey)

Variable Documentation

◆ hasTimeStepScalingFactor

template<typename Statistics>
bool mfront::generic_parallel::hasTimeStepScalingFactor
inlineconstexpr
Initial value:
= requires(Statistics& s) {
s.rdt;
}

true if the statistics updated by the devices hold a time step scaling factor, false otherwise, which is the case of the statistics of the material properties

◆ maximal_number_of_checks

atomic_size_type mfront::generic_parallel::maximal_number_of_checks
inlineconstexpr
Initial value:
=
::mfront_gp_atomic_size_type atomic_size_type
a simple alias
Definition StatisticsKeys.hxx:24
constexpr unsigned int check_bits
number of bits of the identifier of a check in a key. The other bits hold the index of the point.
Definition StatisticsKeys.hxx:32

maximal number of checks

◆ maximal_number_of_points

atomic_size_type mfront::generic_parallel::maximal_number_of_points
inlineconstexpr
Initial value:
=
(atomic_size_type{1} << (64 - check_bits)) - 1

maximal number of points of a batch

◆ stack_size_error_message

const char* mfront::generic_parallel::stack_size_error_message
inlineconstexpr
Initial value:
=
"unable to set the stack size of the threads of the device, or the "
"stack size is too small and must be preserved"

error message associated with setMinimalCUDAStackSize