Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:52

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 "VecGeom/base/Config.h"
0012 
0013 #ifdef VECGEOM_FLOAT_PRECISION
0014 #define VECCORE_SINGLE_PRECISION
0015 using Precision = float;
0016 #else
0017 using Precision = double;
0018 #endif
0019 
0020 #include <VecCore/VecCore>
0021 
0022 #include "VecGeom/base/Config.h"
0023 #include "VecGeom/base/Cuda.h"
0024 #include "VecGeom/base/Math.h"
0025 #include <type_traits>
0026 
0027 using uint       = unsigned int;
0028 using NavIndex_t = unsigned int;
0029 
0030 #define VECGEOM
0031 
0032 #ifdef __INTEL_COMPILER
0033 // Compiling with icc
0034 #define VECGEOM_INTEL
0035 #define VECGEOM_FORCE_INLINE inline
0036 #ifndef VECCORE_CUDA
0037 #define VECGEOM_ALIGNED __attribute__((aligned(64)))
0038 #endif
0039 #else
0040 #if (defined(__GNUC__) || defined(__GNUG__) || defined(__clang__)) && !defined(__NO_INLINE__) && \
0041     !defined(VECGEOM_NOINLINE)
0042 #define VECGEOM_FORCE_INLINE inline __attribute__((always_inline))
0043 #ifndef VECCORE_CUDA
0044 #define VECGEOM_ALIGNED __attribute__((aligned(64)))
0045 #endif
0046 #else
0047 // Clang or forced inlining is disabled ( by falling back to compiler decision )
0048 #define VECGEOM_FORCE_INLINE inline
0049 #ifndef VECCORE_CUDA
0050 #define VECGEOM_ALIGNED
0051 #endif
0052 #endif
0053 #endif
0054 
0055 // Allow constexpr variables and functions if possible
0056 #define VECGEOM_CONSTEXPR constexpr
0057 #define VECGEOM_CONSTEXPR_RETURN constexpr
0058 
0059 // Qualifier(s) of global constants
0060 #ifdef VECCORE_CUDA_DEVICE_COMPILATION
0061 // constexpr not supported on device in CUDA 6.5
0062 #define VECGEOM_GLOBAL static __constant__ const
0063 #define VECGEOM_CLASS_GLOBAL static const
0064 #else
0065 #define VECGEOM_GLOBAL static constexpr
0066 #define VECGEOM_CLASS_GLOBAL static constexpr
0067 #endif
0068 
0069 namespace vecgeom {
0070 inline namespace VECGEOM_IMPL_NAMESPACE {
0071 enum EnumInside {
0072   eInside  = 1, /* for USOLID compatibility */
0073   kInside  = eInside,
0074   eSurface = 2,
0075   kSurface = eSurface,
0076   eOutside = 3,
0077   kOutside = eOutside,
0078 };
0079 
0080 using Inside_t = int;
0081 
0082 VECGEOM_GLOBAL int kAlignmentBoundary = 32;
0083 
0084 namespace EInside {
0085 VECGEOM_GLOBAL vecgeom::Inside_t kInside  = 1;
0086 VECGEOM_GLOBAL vecgeom::Inside_t kSurface = 2;
0087 VECGEOM_GLOBAL vecgeom::Inside_t kOutside = 3;
0088 } // namespace EInside
0089 
0090 namespace details {
0091 template <typename DataType, typename Target>
0092 struct UseIfSameType {
0093   VECCORE_ATT_HOST_DEVICE
0094   static Target const *Get(DataType *) { return nullptr; }
0095 };
0096 template <typename DataType>
0097 struct UseIfSameType<DataType, DataType> {
0098   VECCORE_ATT_HOST_DEVICE
0099   static DataType const *Get(DataType *ptr) { return ptr; }
0100 };
0101 } // namespace details
0102 
0103 // some static MACROS
0104 #define VECGEOM_MAXDAUGHTERS 2000 // macro mainly used to allocated static (stack) arrays/workspaces
0105 #define VECGEOM_MAXFACETS 20000   // macro mainly used to allocated static (stack hybrid navigator arrays/workspaces
0106 
0107 // choosing the Vector and Scalar backends
0108 // trying to set some sort of default scalar and vector backend
0109 #if defined(VECGEOM_VC) && !defined(VECCORE_CUDA)
0110 using VectorBackend = vecCore::backend::VcVectorT<Precision>;
0111 #else
0112 using VectorBackend = vecCore::backend::ScalarT<Precision>;
0113 #endif
0114 using ScalarBackend = vecCore::backend::ScalarT<Precision>;
0115 
0116 // anonymous namespace around purely local helper functions
0117 namespace {
0118 // helper code for the MaskedAssignFunc macro
0119 template <typename T>
0120 VECGEOM_FORCE_INLINE
0121 VECCORE_ATT_HOST_DEVICE
0122 bool ToBool(T /* mask */)
0123 {
0124   return false;
0125 }
0126 #pragma GCC diagnostic push
0127 #pragma GCC diagnostic ignored "-Wunused-function"
0128 template <>
0129 VECGEOM_FORCE_INLINE
0130 VECCORE_ATT_HOST_DEVICE
0131 bool ToBool<bool>(bool mask)
0132 {
0133   return mask;
0134 #pragma GCC diagnostic pop
0135 }
0136 } // end anonymous namespace
0137 
0138 // define a macro for MaskedAssignFunc which should be
0139 // used in case the third argument are expensive expressions
0140 // (such as function calls or arithmetic operations)
0141 // FIXME: move this to VecCore
0142 #define vecCore__MaskedAssignFunc(Dest, Mask, FuncCallExpr)                                 \
0143   {                                                                                         \
0144     if (vecCore::VectorSize<typename std::remove_reference<decltype(Dest)>::type>() == 1) { \
0145       if (vecgeom::ToBool(Mask)) Dest = FuncCallExpr;                                       \
0146     } else {                                                                                \
0147       vecCore::MaskedAssign(Dest, Mask, FuncCallExpr);                                      \
0148     }                                                                                       \
0149   }
0150 
0151 } // namespace VECGEOM_IMPL_NAMESPACE
0152 
0153 // defining an infinite length constant
0154 template <typename T>
0155 VECGEOM_FORCE_INLINE
0156 VECCORE_ATT_HOST_DEVICE
0157 T InfinityLength() noexcept
0158 {
0159   return vecCore::NumericLimits<T>::Max();
0160 }
0161 
0162 // is this in VecCore??
0163 template <typename T>
0164 VECGEOM_FORCE_INLINE
0165 VECCORE_ATT_HOST_DEVICE
0166 T NonZeroAbs(T const &x)
0167 {
0168   return Abs(x) + T(1.0e-30);
0169 }
0170 
0171 template <typename T>
0172 VECGEOM_FORCE_INLINE
0173 VECCORE_ATT_HOST_DEVICE
0174 T NonZero(T const &x)
0175 {
0176   return x + CopySign(T(1.0e-30), x);
0177 }
0178 
0179 } // namespace vecgeom
0180 
0181 #endif // VECGEOM_BASE_GLOBAL_H_