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_hip_h 18 #define _ceed_hip_h 19 20 #include <ceed/ceed.h> 21 #include <ceed/backend.h> 22 #include <hip/hip_runtime.h> 23 #include <hipblas.h> 24 #include "../hip/ceed-hip-common.h" 25 26 typedef struct { 27 CeedScalar *h_array; 28 CeedScalar *h_array_borrowed; 29 CeedScalar *h_array_owned; 30 CeedScalar *d_array; 31 CeedScalar *d_array_borrowed; 32 CeedScalar *d_array_owned; 33 } CeedVector_Hip; 34 35 typedef struct { 36 hipModule_t module; 37 hipFunction_t StridedTranspose; 38 hipFunction_t StridedNoTranspose; 39 hipFunction_t OffsetTranspose; 40 hipFunction_t OffsetNoTranspose; 41 CeedInt num_nodes; 42 CeedInt *h_ind; 43 CeedInt *h_ind_allocated; 44 CeedInt *d_ind; 45 CeedInt *d_ind_allocated; 46 CeedInt *d_t_offsets; 47 CeedInt *d_t_indices; 48 CeedInt *d_l_vec_indices; 49 } CeedElemRestriction_Hip; 50 51 typedef struct { 52 hipModule_t module; 53 hipFunction_t Interp; 54 hipFunction_t Grad; 55 hipFunction_t Weight; 56 CeedScalar *d_interp_1d; 57 CeedScalar *d_grad_1d; 58 CeedScalar *d_q_weight_1d; 59 } CeedBasis_Hip; 60 61 typedef struct { 62 hipModule_t module; 63 hipFunction_t Interp; 64 hipFunction_t Grad; 65 hipFunction_t Weight; 66 CeedScalar *d_interp; 67 CeedScalar *d_grad; 68 CeedScalar *d_q_weight; 69 } CeedBasisNonTensor_Hip; 70 71 // We use a struct to avoid having to memCpy the array of pointers 72 // __global__ copies by value the struct. 73 typedef struct { 74 const CeedScalar *inputs[CEED_FIELD_MAX]; 75 CeedScalar *outputs[CEED_FIELD_MAX]; 76 } Fields_Hip; 77 78 typedef struct { 79 hipModule_t module; 80 char *qfunction_name; 81 char *qfunction_source; 82 hipFunction_t QFunction; 83 Fields_Hip fields; 84 void *d_c; 85 } CeedQFunction_Hip; 86 87 typedef struct { 88 void *h_data; 89 void *h_data_borrowed; 90 void *h_data_owned; 91 void *d_data; 92 void *d_data_borrowed; 93 void *d_data_owned; 94 } CeedQFunctionContext_Hip; 95 96 typedef struct { 97 hipModule_t module; 98 hipFunction_t linearDiagonal; 99 hipFunction_t linearPointBlock; 100 CeedBasis basisin, basisout; 101 CeedElemRestriction diagrstr, pbdiagrstr; 102 CeedVector elemdiag, pbelemdiag; 103 CeedInt numemodein, numemodeout, nnodes; 104 CeedEvalMode *h_emodein, *h_emodeout; 105 CeedEvalMode *d_emodein, *d_emodeout; 106 CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout; 107 } CeedOperatorDiag_Hip; 108 109 typedef struct { 110 hipModule_t module; 111 hipFunction_t linearAssemble; 112 CeedInt nelem, nnodes, elemsPerBlock; 113 CeedScalar *d_B_in, *d_B_out; 114 } CeedOperatorAssemble_Hip; 115 116 typedef struct { 117 CeedVector *evecs; // E-vectors, inputs followed by outputs 118 CeedVector *qvecsin; // Input Q-vectors needed to apply operator 119 CeedVector *qvecsout; // Output Q-vectors needed to apply operator 120 CeedInt numein; 121 CeedInt numeout; 122 CeedInt qfnumactivein, qfnumactiveout; 123 CeedVector *qfactivein; 124 CeedOperatorDiag_Hip *diag; 125 CeedOperatorAssemble_Hip *asmb; 126 } CeedOperator_Hip; 127 128 CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle); 129 130 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 131 132 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype, 133 CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r); 134 135 CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype, 136 const CeedCopyMode cmode, const CeedInt *indices, 137 const CeedElemRestriction res); 138 139 CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem, 140 CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v); 141 142 CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q, 143 const CeedVector *const u, const CeedVector *v); 144 145 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d, 146 CeedInt Q1d, 147 const CeedScalar *interp1d, 148 const CeedScalar *grad1d, 149 const CeedScalar *qref1d, 150 const CeedScalar *qweight1d, 151 CeedBasis basis); 152 153 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt, 154 CeedInt, const CeedScalar *, 155 const CeedScalar *, const CeedScalar *, 156 const CeedScalar *, CeedBasis); 157 158 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 159 160 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 161 162 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 163 164 CEED_INTERN int CeedCompositeOperatorCreate_Hip(CeedOperator op); 165 #endif 166