xref: /libCEED/rust/libceed-sys/c-src/backends/hip-ref/ceed-hip-ref.h (revision 004e49868906b3e3ec4a252ac682c88f9414881a)
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;
37dce49693SSebastian Grimberg   hipFunction_t OrientedNoTranspose;
38dce49693SSebastian Grimberg   hipFunction_t OrientedTranspose;
39dce49693SSebastian Grimberg   hipFunction_t CurlOrientedNoTranspose;
40dce49693SSebastian Grimberg   hipFunction_t CurlOrientedTranspose;
41dce49693SSebastian Grimberg   hipFunction_t CurlOrientedUnsignedNoTranspose;
42dce49693SSebastian 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;
51dce49693SSebastian Grimberg   bool         *h_orients;
52dce49693SSebastian Grimberg   bool         *h_orients_allocated;
53dce49693SSebastian Grimberg   bool         *d_orients;
54dce49693SSebastian Grimberg   bool         *d_orients_allocated;
55dce49693SSebastian Grimberg   CeedInt8     *h_curl_orients;
56dce49693SSebastian Grimberg   CeedInt8     *h_curl_orients_allocated;
57dce49693SSebastian Grimberg   CeedInt8     *d_curl_orients;
58dce49693SSebastian 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;
105*004e4986SSebastian Grimberg   hipFunction_t       LinearDiagonal;
106*004e4986SSebastian Grimberg   hipFunction_t       LinearPointBlock;
107b7453713SJeremy L Thompson   CeedElemRestriction diag_rstr, point_block_diag_rstr;
108b7453713SJeremy L Thompson   CeedVector          elem_diag, point_block_elem_diag;
109*004e4986SSebastian Grimberg   CeedEvalMode       *d_eval_modes_in, *d_eval_modes_out;
110*004e4986SSebastian Grimberg   CeedScalar         *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in;
111*004e4986SSebastian Grimberg   CeedScalar         *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out;
1120d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip;
1130d0321e0SJeremy L Thompson 
1140d0321e0SJeremy L Thompson typedef struct {
115a835093fSnbeams   hipModule_t   module;
116*004e4986SSebastian Grimberg   hipFunction_t LinearAssemble;
117*004e4986SSebastian Grimberg   CeedInt       block_size_x, block_size_y, elems_per_block;
118a835093fSnbeams   CeedScalar   *d_B_in, *d_B_out;
119a835093fSnbeams } CeedOperatorAssemble_Hip;
120a835093fSnbeams 
121a835093fSnbeams typedef struct {
122b7453713SJeremy L Thompson   CeedVector               *e_vecs;      // E-vectors, inputs followed by outputs
123b7453713SJeremy L Thompson   CeedVector               *q_vecs_in;   // Input Q-vectors needed to apply operator
124b7453713SJeremy L Thompson   CeedVector               *q_vecs_out;  // Output Q-vectors needed to apply operator
125b7453713SJeremy L Thompson   CeedInt                   num_inputs, num_outputs;
126b7453713SJeremy L Thompson   CeedInt                   num_active_in, num_active_out;
127b7453713SJeremy L Thompson   CeedVector               *qf_active_in;
1280d0321e0SJeremy L Thompson   CeedOperatorDiag_Hip     *diag;
129a835093fSnbeams   CeedOperatorAssemble_Hip *asmb;
1300d0321e0SJeremy L Thompson } CeedOperator_Hip;
1310d0321e0SJeremy L Thompson 
132eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
1330d0321e0SJeremy L Thompson 
1341f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
1350d0321e0SJeremy L Thompson 
1360305e208SSebastian Grimberg CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
1370c73c039SSebastian Grimberg                                               const CeedInt8 *curl_orients, CeedElemRestriction r);
1380d0321e0SJeremy L Thompson 
1396574a04fSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
1406574a04fSJeremy L Thompson                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
14151475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
14251475c7cSJeremy L Thompson                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
143d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
144d075f50bSSebastian Grimberg                                         const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
145d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
146d075f50bSSebastian Grimberg                                          const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
1470d0321e0SJeremy L Thompson 
1480d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
1490d0321e0SJeremy L Thompson 
1500d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
1510d0321e0SJeremy L Thompson 
1520d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
1530d0321e0SJeremy L Thompson 
15494b7b29bSJeremy L Thompson #endif  // CEED_HIP_REF_H
155