16c13bbcbSJeremy L Thompson // Copyright (c) 2017-2024, 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" 13*1f6c24feSJeremy L Thompson #include "hip-shared-basis-read-write-templates.h" 146c13bbcbSJeremy L Thompson 156c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------ 166c13bbcbSJeremy L Thompson // Interp kernels 176c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------ 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; 276c13bbcbSJeremy L Thompson data.slice = slice + data.t_id_z * 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); 406c13bbcbSJeremy L Thompson InterpNonTensor<BASIS_NUM_COMP, BASIS_P, BASIS_Q>(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 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; 546c13bbcbSJeremy L Thompson data.slice = slice + data.t_id_z * 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); 676c13bbcbSJeremy L Thompson InterpTransposeNonTensor<BASIS_NUM_COMP, BASIS_P, BASIS_Q>(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 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; 816c13bbcbSJeremy L Thompson data.slice = slice + data.t_id_z * 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); 946c13bbcbSJeremy L Thompson InterpTransposeNonTensor<BASIS_NUM_COMP, BASIS_P, BASIS_Q>(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 //------------------------------------------------------------------------------ 102*1f6c24feSJeremy L Thompson extern "C" __launch_bounds__(BASIS_GRAD_BLOCK_SIZE) __global__ 103*1f6c24feSJeremy 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; 1116c13bbcbSJeremy L Thompson data.slice = slice + data.t_id_z * 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 1176c13bbcbSJeremy L Thompson __shared__ CeedScalar s_G[BASIS_P * BASIS_Q]; 1186c13bbcbSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q>(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); 1246c13bbcbSJeremy L Thompson GradNonTensor<BASIS_NUM_COMP, BASIS_DIM, BASIS_P, BASIS_Q>(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 1296c13bbcbSJeremy L Thompson extern "C" __launch_bounds__(BASIS_GRAD_BLOCK_SIZE) __global__ 130*1f6c24feSJeremy 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; 1386c13bbcbSJeremy L Thompson data.slice = slice + data.t_id_z * 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 1446c13bbcbSJeremy L Thompson __shared__ CeedScalar s_G[BASIS_P * BASIS_Q]; 1456c13bbcbSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q>(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); 1516c13bbcbSJeremy L Thompson GradTransposeNonTensor<BASIS_NUM_COMP, BASIS_DIM, BASIS_P, BASIS_Q>(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 1566c13bbcbSJeremy L Thompson extern "C" __launch_bounds__(BASIS_GRAD_BLOCK_SIZE) __global__ 1576c13bbcbSJeremy L Thompson void GradTransposeAdd(const CeedInt num_elem, const CeedScalar *c_B, const CeedScalar *c_G, const CeedScalar *__restrict__ d_U, 1586c13bbcbSJeremy L Thompson CeedScalar *__restrict__ d_V) { 1596c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[]; 1606c13bbcbSJeremy L Thompson 1616c13bbcbSJeremy L Thompson SharedData_Hip data; 1626c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x; 1636c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y; 1646c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z; 1656c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x; 1666c13bbcbSJeremy L Thompson data.slice = &slice[data.t_id_z * T_1D]; 1676c13bbcbSJeremy L Thompson 1686c13bbcbSJeremy L Thompson CeedScalar r_U[BASIS_NUM_COMP * BASIS_DIM]; 1696c13bbcbSJeremy L Thompson CeedScalar r_V[BASIS_NUM_COMP]; 1706c13bbcbSJeremy L Thompson 1716c13bbcbSJeremy L Thompson // load grad into shared memory 1726c13bbcbSJeremy L Thompson __shared__ CeedScalar s_G[BASIS_P * BASIS_Q]; 1736c13bbcbSJeremy L Thompson LoadMatrix<BASIS_P, BASIS_Q>(data, c_G, s_G); 1746c13bbcbSJeremy L Thompson __syncthreads(); 1756c13bbcbSJeremy L Thompson 1766c13bbcbSJeremy L Thompson // Apply basis element by element 1776c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) { 1786c13bbcbSJeremy L Thompson ReadElementStrided1d<BASIS_NUM_COMP * BASIS_DIM, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, d_U, r_U); 1796c13bbcbSJeremy L Thompson GradTransposeNonTensor<BASIS_NUM_COMP, BASIS_DIM, BASIS_P, BASIS_Q>(data, r_U, s_G, r_V); 1806c13bbcbSJeremy L Thompson SumElementStrided1d<BASIS_NUM_COMP, BASIS_P>(data, elem, 1, BASIS_P * num_elem, BASIS_P, r_V, d_V); 1816c13bbcbSJeremy L Thompson } 1826c13bbcbSJeremy L Thompson } 1836c13bbcbSJeremy L Thompson 1846c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------ 1856c13bbcbSJeremy L Thompson // Weight kernel 1866c13bbcbSJeremy L Thompson //------------------------------------------------------------------------------ 1876c13bbcbSJeremy L Thompson extern "C" __launch_bounds__(BASIS_WEIGHT_BLOCK_SIZE) __global__ 1886c13bbcbSJeremy L Thompson void Weight(const CeedInt num_elem, const CeedScalar *__restrict__ q_weight_1d, CeedScalar *__restrict__ d_W) { 1896c13bbcbSJeremy L Thompson extern __shared__ CeedScalar slice[]; 1906c13bbcbSJeremy L Thompson 1916c13bbcbSJeremy L Thompson SharedData_Hip data; 1926c13bbcbSJeremy L Thompson data.t_id_x = threadIdx.x; 1936c13bbcbSJeremy L Thompson data.t_id_y = threadIdx.y; 1946c13bbcbSJeremy L Thompson data.t_id_z = threadIdx.z; 1956c13bbcbSJeremy L Thompson data.t_id = threadIdx.x + threadIdx.y * blockDim.x + threadIdx.z * blockDim.y * blockDim.x; 1966c13bbcbSJeremy L Thompson data.slice = slice + data.t_id_z * T_1D; 1976c13bbcbSJeremy L Thompson 1986c13bbcbSJeremy L Thompson CeedScalar r_W[1]; 1996c13bbcbSJeremy L Thompson 2006c13bbcbSJeremy L Thompson for (CeedInt elem = blockIdx.x * blockDim.z + threadIdx.z; elem < num_elem; elem += gridDim.x * blockDim.z) { 2016c13bbcbSJeremy L Thompson WeightNonTensor<BASIS_Q>(data, q_weight, r_W); 2026c13bbcbSJeremy L Thompson WriteElementStrided1d<1, BASIS_Q>(data, elem, 1, BASIS_Q * num_elem, BASIS_Q, r_W, d_W); 2036c13bbcbSJeremy L Thompson } 2046c13bbcbSJeremy L Thompson } 205