xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 53f7acb178914a16137d9c91c84843f149b8f9af)
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_h
9 #define _ceed_hip_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 
16 #if (HIP_VERSION >= 50200000)
17 #include <hipblas/hipblas.h>  // IWYU pragma: export
18 #else
19 #include <hipblas.h>  // IWYU pragma: export
20 #endif
21 
22 typedef struct {
23   CeedScalar *h_array;
24   CeedScalar *h_array_borrowed;
25   CeedScalar *h_array_owned;
26   CeedScalar *d_array;
27   CeedScalar *d_array_borrowed;
28   CeedScalar *d_array_owned;
29 } CeedVector_Hip;
30 
31 typedef struct {
32   hipModule_t   module;
33   hipFunction_t StridedNoTranspose;
34   hipFunction_t StridedTranspose;
35   hipFunction_t OffsetNoTranspose;
36   hipFunction_t OffsetTranspose;
37   hipFunction_t OffsetTransposeDet;
38   CeedInt       num_nodes;
39   CeedInt      *h_ind;
40   CeedInt      *h_ind_allocated;
41   CeedInt      *d_ind;
42   CeedInt      *d_ind_allocated;
43   CeedInt      *d_t_offsets;
44   CeedInt      *d_t_indices;
45   CeedInt      *d_l_vec_indices;
46 } CeedElemRestriction_Hip;
47 
48 typedef struct {
49   hipModule_t   module;
50   hipFunction_t Interp;
51   hipFunction_t Grad;
52   hipFunction_t Weight;
53   CeedScalar   *d_interp_1d;
54   CeedScalar   *d_grad_1d;
55   CeedScalar   *d_q_weight_1d;
56 } CeedBasis_Hip;
57 
58 typedef struct {
59   hipModule_t   module;
60   hipFunction_t Interp;
61   hipFunction_t Grad;
62   hipFunction_t Weight;
63   CeedScalar   *d_interp;
64   CeedScalar   *d_grad;
65   CeedScalar   *d_q_weight;
66 } CeedBasisNonTensor_Hip;
67 
68 typedef struct {
69   hipModule_t   module;
70   char         *qfunction_name;
71   char         *qfunction_source;
72   hipFunction_t QFunction;
73   Fields_Hip    fields;
74   void         *d_c;
75 } CeedQFunction_Hip;
76 
77 typedef struct {
78   void *h_data;
79   void *h_data_borrowed;
80   void *h_data_owned;
81   void *d_data;
82   void *d_data_borrowed;
83   void *d_data_owned;
84 } CeedQFunctionContext_Hip;
85 
86 typedef struct {
87   hipModule_t         module;
88   hipFunction_t       linearDiagonal;
89   hipFunction_t       linearPointBlock;
90   CeedBasis           basisin, basisout;
91   CeedElemRestriction diagrstr, pbdiagrstr;
92   CeedVector          elemdiag, pbelemdiag;
93   CeedInt             numemodein, numemodeout, nnodes;
94   CeedEvalMode       *h_emodein, *h_emodeout;
95   CeedEvalMode       *d_emodein, *d_emodeout;
96   CeedScalar         *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
97 } CeedOperatorDiag_Hip;
98 
99 typedef struct {
100   hipModule_t   module;
101   hipFunction_t linearAssemble;
102   CeedInt       nelem, block_size_x, block_size_y, elemsPerBlock;
103   CeedScalar   *d_B_in, *d_B_out;
104 } CeedOperatorAssemble_Hip;
105 
106 typedef struct {
107   CeedVector               *evecs;     // E-vectors, inputs followed by outputs
108   CeedVector               *qvecsin;   // Input Q-vectors needed to apply operator
109   CeedVector               *qvecsout;  // Output Q-vectors needed to apply operator
110   CeedInt                   numein;
111   CeedInt                   numeout;
112   CeedInt                   qfnumactivein, qfnumactiveout;
113   CeedVector               *qfactivein;
114   CeedOperatorDiag_Hip     *diag;
115   CeedOperatorAssemble_Hip *asmb;
116 } CeedOperator_Hip;
117 
118 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
119 
120 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
121 
122 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
123                                               const CeedInt8 *curl_orients, CeedElemRestriction r);
124 
125 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
126                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
127 
128 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
129                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
130 
131 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
132 
133 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
134 
135 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
136 
137 #endif
138