xref: /libCEED/rust/libceed-sys/c-src/backends/hip-ref/ceed-hip-ref.h (revision d075f50ba6d3b1e38c233860adb1de6c814f0afc) !
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 
894b7b29bSJeremy L Thompson #ifndef CEED_HIP_REF_H
994b7b29bSJeremy L Thompson #define CEED_HIP_REF_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>
1505c335cbSnbeams #if (HIP_VERSION >= 50200000)
1605c335cbSnbeams #include <hipblas/hipblas.h>  // IWYU pragma: export
1705c335cbSnbeams #else
1805c335cbSnbeams #include <hipblas.h>  // IWYU pragma: export
1905c335cbSnbeams #endif
2005c335cbSnbeams 
210d0321e0SJeremy L Thompson typedef struct {
220d0321e0SJeremy L Thompson   CeedScalar *h_array;
230d0321e0SJeremy L Thompson   CeedScalar *h_array_borrowed;
240d0321e0SJeremy L Thompson   CeedScalar *h_array_owned;
250d0321e0SJeremy L Thompson   CeedScalar *d_array;
260d0321e0SJeremy L Thompson   CeedScalar *d_array_borrowed;
270d0321e0SJeremy L Thompson   CeedScalar *d_array_owned;
280d0321e0SJeremy L Thompson } CeedVector_Hip;
290d0321e0SJeremy L Thompson 
300d0321e0SJeremy L Thompson typedef struct {
310d0321e0SJeremy L Thompson   hipModule_t   module;
32437930d1SJeremy L Thompson   hipFunction_t StridedNoTranspose;
3358549094SSebastian Grimberg   hipFunction_t StridedTranspose;
34437930d1SJeremy L Thompson   hipFunction_t OffsetNoTranspose;
3558549094SSebastian Grimberg   hipFunction_t OffsetTranspose;
3658549094SSebastian Grimberg   hipFunction_t OffsetTransposeDet;
37437930d1SJeremy L Thompson   CeedInt       num_nodes;
380d0321e0SJeremy L Thompson   CeedInt      *h_ind;
390d0321e0SJeremy L Thompson   CeedInt      *h_ind_allocated;
400d0321e0SJeremy L Thompson   CeedInt      *d_ind;
410d0321e0SJeremy L Thompson   CeedInt      *d_ind_allocated;
42437930d1SJeremy L Thompson   CeedInt      *d_t_offsets;
43437930d1SJeremy L Thompson   CeedInt      *d_t_indices;
44437930d1SJeremy L Thompson   CeedInt      *d_l_vec_indices;
450d0321e0SJeremy L Thompson } CeedElemRestriction_Hip;
460d0321e0SJeremy L Thompson 
47437930d1SJeremy L Thompson typedef struct {
48437930d1SJeremy L Thompson   hipModule_t   module;
49437930d1SJeremy L Thompson   hipFunction_t Interp;
50437930d1SJeremy L Thompson   hipFunction_t Grad;
51437930d1SJeremy L Thompson   hipFunction_t Weight;
52437930d1SJeremy L Thompson   CeedScalar   *d_interp_1d;
53437930d1SJeremy L Thompson   CeedScalar   *d_grad_1d;
54437930d1SJeremy L Thompson   CeedScalar   *d_q_weight_1d;
55437930d1SJeremy L Thompson } CeedBasis_Hip;
56437930d1SJeremy L Thompson 
57437930d1SJeremy L Thompson typedef struct {
58437930d1SJeremy L Thompson   hipModule_t   module;
59437930d1SJeremy L Thompson   hipFunction_t Interp;
60*d075f50bSSebastian Grimberg   hipFunction_t InterpTranspose;
61*d075f50bSSebastian Grimberg   hipFunction_t Deriv;
62*d075f50bSSebastian Grimberg   hipFunction_t DerivTranspose;
63437930d1SJeremy L Thompson   hipFunction_t Weight;
64437930d1SJeremy L Thompson   CeedScalar   *d_interp;
65437930d1SJeremy L Thompson   CeedScalar   *d_grad;
66*d075f50bSSebastian Grimberg   CeedScalar   *d_div;
67*d075f50bSSebastian Grimberg   CeedScalar   *d_curl;
68437930d1SJeremy L Thompson   CeedScalar   *d_q_weight;
69437930d1SJeremy L Thompson } CeedBasisNonTensor_Hip;
70437930d1SJeremy L Thompson 
710d0321e0SJeremy L Thompson typedef struct {
720d0321e0SJeremy L Thompson   hipModule_t   module;
73437930d1SJeremy L Thompson   char         *qfunction_name;
74437930d1SJeremy L Thompson   char         *qfunction_source;
75437930d1SJeremy L Thompson   hipFunction_t QFunction;
760d0321e0SJeremy L Thompson   Fields_Hip    fields;
770d0321e0SJeremy L Thompson   void         *d_c;
780d0321e0SJeremy L Thompson } CeedQFunction_Hip;
790d0321e0SJeremy L Thompson 
800d0321e0SJeremy L Thompson typedef struct {
810d0321e0SJeremy L Thompson   void *h_data;
820d0321e0SJeremy L Thompson   void *h_data_borrowed;
830d0321e0SJeremy L Thompson   void *h_data_owned;
840d0321e0SJeremy L Thompson   void *d_data;
850d0321e0SJeremy L Thompson   void *d_data_borrowed;
860d0321e0SJeremy L Thompson   void *d_data_owned;
870d0321e0SJeremy L Thompson } CeedQFunctionContext_Hip;
880d0321e0SJeremy L Thompson 
890d0321e0SJeremy L Thompson typedef struct {
900d0321e0SJeremy L Thompson   hipModule_t         module;
910d0321e0SJeremy L Thompson   hipFunction_t       linearDiagonal;
920d0321e0SJeremy L Thompson   hipFunction_t       linearPointBlock;
93b7453713SJeremy L Thompson   CeedBasis           basis_in, basis_out;
94b7453713SJeremy L Thompson   CeedElemRestriction diag_rstr, point_block_diag_rstr;
95b7453713SJeremy L Thompson   CeedVector          elem_diag, point_block_elem_diag;
96b7453713SJeremy L Thompson   CeedInt             num_e_mode_in, num_e_mode_out, num_modes;
97b7453713SJeremy L Thompson   CeedEvalMode       *h_e_mode_in, *h_e_mode_out;
98b7453713SJeremy L Thompson   CeedEvalMode       *d_e_mode_in, *d_e_mode_out;
99b7453713SJeremy L Thompson   CeedScalar         *d_identity, *d_interp_in, *d_interp_out, *d_grad_in, *d_grad_out;
1000d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip;
1010d0321e0SJeremy L Thompson 
1020d0321e0SJeremy L Thompson typedef struct {
103a835093fSnbeams   hipModule_t   module;
104a835093fSnbeams   hipFunction_t linearAssemble;
105b7453713SJeremy L Thompson   CeedInt       num_elem, block_size_x, block_size_y, elem_per_block;
106a835093fSnbeams   CeedScalar   *d_B_in, *d_B_out;
107a835093fSnbeams } CeedOperatorAssemble_Hip;
108a835093fSnbeams 
109a835093fSnbeams typedef struct {
110b7453713SJeremy L Thompson   CeedVector               *e_vecs;      // E-vectors, inputs followed by outputs
111b7453713SJeremy L Thompson   CeedVector               *q_vecs_in;   // Input Q-vectors needed to apply operator
112b7453713SJeremy L Thompson   CeedVector               *q_vecs_out;  // Output Q-vectors needed to apply operator
113b7453713SJeremy L Thompson   CeedInt                   num_inputs, num_outputs;
114b7453713SJeremy L Thompson   CeedInt                   num_active_in, num_active_out;
115b7453713SJeremy L Thompson   CeedVector               *qf_active_in;
1160d0321e0SJeremy L Thompson   CeedOperatorDiag_Hip     *diag;
117a835093fSnbeams   CeedOperatorAssemble_Hip *asmb;
1180d0321e0SJeremy L Thompson } CeedOperator_Hip;
1190d0321e0SJeremy L Thompson 
120eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
1210d0321e0SJeremy L Thompson 
1221f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
1230d0321e0SJeremy L Thompson 
1240305e208SSebastian Grimberg CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
1250c73c039SSebastian Grimberg                                               const CeedInt8 *curl_orients, CeedElemRestriction r);
1260d0321e0SJeremy L Thompson 
1276574a04fSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
1286574a04fSJeremy L Thompson                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
12951475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
13051475c7cSJeremy L Thompson                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
131*d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
132*d075f50bSSebastian Grimberg                                         const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
133*d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
134*d075f50bSSebastian Grimberg                                          const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
1350d0321e0SJeremy L Thompson 
1360d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
1370d0321e0SJeremy L Thompson 
1380d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
1390d0321e0SJeremy L Thompson 
1400d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
1410d0321e0SJeremy L Thompson 
14294b7b29bSJeremy L Thompson #endif  // CEED_HIP_REF_H
143