1 /// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2 /// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3 /// 4 /// SPDX-License-Identifier: BSD-2-Clause 5 /// 6 /// This file is part of CEED: http://github.com/ceed 7 8 /// @file 9 /// Public header for types and macros used in user QFunction source code 10 #ifndef _ceed_qfunction_defs_h 11 #define _ceed_qfunction_defs_h 12 13 #include <stddef.h> 14 #include <stdint.h> 15 16 /** 17 @ingroup CeedQFunction 18 This macro populates the correct function annotations for User QFunction 19 source for code generation backends or populates default values for CPU 20 backends. It also creates a variable `name_loc` populated with the correct 21 source path for creating the respective User QFunction. 22 **/ 23 #ifndef CEED_QFUNCTION 24 #define CEED_QFUNCTION(name) \ 25 static const char name ## _loc[] = __FILE__ ":" #name; \ 26 static int name 27 #endif 28 29 /** 30 @ingroup CeedQFunction 31 This macro populates the correct function annotations for User QFunction 32 helper function source for code generation backends or populates default 33 values for CPU backends. 34 **/ 35 #ifndef CEED_QFUNCTION_HELPER 36 #define CEED_QFUNCTION_HELPER static inline 37 #endif 38 39 /** 40 @ingroup CeedQFunction 41 Using VLA syntax to reshape User QFunction inputs and outputs can make 42 user code more readable. VLA is a C99 feature that is not supported by 43 the C++ dialect used by CUDA. This macro allows users to use the VLA 44 syntax with the CUDA backends. 45 **/ 46 #ifndef CEED_Q_VLA 47 # define CEED_Q_VLA Q 48 #endif 49 50 /** 51 @ingroup Ceed 52 This macro provides the appropriate SIMD Pragma for the compilation 53 environment. Code generation backends may redefine this macro, as needed. 54 **/ 55 #ifndef CeedPragmaSIMD 56 # if defined(__INTEL_COMPILER) 57 # define CeedPragmaSIMD _Pragma("vector") 58 /// Cannot use Intel pragma ivdep because it miscompiles unpacking symmetric tensors, as in 59 /// Poisson2DApply, where the SIMD loop body contains temporaries such as the following. 60 /// 61 /// const CeedScalar dXdxdXdxT[2][2] = {{qd[i+0*Q], qd[i+2*Q]}, 62 /// {qd[i+2*Q], qd[i+1*Q]}}; 63 /// for (int j=0; j<2; j++) 64 /// vg[i+j*Q] = (du[0] * dXdxdXdxT[0][j] + du[1] * dXdxdXdxT[1][j]); 65 /// 66 /// Miscompilation with pragma ivdep observed with icc (ICC) 19.0.5.281 20190815 67 /// at -O2 and above. 68 # elif defined(__GNUC__) && __GNUC__ >= 5 69 # define CeedPragmaSIMD _Pragma("GCC ivdep") 70 # elif defined(_OPENMP) && _OPENMP >= 201307 // OpenMP-4.0 (July, 2013) 71 # define CeedPragmaSIMD _Pragma("omp simd") 72 # else 73 # define CeedPragmaSIMD 74 # endif 75 #endif 76 77 /// Integer type, used for indexing 78 /// @ingroup Ceed 79 typedef int32_t CeedInt; 80 #define CeedInt_FMT "d" 81 82 /// Integer type, used array sizes 83 /// @ingroup Ceed 84 typedef ptrdiff_t CeedSize; 85 86 /// Scalar (floating point) types 87 /// 88 /// @ingroup Ceed 89 typedef enum { 90 /// Single precision 91 CEED_SCALAR_FP32, 92 /// Double precision 93 CEED_SCALAR_FP64 94 } CeedScalarType; 95 /// Base scalar type for the library to use: change which header is 96 /// included to change the precision. 97 #include "ceed-f64.h" 98 99 /// Ceed Errors 100 /// 101 /// This enum is used to specify the type of error returned by a function. 102 /// A zero error code is success, negative error codes indicate terminal errors 103 /// and positive error codes indicate nonterminal errors. With nonterminal errors 104 /// the object state has not been modifiend, but with terminal errors the object 105 /// data is likely modified or corrupted. 106 /// @ingroup Ceed 107 typedef enum { 108 /// Success error code 109 CEED_ERROR_SUCCESS = 0, 110 /// Minor error, generic 111 CEED_ERROR_MINOR = 1, 112 /// Minor error, dimension mismatch in inputs 113 CEED_ERROR_DIMENSION = 2, 114 /// Minor error, incomplete object setup 115 CEED_ERROR_INCOMPLETE = 3, 116 /// Minor error, incompatible arguments/configuration 117 CEED_ERROR_INCOMPATIBLE = 4, 118 /// Minor error, access lock problem 119 CEED_ERROR_ACCESS = 5, 120 /// Major error, generic 121 CEED_ERROR_MAJOR = -1, 122 /// Major error, internal backend error 123 CEED_ERROR_BACKEND = -2, 124 /// Major error, operation unsupported by current backend 125 CEED_ERROR_UNSUPPORTED = -3, 126 } CeedErrorType; 127 128 #endif 129