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 CeedVector *evecs; // E-vectors, inputs followed by outputs 111 CeedVector *qvecsin; // Input Q-vectors needed to apply operator 112 CeedVector *qvecsout; // Output Q-vectors needed to apply operator 113 CeedInt numein; 114 CeedInt numeout; 115 CeedInt qfnumactivein, qfnumactiveout; 116 CeedVector *qfactivein; 117 CeedOperatorDiag_Hip *diag; 118 } CeedOperator_Hip; 119 120 CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle); 121 122 CEED_INTERN int CeedVectorCreate_Hip(CeedInt n, CeedVector vec); 123 124 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype, 125 CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r); 126 127 CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype, 128 const CeedCopyMode cmode, const CeedInt *indices, 129 const CeedElemRestriction res); 130 131 CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem, 132 CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v); 133 134 CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q, 135 const CeedVector *const u, const CeedVector *v); 136 137 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d, 138 CeedInt Q1d, 139 const CeedScalar *interp1d, 140 const CeedScalar *grad1d, 141 const CeedScalar *qref1d, 142 const CeedScalar *qweight1d, 143 CeedBasis basis); 144 145 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt, 146 CeedInt, const CeedScalar *, 147 const CeedScalar *, const CeedScalar *, 148 const CeedScalar *, CeedBasis); 149 150 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 151 152 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 153 154 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 155 156 CEED_INTERN int CeedCompositeOperatorCreate_Hip(CeedOperator op); 157 #endif 158