xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 0d0321e0e600f17fbb9528732fcb5c1d5c63fc0f)
1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3 // All Rights reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 #ifndef _ceed_hip_h
18 #define _ceed_hip_h
19 
20 #include <ceed/ceed.h>
21 #include <ceed/backend.h>
22 #include <hip/hip_runtime.h>
23 #include <hipblas.h>
24 #include "../hip/ceed-hip-common.h"
25 
26 typedef struct {
27   CeedScalar *h_array;
28   CeedScalar *h_array_borrowed;
29   CeedScalar *h_array_owned;
30   CeedScalar *d_array;
31   CeedScalar *d_array_borrowed;
32   CeedScalar *d_array_owned;
33 } CeedVector_Hip;
34 
35 typedef struct {
36   hipModule_t module;
37   hipFunction_t noTrStrided;
38   hipFunction_t noTrOffset;
39   hipFunction_t trStrided;
40   hipFunction_t trOffset;
41   CeedInt nnodes;
42   CeedInt *h_ind;
43   CeedInt *h_ind_allocated;
44   CeedInt *d_ind;
45   CeedInt *d_ind_allocated;
46   CeedInt *d_toffsets;
47   CeedInt *d_tindices;
48   CeedInt *d_lvec_indices;
49 } CeedElemRestriction_Hip;
50 
51 // We use a struct to avoid having to memCpy the array of pointers
52 // __global__ copies by value the struct.
53 typedef struct {
54   const CeedScalar *inputs[CEED_FIELD_MAX];
55   CeedScalar *outputs[CEED_FIELD_MAX];
56 } Fields_Hip;
57 
58 typedef struct {
59   hipModule_t module;
60   char *qFunctionName;
61   char *qFunctionSource;
62   hipFunction_t qFunction;
63   Fields_Hip fields;
64   void *d_c;
65 } CeedQFunction_Hip;
66 
67 typedef struct {
68   void *h_data;
69   void *h_data_borrowed;
70   void *h_data_owned;
71   void *d_data;
72   void *d_data_borrowed;
73   void *d_data_owned;
74 } CeedQFunctionContext_Hip;
75 
76 typedef struct {
77   hipModule_t module;
78   hipFunction_t interp;
79   hipFunction_t grad;
80   hipFunction_t weight;
81   CeedScalar *d_interp1d;
82   CeedScalar *d_grad1d;
83   CeedScalar *d_qweight1d;
84 } CeedBasis_Hip;
85 
86 typedef struct {
87   hipModule_t module;
88   hipFunction_t interp;
89   hipFunction_t grad;
90   hipFunction_t weight;
91   CeedScalar *d_interp;
92   CeedScalar *d_grad;
93   CeedScalar *d_qweight;
94 } CeedBasisNonTensor_Hip;
95 
96 typedef struct {
97   hipModule_t module;
98   hipFunction_t linearDiagonal;
99   hipFunction_t linearPointBlock;
100   CeedBasis basisin, basisout;
101   CeedElemRestriction diagrstr, pbdiagrstr;
102   CeedVector elemdiag, pbelemdiag;
103   CeedInt numemodein, numemodeout, nnodes;
104   CeedEvalMode *h_emodein, *h_emodeout;
105   CeedEvalMode *d_emodein, *d_emodeout;
106   CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
107 } CeedOperatorDiag_Hip;
108 
109 typedef struct {
110   CeedVector *evecs;   // E-vectors, inputs followed by outputs
111   CeedVector *qvecsin;    // Input Q-vectors needed to apply operator
112   CeedVector *qvecsout;   // Output Q-vectors needed to apply operator
113   CeedInt    numein;
114   CeedInt    numeout;
115   CeedInt    qfnumactivein, qfnumactiveout;
116   CeedVector *qfactivein;
117   CeedOperatorDiag_Hip *diag;
118 } CeedOperator_Hip;
119 
120 CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle);
121 
122 CEED_INTERN int CeedVectorCreate_Hip(CeedInt n, CeedVector vec);
123 
124 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype,
125     CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r);
126 
127 CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype,
128     const CeedCopyMode cmode, const CeedInt *indices,
129     const CeedElemRestriction res);
130 
131 CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem,
132                                         CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v);
133 
134 CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q,
135     const CeedVector *const u, const CeedVector *v);
136 
137 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d,
138     CeedInt Q1d,
139     const CeedScalar *interp1d,
140     const CeedScalar *grad1d,
141     const CeedScalar *qref1d,
142     const CeedScalar *qweight1d,
143     CeedBasis basis);
144 
145 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt,
146                                       CeedInt, const CeedScalar *,
147                                       const CeedScalar *, const CeedScalar *,
148                                       const CeedScalar *, CeedBasis);
149 
150 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
151 
152 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
153 
154 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
155 
156 CEED_INTERN int CeedCompositeOperatorCreate_Hip(CeedOperator op);
157 #endif
158