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 /** @defgroup CeedUser Public API for Ceed 27 @ingroup Ceed 28 */ 29 /** @defgroup CeedBackend Backend API for Ceed 30 @ingroup Ceed 31 */ 32 /** @defgroup CeedDeveloper Internal library functions for Ceed 33 @ingroup Ceed 34 */ 35 /** @defgroup CeedVectorUser Public API for CeedVector 36 @ingroup CeedVector 37 */ 38 /** @defgroup CeedVectorBackend Backend API for CeedVector 39 @ingroup CeedVector 40 */ 41 /** @defgroup CeedVectorDeveloper Internal library functions for CeedVector 42 @ingroup CeedVector 43 */ 44 /** @defgroup CeedElemRestrictionUser Public API for CeedElemRestriction 45 @ingroup CeedElemRestriction 46 */ 47 /** @defgroup CeedElemRestrictionBackend Backend API for CeedElemRestriction 48 @ingroup CeedElemRestriction 49 */ 50 /** @defgroup CeedElemRestrictionDeveloper Internal library functions for CeedElemRestriction 51 @ingroup CeedElemRestriction 52 */ 53 /** @defgroup CeedBasisUser Public API for CeedBasis 54 @ingroup CeedBasis 55 */ 56 /** @defgroup CeedBasisBackend Backend API for CeedBasis 57 @ingroup CeedBasis 58 */ 59 /** @defgroup CeedBasisDeveloper Internal library functions for CeedBasis 60 @ingroup CeedBasis 61 */ 62 /** @defgroup CeedQFunctionUser Public API for CeedQFunction 63 @ingroup CeedQFunction 64 */ 65 /** @defgroup CeedQFunctionBackend Backend API for CeedQFunction 66 @ingroup CeedQFunction 67 */ 68 /** @defgroup CeedQFunctionDeveloper Internal library functions for CeedQFunction 69 @ingroup CeedQFunction 70 */ 71 /** @defgroup CeedOperatorUser Public API for CeedOperator 72 @ingroup CeedOperator 73 */ 74 /** @defgroup CeedOperatorBackend Backend API for CeedOperator 75 @ingroup CeedOperator 76 */ 77 /** @defgroup CeedOperatorDeveloper Internal library functions for CeedOperator 78 @ingroup CeedOperator 79 */ 80 81 // Lookup table field for backend functions 82 typedef struct { 83 const char *fname; 84 size_t offset; 85 } foffset; 86 87 // Lookup table field for object delegates 88 typedef struct { 89 char *objname; 90 Ceed delegate; 91 } objdelegate; 92 93 struct Ceed_private { 94 const char *resource; 95 Ceed delegate; 96 Ceed parent; 97 objdelegate *objdelegates; 98 int objdelegatecount; 99 Ceed opfallbackceed, opfallbackparent; 100 const char *opfallbackresource; 101 int (*Error)(Ceed, const char *, int, const char *, int, const char *, 102 va_list); 103 int (*GetPreferredMemType)(CeedMemType *); 104 int (*Destroy)(Ceed); 105 int (*VectorCreate)(CeedInt, CeedVector); 106 int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, 107 const CeedInt *, CeedElemRestriction); 108 int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, 109 const CeedInt *, CeedElemRestriction); 110 int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, 111 const CeedScalar *, const CeedScalar *, 112 const CeedScalar *, CeedBasis); 113 int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, 114 const CeedScalar *, 115 const CeedScalar *, const CeedScalar *, 116 const CeedScalar *, CeedBasis); 117 int (*TensorContractCreate)(CeedBasis, CeedTensorContract); 118 int (*QFunctionCreate)(CeedQFunction); 119 int (*OperatorCreate)(CeedOperator); 120 int (*CompositeOperatorCreate)(CeedOperator); 121 int refcount; 122 bool isDeterministic; 123 void *data; 124 bool debug; 125 char errmsg[CEED_MAX_RESOURCE_LEN]; 126 foffset *foffsets; 127 }; 128 129 struct CeedVector_private { 130 Ceed ceed; 131 int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 132 int (*SetValue)(CeedVector, CeedScalar); 133 int (*SyncArray)(CeedVector, CeedMemType); 134 int (*TakeArray)(CeedVector, CeedMemType, CeedScalar **); 135 int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 136 int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 137 int (*RestoreArray)(CeedVector); 138 int (*RestoreArrayRead)(CeedVector); 139 int (*Norm)(CeedVector, CeedNormType, CeedScalar *); 140 int (*Destroy)(CeedVector); 141 int refcount; 142 CeedInt length; 143 uint64_t state; 144 uint64_t numreaders; 145 void *data; 146 }; 147 148 struct CeedElemRestriction_private { 149 Ceed ceed; 150 int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, 151 CeedRequest *); 152 int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, 153 CeedVector, CeedRequest *); 154 int (*GetOffsets)(CeedElemRestriction, CeedMemType, const CeedInt **); 155 int (*Destroy)(CeedElemRestriction); 156 int refcount; 157 CeedInt nelem; /* number of elements */ 158 CeedInt elemsize; /* number of nodes per element */ 159 CeedInt ncomp; /* number of components */ 160 CeedInt compstride; /* Component stride for L-vector ordering */ 161 CeedInt lsize; /* size of the L-vector, can be used for checking 162 for correct vector sizes */ 163 CeedInt blksize; /* number of elements in a batch */ 164 CeedInt nblk; /* number of blocks of elements */ 165 CeedInt *strides; /* strides between [nodes, components, elements] */ 166 CeedInt layout[3]; /* E-vector layout [nodes, components, elements] */ 167 uint64_t numreaders; /* number of instances of offset read only access */ 168 void *data; /* place for the backend to store any data */ 169 }; 170 171 struct CeedBasis_private { 172 Ceed ceed; 173 int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, 174 CeedVector, CeedVector); 175 int (*Destroy)(CeedBasis); 176 int refcount; 177 bool tensorbasis; /* flag for tensor basis */ 178 CeedInt dim; /* topological dimension */ 179 CeedInt ncomp; /* number of field components (1 for scalar fields) */ 180 CeedInt P1d; /* number of nodes in one dimension */ 181 CeedInt Q1d; /* number of quadrature points in one dimension */ 182 CeedInt P; /* total number of nodes */ 183 CeedInt Q; /* total number of quadrature points */ 184 CeedScalar *qref1d; /* Array of length Q1d holding the locations of 185 quadrature points on the 1D reference 186 element [-1, 1] */ 187 CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on 188 the reference element */ 189 CeedScalar 190 *interp; /* row-major matrix of shape [Q, P] expressing the values of 191 nodal basis functions at quadrature points */ 192 CeedScalar 193 *interp1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of 194 nodal basis functions at quadrature points */ 195 CeedScalar 196 *grad; /* row-major matrix of shape [dim*Q, P] matrix expressing 197 derivatives of nodal basis functions at quadrature points */ 198 CeedScalar 199 *grad1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing 200 derivatives of nodal basis functions at quadrature points */ 201 CeedTensorContract contract; /* tensor contraction object */ 202 void *data; /* place for the backend to store any data */ 203 }; 204 205 struct CeedTensorContract_private { 206 Ceed ceed; 207 int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt, 208 const CeedScalar *restrict, CeedTransposeMode, const CeedInt, 209 const CeedScalar *restrict, CeedScalar *restrict); 210 int (*Destroy)(CeedTensorContract); 211 int refcount; 212 void *data; 213 }; 214 215 struct CeedQFunctionField_private { 216 const char *fieldname; 217 CeedInt size; 218 CeedEvalMode emode; 219 }; 220 221 struct CeedQFunction_private { 222 Ceed ceed; 223 int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *); 224 int (*Destroy)(CeedQFunction); 225 int refcount; 226 CeedInt vlength; /* Number of quadrature points must be padded to a 227 multiple of vlength */ 228 CeedQFunctionField *inputfields; 229 CeedQFunctionField *outputfields; 230 CeedInt numinputfields, numoutputfields; 231 CeedQFunctionUser function; 232 const char *sourcepath; 233 const char *qfname; 234 bool fortranstatus; 235 bool identity; 236 void *ctx; /* user context for function */ 237 size_t ctxsize; /* size of user context; may be used to copy to a device */ 238 void *data; /* place for the backend to store any data */ 239 }; 240 241 /// Struct to handle the context data to use the Fortran QFunction stub 242 /// @ingroup CeedQFunction 243 typedef struct { 244 CeedScalar *innerctx; 245 size_t innerctxsize; 246 void (*f)(void *ctx, int *nq, 247 const CeedScalar *u,const CeedScalar *u1, 248 const CeedScalar *u2,const CeedScalar *u3, 249 const CeedScalar *u4,const CeedScalar *u5, 250 const CeedScalar *u6,const CeedScalar *u7, 251 const CeedScalar *u8,const CeedScalar *u9, 252 const CeedScalar *u10,const CeedScalar *u11, 253 const CeedScalar *u12,const CeedScalar *u13, 254 const CeedScalar *u14,const CeedScalar *u15, 255 CeedScalar *v,CeedScalar *v1,CeedScalar *v2, 256 CeedScalar *v3,CeedScalar *v4,CeedScalar *v5, 257 CeedScalar *v6,CeedScalar *v7,CeedScalar *v8, 258 CeedScalar *v9, CeedScalar *v10,CeedScalar *v11, 259 CeedScalar *v12,CeedScalar *v13,CeedScalar *v14, 260 CeedScalar *v15, int *err); 261 } fContext; 262 263 struct CeedOperatorField_private { 264 CeedElemRestriction Erestrict; /* Restriction from L-vector */ 265 CeedBasis basis; /* Basis or CEED_BASIS_COLLOCATED for 266 collocated fields */ 267 CeedVector vec; /* State vector for passive fields or 268 CEED_VECTOR_NONE for no vector */ 269 }; 270 271 struct CeedOperator_private { 272 Ceed ceed; 273 CeedOperator opfallback; 274 CeedQFunction qffallback; 275 int refcount; 276 int (*LinearAssembleQFunction)(CeedOperator, CeedVector *, 277 CeedElemRestriction *, CeedRequest *); 278 int (*LinearAssembleDiagonal)(CeedOperator, CeedVector, CeedRequest *); 279 int (*LinearAssembleAddDiagonal)(CeedOperator, CeedVector, CeedRequest *); 280 int (*LinearAssemblePointBlockDiagonal)(CeedOperator, CeedVector, 281 CeedRequest *); 282 int (*LinearAssembleAddPointBlockDiagonal)(CeedOperator, CeedVector, 283 CeedRequest *); 284 int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *); 285 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 286 int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 287 int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 288 int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 289 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 290 CeedVector, CeedRequest *); 291 int (*Destroy)(CeedOperator); 292 CeedOperatorField *inputfields; 293 CeedOperatorField *outputfields; 294 CeedInt numelements; /// Number of elements 295 CeedInt numqpoints; /// Number of quadrature points over all elements 296 CeedInt nfields; /// Number of fields that have been set 297 CeedQFunction qf; 298 CeedQFunction dqf; 299 CeedQFunction dqfT; 300 bool setupdone; 301 bool composite; 302 bool hasrestriction; 303 CeedOperator *suboperators; 304 CeedInt numsub; 305 void *data; 306 }; 307 308 #endif 309