15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 30d0321e0SJeremy L Thompson // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 50d0321e0SJeremy L Thompson // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7509d4af6SJeremy L Thompson #pragma once 80d0321e0SJeremy L Thompson 949aac155SJeremy L Thompson #include <ceed.h> 100d0321e0SJeremy L Thompson #include <ceed/backend.h> 1149aac155SJeremy L Thompson #include <ceed/jit-source/hip/hip-types.h> 120d0321e0SJeremy L Thompson #include <hip/hip_runtime.h> 1305c335cbSnbeams #if (HIP_VERSION >= 50200000) 1405c335cbSnbeams #include <hipblas/hipblas.h> // IWYU pragma: export 1505c335cbSnbeams #else 1605c335cbSnbeams #include <hipblas.h> // IWYU pragma: export 1705c335cbSnbeams #endif 1805c335cbSnbeams 190d0321e0SJeremy L Thompson typedef struct { 200d0321e0SJeremy L Thompson CeedScalar *h_array; 210d0321e0SJeremy L Thompson CeedScalar *h_array_borrowed; 220d0321e0SJeremy L Thompson CeedScalar *h_array_owned; 230d0321e0SJeremy L Thompson CeedScalar *d_array; 240d0321e0SJeremy L Thompson CeedScalar *d_array_borrowed; 250d0321e0SJeremy L Thompson CeedScalar *d_array_owned; 260d0321e0SJeremy L Thompson } CeedVector_Hip; 270d0321e0SJeremy L Thompson 280d0321e0SJeremy L Thompson typedef struct { 290d0321e0SJeremy L Thompson hipModule_t module; 30cf8cbdd6SSebastian Grimberg hipFunction_t ApplyNoTranspose, ApplyTranspose; 31cf8cbdd6SSebastian Grimberg hipFunction_t ApplyUnsignedNoTranspose, ApplyUnsignedTranspose; 32cf8cbdd6SSebastian Grimberg hipFunction_t ApplyUnorientedNoTranspose, ApplyUnorientedTranspose; 33437930d1SJeremy L Thompson CeedInt num_nodes; 34f5d1e504SJeremy L Thompson const CeedInt *h_offsets; 35f5d1e504SJeremy L Thompson const CeedInt *h_offsets_borrowed; 36f5d1e504SJeremy L Thompson const CeedInt *h_offsets_owned; 37081aa29dSJeremy L Thompson const CeedInt *d_offsets; 38f5d1e504SJeremy L Thompson const CeedInt *d_offsets_borrowed; 39f5d1e504SJeremy L Thompson const CeedInt *d_offsets_owned; 40081aa29dSJeremy L Thompson const CeedInt *d_t_offsets; 41081aa29dSJeremy L Thompson const CeedInt *d_t_indices; 42081aa29dSJeremy L Thompson const CeedInt *d_l_vec_indices; 43f5d1e504SJeremy L Thompson const bool *h_orients; 44f5d1e504SJeremy L Thompson const bool *h_orients_borrowed; 45f5d1e504SJeremy L Thompson const bool *h_orients_owned; 46f5d1e504SJeremy L Thompson const bool *d_orients; 47f5d1e504SJeremy L Thompson const bool *d_orients_borrowed; 48f5d1e504SJeremy L Thompson const bool *d_orients_owned; 49f5d1e504SJeremy L Thompson const CeedInt8 *h_curl_orients; 50f5d1e504SJeremy L Thompson const CeedInt8 *h_curl_orients_borrowed; 51f5d1e504SJeremy L Thompson const CeedInt8 *h_curl_orients_owned; 52f5d1e504SJeremy L Thompson const CeedInt8 *d_curl_orients; 53f5d1e504SJeremy L Thompson const CeedInt8 *d_curl_orients_borrowed; 54f5d1e504SJeremy L Thompson const CeedInt8 *d_curl_orients_owned; 55*fe960054SJeremy L Thompson const CeedInt *h_offsets_at_points; 56*fe960054SJeremy L Thompson const CeedInt *h_offsets_at_points_borrowed; 57*fe960054SJeremy L Thompson const CeedInt *h_offsets_at_points_owned; 58*fe960054SJeremy L Thompson const CeedInt *d_offsets_at_points; 59*fe960054SJeremy L Thompson const CeedInt *d_offsets_at_points_borrowed; 60*fe960054SJeremy L Thompson const CeedInt *d_offsets_at_points_owned; 610d0321e0SJeremy L Thompson } CeedElemRestriction_Hip; 620d0321e0SJeremy L Thompson 63437930d1SJeremy L Thompson typedef struct { 64437930d1SJeremy L Thompson hipModule_t module; 65437930d1SJeremy L Thompson hipFunction_t Interp; 66437930d1SJeremy L Thompson hipFunction_t Grad; 67437930d1SJeremy L Thompson hipFunction_t Weight; 68437930d1SJeremy L Thompson CeedScalar *d_interp_1d; 69437930d1SJeremy L Thompson CeedScalar *d_grad_1d; 70437930d1SJeremy L Thompson CeedScalar *d_q_weight_1d; 71437930d1SJeremy L Thompson } CeedBasis_Hip; 72437930d1SJeremy L Thompson 73437930d1SJeremy L Thompson typedef struct { 74437930d1SJeremy L Thompson hipModule_t module; 75437930d1SJeremy L Thompson hipFunction_t Interp; 76d075f50bSSebastian Grimberg hipFunction_t InterpTranspose; 77d075f50bSSebastian Grimberg hipFunction_t Deriv; 78d075f50bSSebastian Grimberg hipFunction_t DerivTranspose; 79437930d1SJeremy L Thompson hipFunction_t Weight; 80437930d1SJeremy L Thompson CeedScalar *d_interp; 81437930d1SJeremy L Thompson CeedScalar *d_grad; 82d075f50bSSebastian Grimberg CeedScalar *d_div; 83d075f50bSSebastian Grimberg CeedScalar *d_curl; 84437930d1SJeremy L Thompson CeedScalar *d_q_weight; 85437930d1SJeremy L Thompson } CeedBasisNonTensor_Hip; 86437930d1SJeremy L Thompson 870d0321e0SJeremy L Thompson typedef struct { 880d0321e0SJeremy L Thompson hipModule_t module; 897d023984SJeremy L Thompson const char *qfunction_name; 90f8d308faSJed Brown const char *qfunction_source; 91437930d1SJeremy L Thompson hipFunction_t QFunction; 920d0321e0SJeremy L Thompson Fields_Hip fields; 930d0321e0SJeremy L Thompson void *d_c; 940d0321e0SJeremy L Thompson } CeedQFunction_Hip; 950d0321e0SJeremy L Thompson 960d0321e0SJeremy L Thompson typedef struct { 970d0321e0SJeremy L Thompson void *h_data; 980d0321e0SJeremy L Thompson void *h_data_borrowed; 990d0321e0SJeremy L Thompson void *h_data_owned; 1000d0321e0SJeremy L Thompson void *d_data; 1010d0321e0SJeremy L Thompson void *d_data_borrowed; 1020d0321e0SJeremy L Thompson void *d_data_owned; 1030d0321e0SJeremy L Thompson } CeedQFunctionContext_Hip; 1040d0321e0SJeremy L Thompson 1050d0321e0SJeremy L Thompson typedef struct { 106cbfe683aSSebastian Grimberg hipModule_t module, module_point_block; 107004e4986SSebastian Grimberg hipFunction_t LinearDiagonal; 108004e4986SSebastian Grimberg hipFunction_t LinearPointBlock; 109b7453713SJeremy L Thompson CeedElemRestriction diag_rstr, point_block_diag_rstr; 110b7453713SJeremy L Thompson CeedVector elem_diag, point_block_elem_diag; 111004e4986SSebastian Grimberg CeedEvalMode *d_eval_modes_in, *d_eval_modes_out; 112004e4986SSebastian Grimberg CeedScalar *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in; 113004e4986SSebastian Grimberg CeedScalar *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out; 1140d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip; 1150d0321e0SJeremy L Thompson 1160d0321e0SJeremy L Thompson typedef struct { 117a835093fSnbeams hipModule_t module; 118004e4986SSebastian Grimberg hipFunction_t LinearAssemble; 119004e4986SSebastian Grimberg CeedInt block_size_x, block_size_y, elems_per_block; 120a835093fSnbeams CeedScalar *d_B_in, *d_B_out; 121a835093fSnbeams } CeedOperatorAssemble_Hip; 122a835093fSnbeams 123a835093fSnbeams typedef struct { 124b7453713SJeremy L Thompson CeedVector *e_vecs; // E-vectors, inputs followed by outputs 125b7453713SJeremy L Thompson CeedVector *q_vecs_in; // Input Q-vectors needed to apply operator 126b7453713SJeremy L Thompson CeedVector *q_vecs_out; // Output Q-vectors needed to apply operator 127b7453713SJeremy L Thompson CeedInt num_inputs, num_outputs; 128b7453713SJeremy L Thompson CeedInt num_active_in, num_active_out; 129b7453713SJeremy L Thompson CeedVector *qf_active_in; 1300d0321e0SJeremy L Thompson CeedOperatorDiag_Hip *diag; 131a835093fSnbeams CeedOperatorAssemble_Hip *asmb; 1320d0321e0SJeremy L Thompson } CeedOperator_Hip; 1330d0321e0SJeremy L Thompson 134eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle); 1350d0321e0SJeremy L Thompson 1361f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 1370d0321e0SJeremy L Thompson 138a267acd1SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients, 139a267acd1SJeremy L Thompson const CeedInt8 *curl_orients, CeedElemRestriction rstr); 1400d0321e0SJeremy L Thompson 1416574a04fSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 1426574a04fSJeremy L Thompson const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 14351475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 14451475c7cSJeremy L Thompson const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 145d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 146d075f50bSSebastian Grimberg const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 147d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 148d075f50bSSebastian Grimberg const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 1490d0321e0SJeremy L Thompson 1500d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 1510d0321e0SJeremy L Thompson 1520d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 1530d0321e0SJeremy L Thompson 1540d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 155