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_REF_H 9 #define CEED_HIP_REF_H 10 11 #include <ceed.h> 12 #include <ceed/backend.h> 13 #include <ceed/jit-source/hip/hip-types.h> 14 #include <hip/hip_runtime.h> 15 #if (HIP_VERSION >= 50200000) 16 #include <hipblas/hipblas.h> // IWYU pragma: export 17 #else 18 #include <hipblas.h> // IWYU pragma: export 19 #endif 20 21 typedef struct { 22 CeedScalar *h_array; 23 CeedScalar *h_array_borrowed; 24 CeedScalar *h_array_owned; 25 CeedScalar *d_array; 26 CeedScalar *d_array_borrowed; 27 CeedScalar *d_array_owned; 28 } CeedVector_Hip; 29 30 typedef struct { 31 hipModule_t module; 32 hipFunction_t StridedNoTranspose; 33 hipFunction_t StridedTranspose; 34 hipFunction_t OffsetNoTranspose; 35 hipFunction_t OffsetTranspose; 36 hipFunction_t OffsetTransposeDet; 37 CeedInt num_nodes; 38 CeedInt *h_ind; 39 CeedInt *h_ind_allocated; 40 CeedInt *d_ind; 41 CeedInt *d_ind_allocated; 42 CeedInt *d_t_offsets; 43 CeedInt *d_t_indices; 44 CeedInt *d_l_vec_indices; 45 } CeedElemRestriction_Hip; 46 47 typedef struct { 48 hipModule_t module; 49 hipFunction_t Interp; 50 hipFunction_t Grad; 51 hipFunction_t Weight; 52 CeedScalar *d_interp_1d; 53 CeedScalar *d_grad_1d; 54 CeedScalar *d_q_weight_1d; 55 } CeedBasis_Hip; 56 57 typedef struct { 58 hipModule_t module; 59 hipFunction_t Interp; 60 hipFunction_t Grad; 61 hipFunction_t Weight; 62 CeedScalar *d_interp; 63 CeedScalar *d_grad; 64 CeedScalar *d_q_weight; 65 } CeedBasisNonTensor_Hip; 66 67 typedef struct { 68 hipModule_t module; 69 char *qfunction_name; 70 char *qfunction_source; 71 hipFunction_t QFunction; 72 Fields_Hip fields; 73 void *d_c; 74 } CeedQFunction_Hip; 75 76 typedef struct { 77 void *h_data; 78 void *h_data_borrowed; 79 void *h_data_owned; 80 void *d_data; 81 void *d_data_borrowed; 82 void *d_data_owned; 83 } CeedQFunctionContext_Hip; 84 85 typedef struct { 86 hipModule_t module; 87 hipFunction_t linearDiagonal; 88 hipFunction_t linearPointBlock; 89 CeedBasis basisin, basisout; 90 CeedElemRestriction diagrstr, pbdiagrstr; 91 CeedVector elemdiag, pbelemdiag; 92 CeedInt numemodein, numemodeout, nnodes; 93 CeedEvalMode *h_emodein, *h_emodeout; 94 CeedEvalMode *d_emodein, *d_emodeout; 95 CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout; 96 } CeedOperatorDiag_Hip; 97 98 typedef struct { 99 hipModule_t module; 100 hipFunction_t linearAssemble; 101 CeedInt nelem, block_size_x, block_size_y, elemsPerBlock; 102 CeedScalar *d_B_in, *d_B_out; 103 } CeedOperatorAssemble_Hip; 104 105 typedef struct { 106 CeedVector *evecs; // E-vectors, inputs followed by outputs 107 CeedVector *qvecsin; // Input Q-vectors needed to apply operator 108 CeedVector *qvecsout; // Output Q-vectors needed to apply operator 109 CeedInt numein; 110 CeedInt numeout; 111 CeedInt qfnumactivein, qfnumactiveout; 112 CeedVector *qfactivein; 113 CeedOperatorDiag_Hip *diag; 114 CeedOperatorAssemble_Hip *asmb; 115 } CeedOperator_Hip; 116 117 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle); 118 119 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 120 121 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients, 122 const CeedInt8 *curl_orients, CeedElemRestriction r); 123 124 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 125 const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 126 127 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 128 const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 129 130 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 131 132 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 133 134 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 135 136 #endif // CEED_HIP_REF_H 137