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 -- 3D 10*f80f4a74SSebastian Grimberg template <typename T, int DIM_, int NCOMP_, int Q_, int iDIM, int iCOMP> 11*f80f4a74SSebastian Grimberg __device__ __inline__ void magma_weight_3d_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_^2 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_ * Q_)) { 20*f80f4a74SSebastian Grimberg // x sTweight[j] for first update 21*f80f4a74SSebastian Grimberg // x sTweight[tx%Q_] for second update 22*f80f4a74SSebastian Grimberg // x sTweight[tx/Q_] for third update 23*f80f4a74SSebastian Grimberg for (int j = 0; j < Q_; j++) { 24*f80f4a74SSebastian Grimberg rV[iDIM][iCOMP][j] = sTweight[j] * sTweight[tx % Q_] * sTweight[tx / Q_]; 25*f80f4a74SSebastian Grimberg } 26*f80f4a74SSebastian Grimberg } 27*f80f4a74SSebastian Grimberg } 28*f80f4a74SSebastian Grimberg 29*f80f4a74SSebastian Grimberg ////////////////////////////////////////////////////////////////////////////////////////// 30*f80f4a74SSebastian Grimberg extern "C" __launch_bounds__(MAGMA_BASIS_BOUNDS(Q *Q, MAGMA_MAXTHREADS_3D)) __global__ 31*f80f4a74SSebastian Grimberg void magma_weight_3d_kernel(const CeedScalar *dqweight1d, CeedScalar *dV, const int v_stride, const int nelem) { 32*f80f4a74SSebastian Grimberg MAGMA_DEVICE_SHARED(CeedScalar, shared_data) 33*f80f4a74SSebastian Grimberg 34*f80f4a74SSebastian Grimberg const int tx = threadIdx.x; 35*f80f4a74SSebastian Grimberg const int ty = threadIdx.y; 36*f80f4a74SSebastian Grimberg const int elem_id = (blockIdx.x * blockDim.y) + ty; 37*f80f4a74SSebastian Grimberg 38*f80f4a74SSebastian Grimberg if (elem_id >= nelem) return; 39*f80f4a74SSebastian Grimberg 40*f80f4a74SSebastian Grimberg CeedScalar rV[1][1][Q]; // allocate with DIM=NCOMP=1, but sizes may differ for a fused operator 41*f80f4a74SSebastian Grimberg // global memory pointers 42*f80f4a74SSebastian Grimberg dV += elem_id * v_stride; 43*f80f4a74SSebastian Grimberg 44*f80f4a74SSebastian Grimberg // shared memory pointers 45*f80f4a74SSebastian Grimberg CeedScalar *sTweight = (CeedScalar *)shared_data; 46*f80f4a74SSebastian Grimberg 47*f80f4a74SSebastian Grimberg // read dqweight_1d 48*f80f4a74SSebastian Grimberg if (tx < Q) { 49*f80f4a74SSebastian Grimberg sTweight[tx] = dqweight1d[tx]; 50*f80f4a74SSebastian Grimberg } 51*f80f4a74SSebastian Grimberg __syncthreads(); 52*f80f4a74SSebastian Grimberg 53*f80f4a74SSebastian Grimberg magma_weight_3d_device<CeedScalar, 1, 1, Q, 0, 0>(sTweight, rV, tx); 54*f80f4a74SSebastian Grimberg 55*f80f4a74SSebastian Grimberg // write V 56*f80f4a74SSebastian Grimberg if (tx < (Q * Q)) { 57*f80f4a74SSebastian Grimberg for (int j = 0; j < Q; j++) { 58*f80f4a74SSebastian Grimberg dV[j * (Q * Q) + tx] = rV[0][0][j]; 59*f80f4a74SSebastian Grimberg } 60*f80f4a74SSebastian Grimberg } 61*f80f4a74SSebastian Grimberg } 62