xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 9a3a46e1d4300a3ad2fa9b1d35445254cd604d16)
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/ceed.h>
12 #include <ceed/backend.h>
13 #include <hip/hip_runtime.h>
14 #include <hipblas.h>
15 #include "../hip/ceed-hip-common.h"
16 
17 typedef struct {
18   CeedScalar *h_array;
19   CeedScalar *h_array_borrowed;
20   CeedScalar *h_array_owned;
21   CeedScalar *d_array;
22   CeedScalar *d_array_borrowed;
23   CeedScalar *d_array_owned;
24 } CeedVector_Hip;
25 
26 typedef struct {
27   hipModule_t module;
28   hipFunction_t StridedTranspose;
29   hipFunction_t StridedNoTranspose;
30   hipFunction_t OffsetTranspose;
31   hipFunction_t OffsetNoTranspose;
32   CeedInt num_nodes;
33   CeedInt *h_ind;
34   CeedInt *h_ind_allocated;
35   CeedInt *d_ind;
36   CeedInt *d_ind_allocated;
37   CeedInt *d_t_offsets;
38   CeedInt *d_t_indices;
39   CeedInt *d_l_vec_indices;
40 } CeedElemRestriction_Hip;
41 
42 typedef struct {
43   hipModule_t module;
44   hipFunction_t Interp;
45   hipFunction_t Grad;
46   hipFunction_t Weight;
47   CeedScalar *d_interp_1d;
48   CeedScalar *d_grad_1d;
49   CeedScalar *d_q_weight_1d;
50 } CeedBasis_Hip;
51 
52 typedef struct {
53   hipModule_t module;
54   hipFunction_t Interp;
55   hipFunction_t Grad;
56   hipFunction_t Weight;
57   CeedScalar *d_interp;
58   CeedScalar *d_grad;
59   CeedScalar *d_q_weight;
60 } CeedBasisNonTensor_Hip;
61 
62 // We use a struct to avoid having to memCpy the array of pointers
63 // __global__ copies by value the struct.
64 typedef struct {
65   const CeedScalar *inputs[CEED_FIELD_MAX];
66   CeedScalar *outputs[CEED_FIELD_MAX];
67 } Fields_Hip;
68 
69 typedef struct {
70   hipModule_t module;
71   char *qfunction_name;
72   char *qfunction_source;
73   hipFunction_t QFunction;
74   Fields_Hip fields;
75   void *d_c;
76 } CeedQFunction_Hip;
77 
78 typedef struct {
79   void *h_data;
80   void *h_data_borrowed;
81   void *h_data_owned;
82   void *d_data;
83   void *d_data_borrowed;
84   void *d_data_owned;
85 } CeedQFunctionContext_Hip;
86 
87 typedef struct {
88   hipModule_t module;
89   hipFunction_t linearDiagonal;
90   hipFunction_t linearPointBlock;
91   CeedBasis basisin, basisout;
92   CeedElemRestriction diagrstr, pbdiagrstr;
93   CeedVector elemdiag, pbelemdiag;
94   CeedInt numemodein, numemodeout, nnodes;
95   CeedEvalMode *h_emodein, *h_emodeout;
96   CeedEvalMode *d_emodein, *d_emodeout;
97   CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
98 } CeedOperatorDiag_Hip;
99 
100 typedef struct {
101   hipModule_t module;
102   hipFunction_t linearAssemble;
103   CeedInt nelem, block_size_x, block_size_y, elemsPerBlock;
104   CeedScalar *d_B_in, *d_B_out;
105 } CeedOperatorAssemble_Hip;
106 
107 typedef struct {
108   CeedVector *evecs;   // E-vectors, inputs followed by outputs
109   CeedVector *qvecsin;    // Input Q-vectors needed to apply operator
110   CeedVector *qvecsout;   // Output Q-vectors needed to apply operator
111   CeedInt    numein;
112   CeedInt    numeout;
113   CeedInt    qfnumactivein, qfnumactiveout;
114   CeedVector *qfactivein;
115   CeedOperatorDiag_Hip *diag;
116   CeedOperatorAssemble_Hip *asmb;
117 } CeedOperator_Hip;
118 
119 CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle);
120 
121 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
122 
123 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype,
124     CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r);
125 
126 CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype,
127     const CeedCopyMode cmode, const CeedInt *indices,
128     const CeedElemRestriction res);
129 
130 CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem,
131                                         CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v);
132 
133 CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q,
134     const CeedVector *const u, const CeedVector *v);
135 
136 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d,
137     CeedInt Q1d,
138     const CeedScalar *interp1d,
139     const CeedScalar *grad1d,
140     const CeedScalar *qref1d,
141     const CeedScalar *qweight1d,
142     CeedBasis basis);
143 
144 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt,
145                                       CeedInt, const CeedScalar *,
146                                       const CeedScalar *, const CeedScalar *,
147                                       const CeedScalar *, CeedBasis);
148 
149 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
150 
151 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
152 
153 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
154 
155 #endif
156