13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, 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 70d0321e0SJeremy L Thompson 80d0321e0SJeremy L Thompson #ifndef _ceed_hip_h 90d0321e0SJeremy L Thompson #define _ceed_hip_h 100d0321e0SJeremy L Thompson 1149aac155SJeremy L Thompson #include <ceed.h> 120d0321e0SJeremy L Thompson #include <ceed/backend.h> 1349aac155SJeremy L Thompson #include <ceed/jit-source/hip/hip-types.h> 140d0321e0SJeremy L Thompson #include <hip/hip_runtime.h> 152b730f8bSJeremy L Thompson 1605c335cbSnbeams #if (HIP_VERSION >= 50200000) 1705c335cbSnbeams #include <hipblas/hipblas.h> // IWYU pragma: export 1805c335cbSnbeams #else 1905c335cbSnbeams #include <hipblas.h> // IWYU pragma: export 2005c335cbSnbeams #endif 2105c335cbSnbeams 220d0321e0SJeremy L Thompson typedef struct { 230d0321e0SJeremy L Thompson CeedScalar *h_array; 240d0321e0SJeremy L Thompson CeedScalar *h_array_borrowed; 250d0321e0SJeremy L Thompson CeedScalar *h_array_owned; 260d0321e0SJeremy L Thompson CeedScalar *d_array; 270d0321e0SJeremy L Thompson CeedScalar *d_array_borrowed; 280d0321e0SJeremy L Thompson CeedScalar *d_array_owned; 290d0321e0SJeremy L Thompson } CeedVector_Hip; 300d0321e0SJeremy L Thompson 310d0321e0SJeremy L Thompson typedef struct { 320d0321e0SJeremy L Thompson hipModule_t module; 33437930d1SJeremy L Thompson hipFunction_t StridedNoTranspose; 34*58549094SSebastian Grimberg hipFunction_t StridedTranspose; 35437930d1SJeremy L Thompson hipFunction_t OffsetNoTranspose; 36*58549094SSebastian Grimberg hipFunction_t OffsetTranspose; 37*58549094SSebastian Grimberg hipFunction_t OffsetTransposeDet; 38437930d1SJeremy L Thompson CeedInt num_nodes; 390d0321e0SJeremy L Thompson CeedInt *h_ind; 400d0321e0SJeremy L Thompson CeedInt *h_ind_allocated; 410d0321e0SJeremy L Thompson CeedInt *d_ind; 420d0321e0SJeremy L Thompson CeedInt *d_ind_allocated; 43437930d1SJeremy L Thompson CeedInt *d_t_offsets; 44437930d1SJeremy L Thompson CeedInt *d_t_indices; 45437930d1SJeremy L Thompson CeedInt *d_l_vec_indices; 460d0321e0SJeremy L Thompson } CeedElemRestriction_Hip; 470d0321e0SJeremy L Thompson 48437930d1SJeremy L Thompson typedef struct { 49437930d1SJeremy L Thompson hipModule_t module; 50437930d1SJeremy L Thompson hipFunction_t Interp; 51437930d1SJeremy L Thompson hipFunction_t Grad; 52437930d1SJeremy L Thompson hipFunction_t Weight; 53437930d1SJeremy L Thompson CeedScalar *d_interp_1d; 54437930d1SJeremy L Thompson CeedScalar *d_grad_1d; 55437930d1SJeremy L Thompson CeedScalar *d_q_weight_1d; 56437930d1SJeremy L Thompson } CeedBasis_Hip; 57437930d1SJeremy L Thompson 58437930d1SJeremy L Thompson typedef struct { 59437930d1SJeremy L Thompson hipModule_t module; 60437930d1SJeremy L Thompson hipFunction_t Interp; 61437930d1SJeremy L Thompson hipFunction_t Grad; 62437930d1SJeremy L Thompson hipFunction_t Weight; 63437930d1SJeremy L Thompson CeedScalar *d_interp; 64437930d1SJeremy L Thompson CeedScalar *d_grad; 65437930d1SJeremy L Thompson CeedScalar *d_q_weight; 66437930d1SJeremy L Thompson } CeedBasisNonTensor_Hip; 67437930d1SJeremy L Thompson 680d0321e0SJeremy L Thompson typedef struct { 690d0321e0SJeremy L Thompson hipModule_t module; 70437930d1SJeremy L Thompson char *qfunction_name; 71437930d1SJeremy L Thompson char *qfunction_source; 72437930d1SJeremy L Thompson hipFunction_t QFunction; 730d0321e0SJeremy L Thompson Fields_Hip fields; 740d0321e0SJeremy L Thompson void *d_c; 750d0321e0SJeremy L Thompson } CeedQFunction_Hip; 760d0321e0SJeremy L Thompson 770d0321e0SJeremy L Thompson typedef struct { 780d0321e0SJeremy L Thompson void *h_data; 790d0321e0SJeremy L Thompson void *h_data_borrowed; 800d0321e0SJeremy L Thompson void *h_data_owned; 810d0321e0SJeremy L Thompson void *d_data; 820d0321e0SJeremy L Thompson void *d_data_borrowed; 830d0321e0SJeremy L Thompson void *d_data_owned; 840d0321e0SJeremy L Thompson } CeedQFunctionContext_Hip; 850d0321e0SJeremy L Thompson 860d0321e0SJeremy L Thompson typedef struct { 870d0321e0SJeremy L Thompson hipModule_t module; 880d0321e0SJeremy L Thompson hipFunction_t linearDiagonal; 890d0321e0SJeremy L Thompson hipFunction_t linearPointBlock; 900d0321e0SJeremy L Thompson CeedBasis basisin, basisout; 910d0321e0SJeremy L Thompson CeedElemRestriction diagrstr, pbdiagrstr; 920d0321e0SJeremy L Thompson CeedVector elemdiag, pbelemdiag; 930d0321e0SJeremy L Thompson CeedInt numemodein, numemodeout, nnodes; 940d0321e0SJeremy L Thompson CeedEvalMode *h_emodein, *h_emodeout; 950d0321e0SJeremy L Thompson CeedEvalMode *d_emodein, *d_emodeout; 960d0321e0SJeremy L Thompson CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout; 970d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip; 980d0321e0SJeremy L Thompson 990d0321e0SJeremy L Thompson typedef struct { 100a835093fSnbeams hipModule_t module; 101a835093fSnbeams hipFunction_t linearAssemble; 10259ad764aSnbeams CeedInt nelem, block_size_x, block_size_y, elemsPerBlock; 103a835093fSnbeams CeedScalar *d_B_in, *d_B_out; 104a835093fSnbeams } CeedOperatorAssemble_Hip; 105a835093fSnbeams 106a835093fSnbeams typedef struct { 1070d0321e0SJeremy L Thompson CeedVector *evecs; // E-vectors, inputs followed by outputs 1080d0321e0SJeremy L Thompson CeedVector *qvecsin; // Input Q-vectors needed to apply operator 1090d0321e0SJeremy L Thompson CeedVector *qvecsout; // Output Q-vectors needed to apply operator 1100d0321e0SJeremy L Thompson CeedInt numein; 1110d0321e0SJeremy L Thompson CeedInt numeout; 1120d0321e0SJeremy L Thompson CeedInt qfnumactivein, qfnumactiveout; 1130d0321e0SJeremy L Thompson CeedVector *qfactivein; 1140d0321e0SJeremy L Thompson CeedOperatorDiag_Hip *diag; 115a835093fSnbeams CeedOperatorAssemble_Hip *asmb; 1160d0321e0SJeremy L Thompson } CeedOperator_Hip; 1170d0321e0SJeremy L Thompson 118eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle); 1190d0321e0SJeremy L Thompson 1201f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec); 1210d0321e0SJeremy L Thompson 1220305e208SSebastian Grimberg CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients, 1230c73c039SSebastian Grimberg const CeedInt8 *curl_orients, CeedElemRestriction r); 1240d0321e0SJeremy L Thompson 1256574a04fSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 1266574a04fSJeremy L Thompson const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis); 1270d0321e0SJeremy L Thompson 12851475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 12951475c7cSJeremy L Thompson const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis); 1300d0321e0SJeremy L Thompson 1310d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf); 1320d0321e0SJeremy L Thompson 1330d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx); 1340d0321e0SJeremy L Thompson 1350d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op); 1360d0321e0SJeremy L Thompson 1370d0321e0SJeremy L Thompson #endif 138