xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 5aed82e4fa97acf4ba24a7f10a35f5303a6798e0)
1*5aed82e4SJeremy 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
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;
32cf8cbdd6SSebastian Grimberg   hipFunction_t   ApplyNoTranspose, ApplyTranspose;
33cf8cbdd6SSebastian Grimberg   hipFunction_t   ApplyUnsignedNoTranspose, ApplyUnsignedTranspose;
34cf8cbdd6SSebastian Grimberg   hipFunction_t   ApplyUnorientedNoTranspose, ApplyUnorientedTranspose;
35437930d1SJeremy L Thompson   CeedInt         num_nodes;
36f5d1e504SJeremy L Thompson   const CeedInt  *h_offsets;
37f5d1e504SJeremy L Thompson   const CeedInt  *h_offsets_borrowed;
38f5d1e504SJeremy L Thompson   const CeedInt  *h_offsets_owned;
39081aa29dSJeremy L Thompson   const CeedInt  *d_offsets;
40f5d1e504SJeremy L Thompson   const CeedInt  *d_offsets_borrowed;
41f5d1e504SJeremy L Thompson   const CeedInt  *d_offsets_owned;
42081aa29dSJeremy L Thompson   const CeedInt  *d_t_offsets;
43081aa29dSJeremy L Thompson   const CeedInt  *d_t_indices;
44081aa29dSJeremy L Thompson   const CeedInt  *d_l_vec_indices;
45f5d1e504SJeremy L Thompson   const bool     *h_orients;
46f5d1e504SJeremy L Thompson   const bool     *h_orients_borrowed;
47f5d1e504SJeremy L Thompson   const bool     *h_orients_owned;
48f5d1e504SJeremy L Thompson   const bool     *d_orients;
49f5d1e504SJeremy L Thompson   const bool     *d_orients_borrowed;
50f5d1e504SJeremy L Thompson   const bool     *d_orients_owned;
51f5d1e504SJeremy L Thompson   const CeedInt8 *h_curl_orients;
52f5d1e504SJeremy L Thompson   const CeedInt8 *h_curl_orients_borrowed;
53f5d1e504SJeremy L Thompson   const CeedInt8 *h_curl_orients_owned;
54f5d1e504SJeremy L Thompson   const CeedInt8 *d_curl_orients;
55f5d1e504SJeremy L Thompson   const CeedInt8 *d_curl_orients_borrowed;
56f5d1e504SJeremy L Thompson   const CeedInt8 *d_curl_orients_owned;
570d0321e0SJeremy L Thompson } CeedElemRestriction_Hip;
580d0321e0SJeremy L Thompson 
59437930d1SJeremy L Thompson typedef struct {
60437930d1SJeremy L Thompson   hipModule_t   module;
61437930d1SJeremy L Thompson   hipFunction_t Interp;
62437930d1SJeremy L Thompson   hipFunction_t Grad;
63437930d1SJeremy L Thompson   hipFunction_t Weight;
64437930d1SJeremy L Thompson   CeedScalar   *d_interp_1d;
65437930d1SJeremy L Thompson   CeedScalar   *d_grad_1d;
66437930d1SJeremy L Thompson   CeedScalar   *d_q_weight_1d;
67437930d1SJeremy L Thompson } CeedBasis_Hip;
68437930d1SJeremy L Thompson 
69437930d1SJeremy L Thompson typedef struct {
70437930d1SJeremy L Thompson   hipModule_t   module;
71437930d1SJeremy L Thompson   hipFunction_t Interp;
72d075f50bSSebastian Grimberg   hipFunction_t InterpTranspose;
73d075f50bSSebastian Grimberg   hipFunction_t Deriv;
74d075f50bSSebastian Grimberg   hipFunction_t DerivTranspose;
75437930d1SJeremy L Thompson   hipFunction_t Weight;
76437930d1SJeremy L Thompson   CeedScalar   *d_interp;
77437930d1SJeremy L Thompson   CeedScalar   *d_grad;
78d075f50bSSebastian Grimberg   CeedScalar   *d_div;
79d075f50bSSebastian Grimberg   CeedScalar   *d_curl;
80437930d1SJeremy L Thompson   CeedScalar   *d_q_weight;
81437930d1SJeremy L Thompson } CeedBasisNonTensor_Hip;
82437930d1SJeremy L Thompson 
830d0321e0SJeremy L Thompson typedef struct {
840d0321e0SJeremy L Thompson   hipModule_t   module;
857d023984SJeremy L Thompson   const char   *qfunction_name;
86f8d308faSJed Brown   const char   *qfunction_source;
87437930d1SJeremy L Thompson   hipFunction_t QFunction;
880d0321e0SJeremy L Thompson   Fields_Hip    fields;
890d0321e0SJeremy L Thompson   void         *d_c;
900d0321e0SJeremy L Thompson } CeedQFunction_Hip;
910d0321e0SJeremy L Thompson 
920d0321e0SJeremy L Thompson typedef struct {
930d0321e0SJeremy L Thompson   void *h_data;
940d0321e0SJeremy L Thompson   void *h_data_borrowed;
950d0321e0SJeremy L Thompson   void *h_data_owned;
960d0321e0SJeremy L Thompson   void *d_data;
970d0321e0SJeremy L Thompson   void *d_data_borrowed;
980d0321e0SJeremy L Thompson   void *d_data_owned;
990d0321e0SJeremy L Thompson } CeedQFunctionContext_Hip;
1000d0321e0SJeremy L Thompson 
1010d0321e0SJeremy L Thompson typedef struct {
102cbfe683aSSebastian Grimberg   hipModule_t         module, module_point_block;
103004e4986SSebastian Grimberg   hipFunction_t       LinearDiagonal;
104004e4986SSebastian Grimberg   hipFunction_t       LinearPointBlock;
105b7453713SJeremy L Thompson   CeedElemRestriction diag_rstr, point_block_diag_rstr;
106b7453713SJeremy L Thompson   CeedVector          elem_diag, point_block_elem_diag;
107004e4986SSebastian Grimberg   CeedEvalMode       *d_eval_modes_in, *d_eval_modes_out;
108004e4986SSebastian Grimberg   CeedScalar         *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in;
109004e4986SSebastian Grimberg   CeedScalar         *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out;
1100d0321e0SJeremy L Thompson } CeedOperatorDiag_Hip;
1110d0321e0SJeremy L Thompson 
1120d0321e0SJeremy L Thompson typedef struct {
113a835093fSnbeams   hipModule_t   module;
114004e4986SSebastian Grimberg   hipFunction_t LinearAssemble;
115004e4986SSebastian Grimberg   CeedInt       block_size_x, block_size_y, elems_per_block;
116a835093fSnbeams   CeedScalar   *d_B_in, *d_B_out;
117a835093fSnbeams } CeedOperatorAssemble_Hip;
118a835093fSnbeams 
119a835093fSnbeams typedef struct {
120b7453713SJeremy L Thompson   CeedVector               *e_vecs;      // E-vectors, inputs followed by outputs
121b7453713SJeremy L Thompson   CeedVector               *q_vecs_in;   // Input Q-vectors needed to apply operator
122b7453713SJeremy L Thompson   CeedVector               *q_vecs_out;  // Output Q-vectors needed to apply operator
123b7453713SJeremy L Thompson   CeedInt                   num_inputs, num_outputs;
124b7453713SJeremy L Thompson   CeedInt                   num_active_in, num_active_out;
125b7453713SJeremy L Thompson   CeedVector               *qf_active_in;
1260d0321e0SJeremy L Thompson   CeedOperatorDiag_Hip     *diag;
127a835093fSnbeams   CeedOperatorAssemble_Hip *asmb;
1280d0321e0SJeremy L Thompson } CeedOperator_Hip;
1290d0321e0SJeremy L Thompson 
130eb7e6cafSJeremy L Thompson CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
1310d0321e0SJeremy L Thompson 
1321f9221feSJeremy L Thompson CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
1330d0321e0SJeremy L Thompson 
134a267acd1SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients,
135a267acd1SJeremy L Thompson                                               const CeedInt8 *curl_orients, CeedElemRestriction rstr);
1360d0321e0SJeremy L Thompson 
1376574a04fSJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
1386574a04fSJeremy L Thompson                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
13951475c7cSJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
14051475c7cSJeremy L Thompson                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
141d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
142d075f50bSSebastian Grimberg                                         const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
143d075f50bSSebastian Grimberg CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
144d075f50bSSebastian Grimberg                                          const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
1450d0321e0SJeremy L Thompson 
1460d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
1470d0321e0SJeremy L Thompson 
1480d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
1490d0321e0SJeremy L Thompson 
1500d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
1510d0321e0SJeremy L Thompson 
15294b7b29bSJeremy L Thompson #endif  // CEED_HIP_REF_H
153