xref: /libCEED/backends/cuda-ref/ceed-cuda-ref.h (revision 30e1b2c7fb15f28dd172201f6d9e657bf5f698ea)
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 ApplyNoTranspose, ApplyTranspose;
29   CUfunction ApplyUnsignedNoTranspose, ApplyUnsignedTranspose;
30   CUfunction ApplyUnorientedNoTranspose, ApplyUnorientedTranspose;
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   bool      *h_orients;
40   bool      *h_orients_allocated;
41   bool      *d_orients;
42   bool      *d_orients_allocated;
43   CeedInt8  *h_curl_orients;
44   CeedInt8  *h_curl_orients_allocated;
45   CeedInt8  *d_curl_orients;
46   CeedInt8  *d_curl_orients_allocated;
47 } CeedElemRestriction_Cuda;
48 
49 typedef struct {
50   CUmodule    module;
51   CUfunction  Interp;
52   CUfunction  Grad;
53   CUfunction  Weight;
54   CeedScalar *d_interp_1d;
55   CeedScalar *d_grad_1d;
56   CeedScalar *d_q_weight_1d;
57 } CeedBasis_Cuda;
58 
59 typedef struct {
60   CUmodule    module;
61   CUfunction  Interp;
62   CUfunction  InterpTranspose;
63   CUfunction  Deriv;
64   CUfunction  DerivTranspose;
65   CUfunction  Weight;
66   CeedScalar *d_interp;
67   CeedScalar *d_grad;
68   CeedScalar *d_div;
69   CeedScalar *d_curl;
70   CeedScalar *d_q_weight;
71 } CeedBasisNonTensor_Cuda;
72 
73 typedef struct {
74   CUmodule    module;
75   char       *qfunction_name;
76   char       *qfunction_source;
77   CUfunction  QFunction;
78   Fields_Cuda fields;
79   void       *d_c;
80 } CeedQFunction_Cuda;
81 
82 typedef struct {
83   void *h_data;
84   void *h_data_borrowed;
85   void *h_data_owned;
86   void *d_data;
87   void *d_data_borrowed;
88   void *d_data_owned;
89 } CeedQFunctionContext_Cuda;
90 
91 typedef struct {
92   CUmodule            module, module_point_block;
93   CUfunction          LinearDiagonal;
94   CUfunction          LinearPointBlock;
95   CeedElemRestriction diag_rstr, point_block_diag_rstr;
96   CeedVector          elem_diag, point_block_elem_diag;
97   CeedEvalMode       *d_eval_modes_in, *d_eval_modes_out;
98   CeedScalar         *d_identity, *d_interp_in, *d_grad_in, *d_div_in, *d_curl_in;
99   CeedScalar         *d_interp_out, *d_grad_out, *d_div_out, *d_curl_out;
100 } CeedOperatorDiag_Cuda;
101 
102 typedef struct {
103   CUmodule    module;
104   CUfunction  LinearAssemble;
105   CeedInt     block_size_x, block_size_y, elems_per_block;
106   CeedScalar *d_B_in, *d_B_out;
107 } CeedOperatorAssemble_Cuda;
108 
109 typedef struct {
110   CeedVector                *e_vecs;      // E-vectors, inputs followed by outputs
111   CeedVector                *q_vecs_in;   // Input Q-vectors needed to apply operator
112   CeedVector                *q_vecs_out;  // Output Q-vectors needed to apply operator
113   CeedInt                    num_inputs, num_outputs;
114   CeedInt                    num_active_in, num_active_out;
115   CeedVector                *qf_active_in;
116   CeedOperatorDiag_Cuda     *diag;
117   CeedOperatorAssemble_Cuda *asmb;
118 } CeedOperator_Cuda;
119 
120 CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle);
121 
122 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec);
123 
124 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
125                                                const CeedInt8 *curl_orients, CeedElemRestriction r);
126 
127 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
128                                              const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
129 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
130                                        const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
131 CEED_INTERN int CeedBasisCreateHdiv_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
132                                          const CeedScalar *div, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
133 CEED_INTERN int CeedBasisCreateHcurl_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
134                                           const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
135 
136 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf);
137 
138 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx);
139 
140 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op);
141 
142 #endif  // CEED_CUDA_REF_H
143