1*9ba83ac0SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
26c13bbcbSJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
36c13bbcbSJeremy L Thompson //
46c13bbcbSJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
56c13bbcbSJeremy L Thompson //
66c13bbcbSJeremy L Thompson // This file is part of CEED: http://github.com/ceed
76c13bbcbSJeremy L Thompson
86c13bbcbSJeremy L Thompson /// @file
96c13bbcbSJeremy L Thompson /// Internal header for HIP shared memory non-tensor basis
106c13bbcbSJeremy L Thompson #include <ceed/types.h>
116c13bbcbSJeremy L Thompson
126c13bbcbSJeremy L Thompson #include "hip-shared-basis-nontensor-templates.h"
131f6c24feSJeremy L Thompson #include "hip-shared-basis-read-write-templates.h"
146c13bbcbSJeremy L Thompson
156c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------
166c13bbcbSJeremy L Thompson // Interp kernels
176c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)186c13bbcbSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
196c13bbcbSJeremy L Thompson void Interp(const CeedInt num_elem, const CeedScalar *c_B, const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) {
206c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
216c13bbcbSJeremy L Thompson
226c13bbcbSJeremy L Thompson SharedData_Hip data;
236c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
246c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
256c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
266c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
276b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
286c13bbcbSJeremy L Thompson
296c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP];
306c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP];
316c13bbcbSJeremy L Thompson
326c13bbcbSJeremy L Thompson // load interp into shared memory
336c13bbcbSJeremy L Thompson __shared__ CeedScalar s_B[BASIS_P * BASIS_Q];
346c13bbcbSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q>(data, c_B, s_B);
356c13bbcbSJeremy L Thompson __syncthreads();
366c13bbcbSJeremy L Thompson
376c13bbcbSJeremy L Thompson // Apply basis element by element
386c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
396c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, d_U, r_U);
406b92dc4bSJeremy L Thompson InterpNonTensor<BASIS_NUM_COMP, BASIS_P, BASIS_Q, BASIS_T_1D>(data, r_U, s_B, r_V);
416c13bbcbSJeremy L Thompson WriteElementStrided1d<BASIS_NUM_COMP, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, r_V, d_V);
426c13bbcbSJeremy L Thompson }
436c13bbcbSJeremy L Thompson }
446c13bbcbSJeremy L Thompson
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)456c13bbcbSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
466c13bbcbSJeremy L Thompson void InterpTranspose(const CeedInt num_elem, const CeedScalar *c_B, const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) {
476c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
486c13bbcbSJeremy L Thompson
496c13bbcbSJeremy L Thompson SharedData_Hip data;
506c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
516c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
526c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
536c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
546b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
556c13bbcbSJeremy L Thompson
566c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP];
576c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP];
586c13bbcbSJeremy L Thompson
596c13bbcbSJeremy L Thompson // load interp into shared memory
606c13bbcbSJeremy L Thompson __shared__ CeedScalar s_B[BASIS_P * BASIS_Q];
616c13bbcbSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q>(data, c_B, s_B);
626c13bbcbSJeremy L Thompson __syncthreads();
636c13bbcbSJeremy L Thompson
646c13bbcbSJeremy L Thompson // Apply basis element by element
656c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
666c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, d_U, r_U);
676b92dc4bSJeremy L Thompson InterpTransposeNonTensor<BASIS_NUM_COMP, BASIS_P, BASIS_Q, BASIS_T_1D>(data, r_U, s_B, r_V);
686c13bbcbSJeremy L Thompson WriteElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, r_V, d_V);
696c13bbcbSJeremy L Thompson }
706c13bbcbSJeremy L Thompson }
716c13bbcbSJeremy L Thompson
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)726c13bbcbSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
736c13bbcbSJeremy L Thompson void InterpTransposeAdd(const CeedInt num_elem, const CeedScalar *c_B, const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) {
746c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
756c13bbcbSJeremy L Thompson
766c13bbcbSJeremy L Thompson SharedData_Hip data;
776c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
786c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
796c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
806c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
816b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
826c13bbcbSJeremy L Thompson
836c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP];
846c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP];
856c13bbcbSJeremy L Thompson
866c13bbcbSJeremy L Thompson // load interp into shared memory
876c13bbcbSJeremy L Thompson __shared__ CeedScalar s_B[BASIS_P * BASIS_Q];
886c13bbcbSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q>(data, c_B, s_B);
896c13bbcbSJeremy L Thompson __syncthreads();
906c13bbcbSJeremy L Thompson
916c13bbcbSJeremy L Thompson // Apply basis element by element
926c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
936c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, d_U, r_U);
946b92dc4bSJeremy L Thompson InterpTransposeNonTensor<BASIS_NUM_COMP, BASIS_P, BASIS_Q, BASIS_T_1D>(data, r_U, s_B, r_V);
956c13bbcbSJeremy L Thompson SumElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, r_V, d_V);
966c13bbcbSJeremy L Thompson }
976c13bbcbSJeremy L Thompson }
986c13bbcbSJeremy L Thompson
996c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------
1006c13bbcbSJeremy L Thompson // Grad kernels
1016c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)1022d217acfSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
1031f6c24feSJeremy L Thompson void Grad(const CeedInt num_elem, const CeedScalar *c_G, const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) {
1046c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
1056c13bbcbSJeremy L Thompson
1066c13bbcbSJeremy L Thompson SharedData_Hip data;
1076c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
1086c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
1096c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
1106c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
1116b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
1126c13bbcbSJeremy L Thompson
1136c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP];
1146c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP * BASIS_DIM];
1156c13bbcbSJeremy L Thompson
1166c13bbcbSJeremy L Thompson // load grad into shared memory
1172d217acfSJeremy L Thompson __shared__ CeedScalar s_G[BASIS_P * BASIS_Q * BASIS_DIM];
1182d217acfSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q * BASIS_DIM>(data, c_G, s_G);
1196c13bbcbSJeremy L Thompson __syncthreads();
1206c13bbcbSJeremy L Thompson
1216c13bbcbSJeremy L Thompson // Apply basis element by element
1226c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
1236c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, d_U, r_U);
1246b92dc4bSJeremy L Thompson GradNonTensor<BASIS_NUM_COMP, BASIS_DIM, BASIS_P, BASIS_Q, BASIS_T_1D>(data, r_U, s_G, r_V);
1256c13bbcbSJeremy L Thompson WriteElementStrided1d<BASIS_NUM_COMP * BASIS_DIM, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, r_V, d_V);
1266c13bbcbSJeremy L Thompson }
1276c13bbcbSJeremy L Thompson }
1286c13bbcbSJeremy L Thompson
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)1292d217acfSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
1301f6c24feSJeremy L Thompson void GradTranspose(const CeedInt num_elem, const CeedScalar *c_G, const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) {
1316c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
1326c13bbcbSJeremy L Thompson
1336c13bbcbSJeremy L Thompson SharedData_Hip data;
1346c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
1356c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
1366c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
1376c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
1386b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
1396c13bbcbSJeremy L Thompson
1406c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP * BASIS_DIM];
1416c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP];
1426c13bbcbSJeremy L Thompson
1436c13bbcbSJeremy L Thompson // load grad into shared memory
1442d217acfSJeremy L Thompson __shared__ CeedScalar s_G[BASIS_P * BASIS_Q * BASIS_DIM];
1452d217acfSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q * BASIS_DIM>(data, c_G, s_G);
1466c13bbcbSJeremy L Thompson __syncthreads();
1476c13bbcbSJeremy L Thompson
1486c13bbcbSJeremy L Thompson // Apply basis element by element
1496c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
1506c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP * BASIS_DIM, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, d_U, r_U);
1516b92dc4bSJeremy L Thompson GradTransposeNonTensor<BASIS_NUM_COMP, BASIS_DIM, BASIS_P, BASIS_Q, BASIS_T_1D>(data, r_U, s_G, r_V);
1526c13bbcbSJeremy L Thompson WriteElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, r_V, d_V);
1536c13bbcbSJeremy L Thompson }
1546c13bbcbSJeremy L Thompson }
1556c13bbcbSJeremy L Thompson
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)1562d217acfSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
1572d217acfSJeremy L Thompson void GradTransposeAdd(const CeedInt num_elem, const CeedScalar *c_G, const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) {
1586c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
1596c13bbcbSJeremy L Thompson
1606c13bbcbSJeremy L Thompson SharedData_Hip data;
1616c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
1626c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
1636c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
1646c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
1656b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
1666c13bbcbSJeremy L Thompson
1676c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP * BASIS_DIM];
1686c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP];
1696c13bbcbSJeremy L Thompson
1706c13bbcbSJeremy L Thompson // load grad into shared memory
1712d217acfSJeremy L Thompson __shared__ CeedScalar s_G[BASIS_P * BASIS_Q * BASIS_DIM];
1722d217acfSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q * BASIS_DIM>(data, c_G, s_G);
1736c13bbcbSJeremy L Thompson __syncthreads();
1746c13bbcbSJeremy L Thompson
1756c13bbcbSJeremy L Thompson // Apply basis element by element
1766c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
1776c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP * BASIS_DIM, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, d_U, r_U);
1786b92dc4bSJeremy L Thompson GradTransposeNonTensor<BASIS_NUM_COMP, BASIS_DIM, BASIS_P, BASIS_Q, BASIS_T_1D>(data, r_U, s_G, r_V);
1796c13bbcbSJeremy L Thompson SumElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, r_V, d_V);
1806c13bbcbSJeremy L Thompson }
1816c13bbcbSJeremy L Thompson }
1826c13bbcbSJeremy L Thompson
1836c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------
1846c13bbcbSJeremy L Thompson // Weight kernel
1856c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------
__launch_bounds__(BASIS_INTERP_BLOCK_SIZE)1862d217acfSJeremy L Thompson extern "C" __launch_bounds__(BASIS_INTERP_BLOCK_SIZE) __global__
1872d217acfSJeremy L Thompson void Weight(const CeedInt num_elem, const CeedScalar *__restrict__ q_weight, CeedScalar *__restrict__ d_W) {
1886c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[];
1896c13bbcbSJeremy L Thompson
1906c13bbcbSJeremy L Thompson SharedData_Hip data;
1916c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x;
1926c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y;
1936c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z;
1946c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x;
1956b92dc4bSJeremy L Thompson data.slice = slice + data.t_id_z * BASIS_T_1D;
1966c13bbcbSJeremy L Thompson
1976c13bbcbSJeremy L Thompson CeedScalar r_W[1];
1986c13bbcbSJeremy L Thompson
1996c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) {
200343e3094SJeremy L Thompson WeightNonTensor<BASIS_P, BASIS_Q>(data, q_weight, r_W);
2016c13bbcbSJeremy L Thompson WriteElementStrided1d<1, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, r_W, d_W);
2026c13bbcbSJeremy L Thompson }
2036c13bbcbSJeremy L Thompson }
204