1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 #ifndef _ceed_cuda_h 18 #define _ceed_cuda_h 19 20 #include <ceed/ceed.h> 21 #include <ceed/backend.h> 22 #include <cuda.h> 23 #include "../cuda/ceed-cuda-common.h" 24 25 typedef struct { 26 CeedScalar *h_array; 27 CeedScalar *h_array_borrowed; 28 CeedScalar *h_array_owned; 29 CeedScalar *d_array; 30 CeedScalar *d_array_borrowed; 31 CeedScalar *d_array_owned; 32 } CeedVector_Cuda; 33 34 typedef struct { 35 CUmodule module; 36 CUfunction StridedTranspose; 37 CUfunction StridedNoTranspose; 38 CUfunction OffsetTranspose; 39 CUfunction OffsetNoTranspose; 40 CeedInt num_nodes; 41 CeedInt *h_ind; 42 CeedInt *h_ind_allocated; 43 CeedInt *d_ind; 44 CeedInt *d_ind_allocated; 45 CeedInt *d_t_offsets; 46 CeedInt *d_t_indices; 47 CeedInt *d_l_vec_indices; 48 } CeedElemRestriction_Cuda; 49 50 typedef struct { 51 CUmodule module; 52 CUfunction Interp; 53 CUfunction Grad; 54 CUfunction Weight; 55 CeedScalar *d_interp_1d; 56 CeedScalar *d_grad_1d; 57 CeedScalar *d_q_weight_1d; 58 } CeedBasis_Cuda; 59 60 typedef struct { 61 CUmodule module; 62 CUfunction Interp; 63 CUfunction Grad; 64 CUfunction Weight; 65 CeedScalar *d_interp; 66 CeedScalar *d_grad; 67 CeedScalar *d_q_weight; 68 } CeedBasisNonTensor_Cuda; 69 70 // We use a struct to avoid having to memCpy the array of pointers 71 // __global__ copies by value the struct. 72 typedef struct { 73 const CeedScalar *inputs[CEED_FIELD_MAX]; 74 CeedScalar *outputs[CEED_FIELD_MAX]; 75 } Fields_Cuda; 76 77 typedef struct { 78 CUmodule module; 79 char *qfunction_name; 80 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; 97 CUfunction linearDiagonal; 98 CUfunction linearPointBlock; 99 CeedBasis basisin, basisout; 100 CeedElemRestriction diagrstr, pbdiagrstr; 101 CeedVector elemdiag, pbelemdiag; 102 CeedInt numemodein, numemodeout, nnodes; 103 CeedEvalMode *h_emodein, *h_emodeout; 104 CeedEvalMode *d_emodein, *d_emodeout; 105 CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout; 106 } CeedOperatorDiag_Cuda; 107 108 typedef struct { 109 CUmodule module; 110 CUfunction linearAssemble; 111 CeedInt nelem, nnodes, elemsPerBlock; 112 CeedScalar *d_B_in, *d_B_out; 113 } CeedOperatorAssemble_Cuda; 114 115 typedef struct { 116 CeedVector *evecs; // E-vectors, inputs followed by outputs 117 CeedVector *qvecsin; // Input Q-vectors needed to apply operator 118 CeedVector *qvecsout; // Output Q-vectors needed to apply operator 119 CeedInt numein; 120 CeedInt numeout; 121 CeedInt qfnumactivein, qfnumactiveout; 122 CeedVector *qfactivein; 123 CeedOperatorDiag_Cuda *diag; 124 CeedOperatorAssemble_Cuda *asmb; 125 } CeedOperator_Cuda; 126 127 CEED_INTERN int CeedCudaGetCublasHandle(Ceed ceed, cublasHandle_t *handle); 128 129 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec); 130 131 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, 132 CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r); 133 134 CEED_INTERN int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType 135 mem_type, 136 const CeedCopyMode copy_mode, const CeedInt *indices, 137 const CeedElemRestriction res); 138 139 CEED_INTERN int CeedBasisApplyElems_Cuda(CeedBasis basis, 140 const CeedInt num_elem, 141 CeedTransposeMode t_mode, CeedEvalMode eval_mode, const CeedVector u, 142 CeedVector v); 143 144 CEED_INTERN int CeedQFunctionApplyElems_Cuda(CeedQFunction qf, const CeedInt Q, 145 const CeedVector *const u, const CeedVector *v); 146 147 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, 148 CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 149 const CeedScalar *qref_1d, const CeedScalar *qweight_1d, CeedBasis basis); 150 151 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology, CeedInt, CeedInt, 152 CeedInt, const CeedScalar *, 153 const CeedScalar *, const CeedScalar *, 154 const CeedScalar *, CeedBasis); 155 156 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf); 157 158 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx); 159 160 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op); 161 162 CEED_INTERN int CeedCompositeOperatorCreate_Cuda(CeedOperator op); 163 #endif 164