1 // Copyright (c) 2017-2024, 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 ApplyNoTranspose, ApplyTranspose; 33 hipFunction_t ApplyUnsignedNoTranspose, ApplyUnsignedTranspose; 34 hipFunction_t ApplyUnorientedNoTranspose, ApplyUnorientedTranspose; 35 CeedInt num_nodes; 36 const CeedInt *h_offsets; 37 const CeedInt *h_offsets_borrowed; 38 const CeedInt *h_offsets_owned; 39 const CeedInt *d_offsets; 40 const CeedInt *d_offsets_borrowed; 41 const CeedInt *d_offsets_owned; 42 const CeedInt *d_t_offsets; 43 const CeedInt *d_t_indices; 44 const CeedInt *d_l_vec_indices; 45 const bool *h_orients; 46 const bool *h_orients_borrowed; 47 const bool *h_orients_owned; 48 const bool *d_orients; 49 const bool *d_orients_borrowed; 50 const bool *d_orients_owned; 51 const CeedInt8 *h_curl_orients; 52 const CeedInt8 *h_curl_orients_borrowed; 53 const CeedInt8 *h_curl_orients_owned; 54 const CeedInt8 *d_curl_orients; 55 const CeedInt8 *d_curl_orients_borrowed; 56 const CeedInt8 *d_curl_orients_owned; 57 } CeedElemRestriction_Hip; 58 59 typedef struct { 60 hipModule_t module; 61 hipFunction_t Interp; 62 hipFunction_t Grad; 63 hipFunction_t Weight; 64 CeedScalar *d_interp_1d; 65 CeedScalar *d_grad_1d; 66 CeedScalar *d_q_weight_1d; 67 } CeedBasis_Hip; 68 69 typedef struct { 70 hipModule_t module; 71 hipFunction_t Interp; 72 hipFunction_t InterpTranspose; 73 hipFunction_t Deriv; 74 hipFunction_t DerivTranspose; 75 hipFunction_t Weight; 76 CeedScalar *d_interp; 77 CeedScalar *d_grad; 78 CeedScalar *d_div; 79 CeedScalar *d_curl; 80 CeedScalar *d_q_weight; 81 } CeedBasisNonTensor_Hip; 82 83 typedef struct { 84 hipModule_t module; 85 const char *qfunction_name; 86 const char *qfunction_source; 87 hipFunction_t QFunction; 88 Fields_Hip fields; 89 void *d_c; 90 } CeedQFunction_Hip; 91 92 typedef struct { 93 void *h_data; 94 void *h_data_borrowed; 95 void *h_data_owned; 96 void *d_data; 97 void *d_data_borrowed; 98 void *d_data_owned; 99 } CeedQFunctionContext_Hip; 100 101 typedef struct { 102 hipModule_t module, module_point_block; 103 hipFunction_t LinearDiagonal; 104 hipFunction_t LinearPointBlock; 105 CeedElemRestriction diag_rstr, point_block_diag_rstr; 106 CeedVector elem_diag, point_block_elem_diag; 107 CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 108 CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 109 CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 110 } CeedOperatorDiag_Hip; 111 112 typedef struct { 113 hipModule_t module; 114 hipFunction_t LinearAssemble; 115 CeedInt block_size_x, block_size_y, elems_per_block; 116 CeedScalar *d_B_in, *d_B_out; 117 } CeedOperatorAssemble_Hip; 118 119 typedef struct { 120 CeedVector *e_vecs; // E-vectors, inputs followed by outputs 121 CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 122 CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 123 CeedInt num_inputs, num_outputs; 124 CeedInt num_active_in, num_active_out; 125 CeedVector *qf_active_in; 126 CeedOperatorDiag_Hip *diag; 127 CeedOperatorAssemble_Hip *asmb; 128 } CeedOperator_Hip; 129 130 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle); 131 132 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 133 134 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients, 135 const CeedInt8 *curl_orients, CeedElemRestriction rstr); 136 137 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 138 const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 139 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 140 const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 141 CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 142 const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 143 CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 144 const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 145 146 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 147 148 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 149 150 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 151 152 #endif // CEED_HIP_REF_H 153