MGIS 3.1.0
Loading...
Searching...
No Matches
Algorithms.hxx File Reference

CUDA counterpart of MGIS/Function/Algorithms.hxx. It declares the assign algorithm which evaluates an evaluator on the graphic card using the CUDA programming model and the CUDAExecutionConfiguration type used to configure the launch of the CUDA kernels. More...

Classes

struct  mgis::function::CUDAExecutionConfiguration
 execution configuration used to launch CUDA's kernels More...

Namespaces

namespace  mgis
 the namespace mgis encloses all the MGIS project.

Functions

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

Detailed Description

CUDA counterpart of MGIS/Function/Algorithms.hxx. It declares the assign algorithm which evaluates an evaluator on the graphic card using the CUDA programming model and the CUDAExecutionConfiguration type used to configure the launch of the CUDA kernels.

Author
Thomas Helfer
Date
28/06/2026

Function Documentation

◆ assign()

template<typename FunctionType, EvaluatorConcept EvaluatorType>
requires ( (LinearElementSpaceConcept<evaluator_space<EvaluatorType>>) && std::same_as<function_space<FunctionType>, evaluator_space<EvaluatorType>>)
bool mgis::function::assign ( AbstractErrorHandler & ctx,
const CUDAExecutionConfiguration & c,
FunctionType & f,
const EvaluatorType e )
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.

Template Parameters
FunctionTypetype of the function the values are assigned to, which must be defined on the same space as the evaluator
EvaluatorTypetype of the evaluator, which must satisfy the EvaluatorConcept concept and be defined on a linear element space
Parameters
[in]ctxexecution context, used to report the errors
[in]cCUDA execution configuration
[in]fleft hand side, i.e. the function the values are assigned to
[in]eright hand side, i.e. the evaluator computing the values
Returns
true if the assignment succeeded

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:

  • if the function is a lightweight view, it is captured directly by the lambda expression, otherwise a view of it is computed on the host and captured,
  • if the value returned by the function can be assigned from that of the evaluator using operator=, a direct assignment is used, otherwise the internals::assign_value helper is used, which handles the cases where the two values have different, but compatible, types.
Note
the requires-clause restricts the algorithm to evaluators defined on a linear element space and to functions defined on the very same space so that a single linear index can address both the function and the evaluator.