Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-14 09:09:42

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 // Macro allowing downstream codes to use GetDeviceBVH
0024 #define VECGEOM_BVHMANAGER_DEVICE
0025 
0026 /**
0027  * @brief The @c BVHManager class is a singleton class to manage the association between
0028  * logical volumes and their bounding volume hierarchies, using the logical volumes' ids.
0029  */
0030 
0031 class BVHManager {
0032 public:
0033   BVHManager() = delete;
0034 
0035   /**
0036    * Initializes the bounding volume hierarchies for all logical volumes in the geometry.
0037    * Since it uses the ABBoxManager to fetch the pre-computed bounding boxes for each logical volume,
0038    * it must be called after the bounding boxes have already been computed. The depth is not specified,
0039    * to allow the BVH class to choose the depth dynamically based on the number of children of each
0040    * logical volume. This function is called automatically when the geometry is closed.
0041    *
0042    * The BVHManager assumes all volumes have an associated BVH, but only BVHs for volumes whose
0043    * navigator is set to the BVHNavigator are actually accessed at runtime.
0044    */
0045   static void Init();
0046 
0047   /** Initializes bounding volume hierarchies on the GPU. */
0048   static cuda::BVH const *DeviceInit();
0049 
0050   /** Access the device BVH pointer if CUDA is enabled. **/
0051   static cuda::BVH const *GetDeviceBVH();
0052 
0053   VECCORE_ATT_HOST_DEVICE
0054   static BVH const *GetBVH(int id)
0055   {
0056 #ifdef VECCORE_CUDA_DEVICE_COMPILATION
0057     return &cuda::dBVH[id];
0058 #else
0059     return hBVH[id];
0060 #endif
0061   }
0062 
0063   VECCORE_ATT_HOST_DEVICE
0064   static BVH const *GetBVH(LogicalVolume const *v) { return GetBVH(v->id()); }
0065 };
0066 
0067 } // namespace VECGEOM_IMPL_NAMESPACE
0068 } // namespace vecgeom
0069 
0070 #endif