xref: /libCEED/backends/cuda-ref/ceed-cuda-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_cuda_h
18 #define _ceed_cuda_h
19 
20 #include <ceed/ceed.h>
21 #include <ceed/backend.h>
22 #include <cuda.h>
23 #include "../cuda/ceed-cuda-common.h"
24 
25 typedef struct {
26   CeedScalar *h_array;
27   CeedScalar *h_array_borrowed;
28   CeedScalar *h_array_owned;
29   CeedScalar *d_array;
30   CeedScalar *d_array_borrowed;
31   CeedScalar *d_array_owned;
32 } CeedVector_Cuda;
33 
34 typedef struct {
35   CUmodule module;
36   CUfunction noTrStrided;
37   CUfunction noTrOffset;
38   CUfunction trStrided;
39   CUfunction trOffset;
40   CeedInt nnodes;
41   CeedInt *h_ind;
42   CeedInt *h_ind_allocated;
43   CeedInt *d_ind;
44   CeedInt *d_ind_allocated;
45   CeedInt *d_toffsets;
46   CeedInt *d_tindices;
47   CeedInt *d_lvec_indices;
48 } CeedElemRestriction_Cuda;
49 
50 // We use a struct to avoid having to memCpy the array of pointers
51 // __global__ copies by value the struct.
52 typedef struct {
53   const CeedScalar *inputs[CEED_FIELD_MAX];
54   CeedScalar *outputs[CEED_FIELD_MAX];
55 } Fields_Cuda;
56 
57 typedef struct {
58   CUmodule module;
59   char *qFunctionName;
60   char *qFunctionSource;
61   CUfunction qFunction;
62   Fields_Cuda fields;
63   void *d_c;
64 } CeedQFunction_Cuda;
65 
66 typedef struct {
67   void *h_data;
68   void *h_data_borrowed;
69   void *h_data_owned;
70   void *d_data;
71   void *d_data_borrowed;
72   void *d_data_owned;
73 } CeedQFunctionContext_Cuda;
74 
75 typedef struct {
76   CUmodule module;
77   CUfunction interp;
78   CUfunction grad;
79   CUfunction weight;
80   CeedScalar *d_interp1d;
81   CeedScalar *d_grad1d;
82   CeedScalar *d_qweight1d;
83 } CeedBasis_Cuda;
84 
85 typedef struct {
86   CUmodule module;
87   CUfunction interp;
88   CUfunction grad;
89   CUfunction weight;
90   CeedScalar *d_interp;
91   CeedScalar *d_grad;
92   CeedScalar *d_qweight;
93 } CeedBasisNonTensor_Cuda;
94 
95 typedef struct {
96   CUmodule module;
97   CUfunction linearDiagonal;
98   CUfunction linearPointBlock;
99   CeedBasis basisin, basisout;
100   CeedElemRestriction diagrstr, pbdiagrstr;
101   CeedVector elemdiag, pbelemdiag;
102   CeedInt numemodein, numemodeout, nnodes;
103   CeedEvalMode *h_emodein, *h_emodeout;
104   CeedEvalMode *d_emodein, *d_emodeout;
105   CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
106 } CeedOperatorDiag_Cuda;
107 
108 typedef struct {
109   CeedVector *evecs;   // E-vectors, inputs followed by outputs
110   CeedVector *qvecsin;    // Input Q-vectors needed to apply operator
111   CeedVector *qvecsout;   // Output Q-vectors needed to apply operator
112   CeedInt    numein;
113   CeedInt    numeout;
114   CeedInt    qfnumactivein, qfnumactiveout;
115   CeedVector *qfactivein;
116   CeedOperatorDiag_Cuda *diag;
117 } CeedOperator_Cuda;
118 
119 CEED_INTERN int CeedCudaGetCublasHandle(Ceed ceed, cublasHandle_t *handle);
120 
121 CEED_INTERN int CeedVectorCreate_Cuda(CeedInt n, CeedVector vec);
122 
123 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mtype,
124     CeedCopyMode cmode, const CeedInt *indices, CeedElemRestriction r);
125 
126 CEED_INTERN int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType mtype,
127     const CeedCopyMode cmode, const CeedInt *indices,
128     const CeedElemRestriction res);
129 
130 CEED_INTERN int CeedBasisApplyElems_Cuda(CeedBasis basis, const CeedInt nelem,
131     CeedTransposeMode tmode, CeedEvalMode emode, const CeedVector u, CeedVector v);
132 
133 CEED_INTERN int CeedQFunctionApplyElems_Cuda(CeedQFunction qf, const CeedInt Q,
134     const CeedVector *const u, const CeedVector *v);
135 
136 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P1d,
137     CeedInt Q1d,
138     const CeedScalar *interp1d,
139     const CeedScalar *grad1d,
140     const CeedScalar *qref1d,
141     const CeedScalar *qweight1d,
142     CeedBasis basis);
143 
144 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology, CeedInt, CeedInt,
145                                        CeedInt, const CeedScalar *,
146                                        const CeedScalar *, const CeedScalar *,
147                                        const CeedScalar *, CeedBasis);
148 
149 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf);
150 
151 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx);
152 
153 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op);
154 
155 CEED_INTERN int CeedCompositeOperatorCreate_Cuda(CeedOperator op);
156 #endif
157