1 // Copyright (c) 2017-2026, 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 #pragma once 8 9 #include <ceed.h> 10 #include <ceed/backend.h> 11 #include <ceed/jit-source/hip/hip-types.h> 12 #include <hip/hip_runtime.h> 13 #if (HIP_VERSION >= 50200000) 14 #include <hipblas/hipblas.h> // IWYU pragma: export 15 #else 16 #include <hipblas.h> // IWYU pragma: export 17 #endif 18 19 typedef struct { 20 int has_unified_addressing; 21 CeedScalar *h_array; 22 CeedScalar *h_array_borrowed; 23 CeedScalar *h_array_owned; 24 CeedScalar *d_array; 25 CeedScalar *d_array_borrowed; 26 CeedScalar *d_array_owned; 27 } CeedVector_Hip; 28 29 typedef struct { 30 hipModule_t module; 31 hipFunction_t ApplyNoTranspose, ApplyTranspose; 32 hipFunction_t ApplyUnsignedNoTranspose, ApplyUnsignedTranspose; 33 hipFunction_t ApplyUnorientedNoTranspose, ApplyUnorientedTranspose; 34 CeedInt num_nodes; 35 const CeedInt *h_offsets; 36 const CeedInt *h_offsets_borrowed; 37 const CeedInt *h_offsets_owned; 38 const CeedInt *d_offsets; 39 const CeedInt *d_offsets_borrowed; 40 const CeedInt *d_offsets_owned; 41 const CeedInt *d_t_offsets; 42 const CeedInt *d_t_indices; 43 const CeedInt *d_l_vec_indices; 44 const bool *h_orients; 45 const bool *h_orients_borrowed; 46 const bool *h_orients_owned; 47 const bool *d_orients; 48 const bool *d_orients_borrowed; 49 const bool *d_orients_owned; 50 const CeedInt8 *h_curl_orients; 51 const CeedInt8 *h_curl_orients_borrowed; 52 const CeedInt8 *h_curl_orients_owned; 53 const CeedInt8 *d_curl_orients; 54 const CeedInt8 *d_curl_orients_borrowed; 55 const CeedInt8 *d_curl_orients_owned; 56 const CeedInt *h_offsets_at_points; 57 const CeedInt *h_offsets_at_points_borrowed; 58 const CeedInt *h_offsets_at_points_owned; 59 const CeedInt *d_offsets_at_points; 60 const CeedInt *d_offsets_at_points_borrowed; 61 const CeedInt *d_offsets_at_points_owned; 62 const CeedInt *h_points_per_elem; 63 const CeedInt *h_points_per_elem_borrowed; 64 const CeedInt *h_points_per_elem_owned; 65 const CeedInt *d_points_per_elem; 66 const CeedInt *d_points_per_elem_borrowed; 67 const CeedInt *d_points_per_elem_owned; 68 } CeedElemRestriction_Hip; 69 70 typedef struct { 71 hipModule_t module; 72 hipFunction_t Interp; 73 hipFunction_t Grad; 74 hipFunction_t Weight; 75 hipModule_t moduleAtPoints; 76 CeedInt num_points; 77 hipFunction_t InterpAtPoints; 78 hipFunction_t InterpTransposeAtPoints; 79 hipFunction_t GradAtPoints; 80 hipFunction_t GradTransposeAtPoints; 81 CeedScalar *d_interp_1d; 82 CeedScalar *d_grad_1d; 83 CeedScalar *d_q_weight_1d; 84 CeedScalar *d_chebyshev_interp_1d; 85 CeedInt num_elem_at_points; 86 CeedInt *h_points_per_elem; 87 CeedInt *d_points_per_elem; 88 } CeedBasis_Hip; 89 90 typedef struct { 91 hipModule_t module; 92 hipFunction_t Interp; 93 hipFunction_t InterpTranspose; 94 hipFunction_t Deriv; 95 hipFunction_t DerivTranspose; 96 hipFunction_t Weight; 97 CeedScalar *d_interp; 98 CeedScalar *d_grad; 99 CeedScalar *d_div; 100 CeedScalar *d_curl; 101 CeedScalar *d_q_weight; 102 } CeedBasisNonTensor_Hip; 103 104 typedef struct { 105 hipModule_t module; 106 const char *qfunction_name; 107 hipFunction_t QFunction; 108 Fields_Hip fields; 109 void *d_c; 110 } CeedQFunction_Hip; 111 112 typedef struct { 113 void *h_data; 114 void *h_data_borrowed; 115 void *h_data_owned; 116 void *d_data; 117 void *d_data_borrowed; 118 void *d_data_owned; 119 } CeedQFunctionContext_Hip; 120 121 typedef struct { 122 hipModule_t module, module_point_block; 123 hipFunction_t LinearDiagonal; 124 hipFunction_t LinearPointBlock; 125 CeedElemRestriction diag_rstr, point_block_diag_rstr; 126 CeedVector elem_diag, point_block_elem_diag; 127 CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 128 CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 129 CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 130 } CeedOperatorDiag_Hip; 131 132 typedef struct { 133 hipModule_t module; 134 hipFunction_t LinearAssemble; 135 CeedInt block_size_x, block_size_y, elems_per_block; 136 CeedScalar *d_B_in, *d_B_out; 137 } CeedOperatorAssemble_Hip; 138 139 typedef struct { 140 bool *skip_rstr_in, *skip_rstr_out, *apply_add_basis_out; 141 uint64_t *input_states, points_state; // State tracking for passive inputs 142 CeedVector *e_vecs_in, *e_vecs_out; 143 CeedVector *q_vecs_in, *q_vecs_out; 144 CeedInt num_inputs, num_outputs; 145 CeedInt num_active_in, num_active_out; 146 CeedInt *input_field_order, *output_field_order; 147 CeedSize max_active_e_vec_len; 148 CeedInt max_num_points; 149 CeedInt *num_points; 150 CeedVector *qf_active_in, point_coords_elem; 151 CeedOperatorDiag_Hip *diag; 152 CeedOperatorAssemble_Hip *asmb; 153 } CeedOperator_Hip; 154 155 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle); 156 157 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 158 159 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients, 160 const CeedInt8 *curl_orients, CeedElemRestriction rstr); 161 162 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 163 const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 164 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 165 const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 166 CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 167 const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 168 CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 169 const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 170 171 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 172 173 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 174 175 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 176 CEED_INTERN int CeedOperatorCreateAtPoints_Hip(CeedOperator op); 177