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