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/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 *func_name; 84 size_t offset; 85 } FOffset; 86 87 // Lookup table field for object delegates 88 typedef struct { 89 char *obj_name; 90 Ceed delegate; 91 } ObjDelegate; 92 93 struct Ceed_private { 94 const char *resource; 95 Ceed delegate; 96 Ceed parent; 97 ObjDelegate *obj_delegates; 98 int obj_delegate_count; 99 Ceed op_fallback_ceed, op_fallback_parent; 100 const char *op_fallback_resource; 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 (*BasisCreateHdiv)(CeedElemTopology, CeedInt, CeedInt, CeedInt, 118 const CeedScalar *, 119 const CeedScalar *, const CeedScalar *, 120 const CeedScalar *, CeedBasis); 121 int (*TensorContractCreate)(CeedBasis, CeedTensorContract); 122 int (*QFunctionCreate)(CeedQFunction); 123 int (*QFunctionContextCreate)(CeedQFunctionContext); 124 int (*OperatorCreate)(CeedOperator); 125 int (*CompositeOperatorCreate)(CeedOperator); 126 int ref_count; 127 void *data; 128 bool is_debug; 129 bool is_deterministic; 130 char err_msg[CEED_MAX_RESOURCE_LEN]; 131 FOffset *f_offsets; 132 }; 133 134 struct CeedVector_private { 135 Ceed ceed; 136 int (*HasValidArray)(CeedVector, bool *); 137 int (*HasBorrowedArrayOfType)(CeedVector, CeedMemType, bool *); 138 int (*SetArray)(CeedVector, CeedMemType, CeedCopyMode, CeedScalar *); 139 int (*SetValue)(CeedVector, CeedScalar); 140 int (*SyncArray)(CeedVector, CeedMemType); 141 int (*TakeArray)(CeedVector, CeedMemType, CeedScalar **); 142 int (*GetArray)(CeedVector, CeedMemType, CeedScalar **); 143 int (*GetArrayRead)(CeedVector, CeedMemType, const CeedScalar **); 144 int (*GetArrayWrite)(CeedVector, CeedMemType, CeedScalar **); 145 int (*RestoreArray)(CeedVector); 146 int (*RestoreArrayRead)(CeedVector); 147 int (*Norm)(CeedVector, CeedNormType, CeedScalar *); 148 int (*Scale)(CeedVector, CeedScalar); 149 int (*AXPY)(CeedVector, CeedScalar, CeedVector); 150 int (*PointwiseMult)(CeedVector, CeedVector, CeedVector); 151 int (*Reciprocal)(CeedVector); 152 int (*Destroy)(CeedVector); 153 int ref_count; 154 CeedInt length; 155 uint64_t state; 156 uint64_t num_readers; 157 void *data; 158 }; 159 160 struct CeedElemRestriction_private { 161 Ceed ceed; 162 int (*Apply)(CeedElemRestriction, CeedTransposeMode, CeedVector, CeedVector, 163 CeedRequest *); 164 int (*ApplyBlock)(CeedElemRestriction, CeedInt, CeedTransposeMode, CeedVector, 165 CeedVector, CeedRequest *); 166 int (*GetOffsets)(CeedElemRestriction, CeedMemType, const CeedInt **); 167 int (*Destroy)(CeedElemRestriction); 168 int ref_count; 169 CeedInt num_elem; /* number of elements */ 170 CeedInt elem_size; /* number of nodes per element */ 171 CeedInt num_comp; /* number of components */ 172 CeedInt comp_stride; /* Component stride for L-vector ordering */ 173 CeedInt l_size; /* size of the L-vector, can be used for checking 174 for correct vector sizes */ 175 CeedInt blk_size; /* number of elements in a batch */ 176 CeedInt num_blk; /* number of blocks of elements */ 177 CeedInt *strides; /* strides between [nodes, components, elements] */ 178 CeedInt layout[3]; /* E-vector layout [nodes, components, elements] */ 179 uint64_t num_readers; /* number of instances of offset read only access */ 180 void *data; /* place for the backend to store any data */ 181 }; 182 183 struct CeedBasis_private { 184 Ceed ceed; 185 int (*Apply)(CeedBasis, CeedInt, CeedTransposeMode, CeedEvalMode, 186 CeedVector, CeedVector); 187 int (*Destroy)(CeedBasis); 188 int ref_count; 189 bool tensor_basis; /* flag for tensor basis */ 190 CeedInt dim; /* topological dimension */ 191 CeedElemTopology topo; /* element topology */ 192 CeedInt num_comp; /* number of field components (1 for scalar fields) */ 193 CeedInt Q_comp; /* number of Q-vector components (1 for H^1, dim for H(div)) */ 194 CeedInt P_1d; /* number of nodes in one dimension */ 195 CeedInt Q_1d; /* number of quadrature points in one dimension */ 196 CeedInt P; /* total number of nodes */ 197 CeedInt Q; /* total number of quadrature points */ 198 CeedScalar *q_ref_1d; /* Array of length Q1d holding the locations of 199 quadrature points on the 1D reference 200 element [-1, 1] */ 201 CeedScalar 202 *q_weight_1d; /* array of length Q1d holding the quadrature weights on 203 the reference element */ 204 CeedScalar 205 *interp; /* row-major matrix of shape [Q_comp*Q, P] expressing the values of 206 nodal basis functions at quadrature points */ 207 CeedScalar 208 *interp_1d; /* row-major matrix of shape [Q1d, P1d] expressing the values of 209 nodal basis functions at quadrature points */ 210 CeedScalar 211 *grad; /* row-major matrix of shape [dim*Q_comp*Q, P] matrix expressing 212 derivatives of nodal basis functions at quadrature points */ 213 CeedScalar 214 *grad_1d; /* row-major matrix of shape [Q1d, P1d] matrix expressing 215 derivatives of nodal basis functions at quadrature points */ 216 CeedTensorContract contract; /* tensor contraction object */ 217 CeedInt basis_space; /* Initialize in basis constructor 218 with 1,2 for H^1, H(div) FE space */ 219 CeedScalar *div; /* row-major matrix of shape [Q, P] expressing 220 the divergence of nodal basis functions 221 at quadrature points for H(div) discretizations */ 222 void *data; /* place for the backend to store any data */ 223 }; 224 225 struct CeedTensorContract_private { 226 Ceed ceed; 227 int (*Apply)(CeedTensorContract, CeedInt, CeedInt, CeedInt, CeedInt, 228 const CeedScalar *restrict, CeedTransposeMode, const CeedInt, 229 const CeedScalar *restrict, CeedScalar *restrict); 230 int (*Destroy)(CeedTensorContract); 231 int ref_count; 232 void *data; 233 }; 234 235 struct CeedQFunctionField_private { 236 const char *field_name; 237 CeedInt size; 238 CeedEvalMode eval_mode; 239 }; 240 241 struct CeedQFunction_private { 242 Ceed ceed; 243 int (*Apply)(CeedQFunction, CeedInt, CeedVector *, CeedVector *); 244 int (*SetCUDAUserFunction)(CeedQFunction, void *); 245 int (*SetHIPUserFunction)(CeedQFunction, void *); 246 int (*Destroy)(CeedQFunction); 247 int ref_count; 248 CeedInt vec_length; /* Number of quadrature points must be padded to a 249 multiple of vec_length */ 250 CeedQFunctionField *input_fields; 251 CeedQFunctionField *output_fields; 252 CeedInt num_input_fields, num_output_fields; 253 CeedQFunctionUser function; 254 const char *source_path; 255 const char *kernel_name; 256 const char *gallery_name; 257 bool is_gallery; 258 bool is_identity; 259 bool is_fortran; 260 bool is_immutable; 261 CeedQFunctionContext ctx; /* user context for function */ 262 void *data; /* place for the backend to store any data */ 263 }; 264 265 struct CeedQFunctionContext_private { 266 Ceed ceed; 267 int ref_count; 268 int (*HasValidData)(CeedQFunctionContext, bool *); 269 int (*HasBorrowedDataOfType)(CeedQFunctionContext, CeedMemType, bool *); 270 int (*SetData)(CeedQFunctionContext, CeedMemType, CeedCopyMode, void *); 271 int (*TakeData)(CeedQFunctionContext, CeedMemType, void *); 272 int (*GetData)(CeedQFunctionContext, CeedMemType, void *); 273 int (*RestoreData)(CeedQFunctionContext); 274 int (*Destroy)(CeedQFunctionContext); 275 CeedInt num_fields; 276 CeedInt max_fields; 277 CeedQFunctionContextFieldDescription *field_descriptions; 278 uint64_t state; 279 size_t ctx_size; 280 void *data; 281 }; 282 283 /// Struct to handle the context data to use the Fortran QFunction stub 284 /// @ingroup CeedQFunction 285 struct CeedFortranContext_private { 286 CeedQFunctionContext inner_ctx; 287 void (*f)(void *ctx, int *nq, 288 const CeedScalar *u,const CeedScalar *u1, 289 const CeedScalar *u2,const CeedScalar *u3, 290 const CeedScalar *u4,const CeedScalar *u5, 291 const CeedScalar *u6,const CeedScalar *u7, 292 const CeedScalar *u8,const CeedScalar *u9, 293 const CeedScalar *u10,const CeedScalar *u11, 294 const CeedScalar *u12,const CeedScalar *u13, 295 const CeedScalar *u14,const CeedScalar *u15, 296 CeedScalar *v,CeedScalar *v1,CeedScalar *v2, 297 CeedScalar *v3,CeedScalar *v4,CeedScalar *v5, 298 CeedScalar *v6,CeedScalar *v7,CeedScalar *v8, 299 CeedScalar *v9, CeedScalar *v10,CeedScalar *v11, 300 CeedScalar *v12,CeedScalar *v13,CeedScalar *v14, 301 CeedScalar *v15, int *err); 302 }; 303 typedef struct CeedFortranContext_private *CeedFortranContext; 304 305 struct CeedOperatorField_private { 306 CeedElemRestriction elem_restr; /* Restriction from L-vector */ 307 CeedBasis basis; /* Basis or CEED_BASIS_COLLOCATED for 308 collocated fields */ 309 CeedVector vec; /* State vector for passive fields or 310 CEED_VECTOR_NONE for no vector */ 311 const char *field_name; /* matching QFunction field name */ 312 }; 313 314 struct CeedOperator_private { 315 Ceed ceed; 316 CeedOperator op_fallback; 317 CeedQFunction qf_fallback; 318 int ref_count; 319 int (*LinearAssembleQFunction)(CeedOperator, CeedVector *, 320 CeedElemRestriction *, CeedRequest *); 321 int (*LinearAssembleQFunctionUpdate)(CeedOperator, CeedVector, 322 CeedElemRestriction, CeedRequest *); 323 int (*LinearAssembleDiagonal)(CeedOperator, CeedVector, CeedRequest *); 324 int (*LinearAssembleAddDiagonal)(CeedOperator, CeedVector, CeedRequest *); 325 int (*LinearAssemblePointBlockDiagonal)(CeedOperator, CeedVector, 326 CeedRequest *); 327 int (*LinearAssembleAddPointBlockDiagonal)(CeedOperator, CeedVector, 328 CeedRequest *); 329 int (*LinearAssembleSymbolic)(CeedOperator, CeedInt *, CeedInt **, CeedInt **); 330 int (*LinearAssemble)(CeedOperator, CeedVector); 331 int (*CreateFDMElementInverse)(CeedOperator, CeedOperator *, CeedRequest *); 332 int (*Apply)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 333 int (*ApplyComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 334 int (*ApplyAdd)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 335 int (*ApplyAddComposite)(CeedOperator, CeedVector, CeedVector, CeedRequest *); 336 int (*ApplyJacobian)(CeedOperator, CeedVector, CeedVector, CeedVector, 337 CeedVector, CeedRequest *); 338 int (*Destroy)(CeedOperator); 339 CeedOperatorField *input_fields; 340 CeedOperatorField *output_fields; 341 CeedInt num_elem; /* Number of elements */ 342 CeedInt num_qpts; /* Number of quadrature points over all elements */ 343 CeedInt num_fields; /* Number of fields that have been set */ 344 CeedQFunction qf; 345 CeedQFunction dqf; 346 CeedQFunction dqfT; 347 bool is_immutable; 348 bool is_interface_setup; 349 bool is_backend_setup; 350 bool is_composite; 351 bool has_restriction; 352 bool has_qf_assembled; 353 CeedVector qf_assembled; 354 CeedElemRestriction qf_assembled_rstr; 355 CeedOperator *sub_operators; 356 CeedInt num_suboperators; 357 void *data; 358 }; 359 360 #endif 361