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 StridedNoTranspose; 33 hipFunction_t StridedTranspose; 34 hipFunction_t OffsetNoTranspose; 35 hipFunction_t OffsetTranspose; 36 hipFunction_t OffsetTransposeDet; 37 hipFunction_t OrientedNoTranspose; 38 hipFunction_t OrientedTranspose; 39 hipFunction_t CurlOrientedNoTranspose; 40 hipFunction_t CurlOrientedTranspose; 41 hipFunction_t CurlOrientedUnsignedNoTranspose; 42 hipFunction_t CurlOrientedUnsignedTranspose; 43 CeedInt num_nodes; 44 CeedInt *h_ind; 45 CeedInt *h_ind_allocated; 46 CeedInt *d_ind; 47 CeedInt *d_ind_allocated; 48 CeedInt *d_t_offsets; 49 CeedInt *d_t_indices; 50 CeedInt *d_l_vec_indices; 51 bool *h_orients; 52 bool *h_orients_allocated; 53 bool *d_orients; 54 bool *d_orients_allocated; 55 CeedInt8 *h_curl_orients; 56 CeedInt8 *h_curl_orients_allocated; 57 CeedInt8 *d_curl_orients; 58 CeedInt8 *d_curl_orients_allocated; 59 } CeedElemRestriction_Hip; 60 61 typedef struct { 62 hipModule_t module; 63 hipFunction_t Interp; 64 hipFunction_t Grad; 65 hipFunction_t Weight; 66 CeedScalar *d_interp_1d; 67 CeedScalar *d_grad_1d; 68 CeedScalar *d_q_weight_1d; 69 } CeedBasis_Hip; 70 71 typedef struct { 72 hipModule_t module; 73 hipFunction_t Interp; 74 hipFunction_t InterpTranspose; 75 hipFunction_t Deriv; 76 hipFunction_t DerivTranspose; 77 hipFunction_t Weight; 78 CeedScalar *d_interp; 79 CeedScalar *d_grad; 80 CeedScalar *d_div; 81 CeedScalar *d_curl; 82 CeedScalar *d_q_weight; 83 } CeedBasisNonTensor_Hip; 84 85 typedef struct { 86 hipModule_t module; 87 char *qfunction_name; 88 char *qfunction_source; 89 hipFunction_t QFunction; 90 Fields_Hip fields; 91 void *d_c; 92 } CeedQFunction_Hip; 93 94 typedef struct { 95 void *h_data; 96 void *h_data_borrowed; 97 void *h_data_owned; 98 void *d_data; 99 void *d_data_borrowed; 100 void *d_data_owned; 101 } CeedQFunctionContext_Hip; 102 103 typedef struct { 104 hipModule_t module; 105 hipFunction_t linearDiagonal; 106 hipFunction_t linearPointBlock; 107 CeedBasis basis_in, basis_out; 108 CeedElemRestriction diag_rstr, point_block_diag_rstr; 109 CeedVector elem_diag, point_block_elem_diag; 110 CeedInt num_e_mode_in, num_e_mode_out, num_modes; 111 CeedEvalMode *h_e_mode_in, *h_e_mode_out; 112 CeedEvalMode *d_e_mode_in, *d_e_mode_out; 113 CeedScalar *d_identity, *d_interp_in, *d_interp_out, *d_grad_in, *d_grad_out; 114 } CeedOperatorDiag_Hip; 115 116 typedef struct { 117 hipModule_t module; 118 hipFunction_t linearAssemble; 119 CeedInt num_elem, block_size_x, block_size_y, elem_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 *indices, const bool *orients, 139 const CeedInt8 *curl_orients, CeedElemRestriction r); 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 156 #endif // CEED_HIP_REF_H 157