xref: /libCEED/include/ceed-impl.h (revision b52ddc881635b5ddd815835d5b96cf895d69f1e6)
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_COMPOSITE_MAX 16
32 
33 // Lookup table field for backend functions
34 typedef struct {
35   const char *fname;
36   size_t offset;
37 } foffset;
38 
39 // Lookup table field for object delegates
40 typedef struct {
41   char *objname;
42   Ceed delegate;
43 } objdelegate;
44 
45 struct Ceed_private {
46   Ceed delegate;
47   Ceed parent;
48   objdelegate *objdelegates;
49   int objdelegatecount;
50   int (*Error)(Ceed, const char *, int, const char *, int, const char *,
51                va_list);
52   int (*GetPreferredMemType)(CeedMemType *);
53   int (*Destroy)(Ceed);
54   int (*VectorCreate)(CeedInt, CeedVector);
55   int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode,
56                                const CeedInt *, CeedElemRestriction);
57   int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode,
58                                       const CeedInt *, CeedElemRestriction);
59   int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *,
60                              const CeedScalar *, const CeedScalar *,
61                              const CeedScalar *, CeedBasis);
62   int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt,
63                        const CeedScalar *,
64                        const CeedScalar *, const CeedScalar *,
65                        const CeedScalar *, CeedBasis);
66   int (*TensorContractCreate)(CeedBasis, CeedTensorContract);
67   int (*QFunctionCreate)(CeedQFunction);
68   int (*OperatorCreate)(CeedOperator);
69   int (*CompositeOperatorCreate)(CeedOperator);
70   int refcount;
71   void *data;
72   foffset *foffsets;
73 };
74 
75 struct CeedVector_private {
76   Ceed ceed;
77   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
78   int (*SetValue)(CeedVector, CeedScalar);
79   int (*SyncArray)(CeedVector, CeedMemType);
80   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
81   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
82   int (*RestoreArray)(CeedVector);
83   int (*RestoreArrayRead)(CeedVector);
84   int (*Destroy)(CeedVector);
85   int refcount;
86   CeedInt length;
87   uint64_t state;
88   uint64_t numreaders;
89   void *data;
90 };
91 
92 struct CeedElemRestriction_private {
93   Ceed ceed;
94   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode,
95                CeedVector, CeedVector, CeedRequest *);
96   int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode,
97                     CeedTransposeMode, CeedVector, CeedVector, CeedRequest *);
98   int (*Destroy)(CeedElemRestriction);
99   int refcount;
100   CeedInt nelem;    /* number of elements */
101   CeedInt elemsize; /* number of nodes per element */
102   CeedInt nnodes;   /* size of the L-vector, can be used for checking for
103                       correct vector sizes */
104   CeedInt ncomp;    /* number of components */
105   CeedInt blksize;  /* number of elements in a batch */
106   CeedInt nblk;     /* number of blocks of elements */
107   void *data;       /* place for the backend to store any data */
108 };
109 
110 struct CeedBasis_private {
111   Ceed ceed;
112   int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode,
113                CeedVector, CeedVector);
114   int (*Destroy)(CeedBasis);
115   int refcount;
116   bool tensorbasis;      /* flag for tensor basis */
117   CeedInt dim;           /* topological dimension */
118   CeedInt ncomp;         /* number of field components (1 for scalar fields) */
119   CeedInt P1d;           /* number of nodes in one dimension */
120   CeedInt Q1d;           /* number of quadrature points in one dimension */
121   CeedInt P;             /* total number of nodes */
122   CeedInt Q;             /* total number of quadrature points */
123   CeedScalar *qref1d;    /* Array of length Q1d holding the locations of
124                             quadrature points on the 1D reference element [-1, 1] */
125   CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on
126                             the reference element */
127   CeedScalar
128   *interp1d;  /* row-major matrix of shape [Q1d, P1d] expressing the values of
129                             nodal basis functions at quadrature points */
130   CeedScalar
131   *grad1d;    /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of
132                             nodal basis functions at quadrature points */
133   CeedTensorContract contract; /* tensor contraction object */
134   void *data;            /* place for the backend to store any data */
135 };
136 
137 struct CeedTensorContract_private {
138   Ceed ceed;
139   int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt,
140                const CeedScalar *restrict, CeedTransposeMode, const CeedInt,
141                const CeedScalar *restrict, CeedScalar *restrict);
142   int (*Destroy)(CeedTensorContract);
143   int refcount;
144   void *data;
145 };
146 
147 struct CeedQFunctionField_private {
148   const char *fieldname;
149   CeedInt ncomp;
150   CeedEvalMode emode;
151 };
152 
153 struct CeedQFunction_private {
154   Ceed ceed;
155   int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *);
156   int (*Destroy)(CeedQFunction);
157   int refcount;
158   CeedInt vlength;    // Number of quadrature points must be padded to a multiple of vlength
159   CeedQFunctionField *inputfields;
160   CeedQFunctionField *outputfields;
161   CeedInt numinputfields, numoutputfields;
162   CeedQFunctionUser function;
163   const char *focca;
164   bool fortranstatus;
165   void *ctx;      /* user context for function */
166   size_t ctxsize; /* size of user context; may be used to copy to a device */
167   void *data;     /* backend data */
168 };
169 
170 /// Struct to handle the context data to use the Fortran QFunction stub
171 /// @ingroup CeedQFunction
172 typedef struct {
173   CeedScalar *innerctx;
174   size_t innerctxsize;
175   void (*f)(void *ctx, int *nq,
176             const CeedScalar *u,const CeedScalar *u1,
177             const CeedScalar *u2,const CeedScalar *u3,
178             const CeedScalar *u4,const CeedScalar *u5,
179             const CeedScalar *u6,const CeedScalar *u7,
180             const CeedScalar *u8,const CeedScalar *u9,
181             const CeedScalar *u10,const CeedScalar *u11,
182             const CeedScalar *u12,const CeedScalar *u13,
183             const CeedScalar *u14,const CeedScalar *u15,
184             CeedScalar *v,CeedScalar *v1,CeedScalar *v2,
185             CeedScalar *v3,CeedScalar *v4,CeedScalar *v5,
186             CeedScalar *v6,CeedScalar *v7,CeedScalar *v8,
187             CeedScalar *v9, CeedScalar *v10,CeedScalar *v11,
188             CeedScalar *v12,CeedScalar *v13,CeedScalar *v14,
189             CeedScalar *v15, int *err);
190 } fContext;
191 
192 struct CeedOperatorField_private {
193   CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity
194   CeedTransposeMode lmode;       /// Transpose mode for lvector ordering
195   CeedBasis basis;               /// Basis or NULL for collocated fields
196   CeedVector
197   vec;                /// State vector for passive fields, NULL for active fields
198 };
199 
200 struct CeedOperator_private {
201   Ceed ceed;
202   int refcount;
203   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *);
204   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
205                        CeedVector, CeedRequest *);
206   int (*Destroy)(CeedOperator);
207   CeedOperatorField *inputfields;
208   CeedOperatorField *outputfields;
209   CeedInt numelements; /// Number of elements
210   CeedInt numqpoints;  /// Number of quadrature points over all elements
211   CeedInt nfields;     /// Number of fields that have been set
212   CeedQFunction qf;
213   CeedQFunction dqf;
214   CeedQFunction dqfT;
215   bool setupdone;
216   bool composite;
217   CeedOperator *suboperators;
218   CeedInt numsub;
219   void *data;
220 };
221 
222 CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int,
223                                 const char *, va_list);
224 CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int,
225                                const char *, va_list);
226 CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int,
227                               const char *, va_list);
228 CEED_INTERN int CeedSetErrorHandler(Ceed ceed,
229                                     int (eh)(Ceed, const char *, int,
230                                         const char *, int, const char *,
231                                         va_list));
232 
233 #endif
234