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