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