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