xref: /libCEED/backends/cuda-ref/ceed-cuda-ref.h (revision 58c07c4fa7bdba34c2b29fbdcd58893d48c3fd9e)
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           basis_in, basis_out;
86   CeedElemRestriction diag_rstr, point_block_rstr;
87   CeedVector          elem_diag, point_block_elem_diag;
88   CeedInt             num_e_mode_in, num_e_mode_out, num_nodes;
89   CeedEvalMode       *h_e_mode_in, *h_e_mode_out;
90   CeedEvalMode       *d_e_mode_in, *d_e_mode_out;
91   CeedScalar         *d_identity, *d_interp_in, *d_interp_out, *d_grad_in, *d_grad_out;
92 } CeedOperatorDiag_Cuda;
93 
94 typedef struct {
95   CUmodule    module;
96   CUfunction  linearAssemble;
97   CeedInt     num_elem, block_size_x, block_size_y, elem_per_block;
98   CeedScalar *d_B_in, *d_B_out;
99 } CeedOperatorAssemble_Cuda;
100 
101 typedef struct {
102   CeedVector                *e_vecs;      // E-vectors, inputs followed by outputs
103   CeedVector                *q_vecs_in;   // Input Q-vectors needed to apply operator
104   CeedVector                *q_vecs_out;  // Output Q-vectors needed to apply operator
105   CeedInt                    num_inputs, num_outputs;
106   CeedInt                    num_active_in, num_active_out;
107   CeedVector                *qf_active_in;
108   CeedOperatorDiag_Cuda     *diag;
109   CeedOperatorAssemble_Cuda *asmb;
110 } CeedOperator_Cuda;
111 
112 CEED_INTERN int CeedGetCublasHandle_Cuda(Ceed ceed, cublasHandle_t *handle);
113 
114 CEED_INTERN int CeedVectorCreate_Cuda(CeedSize n, CeedVector vec);
115 
116 CEED_INTERN int CeedElemRestrictionCreate_Cuda(CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *indices, const bool *orients,
117                                                const CeedInt8 *curl_orients, CeedElemRestriction r);
118 
119 CEED_INTERN int CeedBasisCreateTensorH1_Cuda(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d,
120                                              const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis);
121 
122 CEED_INTERN int CeedBasisCreateH1_Cuda(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp,
123                                        const CeedScalar *grad, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis);
124 
125 CEED_INTERN int CeedQFunctionCreate_Cuda(CeedQFunction qf);
126 
127 CEED_INTERN int CeedQFunctionContextCreate_Cuda(CeedQFunctionContext ctx);
128 
129 CEED_INTERN int CeedOperatorCreate_Cuda(CeedOperator op);
130 
131 #endif  // CEED_CUDA_REF_H
132