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 CeedVector *evecs; // E-vectors, inputs followed by outputs 110 CeedVector *qvecsin; // Input Q-vectors needed to apply operator 111 CeedVector *qvecsout; // Output Q-vectors needed to apply operator 112 CeedInt numein; 113 CeedInt numeout; 114 CeedInt qfnumactivein, qfnumactiveout; 115 CeedVector *qfactivein; 116 CeedOperatorDiag_Cuda *diag; 117 } CeedOperator_Cuda; 118 119 CEED_INTERN int CeedCudaGetCublasHandle(Ceed ceed, cublasHandle_t *handle); 120 121 CEED_INTERN int CeedVectorCreate_Cuda(CeedInt n, CeedVector vec); 122 123 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, 124 CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r); 125 126 CEED_INTERN int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType 127 mem_type, 128 const CeedCopyMode copy_mode, const CeedInt *indices, 129 const CeedElemRestriction res); 130 131 CEED_INTERN int CeedBasisApplyElems_Cuda(CeedBasis basis, 132 const CeedInt num_elem, 133 CeedTransposeMode t_mode, CeedEvalMode eval_mode, const CeedVector u, 134 CeedVector v); 135 136 CEED_INTERN int CeedQFunctionApplyElems_Cuda(CeedQFunction qf, const CeedInt Q, 137 const CeedVector *const u, const CeedVector *v); 138 139 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, 140 CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 141 const CeedScalar *qref_1d, const CeedScalar *qweight_1d, CeedBasis basis); 142 143 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology, CeedInt, CeedInt, 144 CeedInt, const CeedScalar *, 145 const CeedScalar *, const CeedScalar *, 146 const CeedScalar *, CeedBasis); 147 148 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf); 149 150 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx); 151 152 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op); 153 154 CEED_INTERN int CeedCompositeOperatorCreate_Cuda(CeedOperator op); 155 #endif 156