xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 3e2dab0a8b85af878be609cf4667a5a492ef431d)
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   CeedInt       num_nodes;
38   CeedInt      *h_ind;
39   CeedInt      *h_ind_allocated;
40   CeedInt      *d_ind;
41   CeedInt      *d_ind_allocated;
42   CeedInt      *d_t_offsets;
43   CeedInt      *d_t_indices;
44   CeedInt      *d_l_vec_indices;
45 } CeedElemRestriction_Hip;
46 
47 typedef struct {
48   hipModule_t   module;
49   hipFunction_t Interp;
50   hipFunction_t Grad;
51   hipFunction_t Weight;
52   CeedScalar   *d_interp_1d;
53   CeedScalar   *d_grad_1d;
54   CeedScalar   *d_q_weight_1d;
55 } CeedBasis_Hip;
56 
57 typedef struct {
58   hipModule_t   module;
59   hipFunction_t Interp;
60   hipFunction_t InterpTranspose;
61   hipFunction_t Deriv;
62   hipFunction_t DerivTranspose;
63   hipFunction_t Weight;
64   CeedScalar   *d_interp;
65   CeedScalar   *d_grad;
66   CeedScalar   *d_div;
67   CeedScalar   *d_curl;
68   CeedScalar   *d_q_weight;
69 } CeedBasisNonTensor_Hip;
70 
71 typedef struct {
72   hipModule_t   module;
73   char         *qfunction_name;
74   char         *qfunction_source;
75   hipFunction_t QFunction;
76   Fields_Hip    fields;
77   void         *d_c;
78 } CeedQFunction_Hip;
79 
80 typedef struct {
81   void *h_data;
82   void *h_data_borrowed;
83   void *h_data_owned;
84   void *d_data;
85   void *d_data_borrowed;
86   void *d_data_owned;
87 } CeedQFunctionContext_Hip;
88 
89 typedef struct {
90   hipModule_t         module;
91   hipFunction_t       linearDiagonal;
92   hipFunction_t       linearPointBlock;
93   CeedBasis           basis_in, basis_out;
94   CeedElemRestriction diag_rstr, point_block_diag_rstr;
95   CeedVector          elem_diag, point_block_elem_diag;
96   CeedInt             num_e_mode_in, num_e_mode_out, num_modes;
97   CeedEvalMode       *h_e_mode_in, *h_e_mode_out;
98   CeedEvalMode       *d_e_mode_in, *d_e_mode_out;
99   CeedScalar         *d_identity, *d_interp_in, *d_interp_out, *d_grad_in, *d_grad_out;
100 } CeedOperatorDiag_Hip;
101 
102 typedef struct {
103   hipModule_t   module;
104   hipFunction_t linearAssemble;
105   CeedInt       num_elem, block_size_x, block_size_y, elem_per_block;
106   CeedScalar   *d_B_in, *d_B_out;
107 } CeedOperatorAssemble_Hip;
108 
109 typedef struct {
110   CeedVector               *e_vecs;      // E-vectors, inputs followed by outputs
111   CeedVector               *q_vecs_in;   // Input Q-vectors needed to apply operator
112   CeedVector               *q_vecs_out;  // Output Q-vectors needed to apply operator
113   CeedInt                   num_inputs, num_outputs;
114   CeedInt                   num_active_in, num_active_out;
115   CeedVector               *qf_active_in;
116   CeedOperatorDiag_Hip     *diag;
117   CeedOperatorAssemble_Hip *asmb;
118 } CeedOperator_Hip;
119 
120 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
121 
122 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
123 
124 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
125                                               const CeedInt8 *curl_orients, CeedElemRestriction r);
126 
127 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
128                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
129 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
130                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
131 CEED_INTERN int CeedBasisCreateHdiv_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
132                                         const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
133 CEED_INTERN int CeedBasisCreateHcurl_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
134                                          const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
135 
136 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
137 
138 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
139 
140 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
141 
142 #endif  // CEED_HIP_REF_H
143