28.2 Apply() by Example

In order to apply an element operator to a field in either physical or coefficient representation, a matrix-matrix multiplication has to be performed. This multiplication is currently implemented in three variations: the standard matrix (StdMat), the sum-factorisation (SumFac), and the threaded-by-output-point sum-factorisation (SumFacTOP) approach. These implementations are wrapped in the Apply() function of each operator class and which device specific implementation that is executed depends on the execStr and the implStr with which an operator is initialized. The standard matrix approach is the most straightforward and involves a direct multiplication of the element operator matrix with the input field matrix. The sum-factorisation approach on the other hand, leverages the tensor-product structure of the basis functions to reduce memory consumption and increase computational intensity. Finally, the threaded-by-output-point sum-factorisation approach takes the sum-factorisation and assigns a thread to each output point and it’s associated operations, which can be particularly beneficial when using higher order polynomial bases due to the elevated amount of work this causes per thread.

In order to understand the three approaches, we consider the application of the Backward transform operator. We assume a quadrilateral mesh consisting of N rectangles that each carry a tensorial bases made up of a one-dimensional expansion of order P in both directions. This allows us to restrain ourselves to the different implementations of the Apply() function within what Nektar++ refers to as a block of elements. A block of elements consists of multiple elements with the same shape, expansion base, and quadrature. Blocks are also made up of either all "Regular" or all "Deformed" elements. The notation used in this section is taken from [46]. In order to perform the backward transform and evaluate the physical values at the Q quadrature points, of the block we are considering, in each direction, we need to multiply the coefficient matrix:

                       ^u000    ^u100   ⋅⋅⋅    ^uN00-1
                       ^u001    ^u101   ⋅⋅⋅    ^uN01-1
                       .      .     .      .
                       ..      ..      ..    ..
                       ^u0     ^u1    ⋅⋅⋅    ^uN -1
                        0P     0P           0P
                       ^u010    ^u110   ⋅⋅⋅    ^uN10-1
                    ⌊⌋  ..      ..     ..     ..
                       .      .       .    .
                    ||||  ^u0     ^u1    ⋅⋅⋅    ^uN -1
                    ||||  .1P    .1P   .      .1P
                    ||||  ..      ..      ..    ..
                    ||||   0      1            N -1
                    ||||  ^uP0    ^uP0   ⋅⋅⋅    ^uP 0
                    ||||  ...      ...     ...    ...
                    ||||                      2
^u :=                ||||  ^u0PP    ^u1PP  ∈⋅⋅ℝ⋅(P +1^u)NP×N-P1
                    ||||
                    ||||
                    ||||
                    ||||
                    ||||
                    ||||
                    ⌈⌉

