|
MGIS 3.1.0
|
Implementation of the CUDA assign algorithm declared in MGIS/Function/CUDA/Algorithms.hxx, including the generic CUDA kernel and the helper which launches it. More...
#include "MGIS/Function/Algorithms.hxx"Namespaces | |
| namespace | mgis |
| the namespace mgis encloses all the MGIS project. | |
Functions | |
| template<typename CallableType, typename SpaceSizeType> | |
| __global__ void | mgis::function::cuda::apply_kernel (CallableType f, const SpaceSizeType s) |
| CUDA kernel calling a callable object on every element of a space. | |
| template<typename CallableType, typename SpaceSizeType> | |
| bool | mgis::function::cuda::call_kernel (AbstractErrorHandler &ctx, const CUDAExecutionConfiguration &c, CallableType f, const SpaceSizeType s) |
| launch apply_kernel on the space and wait for its completion | |
| template<typename FunctionType, EvaluatorConcept EvaluatorType> requires ( (LinearElementSpaceConcept<evaluator_space<EvaluatorType>>) && std::same_as<function_space<FunctionType>, evaluator_space<EvaluatorType>>) | |
| bool | mgis::function::assign (AbstractErrorHandler &, const CUDAExecutionConfiguration &, FunctionType &, const EvaluatorType) |
| assign the evaluator to a function | |
Implementation of the CUDA assign algorithm declared in MGIS/Function/CUDA/Algorithms.hxx, including the generic CUDA kernel and the helper which launches it.
| __global__ void mgis::function::cuda::apply_kernel | ( | CallableType | f, |
| const SpaceSizeType | s ) |
CUDA kernel calling a callable object on every element of a space.
Each thread computes its own linear index from the block and thread indices and calls f with this index. Threads whose index is greater than or equal to the size of the space return immediately, which allows the grid to oversubscribe the space.
| CallableType | type of the callable object, which must be callable from the device |
| SpaceSizeType | integral type used to index the space |
| [in] | f | callable object applied to every element |
| [in] | s | size of the space |
|
nodiscard |
assign the evaluator to a function
implementation of the CUDA assign algorithm
This is the CUDA counterpart of the assign algorithm declared in MGIS/Function/Algorithms.hxx: the values are computed on the graphic card by a CUDA kernel instead of being computed on the host. The evaluator and the function must therefore be callable from the device, which means in particular that they must be built on data accessible from the device, e.g. thrust::universal_vectors, and that the lambda expressions they rely on must be MGIS_HOST_DEVICE lambda expressions.
The spaces of the function and of the evaluator and their number of components are compared and the evaluator is checked before the kernel is launched; the launch strategy itself is described in MGIS/Function/CUDA/Algorithms.ixx.
Only the function arguments which can be captured by a kernel are supported: if the function is not a lightweight view, a view of it is computed on the host and captured by the kernel.
| FunctionType | type of the function the values are assigned to, which must be defined on the same space as the evaluator |
| EvaluatorType | type of the evaluator, which must satisfy the EvaluatorConcept concept and be defined on a linear element space |
| [in] | ctx | execution context, used to report the errors |
| [in] | c | CUDA execution configuration |
| [in] | f | left hand side, i.e. the function the values are assigned to |
| [in] | e | right hand side, i.e. the evaluator computing the values |
After checking that the spaces of the function and of the evaluator are equivalent, that their numbers of components match and that the evaluator is valid, a device callable lambda expression is built to assign, for a given index, the value computed by the evaluator to that of the function and is applied to every element of the space by cuda::call_kernel.
Two orthogonal choices are made at compile time:
|
nodiscard |
launch apply_kernel on the space and wait for its completion
The number of threads per block is taken from the configuration and the number of blocks is computed from the size of the space so that every index is covered by at least one thread. Both the launch and the execution of the kernel are checked: the corresponding CUDA error message is registered through the error handler when an error occurs.
| CallableType | type of the callable object, which must be callable from the device |
| SpaceSizeType | integral type used to index the space |
| [in] | ctx | error handler used to report the errors |
| [in] | c | CUDA execution configuration |
| [in] | f | callable object applied to every element of the space |
| [in] | s | size of the space |