1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
/// \file BVHManager.cu
/// \author Guilherme Amadio
#include "VecGeom/management/BVHManager.h"
#include "VecGeom/backend/cuda/Interface.h"
#include <VecGeom/navigation/BVHNavigator.h>
#include <VecGeom/navigation/BVHSafetyEstimator.h>
using vecgeom::cxx::CudaCheckError;
namespace vecgeom {
inline namespace cuda {
void *AllocateDeviceBVHBuffer(size_t n)
{
BVH *ptr = nullptr;
CudaCheckError(cudaMalloc((void **)&ptr, n * sizeof(BVH)));
CudaCheckError(cudaMemcpyToSymbol(dBVH, &ptr, sizeof(ptr)));
CudaCheckError(cudaDeviceSynchronize());
return (void*) ptr;
}
void FreeDeviceBVHBuffer()
{
void *ptr = nullptr;
CudaCheckError(cudaMemcpyFromSymbol(&ptr, dBVH, sizeof(ptr)));
if (ptr)
CudaCheckError(cudaFree(ptr));
}
// Temporary hack (used already in LogicalVolume.cpp) implementing the Instance functionality
// on device for BVHSafetyEstimator and BVHNavigator in the absence of the corresponding
// implementation files
VECCORE_ATT_DEVICE
BVHSafetyEstimator *gBVHSafetyEstimator = nullptr;
VECCORE_ATT_DEVICE
VNavigator *gBVHNavigator = nullptr;
VECCORE_ATT_DEVICE
VSafetyEstimator *BVHSafetyEstimator::Instance()
{
if (gBVHSafetyEstimator == nullptr) gBVHSafetyEstimator = new BVHSafetyEstimator();
return gBVHSafetyEstimator;
}
template <>
VECCORE_ATT_DEVICE
VNavigator *BVHNavigator<false>::Instance()
{
if (gBVHNavigator == nullptr) gBVHNavigator = new BVHNavigator();
return gBVHNavigator;
}
} // namespace cuda
} // namespace vecgeom
|