xref: /libCEED/rust/libceed-sys/c-src/backends/hip-ref/ceed-hip-ref.h (revision dce496930433734c64b503b2c0057d67691234a0)
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;
37*dce49693SSebastian Grimberg   hipFunction_t OrientedNoTranspose;
38*dce49693SSebastian Grimberg   hipFunction_t OrientedTranspose;
39*dce49693SSebastian Grimberg   hipFunction_t CurlOrientedNoTranspose;
40*dce49693SSebastian Grimberg   hipFunction_t CurlOrientedTranspose;
41*dce49693SSebastian Grimberg   hipFunction_t CurlOrientedUnsignedNoTranspose;
42*dce49693SSebastian Grimberg   hipFunction_t CurlOrientedUnsignedTranspose;
43437930d1SJeremy L Thompson   CeedInt       num_nodes;
440d0321e0SJeremy L Thompson   CeedInt      *h_ind;
450d0321e0SJeremy L Thompson   CeedInt      *h_ind_allocated;
460d0321e0SJeremy L Thompson   CeedInt      *d_ind;
470d0321e0SJeremy L Thompson   CeedInt      *d_ind_allocated;
48437930d1SJeremy L Thompson   CeedInt      *d_t_offsets;
49437930d1SJeremy L Thompson   CeedInt      *d_t_indices;
50437930d1SJeremy L Thompson   CeedInt      *d_l_vec_indices;
51*dce49693SSebastian Grimberg   bool         *h_orients;
52*dce49693SSebastian Grimberg   bool         *h_orients_allocated;
53*dce49693SSebastian Grimberg   bool         *d_orients;
54*dce49693SSebastian Grimberg   bool         *d_orients_allocated;
55*dce49693SSebastian Grimberg   CeedInt8     *h_curl_orients;
56*dce49693SSebastian Grimberg   CeedInt8     *h_curl_orients_allocated;
57*dce49693SSebastian Grimberg   CeedInt8     *d_curl_orients;
58*dce49693SSebastian Grimberg   CeedInt8     *d_curl_orients_allocated;
590d0321e0SJeremy L Thompson } CeedElemRestriction_Hip;
600d0321e0SJeremy L Thompson 
61437930d1SJeremy L Thompson typedef struct {
62437930d1SJeremy L Thompson   hipModule_t   module;
63437930d1SJeremy L Thompson   hipFunction_t Interp;
64437930d1SJeremy L Thompson   hipFunction_t Grad;
65437930d1SJeremy L Thompson   hipFunction_t Weight;
66437930d1SJeremy L Thompson   CeedScalar   *d_interp_1d;
67437930d1SJeremy L Thompson   CeedScalar   *d_grad_1d;
68437930d1SJeremy L Thompson   CeedScalar   *d_q_weight_1d;
69437930d1SJeremy L Thompson } CeedBasis_Hip;
70437930d1SJeremy L Thompson 
71437930d1SJeremy L Thompson typedef struct {
72437930d1SJeremy L Thompson   hipModule_t   module;
73437930d1SJeremy L Thompson   hipFunction_t Interp;
74d075f50bSSebastian Grimberg   hipFunction_t InterpTranspose;
75d075f50bSSebastian Grimberg   hipFunction_t Deriv;
76d075f50bSSebastian Grimberg   hipFunction_t DerivTranspose;
77437930d1SJeremy L Thompson   hipFunction_t Weight;
78437930d1SJeremy L Thompson   CeedScalar   *d_interp;
79437930d1SJeremy L Thompson   CeedScalar   *d_grad;
80d075f50bSSebastian Grimberg   CeedScalar   *d_div;
81d075f50bSSebastian Grimberg   CeedScalar   *d_curl;
82437930d1SJeremy L Thompson   CeedScalar   *d_q_weight;
83437930d1SJeremy L Thompson } CeedBasisNonTensor_Hip;
84437930d1SJeremy L Thompson 
850d0321e0SJeremy L Thompson typedef struct {
860d0321e0SJeremy L Thompson   hipModule_t   module;
87437930d1SJeremy L Thompson   char         *qfunction_name;
88437930d1SJeremy L Thompson   char         *qfunction_source;
89437930d1SJeremy L Thompson   hipFunction_t QFunction;
900d0321e0SJeremy L Thompson   Fields_Hip    fields;
910d0321e0SJeremy L Thompson   void         *d_c;
920d0321e0SJeremy L Thompson } CeedQFunction_Hip;
930d0321e0SJeremy L Thompson 
940d0321e0SJeremy L Thompson typedef struct {
950d0321e0SJeremy L Thompson   void *h_data;
960d0321e0SJeremy L Thompson   void *h_data_borrowed;
970d0321e0SJeremy L Thompson   void *h_data_owned;
980d0321e0SJeremy L Thompson   void *d_data;
990d0321e0SJeremy L Thompson   void *d_data_borrowed;
1000d0321e0SJeremy L Thompson   void *d_data_owned;
1010d0321e0SJeremy L Thompson } CeedQFunctionContext_Hip;
1020d0321e0SJeremy L Thompson 
1030d0321e0SJeremy L Thompson typedef struct {
1040d0321e0SJeremy L Thompson   hipModule_t         module;
1050d0321e0SJeremy L Thompson   hipFunction_t       linearDiagonal;
1060d0321e0SJeremy L Thompson   hipFunction_t       linearPointBlock;
107b7453713SJeremy L Thompson   CeedBasis           basis_in, basis_out;
108b7453713SJeremy L Thompson   CeedElemRestriction diag_rstr, point_block_diag_rstr;
109b7453713SJeremy L Thompson   CeedVector          elem_diag, point_block_elem_diag;
110b7453713SJeremy L Thompson   CeedInt             num_e_mode_in, num_e_mode_out, num_modes;
111b7453713SJeremy L Thompson   CeedEvalMode       *h_e_mode_in, *h_e_mode_out;
112b7453713SJeremy L Thompson   CeedEvalMode       *d_e_mode_in, *d_e_mode_out;
113b7453713SJeremy L Thompson   CeedScalar         *d_identity, *d_interp_in, *d_interp_out, *d_grad_in, *d_grad_out;
1140d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip;
1150d0321e0SJeremy L Thompson 
1160d0321e0SJeremy L Thompson typedef struct {
117a835093fSnbeams   hipModule_t   module;
118a835093fSnbeams   hipFunction_t linearAssemble;
119b7453713SJeremy L Thompson   CeedInt       num_elem, block_size_x, block_size_y, elem_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 
1380305e208SSebastian Grimberg CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
1390c73c039SSebastian Grimberg                                               const CeedInt8 *curl_orients, CeedElemRestriction r);
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);
1550d0321e0SJeremy L Thompson 
15694b7b29bSJeremy L Thompson #endif  // CEED_HIP_REF_H
157