Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/VecGeom/base/Global.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /// \file Global.h
0002 /// \author Johannes de Fine Licht (johannes.definelicht@cern.ch)
0003 
0004 #ifndef VECGEOM_BASE_GLOBAL_H_
0005 #define VECGEOM_BASE_GLOBAL_H_
0006 
0007 #if __cplusplus < 201103L
0008 #error VecGeom requires compiler and library support for the ISO C++ 2011 standard.
0009 #endif
0010 
0011 #include <type_traits>
0012 #include <VecCore/VecCore>
0013 
0014 #include "VecGeom/base/Config.h"
0015 #include "VecGeom/base/Cuda.h"
0016 #include "VecGeom/base/Math.h"
0017 
0018 #define VECGEOM
0019 
0020 #ifdef __INTEL_COMPILER
0021 // Compiling with icc
0022 #define VECGEOM_INTEL
0023 #define VECGEOM_FORCE_INLINE inline
0024 #ifndef VECCORE_CUDA
0025 #define VECGEOM_ALIGNED __attribute__((aligned(64)))
0026 #endif
0027 #else
0028 #if (defined(__GNUC__) || defined(__GNUG__) || defined(__clang__)) && !defined(__NO_INLINE__) && \
0029     !defined(VECGEOM_NOINLINE)
0030 #define VECGEOM_FORCE_INLINE inline __attribute__((always_inline))
0031 #ifndef VECCORE_CUDA
0032 #define VECGEOM_ALIGNED __attribute__((aligned(64)))
0033 #endif
0034 #else
0035 // Clang or forced inlining is disabled ( by falling back to compiler decision )
0036 #define VECGEOM_FORCE_INLINE inline
0037 #ifndef VECCORE_CUDA
0038 #define VECGEOM_ALIGNED
0039 #endif
0040 #endif
0041 #endif
0042 
0043 // Portable unroll pragma
0044 // Usage: VECGEOM_PRAGMA_UNROLL(4)
0045 // Expands to:
0046 //   CUDA/NVCC:          #pragma unroll 4
0047 //   Clang (host):       #pragma clang loop unroll_count(4)
0048 //   GCC >= 8 (host):    #pragma GCC unroll 4
0049 //   Other compilers:    (nothing)
0050 
0051 // stringizers for _Pragma
0052 #define VECGEOM_PRAGMA_STR_(x) #x
0053 #define VECGEOM_PRAGMA_STR(x) VECGEOM_PRAGMA_STR_(x)
0054 
0055 #if defined(__CUDACC__) || defined(__CUDA_ARCH__)
0056 // NVCC supports "#pragma unroll N"
0057 #define VECGEOM_PRAGMA_UNROLL(N) _Pragma(VECGEOM_PRAGMA_STR(unroll N))
0058 
0059 #elif defined(__clang__)
0060 // Clang wants: "#pragma clang loop unroll_count(N)"
0061 #define VECGEOM_PRAGMA_UNROLL(N) _Pragma(VECGEOM_PRAGMA_STR(clang loop unroll_count(N)))
0062 
0063 #elif defined(__GNUC__) && (__GNUC__ >= 8)
0064 // GCC supports: "#pragma GCC unroll N"
0065 #define VECGEOM_PRAGMA_UNROLL(N) _Pragma(VECGEOM_PRAGMA_STR(GCC unroll N))
0066 
0067 #else
0068 // Unknown compiler: no-op
0069 #define VECGEOM_PRAGMA_UNROLL(N)
0070 #endif
0071 
0072 // Allow constexpr variables and functions if possible
0073 #define VECGEOM_CONSTEXPR constexpr
0074 #define VECGEOM_CONSTEXPR_RETURN constexpr
0075 
0076 // Qualifier(s) of global constants
0077 #ifdef VECCORE_CUDA_DEVICE_COMPILATION
0078 // constexpr not supported on device in CUDA 6.5
0079 #define VECGEOM_GLOBAL static __constant__ const
0080 #define VECGEOM_CLASS_GLOBAL static const
0081 #else
0082 #define VECGEOM_GLOBAL static constexpr
0083 #define VECGEOM_CLASS_GLOBAL static constexpr
0084 #endif
0085 
0086 namespace vecgeom {
0087 
0088 using uint       = unsigned int;
0089 using NavIndex_t = unsigned int;
0090 
0091 enum class ESolidType : char {
0092   boolean = 0,
0093   box,
0094   cone,
0095   coaxialcones,
0096   cuttube,
0097   ellipsoid,
0098   ellipticalcone,
0099   ellipticaltube,
0100   extruded,
0101   gentrap,
0102   genericpolycone,
0103   hyperboloid,
0104   multiunion,
0105   orb,
0106   paraboloid,
0107   parallelepiped,
0108   polycone,
0109   polyhedron,
0110   sextruded,
0111   scaled,
0112   sphere,
0113   tessellated,
0114   tetrahedron,
0115   torus,
0116   trapezoid,
0117   trd,
0118   tube,
0119   nosolid
0120 };
0121 
0122 inline namespace VECGEOM_IMPL_NAMESPACE {
0123 enum EnumInside {
0124   eInside  = 1, /* for USOLID compatibility */
0125   kInside  = eInside,
0126   eSurface = 2,
0127   kSurface = eSurface,
0128   eOutside = 3,
0129   kOutside = eOutside,
0130 };
0131 
0132 using Inside_t = int;
0133 
0134 VECGEOM_GLOBAL int kAlignmentBoundary = 32;
0135 
0136 namespace EInside {
0137 VECGEOM_GLOBAL vecgeom::Inside_t kInside  = 1;
0138 VECGEOM_GLOBAL vecgeom::Inside_t kSurface = 2;
0139 VECGEOM_GLOBAL vecgeom::Inside_t kOutside = 3;
0140 } // namespace EInside
0141 
0142 namespace details {
0143 template <typename DataType, typename Target>
0144 struct UseIfSameType {
0145   VECCORE_ATT_HOST_DEVICE
0146   static Target const *Get(DataType *) { return nullptr; }
0147 };
0148 template <typename DataType>
0149 struct UseIfSameType<DataType, DataType> {
0150   VECCORE_ATT_HOST_DEVICE
0151   static DataType const *Get(DataType *ptr) { return ptr; }
0152 };
0153 } // namespace details
0154 
0155 // some static MACROS
0156 #define VECGEOM_MAXDAUGHTERS 2000 // macro mainly used to allocated static (stack) arrays/workspaces
0157 #define VECGEOM_MAXFACETS 20000   // macro mainly used to allocated static (stack hybrid navigator arrays/workspaces
0158 
0159 // choosing the Vector and Scalar backends
0160 // trying to set some sort of default scalar and vector backend
0161 #if defined(VECGEOM_VC) && !defined(VECCORE_CUDA)
0162 using VectorBackend = vecCore::backend::VcVectorT<Precision>;
0163 #else
0164 using VectorBackend = vecCore::backend::ScalarT<Precision>;
0165 #endif
0166 using ScalarBackend = vecCore::backend::ScalarT<Precision>;
0167 
0168 // anonymous namespace around purely local helper functions
0169 namespace {
0170 // helper code for the MaskedAssignFunc macro
0171 template <typename T>
0172 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE bool ToBool(T /* mask */)
0173 {
0174   return false;
0175 }
0176 #pragma GCC diagnostic push
0177 #pragma GCC diagnostic ignored "-Wunused-function"
0178 template <>
0179 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE bool ToBool<bool>(bool mask)
0180 {
0181   return mask;
0182 #pragma GCC diagnostic pop
0183 }
0184 } // end anonymous namespace
0185 
0186 // define a macro for MaskedAssignFunc which should be
0187 // used in case the third argument are expensive expressions
0188 // (such as function calls or arithmetic operations)
0189 // FIXME: move this to VecCore
0190 #define vecCore__MaskedAssignFunc(Dest, Mask, FuncCallExpr)                                 \
0191   {                                                                                         \
0192     if (vecCore::VectorSize<typename std::remove_reference<decltype(Dest)>::type>() == 1) { \
0193       if (vecgeom::ToBool(Mask)) Dest = FuncCallExpr;                                       \
0194     } else {                                                                                \
0195       vecCore::MaskedAssign(Dest, Mask, FuncCallExpr);                                      \
0196     }                                                                                       \
0197   }
0198 
0199 } // namespace VECGEOM_IMPL_NAMESPACE
0200 
0201 // defining an infinite length constant
0202 template <typename T>
0203 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T InfinityLength() noexcept
0204 {
0205   return vecCore::NumericLimits<T>::Max();
0206 }
0207 
0208 // is this in VecCore??
0209 template <typename T>
0210 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T NonZeroAbs(T const &x)
0211 {
0212   return Abs(x) + T(1.0e-30);
0213 }
0214 
0215 template <typename T>
0216 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T NonZero(T const &x)
0217 {
0218   return x + CopySign(T(1.0e-30), x);
0219 }
0220 
0221 } // namespace vecgeom
0222 
0223 #endif // VECGEOM_BASE_GLOBAL_H_