Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:26:04

0001 /// \file BVHManager.h
0002 /// \author Guilherme Amadio
0003 
0004 #ifndef VECGEOM_MANAGEMENT_BVHMANAGER_H_
0005 #define VECGEOM_MANAGEMENT_BVHMANAGER_H_
0006 
0007 #include "VecGeom/base/Config.h"
0008 #include "VecGeom/base/Cuda.h"
0009 #include "VecGeom/base/BVH.h"
0010 #include "VecGeom/volumes/LogicalVolume.h"
0011 
0012 #ifdef VECGEOM_ENABLE_CUDA
0013 #include "VecGeom/backend/cuda/Interface.h"
0014 #endif
0015 
0016 namespace vecgeom {
0017 inline namespace VECGEOM_IMPL_NAMESPACE {
0018 inline std::vector<BVH *> hBVH;
0019 #ifdef VECGEOM_ENABLE_CUDA
0020 inline __device__ BVH *dBVH;
0021 #endif
0022 
0023 /**
0024  * @brief The @c BVHManager class is a singleton class to manage the association between
0025  * logical volumes and their bounding volume hierarchies, using the logical volumes' ids.
0026  */
0027 
0028 class BVHManager {
0029 public:
0030   BVHManager() = delete;
0031 
0032   /**
0033    * Initializes the bounding volume hierarchies for all logical volumes in the geometry.
0034    * Since it uses the ABBoxManager to fetch the pre-computed bounding boxes for each logical volume,
0035    * it must be called after the bounding boxes have already been computed. The depth is not specified,
0036    * to allow the BVH class to choose the depth dynamically based on the number of children of each
0037    * logical volume. This function is called automatically when the geometry is closed.
0038    *
0039    * The BVHManager assumes all volumes have an associated BVH, but only BVHs for volumes whose
0040    * navigator is set to the BVHNavigator are actually accessed at runtime.
0041    */
0042   static void Init();
0043 
0044 #ifdef VECGEOM_CUDA_INTERFACE
0045   /** Initializes bounding volume hierarchies on the GPU. */
0046   static void DeviceInit();
0047 #endif
0048 
0049   VECCORE_ATT_HOST_DEVICE
0050   static BVH const *GetBVH(int id)
0051   {
0052 #ifdef VECCORE_CUDA_DEVICE_COMPILATION
0053     return &cuda::dBVH[id];
0054 #else
0055     return hBVH[id];
0056 #endif
0057   }
0058 
0059   VECCORE_ATT_HOST_DEVICE
0060   static BVH const *GetBVH(LogicalVolume const *v) { return GetBVH(v->id()); }
0061 };
0062 
0063 } // namespace VECGEOM_IMPL_NAMESPACE
0064 } // namespace vecgeom
0065 
0066 #endif