xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 5dfaedb85d2aa5da89951bb5d8f41d61be09bbf6)
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 "../hip/ceed-hip-common.h"
15 
16 typedef struct {
17   CeedScalar *h_array;
18   CeedScalar *h_array_borrowed;
19   CeedScalar *h_array_owned;
20   CeedScalar *d_array;
21   CeedScalar *d_array_borrowed;
22   CeedScalar *d_array_owned;
23 } CeedVector_Hip;
24 
25 typedef struct {
26   hipModule_t module;
27   hipFunction_t StridedTranspose;
28   hipFunction_t StridedNoTranspose;
29   hipFunction_t OffsetTranspose;
30   hipFunction_t OffsetNoTranspose;
31   CeedInt num_nodes;
32   CeedInt *h_ind;
33   CeedInt *h_ind_allocated;
34   CeedInt *d_ind;
35   CeedInt *d_ind_allocated;
36   CeedInt *d_t_offsets;
37   CeedInt *d_t_indices;
38   CeedInt *d_l_vec_indices;
39 } CeedElemRestriction_Hip;
40 
41 typedef struct {
42   hipModule_t module;
43   hipFunction_t Interp;
44   hipFunction_t Grad;
45   hipFunction_t Weight;
46   CeedScalar *d_interp_1d;
47   CeedScalar *d_grad_1d;
48   CeedScalar *d_q_weight_1d;
49 } CeedBasis_Hip;
50 
51 typedef struct {
52   hipModule_t module;
53   hipFunction_t Interp;
54   hipFunction_t Grad;
55   hipFunction_t Weight;
56   CeedScalar *d_interp;
57   CeedScalar *d_grad;
58   CeedScalar *d_q_weight;
59 } CeedBasisNonTensor_Hip;
60 
61 // We use a struct to avoid having to memCpy the array of pointers
62 // __global__ copies by value the struct.
63 typedef struct {
64   const CeedScalar *inputs[CEED_FIELD_MAX];
65   CeedScalar *outputs[CEED_FIELD_MAX];
66 } Fields_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 CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle);
119 
120 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
121 
122 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype,
123     CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r);
124 
125 CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype,
126     const CeedCopyMode cmode, const CeedInt *indices,
127     const CeedElemRestriction res);
128 
129 CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem,
130                                         CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v);
131 
132 CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q,
133     const CeedVector *const u, const CeedVector *v);
134 
135 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d,
136     CeedInt Q1d,
137     const CeedScalar *interp1d,
138     const CeedScalar *grad1d,
139     const CeedScalar *qref1d,
140     const CeedScalar *qweight1d,
141     CeedBasis basis);
142 
143 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt,
144                                       CeedInt, const CeedScalar *,
145                                       const CeedScalar *, const CeedScalar *,
146                                       const CeedScalar *, CeedBasis);
147 
148 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
149 
150 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
151 
152 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
153 
154 #endif
155