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