Skip to content

Commit f70262c

Browse files
authored
Enabled surface model for the async mode. (apt-sim#361)
This just enables the surface model replacing the solid one when ADEPT_USE_SURF is ON
1 parent 50ab609 commit f70262c

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

include/AdePT/core/AsyncAdePTTransport.cuh

+19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#ifdef VECGEOM_ENABLE_CUDA
2929
#include <VecGeom/backend/cuda/Interface.h>
3030
#endif
31+
#ifdef ADEPT_USE_SURF
32+
#include <VecGeom/surfaces/cuda/BrepCudaManager.h>
33+
#endif
3134

3235
#include <G4HepEmState.hh>
3336
#include <G4HepEmData.hh>
@@ -392,6 +395,22 @@ __global__ void InitSlotManagers(SlotManager *mgr, std::size_t N)
392395
/// WIP: Free functions implementing the CUDA parts
393396
namespace async_adept_impl {
394397

398+
void CopySurfaceModelToGPU()
399+
{
400+
// Copy surface data to GPU
401+
#ifdef ADEPT_USE_SURF
402+
#ifdef ADEPT_USE_SURF_SINGLE
403+
using SurfData = vgbrep::SurfData<float>;
404+
using BrepCudaManager = vgbrep::BrepCudaManager<float>;
405+
#else
406+
using SurfData = vgbrep::SurfData<double>;
407+
using BrepCudaManager = vgbrep::BrepCudaManager<double>;
408+
#endif
409+
BrepCudaManager::Instance().TransferSurfData(SurfData::Instance());
410+
printf("== Surface data transferred to GPU\n");
411+
#endif
412+
}
413+
395414
G4HepEmState *InitG4HepEm()
396415
{
397416
auto state = new G4HepEmState;

include/AdePT/core/AsyncAdePTTransport.icc

+28-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
#include <AdePT/integration/AdePTGeant4Integration.hh>
77

8+
#include <VecGeom/base/Stopwatch.h>
89
#include <VecGeom/management/BVHManager.h>
9-
#include "VecGeom/management/GeoManager.h"
10+
#include <VecGeom/management/GeoManager.h>
11+
#ifdef ADEPT_USE_SURF
12+
#include <VecGeom/surfaces/BrepHelper.h>
13+
#endif
1014

1115
#include <G4RunManager.hh>
1216
#include <G4Threading.hh>
@@ -39,6 +43,7 @@
3943

4044
/// Forward declarations
4145
namespace async_adept_impl {
46+
void CopySurfaceModelToGPU();
4247
bool InitializeField(double);
4348
bool InitializeGeneralField(GeneralMagneticField &);
4449
void FreeGeneralField(GeneralMagneticField &);
@@ -200,12 +205,32 @@ bool AsyncAdePTTransport<IntegrationLayer>::InitializeGeometry(const vecgeom::cx
200205
std::cout << "CUDA Device heap limit: " << fCUDAHeapLimit << "\n";
201206
cudaDeviceSetLimit(cudaLimitMallocHeapSize, fCUDAHeapLimit);
202207
}
208+
bool success = true;
209+
#ifdef ADEPT_USE_SURF
210+
#ifdef ADEPT_USE_SURF_SINGLE
211+
using SurfData = vgbrep::SurfData<float>;
212+
using BrepHelper = vgbrep::BrepHelper<float>;
213+
#else
214+
using SurfData = vgbrep::SurfData<double>;
215+
using BrepHelper = vgbrep::BrepHelper<double>;
216+
#endif
217+
vecgeom::Stopwatch timer;
218+
timer.Start();
219+
if (!BrepHelper::Instance().Convert()) return 1;
220+
BrepHelper::Instance().PrintSurfData();
221+
std::cout << "== Conversion to surface model done in " << timer.Stop() << " [s]\n";
222+
// Upload only navigation table to the GPU
223+
cudaManager.SynchronizeNavigationTable();
224+
async_adept_impl::CopySurfaceModelToGPU();
225+
#else
226+
// Upload solid geometry to GPU.
203227
cudaManager.LoadGeometry(world);
204228
auto world_dev = cudaManager.Synchronize();
229+
success = world_dev != nullptr;
205230
// Initialize BVH
206231
InitBVH();
207-
208-
return (world_dev != nullptr);
232+
#endif
233+
return success;
209234
}
210235

211236
template <typename IntegrationLayer>

0 commit comments

Comments
 (0)