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