xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision b473a06276daa8a28b9126dca2fc365f20267013)
1 // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 #ifndef CEED_HIP_REF_H
9 #define CEED_HIP_REF_H
10 
11 #include <ceed.h>
12 #include <ceed/backend.h>
13 #include <ceed/jit-source/hip/hip-types.h>
14 #include <hip/hip_runtime.h>
15 #if (HIP_VERSION >= 50200000)
16 #include <hipblas/hipblas.h>  // IWYU pragma: export
17 #else
18 #include <hipblas.h>  // IWYU pragma: export
19 #endif
20 
21 typedef struct {
22   CeedScalar *h_array;
23   CeedScalar *h_array_borrowed;
24   CeedScalar *h_array_owned;
25   CeedScalar *d_array;
26   CeedScalar *d_array_borrowed;
27   CeedScalar *d_array_owned;
28 } CeedVector_Hip;
29 
30 typedef struct {
31   hipModule_t   module;
32   hipFunction_t StridedNoTranspose;
33   hipFunction_t StridedTranspose;
34   hipFunction_t OffsetNoTranspose;
35   hipFunction_t OffsetTranspose;
36   hipFunction_t OffsetTransposeDet;
37   hipFunction_t OrientedNoTranspose;
38   hipFunction_t OrientedTranspose;
39   hipFunction_t OrientedTransposeDet;
40   hipFunction_t CurlOrientedNoTranspose;
41   hipFunction_t CurlOrientedTranspose;
42   hipFunction_t CurlOrientedTransposeDet;
43   hipFunction_t CurlOrientedUnsignedNoTranspose;
44   hipFunction_t CurlOrientedUnsignedTranspose;
45   hipFunction_t CurlOrientedUnsignedTransposeDet;
46   CeedInt       num_nodes;
47   CeedInt      *h_ind;
48   CeedInt      *h_ind_allocated;
49   CeedInt      *d_ind;
50   CeedInt      *d_ind_allocated;
51   CeedInt      *d_t_offsets;
52   CeedInt      *d_t_indices;
53   CeedInt      *d_l_vec_indices;
54   bool         *h_orients;
55   bool         *h_orients_allocated;
56   bool         *d_orients;
57   bool         *d_orients_allocated;
58   CeedInt8     *h_curl_orients;
59   CeedInt8     *h_curl_orients_allocated;
60   CeedInt8     *d_curl_orients;
61   CeedInt8     *d_curl_orients_allocated;
62 } CeedElemRestriction_Hip;
63 
64 typedef struct {
65   hipModule_t   module;
66   hipFunction_t Interp;
67   hipFunction_t Grad;
68   hipFunction_t Weight;
69   CeedScalar   *d_interp_1d;
70   CeedScalar   *d_grad_1d;
71   CeedScalar   *d_q_weight_1d;
72 } CeedBasis_Hip;
73 
74 typedef struct {
75   hipModule_t   module;
76   hipFunction_t Interp;
77   hipFunction_t InterpTranspose;
78   hipFunction_t Deriv;
79   hipFunction_t DerivTranspose;
80   hipFunction_t Weight;
81   CeedScalar   *d_interp;
82   CeedScalar   *d_grad;
83   CeedScalar   *d_div;
84   CeedScalar   *d_curl;
85   CeedScalar   *d_q_weight;
86 } CeedBasisNonTensor_Hip;
87 
88 typedef struct {
89   hipModule_t   module;
90   char         *qfunction_name;
91   char         *qfunction_source;
92   hipFunction_t QFunction;
93   Fields_Hip    fields;
94   void         *d_c;
95 } CeedQFunction_Hip;
96 
97 typedef struct {
98   void *h_data;
99   void *h_data_borrowed;
100   void *h_data_owned;
101   void *d_data;
102   void *d_data_borrowed;
103   void *d_data_owned;
104 } CeedQFunctionContext_Hip;
105 
106 typedef struct {
107   hipModule_t         module;
108   hipFunction_t       LinearDiagonal;
109   hipFunction_t       LinearPointBlock;
110   CeedElemRestriction diag_rstr, point_block_diag_rstr;
111   CeedVector          elem_diag, point_block_elem_diag;
112   CeedEvalMode       *d_eval_modes_in, *d_eval_modes_out;
113   CeedScalar         *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in;
114   CeedScalar         *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out;
115 } CeedOperatorDiag_Hip;
116 
117 typedef struct {
118   hipModule_t   module;
119   hipFunction_t LinearAssemble;
120   CeedInt       block_size_x, block_size_y, elems_per_block;
121   CeedScalar   *d_B_in, *d_B_out;
122 } CeedOperatorAssemble_Hip;
123 
124 typedef struct {
125   CeedVector               *e_vecs;      // E-vectors, inputs followed by outputs
126   CeedVector               *q_vecs_in;   // Input Q-vectors needed to apply operator
127   CeedVector               *q_vecs_out;  // Output Q-vectors needed to apply operator
128   CeedInt                   num_inputs, num_outputs;
129   CeedInt                   num_active_in, num_active_out;
130   CeedVector               *qf_active_in;
131   CeedOperatorDiag_Hip     *diag;
132   CeedOperatorAssemble_Hip *asmb;
133 } CeedOperator_Hip;
134 
135 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
136 
137 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
138 
139 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
140                                               const CeedInt8 *curl_orients, CeedElemRestriction r);
141 
142 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
143                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
144 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
145                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
146 CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
147                                         const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
148 CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
149                                          const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
150 
151 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
152 
153 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
154 
155 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
156 
157 #endif  // CEED_HIP_REF_H
158