xref: /libCEED/backends/hip-ref/ceed-hip-ref.h (revision 1d2f0dcb59e9d9d08cb71f4dd5a108c5de60a891)
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 #include "../hip/ceed-hip-common.h"
17 
18 typedef struct {
19   CeedScalar *h_array;
20   CeedScalar *h_array_borrowed;
21   CeedScalar *h_array_owned;
22   CeedScalar *d_array;
23   CeedScalar *d_array_borrowed;
24   CeedScalar *d_array_owned;
25 } CeedVector_Hip;
26 
27 typedef struct {
28   hipModule_t   module;
29   hipFunction_t StridedTranspose;
30   hipFunction_t StridedNoTranspose;
31   hipFunction_t OffsetTranspose;
32   hipFunction_t OffsetNoTranspose;
33   CeedInt       num_nodes;
34   CeedInt      *h_ind;
35   CeedInt      *h_ind_allocated;
36   CeedInt      *d_ind;
37   CeedInt      *d_ind_allocated;
38   CeedInt      *d_t_offsets;
39   CeedInt      *d_t_indices;
40   CeedInt      *d_l_vec_indices;
41 } CeedElemRestriction_Hip;
42 
43 typedef struct {
44   hipModule_t   module;
45   hipFunction_t Interp;
46   hipFunction_t Grad;
47   hipFunction_t Weight;
48   CeedScalar   *d_interp_1d;
49   CeedScalar   *d_grad_1d;
50   CeedScalar   *d_q_weight_1d;
51 } CeedBasis_Hip;
52 
53 typedef struct {
54   hipModule_t   module;
55   hipFunction_t Interp;
56   hipFunction_t Grad;
57   hipFunction_t Weight;
58   CeedScalar   *d_interp;
59   CeedScalar   *d_grad;
60   CeedScalar   *d_q_weight;
61 } CeedBasisNonTensor_Hip;
62 
63 typedef struct {
64   hipModule_t   module;
65   char         *qfunction_name;
66   char         *qfunction_source;
67   hipFunction_t QFunction;
68   Fields_Hip    fields;
69   void         *d_c;
70 } CeedQFunction_Hip;
71 
72 typedef struct {
73   void *h_data;
74   void *h_data_borrowed;
75   void *h_data_owned;
76   void *d_data;
77   void *d_data_borrowed;
78   void *d_data_owned;
79 } CeedQFunctionContext_Hip;
80 
81 typedef struct {
82   hipModule_t         module;
83   hipFunction_t       linearDiagonal;
84   hipFunction_t       linearPointBlock;
85   CeedBasis           basisin, basisout;
86   CeedElemRestriction diagrstr, pbdiagrstr;
87   CeedVector          elemdiag, pbelemdiag;
88   CeedInt             numemodein, numemodeout, nnodes;
89   CeedEvalMode       *h_emodein, *h_emodeout;
90   CeedEvalMode       *d_emodein, *d_emodeout;
91   CeedScalar         *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
92 } CeedOperatorDiag_Hip;
93 
94 typedef struct {
95   hipModule_t   module;
96   hipFunction_t linearAssemble;
97   CeedInt       nelem, block_size_x, block_size_y, elemsPerBlock;
98   CeedScalar   *d_B_in, *d_B_out;
99 } CeedOperatorAssemble_Hip;
100 
101 typedef struct {
102   CeedVector               *evecs;     // E-vectors, inputs followed by outputs
103   CeedVector               *qvecsin;   // Input Q-vectors needed to apply operator
104   CeedVector               *qvecsout;  // Output Q-vectors needed to apply operator
105   CeedInt                   numein;
106   CeedInt                   numeout;
107   CeedInt                   qfnumactivein, qfnumactiveout;
108   CeedVector               *qfactivein;
109   CeedOperatorDiag_Hip     *diag;
110   CeedOperatorAssemble_Hip *asmb;
111 } CeedOperator_Hip;
112 
113 CEED_INTERN int CeedHipGetHipblasHandle(Ceed ceed, hipblasHandle_t *handle);
114 
115 CEED_INTERN int CeedVectorCreate_Hip(CeedSize n, CeedVector vec);
116 
117 CEED_INTERN int CeedElemRestrictionCreate_Hip(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r);
118 
119 CEED_INTERN int CeedBasisCreateTensorH1_Hip(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
120                                             const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
121 
122 CEED_INTERN int CeedBasisCreateH1_Hip(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
123                                       const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
124 
125 CEED_INTERN int CeedQFunctionCreate_Hip(CeedQFunction qf);
126 
127 CEED_INTERN int CeedQFunctionContextCreate_Hip(CeedQFunctionContext ctx);
128 
129 CEED_INTERN int CeedOperatorCreate_Hip(CeedOperator op);
130 
131 #endif
132