xref: /libCEED/include/ceed-impl.h (revision a5ba6ca96fbccf36e4bea16e68ef8362b5268962)
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 #ifndef _ceed_impl_h
18 #define _ceed_impl_h
19 
20 #include <ceed.h>
21 
22 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden")))
23 
24 #define CEED_MAX_RESOURCE_LEN 1024
25 #define CEED_ALIGN 64
26 
27 struct Ceed_private {
28   int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list);
29   int (*Destroy)(Ceed);
30   int (*VecCreate)(Ceed, CeedInt, CeedVector);
31   int (*ElemRestrictionCreate)(CeedElemRestriction, CeedMemType, CeedCopyMode,
32                                const CeedInt *);
33   int (*BasisCreateTensorH1)(Ceed, CeedInt, CeedInt, CeedInt, const CeedScalar *,
34                              const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis);
35   int (*QFunctionCreate)(CeedQFunction);
36   int (*OperatorCreate)(CeedOperator);
37   void *data;
38 };
39 
40 /* In the next 3 functions, p has to be the address of a pointer type, i.e. p
41    has to be a pointer to a pointer. */
42 CEED_INTERN int CeedMallocArray(size_t n, size_t unit, void *p);
43 CEED_INTERN int CeedCallocArray(size_t n, size_t unit, void *p);
44 CEED_INTERN int CeedReallocArray(size_t n, size_t unit, void *p);
45 CEED_INTERN int CeedFree(void *p);
46 
47 #define CeedChk(ierr) do { if (ierr) return ierr; } while (0)
48 /* Note that CeedMalloc and CeedCalloc will, generally, return pointers with
49    different memory alignments: CeedMalloc returns pointers aligned at
50    CEED_ALIGN bytes, while CeedCalloc uses the alignment of calloc. */
51 #define CeedMalloc(n, p) CeedMallocArray((n), sizeof(**(p)), p)
52 #define CeedCalloc(n, p) CeedCallocArray((n), sizeof(**(p)), p)
53 #define CeedRealloc(n, p) CeedReallocArray((n), sizeof(**(p)), p)
54 
55 // CEED_DEBUG_COLOR default value, forward CeedDebug* declarations & dbg macros
56 #ifndef CEED_DEBUG_COLOR
57 #define CEED_DEBUG_COLOR 0
58 #endif
59 extern CeedInt ceed_debug;
60 CEED_INTERN void CeedDebugImpl(const char*,...);
61 CEED_INTERN void CeedDebugImpl256(const unsigned char,const char*,...);
62 #define CeedDebug(format, ...) CeedDebugImpl (format, ## __VA_ARGS__)
63 #define CeedDebug256(color, ...) CeedDebugImpl256(color, ## __VA_ARGS__)
64 // Generic selection, but since C11; if not acceptable, uncomment dbg CeedDebug
65 #define cdbg(c,...) _Generic((c),  \
66   unsigned char: CeedDebugImpl256, \
67   default: CeedDebugImpl)(c,## __VA_ARGS__)
68 #define dbg(...) cdbg((unsigned char)CEED_DEBUG_COLOR, ## __VA_ARGS__)
69 //#define dbg CeedDebug
70 
71 struct CeedVector_private {
72   Ceed ceed;
73   int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *);
74   int (*GetArray)(CeedVector, CeedMemType, CeedScalar **);
75   int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **);
76   int (*RestoreArray)(CeedVector, CeedScalar **);
77   int (*RestoreArrayRead)(CeedVector, const CeedScalar **);
78   int (*Destroy)(CeedVector);
79   CeedInt length;
80   void *data;
81 };
82 
83 struct CeedElemRestriction_private {
84   Ceed ceed;
85   int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedInt, CeedTransposeMode,
86                CeedVector, CeedVector, CeedRequest *);
87   int (*Destroy)(CeedElemRestriction);
88   CeedInt nelem;    /* number of elements */
89   CeedInt elemsize; /* number of dofs per element */
90   CeedInt ndof;     /* size of the L-vector, can be used for checking for
91                        correct vector sizes */
92   void *data;       /* place for the backend to store any data */
93 };
94 
95 struct CeedBasis_private {
96   Ceed ceed;
97   int (*Apply)(CeedBasis, CeedTransposeMode, CeedEvalMode, const CeedScalar *,
98                CeedScalar *);
99   int (*Destroy)(CeedBasis);
100   CeedInt dim;
101   CeedInt ndof;
102   CeedInt P1d;
103   CeedInt Q1d;
104   CeedScalar *qref1d;
105   CeedScalar *qweight1d;
106   CeedScalar *interp1d;
107   CeedScalar *grad1d;
108   void *data;       /* place for the backend to store any data */
109 };
110 
111 /* FIXME: The number of in-fields and out-fields may be different? */
112 /* FIXME: Shouldn't inmode and outmode be per-in-field and per-out-field,
113    respectively? */
114 struct CeedQFunction_private {
115   Ceed ceed;
116   int (*Apply)(CeedQFunction, void *, CeedInt, const CeedScalar *const *,
117                CeedScalar *const *);
118   int (*Destroy)(CeedQFunction);
119   CeedInt vlength;    // Number of quadrature points must be padded to a multiple of vlength
120   CeedInt nfields;
121   size_t qdatasize;   // Number of bytes of qdata per quadrature point
122   CeedEvalMode inmode, outmode;
123   int (*function)(void *, void *, CeedInt, const CeedScalar *const *,
124                   CeedScalar *const *);
125   const char *focca;
126   void *ctx;      /* user context for function */
127   size_t ctxsize; /* size of user context; may be used to copy to a device */
128   void *data;     /* backend data */
129 };
130 
131 struct CeedOperator_private {
132   Ceed ceed;
133   int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedVector, CeedRequest *);
134   int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector,
135                        CeedVector, CeedRequest *);
136   int (*GetQData)(CeedOperator, CeedVector *);
137   int (*Destroy)(CeedOperator);
138   CeedElemRestriction Erestrict;
139   CeedBasis basis;
140   CeedQFunction qf;
141   CeedQFunction dqf;
142   CeedQFunction dqfT;
143   void *data;
144 };
145 
146 #endif
147