xref: /libCEED/include/ceed-impl.h (revision be9261b744a4f5557a9c58123cb6ee5694c9a713)
1 // Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3 // reserved. See files LICENSE and NOTICE for details.
4 //
5 // This file is part of CEED, a collection of benchmarks, miniapps, software
6 // libraries and APIs for efficient high-order finite element and spectral
7 // element discretizations for exascale applications. For more information and
8 // source code availability see http://github.com/ceed.
9 //
10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11 // a collaborative effort of two U.S. Department of Energy organizations (Office
12 // of Science and the National Nuclear Security Administration) responsible for
13 // the planning and preparation of a capable exascale ecosystem, including
14 // software, applications, hardware, advanced system engineering and early
15 // testbed platforms, in support of the nation's exascale computing imperative.
16 
17 /// @file
18 /// Private header for frontend components of libCEED
19 #ifndef _ceed_impl_h
20 #define _ceed_impl_h
21 
22 #include <ceed.h>
23 #include <ceed-backend.h>
24 #include <stdbool.h>
25 
26 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden")))
27 
28 #define CEED_MAX_RESOURCE_LEN 1024
29 #define CEED_ALIGN 64
30 
31 #define CEED_NUM_BACKEND_FUNCTIONS 31
32 #define CEED_COMPOSITE_MAX 16
33 
34 // Lookup table field for backend functions
35 typedef struct {
36   const char *fname;
37   size_t offset;
38 } foffset;
39 
40 struct Ceed_private {
41   Ceed delegate;
42   Ceed parent;
43   int (*Error)(Ceed, const char *, int, const char *, int, const char *,
44                va_list);
45   int (*GetPreferredMemType)(CeedMemType *);
46   int (*Destroy)(Ceed);
47   int (*VecCreate)(CeedInt, CeedVector);
48   int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode,
49                                const CeedInt *, CeedElemRestriction);
50   int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode,
51                                       const CeedInt *, CeedElemRestriction);
52   int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *,
53                              const CeedScalar *, const CeedScalar *,
54                              const CeedScalar *, CeedBasis);
55   int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt,
56                        const CeedScalar *,
57                        const CeedScalar *, const CeedScalar *,
58                        const CeedScalar *, CeedBasis);
59   int (*TensorContractCreate)(CeedBasis, CeedTensorContract);
60   int (*QFunctionCreate)(CeedQFunction);
61   int (*OperatorCreate)(CeedOperator);
62   int (*CompositeOperatorCreate)(CeedOperator);
63   int refcount;
64   void *data;
65   foffset foffsets[CEED_NUM_BACKEND_FUNCTIONS];
66 };
67 
68 struct CeedVector_private {
69   Ceed ceed;
70   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
71   int (*SetValue)(CeedVector, CeedScalar);
72   int (*SyncArray)(CeedVector, CeedMemType);
73   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
74   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
75   int (*RestoreArray)(CeedVector);
76   int (*RestoreArrayRead)(CeedVector);
77   int (*Destroy)(CeedVector);
78   int refcount;
79   CeedInt length;
80   uint64_t state;
81   uint64_t numreaders;
82   void *data;
83 };
84 
85 struct CeedElemRestriction_private {
86   Ceed ceed;
87   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode,
88                CeedVector, CeedVector, CeedRequest *);
89   int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode,
90                     CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
91   int (*Destroy)(CeedElemRestriction);
92   int refcount;
93   CeedInt nelem;    /* number of elements */
94   CeedInt elemsize; /* number of dofs per element */
95   CeedInt ndof;     /* size of the L-vector, can be used for checking for
96                       correct vector sizes */
97   CeedInt ncomp;    /* number of components */
98   CeedInt blksize;  /* number of elements in a batch */
99   CeedInt nblk;     /* number of blocks of elements */
100   void *data;       /* place for the backend to store any data */
101 };
102 
103 struct CeedBasis_private {
104   Ceed ceed;
105   int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode,
106                CeedVector, CeedVector);
107   int (*Destroy)(CeedBasis);
108   int refcount;
109   bool tensorbasis;      /* flag for tensor basis */
110   CeedInt dim;           /* topological dimension */
111   CeedInt ncomp;         /* number of field components (1 for scalar fields) */
112   CeedInt P1d;           /* number of nodes in one dimension */
113   CeedInt Q1d;           /* number of quadrature points in one dimension */
114   CeedInt P;             /* total number of nodes */
115   CeedInt Q;             /* total number of quadrature points */
116   CeedScalar *qref1d;    /* Array of length Q1d holding the locations of
117                             quadrature points on the 1D reference element [-1, 1] */
118   CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on
119                             the reference element */
120   CeedScalar
121   *interp1d;  /* row-major matrix of shape [Q1d, P1d] expressing the values of
122                             nodal basis functions at quadrature points */
123   CeedScalar
124   *grad1d;    /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of
125                             nodal basis functions at quadrature points */
126   CeedTensorContract contract; /* tensor contraction object */
127   void *data;            /* place for the backend to store any data */
128 };
129 
130 struct CeedTensorContract_private {
131   Ceed ceed;
132   int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt,
133                const CeedScalar *restrict, CeedTransposeMode, const CeedInt,
134                const CeedScalar *restrict, CeedScalar *restrict);
135   int (*Destroy)(CeedTensorContract);
136   int refcount;
137   void *data;
138 };
139 
140 struct CeedQFunctionField_private {
141   const char *fieldname;
142   CeedInt ncomp;
143   CeedEvalMode emode;
144 };
145 
146 struct CeedQFunction_private {
147   Ceed ceed;
148   int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *);
149   int (*Destroy)(CeedQFunction);
150   int refcount;
151   CeedInt vlength;    // Number of quadrature points must be padded to a multiple of vlength
152   CeedQFunctionField *inputfields;
153   CeedQFunctionField *outputfields;
154   CeedInt numinputfields, numoutputfields;
155   CeedQFunctionUser function;
156   const char *focca;
157   bool fortranstatus;
158   void *ctx;      /* user context for function */
159   size_t ctxsize; /* size of user context; may be used to copy to a device */
160   void *data;     /* backend data */
161 };
162 
163 /// Struct to handle the context data to use the Fortran QFunction stub
164 /// @ingroup CeedQFunction
165 typedef struct {
166   CeedScalar *innerctx;
167   size_t innerctxsize;
168   void (*f)(void *ctx, int *nq,
169             const CeedScalar *u,const CeedScalar *u1,
170             const CeedScalar *u2,const CeedScalar *u3,
171             const CeedScalar *u4,const CeedScalar *u5,
172             const CeedScalar *u6,const CeedScalar *u7,
173             const CeedScalar *u8,const CeedScalar *u9,
174             const CeedScalar *u10,const CeedScalar *u11,
175             const CeedScalar *u12,const CeedScalar *u13,
176             const CeedScalar *u14,const CeedScalar *u15,
177             CeedScalar *v,CeedScalar *v1,CeedScalar *v2,
178             CeedScalar *v3,CeedScalar *v4,CeedScalar *v5,
179             CeedScalar *v6,CeedScalar *v7,CeedScalar *v8,
180             CeedScalar *v9, CeedScalar *v10,CeedScalar *v11,
181             CeedScalar *v12,CeedScalar *v13,CeedScalar *v14,
182             CeedScalar *v15, int *err);
183 } fContext;
184 
185 struct CeedOperatorField_private {
186   CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity
187   CeedTransposeMode lmode;       /// Transpose mode for lvector ordering
188   CeedBasis basis;               /// Basis or NULL for collocated fields
189   CeedVector
190   vec;                /// State vector for passive fields, NULL for active fields
191 };
192 
193 struct CeedOperator_private {
194   Ceed ceed;
195   int refcount;
196   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
197   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
198                        CeedVector, CeedRequest *);
199   int (*Destroy)(CeedOperator);
200   CeedOperatorField *inputfields;
201   CeedOperatorField *outputfields;
202   CeedInt numelements; /// Number of elements
203   CeedInt numqpoints;  /// Number of quadrature points over all elements
204   CeedInt nfields;     /// Number of fields that have been set
205   CeedQFunction qf;
206   CeedQFunction dqf;
207   CeedQFunction dqfT;
208   bool setupdone;
209   bool composite;
210   CeedOperator *suboperators;
211   CeedInt numsub;
212   void *data;
213 };
214 
215 CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int,
216                                 const char *, va_list);
217 CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int,
218                                const char *, va_list);
219 CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int,
220                               const char *, va_list);
221 CEED_INTERN int CeedSetErrorHandler(Ceed ceed,
222                                     int (eh)(Ceed, const char *, int,
223                                         const char *, int, const char *,
224                                         va_list));
225 
226 #endif
227