13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 30d0321e0SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 50d0321e0SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 70d0321e0SJeremy L Thompson 894b7b29bSJeremy L Thompson #ifndef CEED_CUDA_REF_H 994b7b29bSJeremy L Thompson #define CEED_CUDA_REF_H 100d0321e0SJeremy L Thompson 1149aac155SJeremy L Thompson #include <ceed.h> 120d0321e0SJeremy L Thompson #include <ceed/backend.h> 1349aac155SJeremy L Thompson #include <ceed/jit-source/cuda/cuda-types.h> 1449aac155SJeremy L Thompson #include <cublas_v2.h> 150d0321e0SJeremy L Thompson #include <cuda.h> 162b730f8bSJeremy L Thompson 170d0321e0SJeremy L Thompson typedef struct { 180d0321e0SJeremy L Thompson CeedScalar *h_array; 190d0321e0SJeremy L Thompson CeedScalar *h_array_borrowed; 200d0321e0SJeremy L Thompson CeedScalar *h_array_owned; 210d0321e0SJeremy L Thompson CeedScalar *d_array; 220d0321e0SJeremy L Thompson CeedScalar *d_array_borrowed; 230d0321e0SJeremy L Thompson CeedScalar *d_array_owned; 240d0321e0SJeremy L Thompson } CeedVector_Cuda; 250d0321e0SJeremy L Thompson 260d0321e0SJeremy L Thompson typedef struct { 270d0321e0SJeremy L Thompson CUmodule module; 28*cf8cbdd6SSebastian Grimberg CUfunction ApplyNoTranspose, ApplyTranspose; 29*cf8cbdd6SSebastian Grimberg CUfunction ApplyUnsignedNoTranspose, ApplyUnsignedTranspose; 30*cf8cbdd6SSebastian Grimberg CUfunction ApplyUnorientedNoTranspose, ApplyUnorientedTranspose; 31437930d1SJeremy L Thompson CeedInt num_nodes; 320d0321e0SJeremy L Thompson CeedInt *h_ind; 330d0321e0SJeremy L Thompson CeedInt *h_ind_allocated; 340d0321e0SJeremy L Thompson CeedInt *d_ind; 350d0321e0SJeremy L Thompson CeedInt *d_ind_allocated; 36437930d1SJeremy L Thompson CeedInt *d_t_offsets; 37437930d1SJeremy L Thompson CeedInt *d_t_indices; 38437930d1SJeremy L Thompson CeedInt *d_l_vec_indices; 39dce49693SSebastian Grimberg bool *h_orients; 40dce49693SSebastian Grimberg bool *h_orients_allocated; 41dce49693SSebastian Grimberg bool *d_orients; 42dce49693SSebastian Grimberg bool *d_orients_allocated; 43dce49693SSebastian Grimberg CeedInt8 *h_curl_orients; 44dce49693SSebastian Grimberg CeedInt8 *h_curl_orients_allocated; 45dce49693SSebastian Grimberg CeedInt8 *d_curl_orients; 46dce49693SSebastian Grimberg CeedInt8 *d_curl_orients_allocated; 470d0321e0SJeremy L Thompson } CeedElemRestriction_Cuda; 480d0321e0SJeremy L Thompson 49437930d1SJeremy L Thompson typedef struct { 50437930d1SJeremy L Thompson CUmodule module; 51437930d1SJeremy L Thompson CUfunction Interp; 52437930d1SJeremy L Thompson CUfunction Grad; 53437930d1SJeremy L Thompson CUfunction Weight; 54437930d1SJeremy L Thompson CeedScalar *d_interp_1d; 55437930d1SJeremy L Thompson CeedScalar *d_grad_1d; 56437930d1SJeremy L Thompson CeedScalar *d_q_weight_1d; 57437930d1SJeremy L Thompson } CeedBasis_Cuda; 58437930d1SJeremy L Thompson 59437930d1SJeremy L Thompson typedef struct { 60437930d1SJeremy L Thompson CUmodule module; 61437930d1SJeremy L Thompson CUfunction Interp; 62d075f50bSSebastian Grimberg CUfunction InterpTranspose; 63d075f50bSSebastian Grimberg CUfunction Deriv; 64d075f50bSSebastian Grimberg CUfunction DerivTranspose; 65437930d1SJeremy L Thompson CUfunction Weight; 66437930d1SJeremy L Thompson CeedScalar *d_interp; 67437930d1SJeremy L Thompson CeedScalar *d_grad; 68d075f50bSSebastian Grimberg CeedScalar *d_div; 69d075f50bSSebastian Grimberg CeedScalar *d_curl; 70437930d1SJeremy L Thompson CeedScalar *d_q_weight; 71437930d1SJeremy L Thompson } CeedBasisNonTensor_Cuda; 72437930d1SJeremy L Thompson 730d0321e0SJeremy L Thompson typedef struct { 740d0321e0SJeremy L Thompson CUmodule module; 75437930d1SJeremy L Thompson char *qfunction_name; 76437930d1SJeremy L Thompson char *qfunction_source; 77437930d1SJeremy L Thompson CUfunction QFunction; 780d0321e0SJeremy L Thompson Fields_Cuda fields; 790d0321e0SJeremy L Thompson void *d_c; 800d0321e0SJeremy L Thompson } CeedQFunction_Cuda; 810d0321e0SJeremy L Thompson 820d0321e0SJeremy L Thompson typedef struct { 830d0321e0SJeremy L Thompson void *h_data; 840d0321e0SJeremy L Thompson void *h_data_borrowed; 850d0321e0SJeremy L Thompson void *h_data_owned; 860d0321e0SJeremy L Thompson void *d_data; 870d0321e0SJeremy L Thompson void *d_data_borrowed; 880d0321e0SJeremy L Thompson void *d_data_owned; 890d0321e0SJeremy L Thompson } CeedQFunctionContext_Cuda; 900d0321e0SJeremy L Thompson 910d0321e0SJeremy L Thompson typedef struct { 92cbfe683aSSebastian Grimberg CUmodule module, module_point_block; 93004e4986SSebastian Grimberg CUfunction LinearDiagonal; 94004e4986SSebastian Grimberg CUfunction LinearPointBlock; 95506b1a0cSSebastian Grimberg CeedElemRestriction diag_rstr, point_block_diag_rstr; 96ca735530SJeremy L Thompson CeedVector elem_diag, point_block_elem_diag; 97004e4986SSebastian Grimberg CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 98004e4986SSebastian Grimberg CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 99004e4986SSebastian Grimberg CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 1000d0321e0SJeremy L Thompson } CeedOperatorDiag_Cuda; 1010d0321e0SJeremy L Thompson 1020d0321e0SJeremy L Thompson typedef struct { 103cc132f9aSnbeams CUmodule module; 104004e4986SSebastian Grimberg CUfunction LinearAssemble; 105004e4986SSebastian Grimberg CeedInt block_size_x, block_size_y, elems_per_block; 106cc132f9aSnbeams CeedScalar *d_B_in, *d_B_out; 107cc132f9aSnbeams } CeedOperatorAssemble_Cuda; 108cc132f9aSnbeams 109cc132f9aSnbeams typedef struct { 110ca735530SJeremy L Thompson CeedVector *e_vecs; // E-vectors, inputs followed by outputs 111ca735530SJeremy L Thompson CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 112ca735530SJeremy L Thompson CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 113ca735530SJeremy L Thompson CeedInt num_inputs, num_outputs; 114ca735530SJeremy L Thompson CeedInt num_active_in, num_active_out; 115ca735530SJeremy L Thompson CeedVector *qf_active_in; 1160d0321e0SJeremy L Thompson CeedOperatorDiag_Cuda *diag; 117cc132f9aSnbeams CeedOperatorAssemble_Cuda *asmb; 1180d0321e0SJeremy L Thompson } CeedOperator_Cuda; 1190d0321e0SJeremy L Thompson 120eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle); 1210d0321e0SJeremy L Thompson 1221f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec); 1230d0321e0SJeremy L Thompson 1240305e208SSebastian Grimberg CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients, 1250c73c039SSebastian Grimberg const CeedInt8 *curl_orients, CeedElemRestriction r); 1260d0321e0SJeremy L Thompson 1272b730f8bSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 1286574a04fSJeremy L Thompson const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 12951475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 13051475c7cSJeremy L Thompson const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 131d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHdiv_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 132d075f50bSSebastian Grimberg const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 133d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHcurl_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 134d075f50bSSebastian Grimberg const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 1350d0321e0SJeremy L Thompson 1360d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf); 1370d0321e0SJeremy L Thompson 1380d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx); 1390d0321e0SJeremy L Thompson 1400d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op); 1410d0321e0SJeremy L Thompson 14294b7b29bSJeremy L Thompson #endif // CEED_CUDA_REF_H 143