Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:25:59

0001 /// \file scalar/Backend.h
0002 /// \author Johannes de Fine Licht (johannes.definelicht@cern.ch)
0003 
0004 #ifndef VECGEOM_BACKEND_SCALARBACKEND_H_
0005 #define VECGEOM_BACKEND_SCALARBACKEND_H_
0006 
0007 #include "VecGeom/base/Global.h"
0008 
0009 #include <algorithm>
0010 #include <cstring>
0011 
0012 namespace vecgeom {
0013 inline namespace VECGEOM_IMPL_NAMESPACE {
0014 
0015 struct kScalar {
0016   typedef int int_v;
0017   typedef Precision precision_v;
0018   typedef bool bool_v;
0019   typedef Inside_t inside_v;
0020   // alternative typedefs ( might supercede above typedefs )
0021   typedef int Int_t;
0022   typedef Precision Double_t;
0023   typedef bool Bool_t;
0024   typedef int Index_t; // the type of indices
0025 
0026   constexpr static precision_v kOne  = 1.0;
0027   constexpr static precision_v kZero = 0.0;
0028   const static bool_v kTrue          = true;
0029   const static bool_v kFalse         = false;
0030 
0031   template <class Backend>
0032   VECCORE_ATT_HOST_DEVICE
0033   static VECGEOM_CONSTEXPR_RETURN bool IsEqual()
0034   {
0035     return false;
0036   }
0037 
0038   VECCORE_ATT_HOST_DEVICE
0039   VECGEOM_FORCE_INLINE
0040   static Precision Convert(Precision const &input) { return input; }
0041 };
0042 
0043 template <>
0044 VECCORE_ATT_HOST_DEVICE
0045 inline VECGEOM_CONSTEXPR_RETURN bool kScalar::IsEqual<kScalar>()
0046 {
0047   return true;
0048 }
0049 
0050 typedef kScalar::int_v ScalarInt;
0051 typedef kScalar::precision_v ScalarDouble;
0052 typedef kScalar::bool_v ScalarBool;
0053 
0054 #ifdef VECGEOM_SCALAR
0055 constexpr size_t kVectorSize = 1;
0056 #define VECGEOM_BACKEND_TYPE vecgeom::kScalar
0057 #define VECGEOM_BACKEND_PRECISION_FROM_PTR(P) (*(P))
0058 #define VECGEOM_BACKEND_PRECISION_TYPE vecgeom::Precision
0059 #define VECGEOM_BACKEND_PRECISION_TYPE_SIZE 1
0060 //#define VECGEOM_BACKEND_PRECISION_NOT_SCALAR
0061 #define VECGEOM_BACKEND_BOOL vecgeom::ScalarBool
0062 #define VECGEOM_BACKEND_INSIDE vecgeom::kScalar::inside_v
0063 #endif
0064 
0065 // template <typename Type>
0066 // VECGEOM_FORCE_INLINE
0067 // VECCORE_ATT_HOST_DEVICE
0068 // void swap(Type &a, Type &b)
0069 //{
0070 //  std::swap(a, b);
0071 //}
0072 
0073 template <typename Type>
0074 VECGEOM_FORCE_INLINE
0075 VECCORE_ATT_HOST_DEVICE
0076 void copy(Type const *begin, Type const *const end, Type *const target)
0077 {
0078 #ifndef VECCORE_CUDA_DEVICE_COMPILATION
0079   std::copy(begin, end, target);
0080 #else
0081   std::memcpy(target, begin, sizeof(Type) * (end - begin));
0082 #endif
0083 }
0084 
0085 template <typename Type>
0086 VECGEOM_FORCE_INLINE
0087 VECCORE_ATT_HOST_DEVICE
0088 Type *AlignedAllocate(size_t size)
0089 {
0090 #ifndef VECCORE_CUDA
0091   return static_cast<Type *>(vecCore::AlignedAlloc(kAlignmentBoundary, sizeof(Type) * size));
0092 #else
0093   return new Type[size];
0094 #endif
0095 }
0096 
0097 template <typename Type>
0098 VECGEOM_FORCE_INLINE
0099 VECCORE_ATT_HOST_DEVICE
0100 void AlignedFree(Type *allocated)
0101 {
0102 #ifndef VECCORE_CUDA
0103   vecCore::AlignedFree(allocated);
0104 #else
0105   delete[] allocated;
0106 #endif
0107 }
0108 
0109 template <typename InputIterator1, typename InputIterator2>
0110 VECGEOM_FORCE_INLINE
0111 VECCORE_ATT_HOST_DEVICE
0112 bool equal(InputIterator1 first, InputIterator1 last, InputIterator2 target)
0113 {
0114 #ifndef VECCORE_CUDA_DEVICE_COMPILATION
0115   return std::equal(first, last, target);
0116 #else
0117   while (first != last) {
0118     if (*first++ != *target++) return false;
0119   }
0120   return true;
0121 #endif
0122 }
0123 } // namespace VECGEOM_IMPL_NAMESPACE
0124 } // namespace vecgeom
0125 
0126 #endif // VECGEOM_BACKEND_SCALARBACKEND_H_