1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 // 4 // SPDX-License-Identifier: BSD-2-Clause 5 // 6 // This file is part of CEED: http://github.com/ceed 7 8 #ifndef CEED_CUDA_REF_H 9 #define CEED_CUDA_REF_H 10 11 #include <ceed.h> 12 #include <ceed/backend.h> 13 #include <ceed/jit-source/cuda/cuda-types.h> 14 #include <cublas_v2.h> 15 #include <cuda.h> 16 17 typedef struct { 18 CeedScalar *h_array; 19 CeedScalar *h_array_borrowed; 20 CeedScalar *h_array_owned; 21 CeedScalar *d_array; 22 CeedScalar *d_array_borrowed; 23 CeedScalar *d_array_owned; 24 } CeedVector_Cuda; 25 26 typedef struct { 27 CUmodule module; 28 CUfunction ApplyNoTranspose, ApplyTranspose; 29 CUfunction ApplyUnsignedNoTranspose, ApplyUnsignedTranspose; 30 CUfunction ApplyUnorientedNoTranspose, ApplyUnorientedTranspose; 31 CeedInt num_nodes; 32 const CeedInt *h_offsets; 33 const CeedInt *h_offsets_borrowed; 34 const CeedInt *h_offsets_owned; 35 const CeedInt *d_offsets; 36 const CeedInt *d_offsets_borrowed; 37 const CeedInt *d_offsets_owned; 38 const CeedInt *d_t_offsets; 39 const CeedInt *d_t_indices; 40 const CeedInt *d_l_vec_indices; 41 const bool *h_orients; 42 const bool *h_orients_borrowed; 43 const bool *h_orients_owned; 44 const bool *d_orients; 45 const bool *d_orients_borrowed; 46 const bool *d_orients_owned; 47 const CeedInt8 *h_curl_orients; 48 const CeedInt8 *h_curl_orients_borrowed; 49 const CeedInt8 *h_curl_orients_owned; 50 const CeedInt8 *d_curl_orients; 51 const CeedInt8 *d_curl_orients_borrowed; 52 const CeedInt8 *d_curl_orients_owned; 53 } CeedElemRestriction_Cuda; 54 55 typedef struct { 56 CUmodule module; 57 CUfunction Interp; 58 CUfunction Grad; 59 CUfunction Weight; 60 CeedScalar *d_interp_1d; 61 CeedScalar *d_grad_1d; 62 CeedScalar *d_q_weight_1d; 63 } CeedBasis_Cuda; 64 65 typedef struct { 66 CUmodule module; 67 CUfunction Interp; 68 CUfunction InterpTranspose; 69 CUfunction Deriv; 70 CUfunction DerivTranspose; 71 CUfunction Weight; 72 CeedScalar *d_interp; 73 CeedScalar *d_grad; 74 CeedScalar *d_div; 75 CeedScalar *d_curl; 76 CeedScalar *d_q_weight; 77 } CeedBasisNonTensor_Cuda; 78 79 typedef struct { 80 CUmodule module; 81 const char *qfunction_name; 82 const char *qfunction_source; 83 CUfunction QFunction; 84 Fields_Cuda fields; 85 void *d_c; 86 } CeedQFunction_Cuda; 87 88 typedef struct { 89 void *h_data; 90 void *h_data_borrowed; 91 void *h_data_owned; 92 void *d_data; 93 void *d_data_borrowed; 94 void *d_data_owned; 95 } CeedQFunctionContext_Cuda; 96 97 typedef struct { 98 CUmodule module, module_point_block; 99 CUfunction LinearDiagonal; 100 CUfunction LinearPointBlock; 101 CeedElemRestriction diag_rstr, point_block_diag_rstr; 102 CeedVector elem_diag, point_block_elem_diag; 103 CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 104 CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 105 CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 106 } CeedOperatorDiag_Cuda; 107 108 typedef struct { 109 CUmodule module; 110 CUfunction LinearAssemble; 111 CeedInt block_size_x, block_size_y, elems_per_block; 112 CeedScalar *d_B_in, *d_B_out; 113 } CeedOperatorAssemble_Cuda; 114 115 typedef struct { 116 CeedVector *e_vecs; // E-vectors, inputs followed by outputs 117 CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 118 CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 119 CeedInt num_inputs, num_outputs; 120 CeedInt num_active_in, num_active_out; 121 CeedVector *qf_active_in; 122 CeedOperatorDiag_Cuda *diag; 123 CeedOperatorAssemble_Cuda *asmb; 124 } CeedOperator_Cuda; 125 126 CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle); 127 128 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec); 129 130 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients, 131 const CeedInt8 *curl_orients, CeedElemRestriction r); 132 133 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 134 const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 135 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 136 const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 137 CEED_INTERN int CeedBasisCreateHdiv_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 138 const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 139 CEED_INTERN int CeedBasisCreateHcurl_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 140 const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 141 142 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf); 143 144 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx); 145 146 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op); 147 148 #endif // CEED_CUDA_REF_H 149