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 defines compiler attributes to the CEED_QFUNCTION to force inlining 19 for called functions. The `inline` declaration does not necessarily enforce a 20 compiler to inline a function. This can be deterimental to performance, so 21 here we force inlining to occur unless inlining has been forced off (like 22 during debugging). 23 **/ 24 #ifndef CEED_QFUNCTION_ATTR 25 #ifndef __NO_INLINE__ 26 # if defined(__GNUC__) || defined(__clang__) 27 # define CEED_QFUNCTION_ATTR __attribute__((flatten)) 28 # elif defined(__INTEL_COMPILER) 29 # define CEED_QFUNCTION_ATTR _Pragma("forceinline") 30 # else 31 # define CEED_QFUNCTION_ATTR 32 # endif 33 #else 34 # define CEED_QFUNCTION_ATTR 35 #endif 36 #endif 37 38 /** 39 @ingroup CeedQFunction 40 This macro populates the correct function annotations for User QFunction 41 source for code generation backends or populates default values for CPU 42 backends. It also creates a variable `name_loc` populated with the correct 43 source path for creating the respective User QFunction. 44 **/ 45 #ifndef CEED_QFUNCTION 46 #define CEED_QFUNCTION(name) \ 47 static const char name ## _loc[] = __FILE__ ":" #name; \ 48 CEED_QFUNCTION_ATTR static int name 49 #endif 50 51 /** 52 @ingroup CeedQFunction 53 This macro populates the correct function annotations for User QFunction 54 helper function source for code generation backends or populates default 55 values for CPU backends. 56 **/ 57 #ifndef CEED_QFUNCTION_HELPER 58 #define CEED_QFUNCTION_HELPER CEED_QFUNCTION_ATTR static inline 59 #endif 60 61 /** 62 @ingroup CeedQFunction 63 Using VLA syntax to reshape User QFunction inputs and outputs can make 64 user code more readable. VLA is a C99 feature that is not supported by 65 the C++ dialect used by CUDA. This macro allows users to use the VLA 66 syntax with the CUDA backends. 67 **/ 68 #ifndef CEED_Q_VLA 69 # define CEED_Q_VLA Q 70 #endif 71 72 /** 73 @ingroup Ceed 74 This macro provides the appropriate SIMD Pragma for the compilation 75 environment. Code generation backends may redefine this macro, as needed. 76 **/ 77 #ifndef CeedPragmaSIMD 78 # if defined(__INTEL_COMPILER) 79 # define CeedPragmaSIMD _Pragma("vector") 80 /// Cannot use Intel pragma ivdep because it miscompiles unpacking symmetric tensors, as in 81 /// Poisson2DApply, where the SIMD loop body contains temporaries such as the following. 82 /// 83 /// const CeedScalar dXdxdXdxT[2][2] = {{qd[i+0*Q], qd[i+2*Q]}, 84 /// {qd[i+2*Q], qd[i+1*Q]}}; 85 /// for (int j=0; j<2; j++) 86 /// vg[i+j*Q] = (du[0] * dXdxdXdxT[0][j] + du[1] * dXdxdXdxT[1][j]); 87 /// 88 /// Miscompilation with pragma ivdep observed with icc (ICC) 19.0.5.281 20190815 89 /// at -O2 and above. 90 # elif defined(__GNUC__) && __GNUC__ >= 5 91 # define CeedPragmaSIMD _Pragma("GCC ivdep") 92 # elif defined(_OPENMP) && _OPENMP >= 201307 // OpenMP-4.0 (July, 2013) 93 # define CeedPragmaSIMD _Pragma("omp simd") 94 # else 95 # define CeedPragmaSIMD 96 # endif 97 #endif 98 99 /// Integer type, used for indexing 100 /// @ingroup Ceed 101 typedef int32_t CeedInt; 102 #define CeedInt_FMT "d" 103 104 /// Integer type, used array sizes 105 /// @ingroup Ceed 106 typedef ptrdiff_t CeedSize; 107 108 /// Scalar (floating point) types 109 /// 110 /// @ingroup Ceed 111 typedef enum { 112 /// Single precision 113 CEED_SCALAR_FP32, 114 /// Double precision 115 CEED_SCALAR_FP64 116 } CeedScalarType; 117 /// Base scalar type for the library to use: change which header is 118 /// included to change the precision. 119 #include "ceed-f64.h" 120 121 /// Ceed Errors 122 /// 123 /// This enum is used to specify the type of error returned by a function. 124 /// A zero error code is success, negative error codes indicate terminal errors 125 /// and positive error codes indicate nonterminal errors. With nonterminal errors 126 /// the object state has not been modifiend, but with terminal errors the object 127 /// data is likely modified or corrupted. 128 /// @ingroup Ceed 129 typedef enum { 130 /// Success error code 131 CEED_ERROR_SUCCESS = 0, 132 /// Minor error, generic 133 CEED_ERROR_MINOR = 1, 134 /// Minor error, dimension mismatch in inputs 135 CEED_ERROR_DIMENSION = 2, 136 /// Minor error, incomplete object setup 137 CEED_ERROR_INCOMPLETE = 3, 138 /// Minor error, incompatible arguments/configuration 139 CEED_ERROR_INCOMPATIBLE = 4, 140 /// Minor error, access lock problem 141 CEED_ERROR_ACCESS = 5, 142 /// Major error, generic 143 CEED_ERROR_MAJOR = -1, 144 /// Major error, internal backend error 145 CEED_ERROR_BACKEND = -2, 146 /// Major error, operation unsupported by current backend 147 CEED_ERROR_UNSUPPORTED = -3, 148 } CeedErrorType; 149 150 #endif 151