1*5aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 2d075f50bSSebastian Grimberg // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3d075f50bSSebastian Grimberg // 4d075f50bSSebastian Grimberg // SPDX-License-Identifier: BSD-2-Clause 5d075f50bSSebastian Grimberg // 6d075f50bSSebastian Grimberg // This file is part of CEED: http://github.com/ceed 7d075f50bSSebastian Grimberg 8d075f50bSSebastian Grimberg /// @file 9d075f50bSSebastian Grimberg /// Internal header for CUDA non-tensor product basis templates 10d075f50bSSebastian Grimberg #ifndef CEED_CUDA_REF_BASIS_NONTENSOR_TEMPLATES_H 11d075f50bSSebastian Grimberg #define CEED_CUDA_REF_BASIS_NONTENSOR_TEMPLATES_H 12d075f50bSSebastian Grimberg 13d075f50bSSebastian Grimberg #include <ceed.h> 14d075f50bSSebastian Grimberg 15d075f50bSSebastian Grimberg //------------------------------------------------------------------------------ 16d075f50bSSebastian Grimberg // Tensor contraction 17d075f50bSSebastian Grimberg //------------------------------------------------------------------------------ 18d075f50bSSebastian Grimberg template <int NUM_COMP, int Q_COMP, int P, int Q> 19d075f50bSSebastian Grimberg inline __device__ void Contract(const CeedInt elem, const CeedInt strides_elem_U, const CeedInt strides_elem_V, const CeedInt strides_comp_U, 20d075f50bSSebastian Grimberg const CeedInt strides_comp_V, const CeedInt strides_q_comp_V, const CeedScalar *__restrict__ d_B, 21d075f50bSSebastian Grimberg const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) { 22d075f50bSSebastian Grimberg const CeedInt t_id = threadIdx.x; 23d075f50bSSebastian Grimberg const CeedScalar *U; 24d075f50bSSebastian Grimberg CeedScalar r_V[Q_COMP]; 25d075f50bSSebastian Grimberg // TODO load B in shared memory if blockDim.z > 1? 26d075f50bSSebastian Grimberg 27d075f50bSSebastian Grimberg for (CeedInt comp = 0; comp < NUM_COMP; comp++) { 28d075f50bSSebastian Grimberg // Run with Q threads 29d075f50bSSebastian Grimberg U = d_U + elem * strides_elem_U + comp * strides_comp_U; 30d075f50bSSebastian Grimberg for (CeedInt d = 0; d < Q_COMP; d++) r_V[d] = 0.0; 31d075f50bSSebastian Grimberg for (CeedInt i = 0; i < P; i++) { 32d075f50bSSebastian Grimberg const CeedScalar val = U[i]; 33d075f50bSSebastian Grimberg 34d075f50bSSebastian Grimberg for (CeedInt d = 0; d < Q_COMP; d++) r_V[d] += d_B[i + t_id * P + d * P * Q] * val; 35d075f50bSSebastian Grimberg } 36d075f50bSSebastian Grimberg for (CeedInt d = 0; d < Q_COMP; d++) { 37d075f50bSSebastian Grimberg d_V[elem * strides_elem_V + comp * strides_comp_V + d * strides_q_comp_V + t_id] = r_V[d]; 38d075f50bSSebastian Grimberg } 39d075f50bSSebastian Grimberg } 40d075f50bSSebastian Grimberg } 41d075f50bSSebastian Grimberg 42d075f50bSSebastian Grimberg //------------------------------------------------------------------------------ 43d075f50bSSebastian Grimberg // Tensor contraction transpose 44d075f50bSSebastian Grimberg //------------------------------------------------------------------------------ 45d075f50bSSebastian Grimberg template <int NUM_COMP, int Q_COMP, int P, int Q> 46d075f50bSSebastian Grimberg inline __device__ void ContractTranspose(const CeedInt elem, const CeedInt strides_elem_U, const CeedInt strides_elem_V, const CeedInt strides_comp_U, 47d075f50bSSebastian Grimberg const CeedInt strides_comp_V, const CeedInt strides_q_comp_U, const CeedScalar *__restrict__ d_B, 48d075f50bSSebastian Grimberg const CeedScalar *__restrict__ d_U, CeedScalar *__restrict__ d_V) { 49d075f50bSSebastian Grimberg const CeedInt t_id = threadIdx.x; 50d075f50bSSebastian Grimberg const CeedScalar *U; 51d075f50bSSebastian Grimberg CeedScalar r_V; 52d075f50bSSebastian Grimberg // TODO load B in shared memory if blockDim.z > 1? 53d075f50bSSebastian Grimberg 54d075f50bSSebastian Grimberg for (CeedInt comp = 0; comp < NUM_COMP; comp++) { 55d075f50bSSebastian Grimberg // Run with P threads 56d075f50bSSebastian Grimberg r_V = 0.0; 57d075f50bSSebastian Grimberg for (CeedInt d = 0; d < Q_COMP; d++) { 58d075f50bSSebastian Grimberg U = d_U + elem * strides_elem_U + comp * strides_comp_U + d * strides_q_comp_U; 59d075f50bSSebastian Grimberg for (CeedInt i = 0; i < Q; i++) r_V += d_B[t_id + i * P + d * P * Q] * U[i]; 60d075f50bSSebastian Grimberg } 61d075f50bSSebastian Grimberg d_V[elem * strides_elem_V + comp * strides_comp_V + t_id] = r_V; 62d075f50bSSebastian Grimberg } 63d075f50bSSebastian Grimberg } 64d075f50bSSebastian Grimberg 65d075f50bSSebastian Grimberg //------------------------------------------------------------------------------ 66d075f50bSSebastian Grimberg 67d075f50bSSebastian Grimberg #endif // CEED_CUDA_REF_BASIS_NONTENSOR_TEMPLATES_H 68