by the operator matrix:

                                                                                           ϕ0(ξ0)ϕ0(ξ0)        ϕ0(ξ0)ϕ1 (ξ0) ⋅⋅⋅         ϕ0(ξ0)ϕP (ξ0)       ϕ1(ξ0)ϕ0(ξ0) ⋅⋅⋅          &
                                                                                           ϕ (ξ )ϕ (ξ)        ϕ (ξ )ϕ  (ξ ) ⋅⋅⋅         ϕ (ξ)ϕ  (ξ )       ϕ (ξ)ϕ (ξ ) ⋅⋅⋅          ϕ (
                                                                                           .0  0  0  1        .0  0  1 1  .           .0  0  P  1        .1  0  0 1  .           .1 0  P  1  .           .P  0  0  1 .           .P  0  P  1
                                                                                           ..                  ..            ..          ..                  ..           ..          ..            ..          ..            ..         ..

                                                                                           ϕ0(ξ0)ϕ0(ξQ-1)     ϕ0(ξ0)ϕ1 (ξQ -1⋅)⋅⋅         ϕ0(ξ0)ϕP (ξQ-1)     ϕ1(ξ0)ϕ0(ξQ- 1)
                                                                                  ⌊⌋       ...                  ...           ...          ...                  ...           ...          ...           ...          ...           ...         ...
                                                                                  ||
                                                                                           ϕ0(ξQ-1)ϕ0(ξ0)     ϕ0(ξQ-1)ϕ1(ξ0⋅)⋅⋅         ϕ0(ξQ-1)ϕP(ξ0)     ϕ1(ξQ-1)ϕ0(ξ0)
                                                                                  ||||
                                                                                           ϕ0(ξQ-1)ϕ0(ξ1)     ϕ0(ξQ-1)ϕ1(ξ1⋅)⋅⋅         ϕ0(ξQ-1)ϕP(ξ1)     ϕ1(ξQ-1)ϕ0(ξ1)
                                                                                  ||||       ...                  ...           ...          ...                  ...           ...          ...           ...          ...           ...         ...
                                                                                  ||||                                                                                 2      2
B :=                                                                                       ϕ0(ξQ-1)ϕ0(ξQ- 1)  ϕ0(ξQ-1)ϕ1(ξQ⋅-⋅1⋅)        ϕ0(ξQ-1)ϕP(ξQ- 1)  ϕ1(ξQ-1)ϕ0
                                                                                  ||||
                                                                                  ||||
                                                                                  ||||
                                                                                  ||||
                                                                                  ⌈⌉

Here, ϕp(ξi) denotes the p-th one-dimensional basis function evaluated at the i-th quadrature point for p ∈{0,1,...,P},i ∈{0,1,...,Q - 1}. The 2D basis functions are constructed as the tensor product of the 1D basis functions, i.e., ϕpq(ξi,ξj) = ϕp(ξi)ϕq(ξj) for p,q ∈{0,1,...,P},i,j ∈{0,1,...,Q - 1}. The values ûpqe denote the coefficients of the expansion for element e ∈{0,1,...,N  - 1}.

We denote the resulting physical values at the quadrature points for each element as ui,je := u  e         e
(χ1(ξi,ξj) ,χ2(ξi,ξj)). The one-to-one maps χ1e,χ2e take the local coordinates of the element e to the global coordiantes x1 and x2 respectively. The physical values and the coefficients relate as follows:

                                                           u0         u1      ⋅⋅⋅      uN- 1
                                                            0,0         0,0               0,0
                                                           u00,1        u10,1     ⋅⋅⋅      uN0-,1 1
                                                           ..          ..       ...      ..
                                                           .          .                .
                                                           u00,Q- 1     u10,Q -1  ⋅⋅⋅      uN0-,Q-11
                                                      ⌊⌋    ..          ..       ..       ..
                                                           .          .         .      .
                                                      ||||    u0         u1      ⋅⋅⋅      uN- 1
                                                      ||||     Q-1,0      Q- 1,0            Q-1,0
                                                      ||||    u0Q-1,1     u1Q- 1,1  ⋅⋅⋅      uNQ--11,1
                                                      ||||    ..          ..       ..       ..
                                                      ||||    .          .         .      .
                            u :=                      ||||    u0         u1      ⋅⋅⋅      uN- 1
                                                      ||||     Q-1,Q-1    Q- 1,Q- 1         Q-1,Q-1
                                                      ||||
                                                      ||||
                                                      ||||       ∑   ^u0 ϕk(ξ0)ϕl(ξ0)        ∑    ^u1ϕk (ξ0)ϕl(ξ⋅0)⋅⋅              ∑    ^uN- 1ϕk(ξ0)ϕl(ξ0)
                                                      ||||       ∑ k,l  kl                   ∑ k,l kl                         ∑ k,l kl
                                                      ⌈⌉         k,l ^u0klϕk(ξ0)ϕl(ξ1)         k,l ^u1klϕk (ξ0)ϕl(ξ⋅1)⋅⋅               k,l ^uNk-l 1ϕk(ξ0)ϕl(ξ1)
                                                              ..                         ..               ..               ..
                                                              .                         .                 .              .
                                                  =           ∑     0                   ∑     1                          ∑     N- 1
                                                                k,l ^u klϕk(ξ0)ϕl(ξQ- 1)      k,l ^uklϕk (ξ0)ϕl(ξ⋅Q⋅-⋅1)             k,l ^ukl ϕk(ξ0)ϕl(ξQ-1)
                                                  ⌊⌋           ...                         ...               ...              ...
                                                  ||
                                                  ||||           ∑k,l ^u0klϕk(ξQ-1)ϕl(ξ0)    ∑k,l ^u1klϕk (ξQ -1)ϕl⋅(⋅ξ⋅0)            ∑k,l ^uNk-l 1ϕk(ξQ-1)ϕl(ξ0)
                                                  ||||           ∑                         ∑                                ∑
                                                  ||||             k,l ^u0klϕk(ξQ-1)ϕl(ξ1)      k,l ^u1klϕk (ξQ -1)ϕl⋅(⋅ξ⋅1)             k,l ^uNk-l 1ϕk(ξQ-1)ϕl(ξ1)
                                                  ||||           ..                         ..               ..               ..
                                                  ||||           .                         .                 .              .
B^u =                                              ||||           ∑   ^u0 ϕ (ξ   )ϕ (ξ   )   ∑    ^u1∈ϕℝQ(ξ2 ×N )ϕ⋅(⋅ξ⋅    )         ∑    ^uN- 1ϕ (ξ   )ϕ (ξ    )
                                                  ||||             k,l  kl k  Q-1  l  Q-1      k,l kl k Q -1  l Q- 1            k,l kl   k  Q-1  l Q -1
                                                  ||||
                                                  ||||
                                                  ||||
                                                  ||||
                                                  |⌈|⌉

The described matrix-matrix multiplication contains all operations that need to be performed during the backwards transformation. For later use with the sum factorisation approaches we introduce a visualisation technique for the standard matrix approach as seen in figure 28.2. The individual colours serve to represent one element each in either physical or coefficient space. The matrix visualized by black dots show the operator matrix B, which is applied to the coefficient matrix û on the right to obtain the physical values u on the left. The work assigned to a single thread is determined by the underlying function call as opposed to the implementations introduced later in this section, where a more granular load balancing is performed.


⌊⌋⌊⌋

||||||||⌊⌋
||||||||
||||=|||||⌈|⌉Library- internal threading
||||||||
|⌈|⌉|⌈|⌉

Figure 28.2 Visualisation of the standard matrix approach. Threading is handled by the underlying matrix-matrix multiplication routine, which is a highly optimised library such as blas, cublas, or hipblas.


In Nektar++, the actual matrix-matrix multiplication is performed using the NekBlas::Gemm function, which in turn calls blas, cublas, or hipblas depending on the execution space of the operator and the device backend Nektar++ was built with. The generic interface NekBlas.hpp takes an opaque NekBlas::Handle<ExecSpace>, which only carries the stream ID; it includes no BLAS library header. Each backend implements the routines in its own compilation unit (blas.cpp, cuBlas.cpp, hipBlas.cpp, ...), where it looks up its library handle for the stream. The cuBLAS implementation of NekBlas::Gemm is shown in listing 28.1.

Listing 28.1: cuBLAS implementation of NekBlas::Gemm (cublasSgemm, cublasDgemm).
1template <typename TData> 
2void Gemm(Handle<NektarSpaces::Device> handle, std::string transposeA, 
3          std::string transposeB, const int M, const int N, const int K, 
4          const TData alpha, const TData *a, const int lda, const TData *b, 
5          const int ldb, const TData beta, TData *c, const int ldc) 
6{ 
7    auto cublasHandle = GetCuBlasHandle(handle.GetStreamID()); 
8 
9    auto transA = (transposeA == "N") ? CUBLAS_OP_N : CUBLAS_OP_T; 
10    auto transB = (transposeB == "N") ? CUBLAS_OP_N : CUBLAS_OP_T; 
11 
12    if constexpr (std::is_same_v<TData, float>) 
13    { 
14        CUBLAS_CHECK(cublasSgemm(cublasHandle, transA, transB, M, N, K, 
15                                 &alpha, a, lda, b, ldb, &beta, c, ldc)); 
16    } 
17    else if constexpr (std::is_same_v<TData, double>) 
18    { 
19        CUBLAS_CHECK(cublasDgemm(cublasHandle, transA, transB, M, N, K, 
20                                 &alpha, a, lda, b, ldb, &beta, c, ldc)); 
21    } 
22}

The arguments of the NekBlas::Gemm call and their meanings are listed in table 28.2.


Table 28.2 NekBlas::Gemm Parameters with Roles and Values from the Example.

Parameter

Role in the Matrix Equation (Z = α ⋅X ⋅Y + β ⋅Z)

Value in BwdTrans

handle

Opaque handle for the execution space and stream.

NekBlas:: Handle<ExecSpace>:: GetInstance(streamID)

transposeA

Specifies if matrix X should be transposed.

"N" → no transpose

transposeB

Specifies if matrix Y should be transposed.

"N" → no transpose

M

Number of rows in matrices X and Z.

Q2

N

Number of columns in matrices Y and Z.

N

K

Number of columns in X and rows in Y .

P2

alpha

The scalar multiplier α.

1.0

a

Pointer to the data for matrix X.

Pointer to operator matrix B

lda

The leading dimension of matrix X.

Q2

b

Pointer to the data for matrix Y .

Pointer to vector matrix û

ldb

The leading dimension of matrix Y .

P2

beta

The scalar multiplier β.

0.0

c

Pointer to the data for the output matrix Z.

Pointer to physical value vector u

ldc

The leading dimension of matrix Z.

Q2


Having introduced the standard matrix approach, we can now turn to the implementation of the sum-factorisation approach. In order to reduce memory consumption and increase computational intensity, the sum-factorisation approach decomposes the operator matrix B into two matrices Be:

      ⌊                                 ⌋
      | ϕ0 (ξ0)    ϕ1 (ξ0)   ⋅⋅⋅   ϕP(ξ0) |
  e   || ϕ0 (ξ1)    ϕ1 (ξ1)   ⋅⋅⋅   ϕP(ξ1) ||    Q ×(P+1)
B  := |    ..         ..     ...      ..   | ∈ ℝ        .
      ⌈    .         .              .   ⌉
       ϕ0(ξQ- 1) ϕ1(ξQ- 1) ⋅⋅⋅  ϕP(ξQ-1)

The field coefficient matrix û is decomposed as well:

     ⌊                   ⌋
       ^ue00  ^ue01  ⋅⋅⋅  ^ue0P
     || ^ue10  ^ue11  ⋅⋅⋅  ^ue1P||
^ue := || ..    ..   ..    .. || ∈ ℝ(P+1)×(P+1).
     ⌈  .    .     .   . ⌉
       ^ueP0  ^ueP1  ⋅⋅⋅ u^ePP

and the element-wise computation of u is performed in two "stages" that correspond to the two directions (referred to as direction 0 and direction 1) of our quadrilaterals:

Stage 1: Transformation in the first direction

Beûe = ⌊  ∑P    e           ∑P     e               ∑P     e        ⌋
|  ∑Pk=0 ^uke0ϕk(ξ0)   ∑Pk=0 ^uke1ϕk(ξ0)   ⋅⋅⋅   ∑Pk=0 ^ukePϕk(ξ0) |
||    k=0 ^uk0ϕk(ξ1)     k=0 ^uk1ϕk(ξ1)   ⋅⋅⋅     k=0 ^ukPϕk(ξ1) ||
|⌈         ...                 ...          ...          ...        |⌉
  ∑P    e           ∑P     e               ∑P    e
    k=0 ^uk0ϕk(ξQ-1)    k=0u^k1ϕk (ξQ -1)  ⋅⋅⋅    k=0 ^ukP ϕk(ξQ-1)
Stage 2: Transformation in the second direction

                                 Be^u(Be)T
                                     =
⌊  ∑    e                ∑     e                    ∑    e                ⌋
   ∑ k,l ^uklϕk(ξ0)ϕl(ξ0)   ∑ k,l ^uklϕk(ξ0)ϕl(ξ1)  ⋅⋅⋅   ∑ k,l ^uklϕk(ξ0)ϕl(ξQ- 1)
||    k,l ^ueklϕk(ξ1)ϕl(ξ0)     k,l ^ueklϕk(ξ1)ϕl(ξ1)  ⋅⋅⋅     k,l ^ueklϕk(ξ1)ϕl(ξQ- 1) ||
||           ..                     ..           ...             ..           ||
|| ∑    e    .           ∑    e    .                ∑    e     .           ||
⌈   k,l ^uklϕk(ξQ-1)ϕl(ξ0)   k,l ^uklϕk(ξQ-1)ϕl(ξ1) ⋅⋅⋅   k,l ^uklϕk(ξQ-1)ϕl(ξQ -1)⌉

                                     =
                ⌊  e      e           e     ⌋
                  u0,0    u0,1   ⋅⋅⋅   u0,Q -1
                || ue1,0    ue1,1   ⋅⋅⋅   ue1,Q -1 ||
                ||  ..      ..    ...      ..   || :=  ue ∈ ℝQ ×Q
                ||  .e     e.          e  .   ||
                ⌈ uQ,0 u Q-1,1  ⋅⋅⋅  uQ-1,Q-1⌉

This decomposition results in lighter memory consumption and a higher computational intensity, as the number of operations per memory access is increased. As for the StdMat approach, we can visualize the sum-factorisation approach using the color scheme introduced earlier. The visualization for the sum-factorised approach is shown in figure 28.3. The individual colours serve to represent one element each in either physical or coefficient space. The matrices with entries visualized as black dots are operator matrices Be and (Be)T , which is applied to the coefficient matrix ue on the right to obtain the physical values ue on the left. In the visualization we have rearranged the results into the same memory layout as for the standard matrix approach to better illustrate the equivalence of both approaches. All operations related to a single element and accordingly performed by one thread, were marked using purple bounding boxes and arrows.


⌊⌋
||
||||⌊⌋
||||[][][][][]
||||⇐⌈⌉1 thread
||||
⌈⌉

Figure 28.3 Visualisation of the sum-factorisation approach. The purple boxes and arrows indicate the operations performed by one thread. One thread computes the results for one element, which corresponds to one column of the leftmost matrix.


This visualization, like the matrix formulation describes the computations related to one element. In the implementation of Nektar++, one thread handles one element at a time, as can be seen in the cuda implementation in listing 28.2:

Listing 28.2: Cuda sum-factorisation kernel for the quadrilateral backward transform.
1template <typename tdata> 
2nek_device_inline static void BwdTransQuadSumFacKernel( 
3    const unsigned int ilane, const unsigned int nm0, const unsigned int nm1, 
4    const unsigned int nq0, const unsigned int nq1, 
5    const tdata *__restrict__ basis0, const tdata *__restrict__ basis1, 
6    const tdata *__restrict__ in, tdata *__restrict__ out, 
7    tdata *__restrict__ wsp) 
8{ 
9    constexpr unsigned int warpsize = nektarspaces::vector_width<tdata>::value; 
10 
11    for (unsigned int i = 0u; i < nq0; ++i) 
12    { 
13        // direction 0 
14        for (unsigned int q = 0u, cnt_qp = 0u; q < nm1; ++q) 
15        { 
16            tdata tmp = 0.0; 
17#pragma unroll 
18            for (unsigned int p = 0u; p < nm0; ++p, ++cnt_qp) 
19            { 
20                tmp += in[warpsize * cnt_qp + ilane] * basis0[p * nq0 + i]; 
21            } 
22            wsp[warpsize * q + ilane] = tmp; 
23        } 
24 
25        // direction 1 
26        for (unsigned int j = 0u; j < nq1; ++j) 
27        { 
28            tdata tmp = 0.0; 
29#pragma unroll 
30            for (unsigned int q = 0u; q < nm1; ++q) 
31            { 
32                tmp += wsp[warpsize * q + ilane] * basis1[q * nq1 + j]; 
33            } 
34            out[warpsize * (nq0 * j + i) + ilane] = tmp; 
35        } 
36    } 
37}
Like the described Stage 1 and Stage 2 made up of the matrix-matrix multiplications of the application of the backwards transformation operator to the field of coefficients, the sum-factorisation implementation is split into two stages. The code also shows that the warpsize of the GPU is being used to vectorize the work being done across elements. One thread computes the results for one element while a warp handles multiple elements in parallel. In a similar manner this vectorization can be preformed though SIMD operations on a CPU, allowing multiple elements to be processed at once even when no GPU is available for Nektar++ to copmute on. In this sense, the implemented sum-factorisation is also commonly referred to as a vectorized sum-factorisation. The arguments and their meanings of the BwdTransQuadSumFacKernel function for the cuda back-end are listed in table 28.3:


Table 28.3 BwdTransQuadSumFacKernel Parameters and Their Roles.

Parameter

Role in the Sum-Factorisation Kernel

Value in BwdTrans

ilane

The unique ID of the current thread within its warp, selects the data for the specific element this thread is processing.

Thread index (0 to warpsize-1)

nm0

The number of modes (coefficients) in direction 0. Defines the inner loop size for stage 1.

Num. modes in direction 0, P + 1

nm1

The number of modes in direction 1. Defines the inner loop size for stage 2 and outer loop for stage 1.

Num. modes in direction 1, P + 1

nq0

The number of quadrature points in direction 0. Defines the main outer loop boundary.

Num. quadrature points in direction 0, Q

nq1

The number of quadrature points in direction 1. Defines the outer loop boundary for stage 2.

Num. quadrature points in direction 1, Q

basis0

Pointer to the 1D basis matrix used in stage 1.

Basis matrix for direction 0, Be

basis1

Pointer to the 1D basis matrix used in stage 2.

Basis matrix for direction 1, Be

in

Pointer to the input array containing the modal coefficients for a batch of elements.

Input coefficients, ûe

out

Pointer to the output array for the final physical values of the element batch.

Output physical values, ue

wsp

Pointer to a temporary workspace array for storing the intermediate results between stage 1 and stage 2.

Intermediate results, Beûe


Finally, the threaded-by-output-point sum-factorisation approach further decomposes the computation by assigning a thread to each output point ui,je and its associated operations. The computation of the value at one output point ui,je is however also performed in two stages, one for each direction:

ti,pe = ∑ k=0P û kpe,ϕ k(ξi) ∀i ∈{0,…,Q -1},p ∈{0,…,P}
ui,je = ∑ p=0P t i,pϕp(ξj), ∀i,j ∈{0,…,Q -1}

Like for previous approaches, we can visualize the threaded-by-output-point sum-factorisation approach using the established colour scheme. The matrices with entries visualized as black dots are operator matrices Be and (Be)T , which is applied to the coefficient matrix ue on the right to obtain the physical values ue on the left. The number of operations has not changed compared to the regular sum-factorisation approach, but the way the work is distributed among individual threads is different. In figure 28.4 we have marked all operations that are performed by one thread using pink and purple lines that correspond to the first and second basis in the 0 as well as the 1 direction respectively. Like in the visualization of the sum-factorisation approach, we have rearranged the results into the same memory layout as for the standard matrix approach to better illustrate the equivalence of all approaches.


⌊⌋
||
||||⌊⌋[][][][][]
||||⌈⌉
||||⇐1 thread
||||
⌈⌉

Figure 28.4 Visualisation of the threaded-by-output-point sum-factorisation approach for a backward transform. The operations performed by one thread are marked using pink and purple lines, which correspond to the first and second basis in the 0 as well as the 1 direction respectively. One thread computes the value of one output point, which corresponds to one entry of the leftmost matrix (i.e. one output-point).


The implementation of the threaded-by-output-point sum-factorisation approach in Nektar++ is implemented in two stages, just like described above. In listing 28.3 we show the cuda implementation of the threaded-by-output-point sum-factorisation kernel. The two stages can clearly be seen in the two main loops, one for each direction and separated by a barrier that assures that the intermediate results are synchronized between all threads before proceeding to the second stage.

Listing 28.3: Cuda threaded-by-output-point sum-factorisation kernel for the quadrilateral backward transform.
1template <typename TthreadBlock, typename TData> 
2NEK_DEVICE_INLINE static void BwdTransQuadSumFacTOPKernel( 
3    const unsigned int nm0, const unsigned int nm1, const unsigned int nq0, 
4    const unsigned int nq1, const unsigned int nqTot, 
5    const TData *__restrict__ basis0, const TData *__restrict__ basis1, 
6    const TData *__restrict__ in, TData *__restrict__ out, 
7    TData *__restrict__ wsp, const TthreadBlock &threadBlock) 
8{ 
9    const unsigned int idx0   = getLocalIdx(threadBlock); 
10    const unsigned int stride = getLocalRange(threadBlock); 
11 
12    // direction 0 
13    for (unsigned int idx = idx0; idx < nq0 * nm1; idx += stride) 
14    { 
15        const unsigned int q = idx % nm1; 
16        const unsigned int i = idx / nm1; 
17        unsigned int cnt_qp  = nm0 * q; 
18 
19        TData tmp = 0.0; 
20#pragma unroll 
21        for (unsigned int p = 0u; p < nm0; ++p, ++cnt_qp) 
22        { 
23            tmp += in[cnt_qp] * basis0[p * nq0 + i]; 
24        } 
25        wsp[idx] = tmp; 
26    } 
27 
28    localBarrier(threadBlock); 
29 
30    // direction 1 
31    for (unsigned int idx = idx0; idx < nqTot; idx += stride) 
32    { 
33        const unsigned int i = idx % nq0; 
34        const unsigned int j = idx / nq0; 
35        unsigned int cnt_iq  = nm1 * i; 
36 
37        TData tmp = 0.0; 
38#pragma unroll 
39        for (unsigned int q = 0u; q < nm1; ++q, ++cnt_iq) 
40        { 
41            tmp += wsp[cnt_iq] * basis1[q * nq1 + j]; 
42        } 
43        out[idx] = tmp; 
44    } 
45 
46    localBarrier(threadBlock); 
47}

The arguments and their meanings of the BwdTransQuadSumFacTOPKernel function for the cuda back-end are listed in the table 28.4.


Table 28.4 BwdTransQuadSumFacTOPKernel Parameters and Their Roles.

Parameter

Role in the Sum-Factorisation Kernel

Value in BwdTrans

nm0

The number of modes (coefficients) in direction 0. Defines the inner loop size for stage 1.

Num. modes in dir 0, P + 1

nm1

The number of modes in direction 1. Defines the inner loop size for stage 2 and outer loop for stage 1.

Num. modes in dir 1, P + 1

nq0

The number of quadrature points in direction 0.

Num. quadrature points in dir 0, Q

nq1

The number of quadrature points in direction 1.

Num. quadrature points in dir 1, Q

nqTot

The total number of quadrature points (nq0 ×nq1). Defines the loop boundary for stage 2.

Total quadrature points, Q2

basis0

Pointer to the 1D basis matrix used in stage 1.

Basis matrix for dir 0, Be

basis1

Pointer to the 1D basis matrix used in stage 2.

Basis matrix for dir 1, Be

in

Pointer to the input array containing the modal coefficients for a single element.

Input coefficients, ûe

out

Pointer to the output array for the final physical values of the single element.

Output physical values, ue

wsp

Pointer to a workspace array shared by all threads in the block to store intermediate results.

Intermediate results, w

threadBlock

A handle to the GPU thread block, used to manage thread indices and synchronization.

GPU thread block context