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 } CeedElemRestriction_Hip; 62 63 typedef struct { 64 hipModule_t module; 65 hipFunction_t Interp; 66 hipFunction_t Grad; 67 hipFunction_t Weight; 68 CeedScalar *d_interp_1d; 69 CeedScalar *d_grad_1d; 70 CeedScalar *d_q_weight_1d; 71 } CeedBasis_Hip; 72 73 typedef struct { 74 hipModule_t module; 75 hipFunction_t Interp; 76 hipFunction_t InterpTranspose; 77 hipFunction_t Deriv; 78 hipFunction_t DerivTranspose; 79 hipFunction_t Weight; 80 CeedScalar *d_interp; 81 CeedScalar *d_grad; 82 CeedScalar *d_div; 83 CeedScalar *d_curl; 84 CeedScalar *d_q_weight; 85 } CeedBasisNonTensor_Hip; 86 87 typedef struct { 88 hipModule_t module; 89 const char *qfunction_name; 90 const char *qfunction_source; 91 hipFunction_t QFunction; 92 Fields_Hip fields; 93 void *d_c; 94 } CeedQFunction_Hip; 95 96 typedef struct { 97 void *h_data; 98 void *h_data_borrowed; 99 void *h_data_owned; 100 void *d_data; 101 void *d_data_borrowed; 102 void *d_data_owned; 103 } CeedQFunctionContext_Hip; 104 105 typedef struct { 106 hipModule_t module, module_point_block; 107 hipFunction_t LinearDiagonal; 108 hipFunction_t LinearPointBlock; 109 CeedElemRestriction diag_rstr, point_block_diag_rstr; 110 CeedVector elem_diag, point_block_elem_diag; 111 CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 112 CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 113 CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 114 } CeedOperatorDiag_Hip; 115 116 typedef struct { 117 hipModule_t module; 118 hipFunction_t LinearAssemble; 119 CeedInt block_size_x, block_size_y, elems_per_block; 120 CeedScalar *d_B_in, *d_B_out; 121 } CeedOperatorAssemble_Hip; 122 123 typedef struct { 124 CeedVector *e_vecs; // E-vectors, inputs followed by outputs 125 CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 126 CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 127 CeedInt num_inputs, num_outputs; 128 CeedInt num_active_in, num_active_out; 129 CeedVector *qf_active_in; 130 CeedOperatorDiag_Hip *diag; 131 CeedOperatorAssemble_Hip *asmb; 132 } CeedOperator_Hip; 133 134 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle); 135 136 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 137 138 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients, 139 const CeedInt8 *curl_orients, CeedElemRestriction rstr); 140 141 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 142 const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 143 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 144 const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 145 CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 146 const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 147 CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 148 const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 149 150 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 151 152 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 153 154 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 155