xref: /libCEED/backends/cuda-ref/ceed-cuda-ref.h (revision 94b7b29b41ad8a17add4c577886859ef16f89dec)
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_REF_H
9 #define CEED_CUDA_REF_H
10 
11 #include <ceed.h>
12 #include <ceed/backend.h>
13 #include <ceed/jit-source/cuda/cuda-types.h>
14 #include <cublas_v2.h>
15 #include <cuda.h>
16 
17 typedef struct {
18   CeedScalar *h_array;
19   CeedScalar *h_array_borrowed;
20   CeedScalar *h_array_owned;
21   CeedScalar *d_array;
22   CeedScalar *d_array_borrowed;
23   CeedScalar *d_array_owned;
24 } CeedVector_Cuda;
25 
26 typedef struct {
27   CUmodule   module;
28   CUfunction StridedNoTranspose;
29   CUfunction StridedTranspose;
30   CUfunction OffsetNoTranspose;
31   CUfunction OffsetTranspose;
32   CUfunction OffsetTransposeDet;
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_Cuda;
42 
43 typedef struct {
44   CUmodule    module;
45   CUfunction  Interp;
46   CUfunction  Grad;
47   CUfunction  Weight;
48   CeedScalar *d_interp_1d;
49   CeedScalar *d_grad_1d;
50   CeedScalar *d_q_weight_1d;
51 } CeedBasis_Cuda;
52 
53 typedef struct {
54   CUmodule    module;
55   CUfunction  Interp;
56   CUfunction  Grad;
57   CUfunction  Weight;
58   CeedScalar *d_interp;
59   CeedScalar *d_grad;
60   CeedScalar *d_q_weight;
61 } CeedBasisNonTensor_Cuda;
62 
63 typedef struct {
64   CUmodule    module;
65   char       *qfunction_name;
66   char       *qfunction_source;
67   CUfunction  QFunction;
68   Fields_Cuda fields;
69   void       *d_c;
70 } CeedQFunction_Cuda;
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_Cuda;
80 
81 typedef struct {
82   CUmodule            module;
83   CUfunction          linearDiagonal;
84   CUfunction          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_Cuda;
93 
94 typedef struct {
95   CUmodule    module;
96   CUfunction  linearAssemble;
97   CeedInt     nelem, block_size_x, block_size_y, elemsPerBlock;
98   CeedScalar *d_B_in, *d_B_out;
99 } CeedOperatorAssemble_Cuda;
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_Cuda     *diag;
110   CeedOperatorAssemble_Cuda *asmb;
111 } CeedOperator_Cuda;
112 
113 CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle);
114 
115 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec);
116 
117 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
118                                                const CeedInt8 *curl_orients, CeedElemRestriction r);
119 
120 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
121                                              const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
122 
123 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
124                                        const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
125 
126 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf);
127 
128 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx);
129 
130 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op);
131 
132 #endif  // CEED_CUDA_REF_H
133