xref: /libCEED/rust/libceed-sys/c-src/backends/cuda-ref/ceed-cuda-ref.h (revision 437930d19388999b5cc2d76e2fe0d14f58fb41f3)
10d0321e0SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
20d0321e0SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
30d0321e0SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details.
40d0321e0SJeremy L Thompson //
50d0321e0SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software
60d0321e0SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral
70d0321e0SJeremy L Thompson // element discretizations for exascale applications. For more information and
80d0321e0SJeremy L Thompson // source code availability see http://github.com/ceed.
90d0321e0SJeremy L Thompson //
100d0321e0SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
110d0321e0SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office
120d0321e0SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for
130d0321e0SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including
140d0321e0SJeremy L Thompson // software, applications, hardware, advanced system engineering and early
150d0321e0SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative.
160d0321e0SJeremy L Thompson 
170d0321e0SJeremy L Thompson #ifndef _ceed_cuda_h
180d0321e0SJeremy L Thompson #define _ceed_cuda_h
190d0321e0SJeremy L Thompson 
200d0321e0SJeremy L Thompson #include <ceed/ceed.h>
210d0321e0SJeremy L Thompson #include <ceed/backend.h>
220d0321e0SJeremy L Thompson #include <cuda.h>
230d0321e0SJeremy L Thompson #include "../cuda/ceed-cuda-common.h"
240d0321e0SJeremy L Thompson 
250d0321e0SJeremy L Thompson typedef struct {
260d0321e0SJeremy L Thompson   CeedScalar *h_array;
270d0321e0SJeremy L Thompson   CeedScalar *h_array_borrowed;
280d0321e0SJeremy L Thompson   CeedScalar *h_array_owned;
290d0321e0SJeremy L Thompson   CeedScalar *d_array;
300d0321e0SJeremy L Thompson   CeedScalar *d_array_borrowed;
310d0321e0SJeremy L Thompson   CeedScalar *d_array_owned;
320d0321e0SJeremy L Thompson } CeedVector_Cuda;
330d0321e0SJeremy L Thompson 
340d0321e0SJeremy L Thompson typedef struct {
350d0321e0SJeremy L Thompson   CUmodule module;
36*437930d1SJeremy L Thompson   CUfunction StridedTranspose;
37*437930d1SJeremy L Thompson   CUfunction StridedNoTranspose;
38*437930d1SJeremy L Thompson   CUfunction OffsetTranspose;
39*437930d1SJeremy L Thompson   CUfunction OffsetNoTranspose;
40*437930d1SJeremy L Thompson   CeedInt num_nodes;
410d0321e0SJeremy L Thompson   CeedInt *h_ind;
420d0321e0SJeremy L Thompson   CeedInt *h_ind_allocated;
430d0321e0SJeremy L Thompson   CeedInt *d_ind;
440d0321e0SJeremy L Thompson   CeedInt *d_ind_allocated;
45*437930d1SJeremy L Thompson   CeedInt *d_t_offsets;
46*437930d1SJeremy L Thompson   CeedInt *d_t_indices;
47*437930d1SJeremy L Thompson   CeedInt *d_l_vec_indices;
480d0321e0SJeremy L Thompson } CeedElemRestriction_Cuda;
490d0321e0SJeremy L Thompson 
50*437930d1SJeremy L Thompson typedef struct {
51*437930d1SJeremy L Thompson   CUmodule module;
52*437930d1SJeremy L Thompson   CUfunction Interp;
53*437930d1SJeremy L Thompson   CUfunction Grad;
54*437930d1SJeremy L Thompson   CUfunction Weight;
55*437930d1SJeremy L Thompson   CeedScalar *d_interp_1d;
56*437930d1SJeremy L Thompson   CeedScalar *d_grad_1d;
57*437930d1SJeremy L Thompson   CeedScalar *d_q_weight_1d;
58*437930d1SJeremy L Thompson } CeedBasis_Cuda;
59*437930d1SJeremy L Thompson 
60*437930d1SJeremy L Thompson typedef struct {
61*437930d1SJeremy L Thompson   CUmodule module;
62*437930d1SJeremy L Thompson   CUfunction Interp;
63*437930d1SJeremy L Thompson   CUfunction Grad;
64*437930d1SJeremy L Thompson   CUfunction Weight;
65*437930d1SJeremy L Thompson   CeedScalar *d_interp;
66*437930d1SJeremy L Thompson   CeedScalar *d_grad;
67*437930d1SJeremy L Thompson   CeedScalar *d_q_weight;
68*437930d1SJeremy L Thompson } CeedBasisNonTensor_Cuda;
69*437930d1SJeremy L Thompson 
700d0321e0SJeremy L Thompson // We use a struct to avoid having to memCpy the array of pointers
710d0321e0SJeremy L Thompson // __global__ copies by value the struct.
720d0321e0SJeremy L Thompson typedef struct {
730d0321e0SJeremy L Thompson   const CeedScalar *inputs[CEED_FIELD_MAX];
740d0321e0SJeremy L Thompson   CeedScalar *outputs[CEED_FIELD_MAX];
750d0321e0SJeremy L Thompson } Fields_Cuda;
760d0321e0SJeremy L Thompson 
770d0321e0SJeremy L Thompson typedef struct {
780d0321e0SJeremy L Thompson   CUmodule module;
79*437930d1SJeremy L Thompson   char *qfunction_name;
80*437930d1SJeremy L Thompson   char *qfunction_source;
81*437930d1SJeremy L Thompson   CUfunction QFunction;
820d0321e0SJeremy L Thompson   Fields_Cuda fields;
830d0321e0SJeremy L Thompson   void *d_c;
840d0321e0SJeremy L Thompson } CeedQFunction_Cuda;
850d0321e0SJeremy L Thompson 
860d0321e0SJeremy L Thompson typedef struct {
870d0321e0SJeremy L Thompson   void *h_data;
880d0321e0SJeremy L Thompson   void *h_data_borrowed;
890d0321e0SJeremy L Thompson   void *h_data_owned;
900d0321e0SJeremy L Thompson   void *d_data;
910d0321e0SJeremy L Thompson   void *d_data_borrowed;
920d0321e0SJeremy L Thompson   void *d_data_owned;
930d0321e0SJeremy L Thompson } CeedQFunctionContext_Cuda;
940d0321e0SJeremy L Thompson 
950d0321e0SJeremy L Thompson typedef struct {
960d0321e0SJeremy L Thompson   CUmodule module;
970d0321e0SJeremy L Thompson   CUfunction linearDiagonal;
980d0321e0SJeremy L Thompson   CUfunction linearPointBlock;
990d0321e0SJeremy L Thompson   CeedBasis basisin, basisout;
1000d0321e0SJeremy L Thompson   CeedElemRestriction diagrstr, pbdiagrstr;
1010d0321e0SJeremy L Thompson   CeedVector elemdiag, pbelemdiag;
1020d0321e0SJeremy L Thompson   CeedInt numemodein, numemodeout, nnodes;
1030d0321e0SJeremy L Thompson   CeedEvalMode *h_emodein, *h_emodeout;
1040d0321e0SJeremy L Thompson   CeedEvalMode *d_emodein, *d_emodeout;
1050d0321e0SJeremy L Thompson   CeedScalar *d_identity, *d_interpin, *d_interpout, *d_gradin, *d_gradout;
1060d0321e0SJeremy L Thompson } CeedOperatorDiag_Cuda;
1070d0321e0SJeremy L Thompson 
1080d0321e0SJeremy L Thompson typedef struct {
1090d0321e0SJeremy L Thompson   CeedVector *evecs;   // E-vectors, inputs followed by outputs
1100d0321e0SJeremy L Thompson   CeedVector *qvecsin;    // Input Q-vectors needed to apply operator
1110d0321e0SJeremy L Thompson   CeedVector *qvecsout;   // Output Q-vectors needed to apply operator
1120d0321e0SJeremy L Thompson   CeedInt    numein;
1130d0321e0SJeremy L Thompson   CeedInt    numeout;
1140d0321e0SJeremy L Thompson   CeedInt    qfnumactivein, qfnumactiveout;
1150d0321e0SJeremy L Thompson   CeedVector *qfactivein;
1160d0321e0SJeremy L Thompson   CeedOperatorDiag_Cuda *diag;
1170d0321e0SJeremy L Thompson } CeedOperator_Cuda;
1180d0321e0SJeremy L Thompson 
1190d0321e0SJeremy L Thompson CEED_INTERN int CeedCudaGetCublasHandle(Ceed ceed, cublasHandle_t *handle);
1200d0321e0SJeremy L Thompson 
1210d0321e0SJeremy L Thompson CEED_INTERN int CeedVectorCreate_Cuda(CeedInt n, CeedVector vec);
1220d0321e0SJeremy L Thompson 
123*437930d1SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type,
124*437930d1SJeremy L Thompson     CeedCopyMode copy_mode, const CeedInt *indices, CeedElemRestriction r);
1250d0321e0SJeremy L Thompson 
126*437930d1SJeremy L Thompson CEED_INTERN int CeedElemRestrictionCreateBlocked_Cuda(const CeedMemType
127*437930d1SJeremy L Thompson     mem_type,
128*437930d1SJeremy L Thompson     const CeedCopyMode copy_mode, const CeedInt *indices,
1290d0321e0SJeremy L Thompson     const CeedElemRestriction res);
1300d0321e0SJeremy L Thompson 
131*437930d1SJeremy L Thompson CEED_INTERN int CeedBasisApplyElems_Cuda(CeedBasis basis,
132*437930d1SJeremy L Thompson     const CeedInt num_elem,
133*437930d1SJeremy L Thompson     CeedTransposeMode t_mode, CeedEvalMode eval_mode, const CeedVector u,
134*437930d1SJeremy L Thompson     CeedVector v);
1350d0321e0SJeremy L Thompson 
1360d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionApplyElems_Cuda(CeedQFunction qf, const CeedInt Q,
1370d0321e0SJeremy L Thompson     const CeedVector *const u, const CeedVector *v);
1380d0321e0SJeremy L Thompson 
139*437930d1SJeremy L Thompson CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d,
140*437930d1SJeremy L Thompson     CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
141*437930d1SJeremy L Thompson     const CeedScalar *qref_1d, const CeedScalar *qweight_1d, CeedBasis basis);
1420d0321e0SJeremy L Thompson 
1430d0321e0SJeremy L Thompson CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology, CeedInt, CeedInt,
1440d0321e0SJeremy L Thompson                                        CeedInt, const CeedScalar *,
1450d0321e0SJeremy L Thompson                                        const CeedScalar *, const CeedScalar *,
1460d0321e0SJeremy L Thompson                                        const CeedScalar *, CeedBasis);
1470d0321e0SJeremy L Thompson 
1480d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf);
1490d0321e0SJeremy L Thompson 
1500d0321e0SJeremy L Thompson CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx);
1510d0321e0SJeremy L Thompson 
1520d0321e0SJeremy L Thompson CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op);
1530d0321e0SJeremy L Thompson 
1540d0321e0SJeremy L Thompson CEED_INTERN int CeedCompositeOperatorCreate_Cuda(CeedOperator op);
1550d0321e0SJeremy L Thompson #endif
156