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 StridedNoTranspose; 29 CUfunction StridedTranspose; 30 CUfunction OffsetNoTranspose; 31 CUfunction OffsetTranspose; 32 CUfunction OffsetTransposeDet; 33 CUfunction OrientedNoTranspose; 34 CUfunction OrientedTranspose; 35 CUfunction OrientedTransposeDet; 36 CUfunction CurlOrientedNoTranspose; 37 CUfunction CurlOrientedTranspose; 38 CUfunction CurlOrientedTransposeDet; 39 CUfunction CurlOrientedUnsignedNoTranspose; 40 CUfunction CurlOrientedUnsignedTranspose; 41 CUfunction CurlOrientedUnsignedTransposeDet; 42 CeedInt num_nodes; 43 CeedInt *h_ind; 44 CeedInt *h_ind_allocated; 45 CeedInt *d_ind; 46 CeedInt *d_ind_allocated; 47 CeedInt *d_t_offsets; 48 CeedInt *d_t_indices; 49 CeedInt *d_l_vec_indices; 50 bool *h_orients; 51 bool *h_orients_allocated; 52 bool *d_orients; 53 bool *d_orients_allocated; 54 CeedInt8 *h_curl_orients; 55 CeedInt8 *h_curl_orients_allocated; 56 CeedInt8 *d_curl_orients; 57 CeedInt8 *d_curl_orients_allocated; 58 } CeedElemRestriction_Cuda; 59 60 typedef struct { 61 CUmodule module; 62 CUfunction Interp; 63 CUfunction Grad; 64 CUfunction Weight; 65 CeedScalar *d_interp_1d; 66 CeedScalar *d_grad_1d; 67 CeedScalar *d_q_weight_1d; 68 } CeedBasis_Cuda; 69 70 typedef struct { 71 CUmodule module; 72 CUfunction Interp; 73 CUfunction InterpTranspose; 74 CUfunction Deriv; 75 CUfunction DerivTranspose; 76 CUfunction Weight; 77 CeedScalar *d_interp; 78 CeedScalar *d_grad; 79 CeedScalar *d_div; 80 CeedScalar *d_curl; 81 CeedScalar *d_q_weight; 82 } CeedBasisNonTensor_Cuda; 83 84 typedef struct { 85 CUmodule module; 86 char *qfunction_name; 87 char *qfunction_source; 88 CUfunction QFunction; 89 Fields_Cuda fields; 90 void *d_c; 91 } CeedQFunction_Cuda; 92 93 typedef struct { 94 void *h_data; 95 void *h_data_borrowed; 96 void *h_data_owned; 97 void *d_data; 98 void *d_data_borrowed; 99 void *d_data_owned; 100 } CeedQFunctionContext_Cuda; 101 102 typedef struct { 103 CUmodule module, module_point_block; 104 CUfunction LinearDiagonal; 105 CUfunction LinearPointBlock; 106 CeedElemRestriction diag_rstr, point_block_diag_rstr; 107 CeedVector elem_diag, point_block_elem_diag; 108 CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 109 CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 110 CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 111 } CeedOperatorDiag_Cuda; 112 113 typedef struct { 114 CUmodule module; 115 CUfunction LinearAssemble; 116 CeedInt block_size_x, block_size_y, elems_per_block; 117 CeedScalar *d_B_in, *d_B_out; 118 } CeedOperatorAssemble_Cuda; 119 120 typedef struct { 121 CeedVector *e_vecs; // E-vectors, inputs followed by outputs 122 CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 123 CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 124 CeedInt num_inputs, num_outputs; 125 CeedInt num_active_in, num_active_out; 126 CeedVector *qf_active_in; 127 CeedOperatorDiag_Cuda *diag; 128 CeedOperatorAssemble_Cuda *asmb; 129 } CeedOperator_Cuda; 130 131 CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle); 132 133 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec); 134 135 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients, 136 const CeedInt8 *curl_orients, CeedElemRestriction r); 137 138 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 139 const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 140 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 141 const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 142 CEED_INTERN int CeedBasisCreateHdiv_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 143 const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 144 CEED_INTERN int CeedBasisCreateHcurl_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 145 const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 146 147 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf); 148 149 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx); 150 151 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op); 152 153 #endif // CEED_CUDA_REF_H 154