xref: /libCEED/backends/cuda-ref/ceed-cuda-ref.h (revision f1c40530bc6f02bc6ca847af718b8b41cc3fd3ca)
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_cuda_h
9 #define _ceed_cuda_h
10 
11 #include <ceed/ceed.h>
12 #include <ceed/backend.h>
13 #include <cuda.h>
14 #include "../cuda/ceed-cuda-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_Cuda;
24 
25 typedef struct {
26   CUmodule module;
27   CUfunction StridedTranspose;
28   CUfunction StridedNoTranspose;
29   CUfunction OffsetTranspose;
30   CUfunction 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_Cuda;
40 
41 typedef struct {
42   CUmodule module;
43   CUfunction Interp;
44   CUfunction Grad;
45   CUfunction Weight;
46   CeedScalar *d_interp_1d;
47   CeedScalar *d_grad_1d;
48   CeedScalar *d_q_weight_1d;
49 } CeedBasis_Cuda;
50 
51 typedef struct {
52   CUmodule module;
53   CUfunction Interp;
54   CUfunction Grad;
55   CUfunction Weight;
56   CeedScalar *d_interp;
57   CeedScalar *d_grad;
58   CeedScalar *d_q_weight;
59 } CeedBasisNonTensor_Cuda;
60 
61 typedef struct {
62   CUmodule module;
63   char *qfunction_name;
64   char *qfunction_source;
65   CUfunction QFunction;
66   Fields_Cuda fields;
67   void *d_c;
68 } CeedQFunction_Cuda;
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_Cuda;
78 
79 typedef struct {
80   CUmodule module;
81   CUfunction linearDiagonal;
82   CUfunction 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_Cuda;
91 
92 typedef struct {
93   CUmodule module;
94   CUfunction linearAssemble;
95   CeedInt nelem, block_size_x, block_size_y, elemsPerBlock;
96   CeedScalar *d_B_in, *d_B_out;
97 } CeedOperatorAssemble_Cuda;
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_Cuda *diag;
108   CeedOperatorAssemble_Cuda *asmb;
109 } CeedOperator_Cuda;
110 
111 CEED_INTERN int CeedCudaGetCublasHandle(Ceed ceed, cublasHandle_t *handle);
112 
113 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec);
114 
115 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type,
116     CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r);
117 
118 CEED_INTERN int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType
119     mem_type,
120     const CeedCopyMode copy_mode, const CeedInt *indices,
121     const CeedElemRestriction res);
122 
123 CEED_INTERN int CeedBasisApplyElems_Cuda(CeedBasis basis,
124     const CeedInt num_elem,
125     CeedTransposeMode t_mode, CeedEvalMode eval_mode, const CeedVector u,
126     CeedVector v);
127 
128 CEED_INTERN int CeedQFunctionApplyElems_Cuda(CeedQFunction qf, const CeedInt Q,
129     const CeedVector *const u, const CeedVector *v);
130 
131 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d,
132     CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
133     const CeedScalar *qref_1d, const CeedScalar *qweight_1d, CeedBasis basis);
134 
135 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology, CeedInt, CeedInt,
136                                        CeedInt, const CeedScalar *,
137                                        const CeedScalar *, const CeedScalar *,
138                                        const CeedScalar *, CeedBasis);
139 
140 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf);
141 
142 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx);
143 
144 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op);
145 
146 #endif
147