xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 2b730f8b5a9c809740a0b3b302db43a719c636b1)
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/backend.h>
12 #include <ceed/ceed.h>
13 #include <hip/hip_runtime.h>
14 
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 typedef struct {
63   hipModule_t   module;
64   char         *qfunction_name;
65   char         *qfunction_source;
66   hipFunction_t QFunction;
67   Fields_Hip    fields;
68   void         *d_c;
69 } CeedQFunction_Hip;
70 
71 typedef struct {
72   void *h_data;
73   void *h_data_borrowed;
74   void *h_data_owned;
75   void *d_data;
76   void *d_data_borrowed;
77   void *d_data_owned;
78 } CeedQFunctionContext_Hip;
79 
80 typedef struct {
81   hipModule_t         module;
82   hipFunction_t       linearDiagonal;
83   hipFunction_t       linearPointBlock;
84   CeedBasis           basisin, basisout;
85   CeedElemRestriction diagrstr, pbdiagrstr;
86   CeedVector          elemdiag, pbelemdiag;
87   CeedInt             numemodein, numemodeout, nnodes;
88   CeedEvalMode       *h_emodein, *h_emodeout;
89   CeedEvalMode       *d_emodein, *d_emodeout;
90   CeedScalar         *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
91 } CeedOperatorDiag_Hip;
92 
93 typedef struct {
94   hipModule_t   module;
95   hipFunction_t linearAssemble;
96   CeedInt       nelem, block_size_x, block_size_y, elemsPerBlock;
97   CeedScalar   *d_B_in, *d_B_out;
98 } CeedOperatorAssemble_Hip;
99 
100 typedef struct {
101   CeedVector               *evecs;     // E-vectors, inputs followed by outputs
102   CeedVector               *qvecsin;   // Input Q-vectors needed to apply operator
103   CeedVector               *qvecsout;  // Output Q-vectors needed to apply operator
104   CeedInt                   numein;
105   CeedInt                   numeout;
106   CeedInt                   qfnumactivein, qfnumactiveout;
107   CeedVector               *qfactivein;
108   CeedOperatorDiag_Hip     *diag;
109   CeedOperatorAssemble_Hip *asmb;
110 } CeedOperator_Hip;
111 
112 CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle);
113 
114 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
115 
116 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mtype, CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r);
117 
118 CEED_INTERN int CeedElemRestrictionCreateBlocked_Hip(const CeedMemType mtype, const CeedCopyMode cmode, const CeedInt *indices,
119                                                      const CeedElemRestriction res);
120 
121 CEED_INTERN int CeedBasisApplyElems_Hip(CeedBasis basis, const CeedInt nelem, CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u,
122                                         CeedVector v);
123 
124 CEED_INTERN int CeedQFunctionApplyElems_Hip(CeedQFunction qf, const CeedInt Q, const CeedVector *const u, const CeedVector *v);
125 
126 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P1d, CeedInt Q1d, const CeedScalar *interp1d, const CeedScalar *grad1d,
127                                             const CeedScalar *qref1d, const CeedScalar *qweight1d, CeedBasis basis);
128 
129 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology, CeedInt, CeedInt, CeedInt, const CeedScalar *, const CeedScalar *, const CeedScalar *,
130                                       const CeedScalar *, CeedBasis);
131 
132 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
133 
134 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
135 
136 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
137 
138 #endif
139