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 <stdbool.h> 24 25 #define CEED_INTERN CEED_EXTERN __attribute__((visibility ("hidden"))) 26 27 #define CEED_MAX_RESOURCE_LEN 1024 28 #define CEED_ALIGN 64 29 #define CEED_NUM_BACKEND_FUNCTIONS 25 30 31 // Lookup table field for backend functions 32 typedef struct { 33 const char *fname; 34 size_t offset; 35 } foffset; 36 37 struct Ceed_private { 38 Ceed delegate; 39 int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list); 40 int (*Destroy)(Ceed); 41 int (*VecCreate)(CeedInt, CeedVector); 42 int (*ElemRestrictionCreate)(CeedMemType, CeedCopyMode, 43 const CeedInt *, CeedElemRestriction); 44 int (*ElemRestrictionCreateBlocked)(CeedMemType, CeedCopyMode, 45 const CeedInt *, CeedElemRestriction); 46 int (*BasisCreateTensorH1)(CeedInt, CeedInt, CeedInt, const CeedScalar *, 47 const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis); 48 int (*BasisCreateH1)(CeedElemTopology, CeedInt, CeedInt, CeedInt, 49 const CeedScalar *, 50 const CeedScalar *, const CeedScalar *, const CeedScalar *, CeedBasis); 51 int (*QFunctionCreate)(CeedQFunction); 52 int (*OperatorCreate)(CeedOperator); 53 int refcount; 54 void *data; 55 foffset foffsets[CEED_NUM_BACKEND_FUNCTIONS]; 56 }; 57 58 struct CeedVector_private { 59 Ceed ceed; 60 int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 61 int (*SetValue)(CeedVector, CeedScalar); 62 int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 63 int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 64 int (*RestoreArray)(CeedVector, CeedScalar **); 65 int (*RestoreArrayRead)(CeedVector, const CeedScalar **); 66 int (*Destroy)(CeedVector); 67 int refcount; 68 CeedInt length; 69 uint64_t state; 70 uint64_t numreaders; 71 void *data; 72 }; 73 74 struct CeedElemRestriction_private { 75 Ceed ceed; 76 int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedTransposeMode, 77 CeedVector, CeedVector, CeedRequest *); 78 int (*Destroy)(CeedElemRestriction); 79 int refcount; 80 CeedInt nelem; /* number of elements */ 81 CeedInt elemsize; /* number of dofs per element */ 82 CeedInt ndof; /* size of the L-vector, can be used for checking for 83 correct vector sizes */ 84 CeedInt ncomp; /* number of components */ 85 CeedInt blksize; /* number of elements in a batch */ 86 CeedInt nblk; /* number of blocks of elements */ 87 void *data; /* place for the backend to store any data */ 88 }; 89 90 struct CeedBasis_private { 91 Ceed ceed; 92 int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, 93 const CeedScalar *, 94 CeedScalar *); 95 int (*Destroy)(CeedBasis); 96 int refcount; 97 bool tensorbasis; /* flag for tensor basis */ 98 CeedInt dim; /* topological dimension */ 99 CeedInt ncomp; /* number of field components (1 for scalar fields) */ 100 CeedInt P1d; /* number of nodes in one dimension */ 101 CeedInt Q1d; /* number of quadrature points in one dimension */ 102 CeedInt P; /* total number of nodes */ 103 CeedInt Q; /* total number of quadrature points */ 104 CeedScalar *qref1d; /* Array of length Q1d holding the locations of 105 quadrature points on the 1D reference element [-1, 1] */ 106 CeedScalar *qweight1d; /* array of length Q1d holding the quadrature weights on 107 the reference element */ 108 CeedScalar 109 *interp1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of 110 nodal basis functions at quadrature points */ 111 CeedScalar 112 *grad1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing derivatives of 113 nodal basis functions at quadrature points */ 114 void *data; /* place for the backend to store any data */ 115 }; 116 117 struct CeedQFunctionField_private { 118 const char *fieldname; 119 CeedInt ncomp; 120 CeedEvalMode emode; 121 }; 122 123 struct CeedQFunction_private { 124 Ceed ceed; 125 int (*Apply)(CeedQFunction, CeedInt, const CeedScalar *const *, 126 CeedScalar *const *); 127 int (*Destroy)(CeedQFunction); 128 int refcount; 129 CeedInt vlength; // Number of quadrature points must be padded to a multiple of vlength 130 CeedQFunctionField *inputfields; 131 CeedQFunctionField *outputfields; 132 CeedInt numinputfields, numoutputfields; 133 int (*function)(void*, CeedInt, const CeedScalar *const*, CeedScalar *const*); 134 const char *focca; 135 void *ctx; /* user context for function */ 136 size_t ctxsize; /* size of user context; may be used to copy to a device */ 137 void *data; /* backend data */ 138 }; 139 140 struct CeedOperatorField_private { 141 CeedElemRestriction Erestrict; /// Restriction from L-vector or NULL if identity 142 CeedTransposeMode lmode; /// Transpose mode for lvector ordering 143 CeedBasis basis; /// Basis or NULL for collocated fields 144 CeedVector 145 vec; /// State vector for passive fields, NULL for active fields 146 }; 147 148 struct CeedOperator_private { 149 Ceed ceed; 150 int refcount; 151 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 152 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 153 CeedVector, CeedRequest *); 154 int (*Destroy)(CeedOperator); 155 CeedOperatorField *inputfields; 156 CeedOperatorField *outputfields; 157 CeedInt numelements; /// Number of elements 158 CeedInt numqpoints; /// Number of quadrature points over all elements 159 CeedInt nfields; /// Number of fields that have been set 160 CeedQFunction qf; 161 CeedQFunction dqf; 162 CeedQFunction dqfT; 163 bool setupdone; 164 void *data; 165 }; 166 167 CEED_INTERN int CeedErrorReturn(Ceed, const char *, int, const char *, int, 168 const char *, va_list); 169 CEED_INTERN int CeedErrorAbort(Ceed, const char *, int, const char *, int, 170 const char *, va_list); 171 CEED_INTERN int CeedErrorExit(Ceed, const char *, int, const char *, int, 172 const char *, va_list); 173 CEED_INTERN int CeedSetErrorHandler(Ceed ceed, 174 int (eh)(Ceed, const char *, int, const char *, 175 int, const char *, va_list)); 176 177 #endif 178