xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 9330daecb0fc008043eec1b94c46ef7aecbb00cd)
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 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 typedef struct {
62   hipModule_t   module;
63   char         *qfunction_name;
64   char         *qfunction_source;
65   hipFunction_t QFunction;
66   Fields_Hip    fields;
67   void         *d_c;
68 } CeedQFunction_Hip;
69 
70 typedef struct {
71   void *h_data;
72   void *h_data_borrowed;
73   void *h_data_owned;
74   void *d_data;
75   void *d_data_borrowed;
76   void *d_data_owned;
77 } CeedQFunctionContext_Hip;
78 
79 typedef struct {
80   hipModule_t         module;
81   hipFunction_t       linearDiagonal;
82   hipFunction_t       linearPointBlock;
83   CeedBasis           basisin, basisout;
84   CeedElemRestriction diagrstr, pbdiagrstr;
85   CeedVector          elemdiag, pbelemdiag;
86   CeedInt             numemodein, numemodeout, nnodes;
87   CeedEvalMode       *h_emodein, *h_emodeout;
88   CeedEvalMode       *d_emodein, *d_emodeout;
89   CeedScalar         *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
90 } CeedOperatorDiag_Hip;
91 
92 typedef struct {
93   hipModule_t   module;
94   hipFunction_t linearAssemble;
95   CeedInt       nelem, block_size_x, block_size_y, elemsPerBlock;
96   CeedScalar   *d_B_in, *d_B_out;
97 } CeedOperatorAssemble_Hip;
98 
99 typedef struct {
100   CeedVector               *evecs;     // E-vectors, inputs followed by outputs
101   CeedVector               *qvecsin;   // Input Q-vectors needed to apply operator
102   CeedVector               *qvecsout;  // Output Q-vectors needed to apply operator
103   CeedInt                   numein;
104   CeedInt                   numeout;
105   CeedInt                   qfnumactivein, qfnumactiveout;
106   CeedVector               *qfactivein;
107   CeedOperatorDiag_Hip     *diag;
108   CeedOperatorAssemble_Hip *asmb;
109 } CeedOperator_Hip;
110 
111 CEED_INTERN int CeedGetHipblasHandle_Hip(Ceed ceed, hipblasHandle_t *handle);
112 
113 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
114 
115 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r);
116 
117 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
118                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
119 
120 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
121                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
122 
123 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
124 
125 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
126 
127 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
128 
129 #endif
130