15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2f80f4a74SSebastian Grimberg // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3f80f4a74SSebastian Grimberg // 4f80f4a74SSebastian Grimberg // SPDX-License-Identifier: BSD-2-Clause 5f80f4a74SSebastian Grimberg // 6f80f4a74SSebastian Grimberg // This file is part of CEED: http://github.com/ceed 7f80f4a74SSebastian Grimberg 83c1e2affSSebastian Grimberg /// @file 93c1e2affSSebastian Grimberg /// Internal header for MAGMA tensor basis interpolation in 1D 103c1e2affSSebastian Grimberg 113c1e2affSSebastian Grimberg #include "magma-common-tensor.h" 123c1e2affSSebastian Grimberg 13f80f4a74SSebastian Grimberg // macros to abstract access of shared memory and reg. file 143c1e2affSSebastian Grimberg #define sT(i, j) sT[(j) * P + (i)] 15f80f4a74SSebastian Grimberg 169e0c01faSSebastian Grimberg //////////////////////////////////////////////////////////////////////////////// 17f80f4a74SSebastian Grimberg // interp basis action (1D) 183c1e2affSSebastian Grimberg template <typename T, int DIM, int NUM_COMP, int P, int Q> 197132caa0SSebastian Grimberg static __device__ __inline__ void magma_interp_1d_device(const T *sT, T *sU[NUM_COMP], T *sV[NUM_COMP], const int tx) { 20f80f4a74SSebastian Grimberg // Assumptions 213c1e2affSSebastian Grimberg // 1. 1D threads of size max(P,Q) 223c1e2affSSebastian Grimberg // 2. sU[i] is 1xP: in shared memory 233c1e2affSSebastian Grimberg // 3. sV[i] is 1xQ: in shared memory 243c1e2affSSebastian Grimberg // 4. P_roduct per component is one row (1xP) times T matrix (PxQ) => one row (1xQ) 25f80f4a74SSebastian Grimberg // 5. Each thread computes one entry in sV[i] 26f80f4a74SSebastian Grimberg // 6. Must sync before and after call 27f80f4a74SSebastian Grimberg // 7. Note that the layout for U and V is different from 2D/3D problem 28f80f4a74SSebastian Grimberg 293c1e2affSSebastian Grimberg if (tx < Q) { 303c1e2affSSebastian Grimberg for (int comp = 0; comp < NUM_COMP; comp++) { 317132caa0SSebastian Grimberg T rv = 0.0; 323c1e2affSSebastian Grimberg for (int i = 0; i < P; i++) { 333c1e2affSSebastian Grimberg rv += sU[comp][i] * sT(i, tx); // sT[tx * P + i]; 34f80f4a74SSebastian Grimberg } 353c1e2affSSebastian Grimberg sV[comp][tx] = rv; 36f80f4a74SSebastian Grimberg } 37f80f4a74SSebastian Grimberg } 38f80f4a74SSebastian Grimberg } 39f80f4a74SSebastian Grimberg 409e0c01faSSebastian Grimberg //////////////////////////////////////////////////////////////////////////////// 413c1e2affSSebastian Grimberg extern "C" __launch_bounds__(MAGMA_BASIS_BOUNDS(BASIS_MAX_P_Q, MAGMA_MAXTHREADS_1D)) __global__ 42f80f4a74SSebastian Grimberg void magma_interpn_1d_kernel(const CeedScalar *dT, const CeedScalar *dU, const int estrdU, const int cstrdU, CeedScalar *dV, const int estrdV, 43f80f4a74SSebastian Grimberg const int cstrdV, const int nelem) { 44f80f4a74SSebastian Grimberg MAGMA_DEVICE_SHARED(CeedScalar, shared_data) 45f80f4a74SSebastian Grimberg 46f80f4a74SSebastian Grimberg const int tx = threadIdx.x; 47f80f4a74SSebastian Grimberg const int ty = threadIdx.y; 48f80f4a74SSebastian Grimberg const int elem_id = (blockIdx.x * blockDim.y) + ty; 49f80f4a74SSebastian Grimberg 50f80f4a74SSebastian Grimberg if (elem_id >= nelem) return; 51f80f4a74SSebastian Grimberg 523c1e2affSSebastian Grimberg CeedScalar *sU[BASIS_NUM_COMP]; 533c1e2affSSebastian Grimberg CeedScalar *sV[BASIS_NUM_COMP]; 54f80f4a74SSebastian Grimberg 55f80f4a74SSebastian Grimberg // shift global memory pointers by elem stride 56f80f4a74SSebastian Grimberg dU += elem_id * estrdU; 57f80f4a74SSebastian Grimberg dV += elem_id * estrdV; 58f80f4a74SSebastian Grimberg 59f80f4a74SSebastian Grimberg // assign shared memory pointers 603c1e2affSSebastian Grimberg CeedScalar *sT = (CeedScalar *)shared_data; 613c1e2affSSebastian Grimberg CeedScalar *sW = sT + BASIS_P * BASIS_Q; 623c1e2affSSebastian Grimberg sU[0] = sW + ty * BASIS_NUM_COMP * (BASIS_P + BASIS_Q); 633c1e2affSSebastian Grimberg sV[0] = sU[0] + (BASIS_NUM_COMP * 1 * BASIS_P); 643c1e2affSSebastian Grimberg for (int comp = 1; comp < BASIS_NUM_COMP; comp++) { 653c1e2affSSebastian Grimberg sU[comp] = sU[comp - 1] + (1 * BASIS_P); 663c1e2affSSebastian Grimberg sV[comp] = sV[comp - 1] + (1 * BASIS_Q); 67f80f4a74SSebastian Grimberg } 68f80f4a74SSebastian Grimberg 69f80f4a74SSebastian Grimberg // read T 70f80f4a74SSebastian Grimberg if (ty == 0) { 719e0c01faSSebastian Grimberg read_T_notrans_gm2sm<BASIS_P, BASIS_Q>(tx, dT, sT); 72f80f4a74SSebastian Grimberg } 73f80f4a74SSebastian Grimberg 74f80f4a74SSebastian Grimberg // read U 753c1e2affSSebastian Grimberg read_1d<CeedScalar, BASIS_P, BASIS_NUM_COMP>(dU, cstrdU, sU, tx); 76f80f4a74SSebastian Grimberg 77f80f4a74SSebastian Grimberg __syncthreads(); 787132caa0SSebastian Grimberg magma_interp_1d_device<CeedScalar, BASIS_DIM, BASIS_NUM_COMP, BASIS_P, BASIS_Q>(sT, sU, sV, tx); 79f80f4a74SSebastian Grimberg __syncthreads(); 80f80f4a74SSebastian Grimberg 81f80f4a74SSebastian Grimberg // write V 823c1e2affSSebastian Grimberg write_1d<CeedScalar, BASIS_Q, BASIS_NUM_COMP>(sV, dV, cstrdV, tx); 83f80f4a74SSebastian Grimberg } 84f80f4a74SSebastian Grimberg 859e0c01faSSebastian Grimberg //////////////////////////////////////////////////////////////////////////////// 863c1e2affSSebastian Grimberg extern "C" __launch_bounds__(MAGMA_BASIS_BOUNDS(BASIS_MAX_P_Q, MAGMA_MAXTHREADS_1D)) __global__ 87f80f4a74SSebastian Grimberg void magma_interpt_1d_kernel(const CeedScalar *dT, const CeedScalar *dU, const int estrdU, const int cstrdU, CeedScalar *dV, const int estrdV, 88f80f4a74SSebastian Grimberg const int cstrdV, const int nelem) { 89f80f4a74SSebastian Grimberg MAGMA_DEVICE_SHARED(CeedScalar, shared_data) 90f80f4a74SSebastian Grimberg 91f80f4a74SSebastian Grimberg const int tx = threadIdx.x; 92f80f4a74SSebastian Grimberg const int ty = threadIdx.y; 93f80f4a74SSebastian Grimberg const int elem_id = (blockIdx.x * blockDim.y) + ty; 94f80f4a74SSebastian Grimberg 95f80f4a74SSebastian Grimberg if (elem_id >= nelem) return; 96f80f4a74SSebastian Grimberg 973c1e2affSSebastian Grimberg CeedScalar *sU[BASIS_NUM_COMP]; 983c1e2affSSebastian Grimberg CeedScalar *sV[BASIS_NUM_COMP]; 99f80f4a74SSebastian Grimberg 100f80f4a74SSebastian Grimberg // shift global memory pointers by elem stride 101f80f4a74SSebastian Grimberg dU += elem_id * estrdU; 102f80f4a74SSebastian Grimberg dV += elem_id * estrdV; 103f80f4a74SSebastian Grimberg 104f80f4a74SSebastian Grimberg // assign shared memory pointers 1053c1e2affSSebastian Grimberg CeedScalar *sT = (CeedScalar *)shared_data; 1063c1e2affSSebastian Grimberg CeedScalar *sW = sT + BASIS_Q * BASIS_P; 1073c1e2affSSebastian Grimberg sU[0] = sW + ty * BASIS_NUM_COMP * (BASIS_Q + BASIS_P); 1083c1e2affSSebastian Grimberg sV[0] = sU[0] + (BASIS_NUM_COMP * 1 * BASIS_Q); 1093c1e2affSSebastian Grimberg for (int comp = 1; comp < BASIS_NUM_COMP; comp++) { 1103c1e2affSSebastian Grimberg sU[comp] = sU[comp - 1] + (1 * BASIS_Q); 1113c1e2affSSebastian Grimberg sV[comp] = sV[comp - 1] + (1 * BASIS_P); 112f80f4a74SSebastian Grimberg } 113f80f4a74SSebastian Grimberg 114f80f4a74SSebastian Grimberg // read T 115f80f4a74SSebastian Grimberg if (ty == 0) { 1169e0c01faSSebastian Grimberg read_T_trans_gm2sm<BASIS_Q, BASIS_P>(tx, dT, sT); 117f80f4a74SSebastian Grimberg } 118f80f4a74SSebastian Grimberg 119f80f4a74SSebastian Grimberg // read U 1203c1e2affSSebastian Grimberg read_1d<CeedScalar, BASIS_Q, BASIS_NUM_COMP>(dU, cstrdU, sU, tx); 121f80f4a74SSebastian Grimberg 122f80f4a74SSebastian Grimberg __syncthreads(); 1237132caa0SSebastian Grimberg magma_interp_1d_device<CeedScalar, BASIS_DIM, BASIS_NUM_COMP, BASIS_Q, BASIS_P>(sT, sU, sV, tx); 124f80f4a74SSebastian Grimberg __syncthreads(); 125f80f4a74SSebastian Grimberg 126f80f4a74SSebastian Grimberg // write V 1273c1e2affSSebastian Grimberg write_1d<CeedScalar, BASIS_P, BASIS_NUM_COMP>(sV, dV, cstrdV, tx); 128f80f4a74SSebastian Grimberg } 129*db2becc9SJeremy L Thompson 130*db2becc9SJeremy L Thompson //////////////////////////////////////////////////////////////////////////////// 131*db2becc9SJeremy L Thompson extern "C" __launch_bounds__(MAGMA_BASIS_BOUNDS(BASIS_MAX_P_Q, MAGMA_MAXTHREADS_1D)) __global__ 132*db2becc9SJeremy L Thompson void magma_interpta_1d_kernel(const CeedScalar *dT, const CeedScalar *dU, const int estrdU, const int cstrdU, CeedScalar *dV, const int estrdV, 133*db2becc9SJeremy L Thompson const int cstrdV, const int nelem) { 134*db2becc9SJeremy L Thompson MAGMA_DEVICE_SHARED(CeedScalar, shared_data) 135*db2becc9SJeremy L Thompson 136*db2becc9SJeremy L Thompson const int tx = threadIdx.x; 137*db2becc9SJeremy L Thompson const int ty = threadIdx.y; 138*db2becc9SJeremy L Thompson const int elem_id = (blockIdx.x * blockDim.y) + ty; 139*db2becc9SJeremy L Thompson 140*db2becc9SJeremy L Thompson if (elem_id >= nelem) return; 141*db2becc9SJeremy L Thompson 142*db2becc9SJeremy L Thompson CeedScalar *sU[BASIS_NUM_COMP]; 143*db2becc9SJeremy L Thompson CeedScalar *sV[BASIS_NUM_COMP]; 144*db2becc9SJeremy L Thompson 145*db2becc9SJeremy L Thompson // shift global memory pointers by elem stride 146*db2becc9SJeremy L Thompson dU += elem_id * estrdU; 147*db2becc9SJeremy L Thompson dV += elem_id * estrdV; 148*db2becc9SJeremy L Thompson 149*db2becc9SJeremy L Thompson // assign shared memory pointers 150*db2becc9SJeremy L Thompson CeedScalar *sT = (CeedScalar *)shared_data; 151*db2becc9SJeremy L Thompson CeedScalar *sW = sT + BASIS_Q * BASIS_P; 152*db2becc9SJeremy L Thompson sU[0] = sW + ty * BASIS_NUM_COMP * (BASIS_Q + BASIS_P); 153*db2becc9SJeremy L Thompson sV[0] = sU[0] + (BASIS_NUM_COMP * 1 * BASIS_Q); 154*db2becc9SJeremy L Thompson for (int comp = 1; comp < BASIS_NUM_COMP; comp++) { 155*db2becc9SJeremy L Thompson sU[comp] = sU[comp - 1] + (1 * BASIS_Q); 156*db2becc9SJeremy L Thompson sV[comp] = sV[comp - 1] + (1 * BASIS_P); 157*db2becc9SJeremy L Thompson } 158*db2becc9SJeremy L Thompson 159*db2becc9SJeremy L Thompson // read T 160*db2becc9SJeremy L Thompson if (ty == 0) { 161*db2becc9SJeremy L Thompson read_T_trans_gm2sm<BASIS_Q, BASIS_P>(tx, dT, sT); 162*db2becc9SJeremy L Thompson } 163*db2becc9SJeremy L Thompson 164*db2becc9SJeremy L Thompson // read U 165*db2becc9SJeremy L Thompson read_1d<CeedScalar, BASIS_Q, BASIS_NUM_COMP>(dU, cstrdU, sU, tx); 166*db2becc9SJeremy L Thompson 167*db2becc9SJeremy L Thompson __syncthreads(); 168*db2becc9SJeremy L Thompson magma_interp_1d_device<CeedScalar, BASIS_DIM, BASIS_NUM_COMP, BASIS_Q, BASIS_P>(sT, sU, sV, tx); 169*db2becc9SJeremy L Thompson __syncthreads(); 170*db2becc9SJeremy L Thompson 171*db2becc9SJeremy L Thompson // sum into V 172*db2becc9SJeremy L Thompson sum_1d<CeedScalar, BASIS_P, BASIS_NUM_COMP>(sV, dV, cstrdV, tx); 173*db2becc9SJeremy L Thompson } 174