15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, 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 7*509d4af6SJeremy L Thompson #pragma once 80d0321e0SJeremy L Thompson 949aac155SJeremy L Thompson #include <ceed.h> 100d0321e0SJeremy L Thompson #include <ceed/backend.h> 1149aac155SJeremy L Thompson #include <ceed/jit-source/cuda/cuda-types.h> 1249aac155SJeremy L Thompson #include <cublas_v2.h> 130d0321e0SJeremy L Thompson #include <cuda.h> 142b730f8bSJeremy L Thompson 150d0321e0SJeremy L Thompson typedef struct { 160d0321e0SJeremy L Thompson CeedScalar *h_array; 170d0321e0SJeremy L Thompson CeedScalar *h_array_borrowed; 180d0321e0SJeremy L Thompson CeedScalar *h_array_owned; 190d0321e0SJeremy L Thompson CeedScalar *d_array; 200d0321e0SJeremy L Thompson CeedScalar *d_array_borrowed; 210d0321e0SJeremy L Thompson CeedScalar *d_array_owned; 220d0321e0SJeremy L Thompson } CeedVector_Cuda; 230d0321e0SJeremy L Thompson 240d0321e0SJeremy L Thompson typedef struct { 250d0321e0SJeremy L Thompson CUmodule module; 26cf8cbdd6SSebastian Grimberg CUfunction ApplyNoTranspose, ApplyTranspose; 27cf8cbdd6SSebastian Grimberg CUfunction ApplyUnsignedNoTranspose, ApplyUnsignedTranspose; 28cf8cbdd6SSebastian Grimberg CUfunction ApplyUnorientedNoTranspose, ApplyUnorientedTranspose; 29437930d1SJeremy L Thompson CeedInt num_nodes; 30f5d1e504SJeremy L Thompson const CeedInt *h_offsets; 31f5d1e504SJeremy L Thompson const CeedInt *h_offsets_borrowed; 32f5d1e504SJeremy L Thompson const CeedInt *h_offsets_owned; 33081aa29dSJeremy L Thompson const CeedInt *d_offsets; 34f5d1e504SJeremy L Thompson const CeedInt *d_offsets_borrowed; 35f5d1e504SJeremy L Thompson const CeedInt *d_offsets_owned; 36081aa29dSJeremy L Thompson const CeedInt *d_t_offsets; 37081aa29dSJeremy L Thompson const CeedInt *d_t_indices; 38081aa29dSJeremy L Thompson const CeedInt *d_l_vec_indices; 39f5d1e504SJeremy L Thompson const bool *h_orients; 40f5d1e504SJeremy L Thompson const bool *h_orients_borrowed; 41f5d1e504SJeremy L Thompson const bool *h_orients_owned; 42f5d1e504SJeremy L Thompson const bool *d_orients; 43f5d1e504SJeremy L Thompson const bool *d_orients_borrowed; 44f5d1e504SJeremy L Thompson const bool *d_orients_owned; 45f5d1e504SJeremy L Thompson const CeedInt8 *h_curl_orients; 46f5d1e504SJeremy L Thompson const CeedInt8 *h_curl_orients_borrowed; 47f5d1e504SJeremy L Thompson const CeedInt8 *h_curl_orients_owned; 48f5d1e504SJeremy L Thompson const CeedInt8 *d_curl_orients; 49f5d1e504SJeremy L Thompson const CeedInt8 *d_curl_orients_borrowed; 50f5d1e504SJeremy L Thompson const CeedInt8 *d_curl_orients_owned; 510d0321e0SJeremy L Thompson } CeedElemRestriction_Cuda; 520d0321e0SJeremy L Thompson 53437930d1SJeremy L Thompson typedef struct { 54437930d1SJeremy L Thompson CUmodule module; 55437930d1SJeremy L Thompson CUfunction Interp; 56437930d1SJeremy L Thompson CUfunction Grad; 57437930d1SJeremy L Thompson CUfunction Weight; 58437930d1SJeremy L Thompson CeedScalar *d_interp_1d; 59437930d1SJeremy L Thompson CeedScalar *d_grad_1d; 60437930d1SJeremy L Thompson CeedScalar *d_q_weight_1d; 61437930d1SJeremy L Thompson } CeedBasis_Cuda; 62437930d1SJeremy L Thompson 63437930d1SJeremy L Thompson typedef struct { 64437930d1SJeremy L Thompson CUmodule module; 65437930d1SJeremy L Thompson CUfunction Interp; 66d075f50bSSebastian Grimberg CUfunction InterpTranspose; 67d075f50bSSebastian Grimberg CUfunction Deriv; 68d075f50bSSebastian Grimberg CUfunction DerivTranspose; 69437930d1SJeremy L Thompson CUfunction Weight; 70437930d1SJeremy L Thompson CeedScalar *d_interp; 71437930d1SJeremy L Thompson CeedScalar *d_grad; 72d075f50bSSebastian Grimberg CeedScalar *d_div; 73d075f50bSSebastian Grimberg CeedScalar *d_curl; 74437930d1SJeremy L Thompson CeedScalar *d_q_weight; 75437930d1SJeremy L Thompson } CeedBasisNonTensor_Cuda; 76437930d1SJeremy L Thompson 770d0321e0SJeremy L Thompson typedef struct { 780d0321e0SJeremy L Thompson CUmodule module; 797d023984SJeremy L Thompson const char *qfunction_name; 80f8d308faSJed Brown const char *qfunction_source; 81437930d1SJeremy L Thompson CUfunction QFunction; 820d0321e0SJeremy L Thompson Fields_Cuda fields; 830d0321e0SJeremy L Thompson void *d_c; 840d0321e0SJeremy L Thompson } CeedQFunction_Cuda; 850d0321e0SJeremy L Thompson 860d0321e0SJeremy L Thompson typedef struct { 870d0321e0SJeremy L Thompson void *h_data; 880d0321e0SJeremy L Thompson void *h_data_borrowed; 890d0321e0SJeremy L Thompson void *h_data_owned; 900d0321e0SJeremy L Thompson void *d_data; 910d0321e0SJeremy L Thompson void *d_data_borrowed; 920d0321e0SJeremy L Thompson void *d_data_owned; 930d0321e0SJeremy L Thompson } CeedQFunctionContext_Cuda; 940d0321e0SJeremy L Thompson 950d0321e0SJeremy L Thompson typedef struct { 96cbfe683aSSebastian Grimberg CUmodule module, module_point_block; 97004e4986SSebastian Grimberg CUfunction LinearDiagonal; 98004e4986SSebastian Grimberg CUfunction LinearPointBlock; 99506b1a0cSSebastian Grimberg CeedElemRestriction diag_rstr, point_block_diag_rstr; 100ca735530SJeremy L Thompson CeedVector elem_diag, point_block_elem_diag; 101004e4986SSebastian Grimberg CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 102004e4986SSebastian Grimberg CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 103004e4986SSebastian Grimberg CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 1040d0321e0SJeremy L Thompson } CeedOperatorDiag_Cuda; 1050d0321e0SJeremy L Thompson 1060d0321e0SJeremy L Thompson typedef struct { 107cc132f9aSnbeams CUmodule module; 108004e4986SSebastian Grimberg CUfunction LinearAssemble; 109004e4986SSebastian Grimberg CeedInt block_size_x, block_size_y, elems_per_block; 110cc132f9aSnbeams CeedScalar *d_B_in, *d_B_out; 111cc132f9aSnbeams } CeedOperatorAssemble_Cuda; 112cc132f9aSnbeams 113cc132f9aSnbeams typedef struct { 114ca735530SJeremy L Thompson CeedVector *e_vecs; // E-vectors, inputs followed by outputs 115ca735530SJeremy L Thompson CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 116ca735530SJeremy L Thompson CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 117ca735530SJeremy L Thompson CeedInt num_inputs, num_outputs; 118ca735530SJeremy L Thompson CeedInt num_active_in, num_active_out; 119ca735530SJeremy L Thompson CeedVector *qf_active_in; 1200d0321e0SJeremy L Thompson CeedOperatorDiag_Cuda *diag; 121cc132f9aSnbeams CeedOperatorAssemble_Cuda *asmb; 1220d0321e0SJeremy L Thompson } CeedOperator_Cuda; 1230d0321e0SJeremy L Thompson 124eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle); 1250d0321e0SJeremy L Thompson 1261f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec); 1270d0321e0SJeremy L Thompson 12858111819SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients, 1290c73c039SSebastian Grimberg const CeedInt8 *curl_orients, CeedElemRestriction r); 1300d0321e0SJeremy L Thompson 1312b730f8bSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 1326574a04fSJeremy L Thompson const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 13351475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 13451475c7cSJeremy L Thompson const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 135d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHdiv_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 136d075f50bSSebastian Grimberg const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 137d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHcurl_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 138d075f50bSSebastian Grimberg const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 1390d0321e0SJeremy L Thompson 1400d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf); 1410d0321e0SJeremy L Thompson 1420d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx); 1430d0321e0SJeremy L Thompson 1440d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op); 145