xref: /libCEED/rust/libceed-sys/c-src/include/ceed/jit-source/magma/magma-basis-weight-2d.h (revision f80f4a748154eed4bc661c135f695b92b1bc45b9)
1*f80f4a74SSebastian Grimberg // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2*f80f4a74SSebastian Grimberg // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*f80f4a74SSebastian Grimberg //
4*f80f4a74SSebastian Grimberg // SPDX-License-Identifier: BSD-2-Clause
5*f80f4a74SSebastian Grimberg //
6*f80f4a74SSebastian Grimberg // This file is part of CEED:  http://github.com/ceed
7*f80f4a74SSebastian Grimberg 
8*f80f4a74SSebastian Grimberg //////////////////////////////////////////////////////////////////////////////////////////
9*f80f4a74SSebastian Grimberg // weight basis action -- 2D
10*f80f4a74SSebastian Grimberg template <typename T, int DIM_, int NCOMP_, int Q_, int iDIM, int iCOMP>
11*f80f4a74SSebastian Grimberg __device__ __inline__ void magma_weight_2d_device(const T *sTweight, T rV[DIM_][NCOMP_][Q_], const int tx) {
12*f80f4a74SSebastian Grimberg   // Assumptions
13*f80f4a74SSebastian Grimberg   // 1. 1D thread configuration of size Q_
14*f80f4a74SSebastian Grimberg   // 2. rV[][][] matches the storage used in other actions (interp, grad, ... etc)
15*f80f4a74SSebastian Grimberg   // 3. iDIM and iCOMP specify which indexes to use in rV,
16*f80f4a74SSebastian Grimberg   //    since the output per thread is a register array of size Q_
17*f80f4a74SSebastian Grimberg   // 4. Sync is recommended after the call (to make sure sTweight can be overwritten)
18*f80f4a74SSebastian Grimberg 
19*f80f4a74SSebastian Grimberg   if (tx < Q_) {
20*f80f4a74SSebastian Grimberg     // x sTweight[j]  for first update
21*f80f4a74SSebastian Grimberg     // x sTweight[tx] for second update
22*f80f4a74SSebastian Grimberg     for (int j = 0; j < Q_; j++) {
23*f80f4a74SSebastian Grimberg       rV[iDIM][iCOMP][j] = sTweight[j] * sTweight[tx];
24*f80f4a74SSebastian Grimberg     }
25*f80f4a74SSebastian Grimberg   }
26*f80f4a74SSebastian Grimberg }
27*f80f4a74SSebastian Grimberg 
28*f80f4a74SSebastian Grimberg //////////////////////////////////////////////////////////////////////////////////////////
29*f80f4a74SSebastian Grimberg extern "C" __launch_bounds__(MAGMA_BASIS_BOUNDS(Q, MAGMA_MAXTHREADS_2D)) __global__
30*f80f4a74SSebastian Grimberg     void magma_weight_2d_kernel(const CeedScalar *dqweight1d, CeedScalar *dV, const int v_stride, const int nelem) {
31*f80f4a74SSebastian Grimberg   MAGMA_DEVICE_SHARED(CeedScalar, shared_data)
32*f80f4a74SSebastian Grimberg 
33*f80f4a74SSebastian Grimberg   const int tx      = threadIdx.x;
34*f80f4a74SSebastian Grimberg   const int ty      = threadIdx.y;
35*f80f4a74SSebastian Grimberg   const int elem_id = (blockIdx.x * blockDim.y) + ty;
36*f80f4a74SSebastian Grimberg 
37*f80f4a74SSebastian Grimberg   if (elem_id >= nelem) return;
38*f80f4a74SSebastian Grimberg 
39*f80f4a74SSebastian Grimberg   CeedScalar rV[1][1][Q];  // allocate with DIM=NCOMP=1, but sizes may differ for a fused operator
40*f80f4a74SSebastian Grimberg   // global memory pointers
41*f80f4a74SSebastian Grimberg   dV += elem_id * v_stride;
42*f80f4a74SSebastian Grimberg 
43*f80f4a74SSebastian Grimberg   // shared memory pointers
44*f80f4a74SSebastian Grimberg   CeedScalar *sTweight = (CeedScalar *)shared_data;
45*f80f4a74SSebastian Grimberg 
46*f80f4a74SSebastian Grimberg   // read dqweight_1d
47*f80f4a74SSebastian Grimberg   if (ty == 0 && tx < Q) {
48*f80f4a74SSebastian Grimberg     sTweight[tx] = dqweight1d[tx];
49*f80f4a74SSebastian Grimberg   }
50*f80f4a74SSebastian Grimberg 
51*f80f4a74SSebastian Grimberg   __syncthreads();
52*f80f4a74SSebastian Grimberg   magma_weight_2d_device<CeedScalar, 1, 1, Q, 0, 0>(sTweight, rV, tx);
53*f80f4a74SSebastian Grimberg 
54*f80f4a74SSebastian Grimberg   // write V
55*f80f4a74SSebastian Grimberg   if (tx < Q) {
56*f80f4a74SSebastian Grimberg     for (int j = 0; j < Q; j++) {
57*f80f4a74SSebastian Grimberg       dV[j * Q + tx] = rV[0][0][j];
58*f80f4a74SSebastian Grimberg     }
59*f80f4a74SSebastian Grimberg   }
60*f80f4a74SSebastian Grimberg }
61