Skip to content

Commit

Permalink
Refactoring the new Async backend components
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanGonzalezCaminero committed Nov 25, 2024
1 parent 8a6a82f commit c135a2f
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 82 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ endif()
#----------------------------------------------------------------------------#
set(ADEPT_G4_INTEGRATION_SRCS
src/AdePTTrackingManager.cc
src/AdePTTrackingManager.cu
src/AdePTPhysics.cc
src/HepEMPhysics.cc
src/AdePTGeant4Integration.cpp
src/AdePTConfigurationMessenger.cc
src/AdePTConfiguration.cc
)

add_library(CopCore INTERFACE)
Expand All @@ -180,8 +180,6 @@ target_include_directories(CopCore

add_library(AdePT_G4_integration SHARED
${ADEPT_G4_INTEGRATION_SRCS}
src/AdePTTransport.cc
src/AdePTTransport.cu
)
target_include_directories(AdePT_G4_integration
PUBLIC
Expand Down
9 changes: 5 additions & 4 deletions include/AdePT/core/AdePTConfiguration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ std::shared_ptr<AdePTTransportInterface> AdePTTransportFactory(unsigned int nThr
///
class AdePTConfiguration {
public:
AdePTConfiguration();
~AdePTConfiguration();
AdePTConfiguration() : fAdePTConfigurationMessenger{new AdePTConfigurationMessenger(this)} {}
~AdePTConfiguration() {}
void SetNumThreads(int numThreads) { fNumThreads = numThreads; }
void SetRandomSeed(int randomSeed) { fRandomSeed = randomSeed; }
void SetTrackInAllRegions(bool trackInAllRegions) { fTrackInAllRegions = trackInAllRegions; }
void AddGPURegionName(std::string name) { fGPURegionNames.push_back(name); }
Expand All @@ -43,6 +44,7 @@ public:

bool GetTrackInAllRegions() { return fTrackInAllRegions; }
bool IsAdePTActivated() { return fAdePTActivated; }
int GetNumThreads() { return fNumThreads; };
int GetVerbosity() { return fVerbosity; };
int GetTransportBufferThreshold() { return fTransportBufferThreshold; }
int GetCUDAStackLimit() { return fCUDAStackLimit; }
Expand All @@ -51,14 +53,13 @@ public:
double GetMillionsOfHitSlots() { return fMillionsOfHitSlots; }
std::vector<std::string> *GetGPURegionNames() { return &fGPURegionNames; }

std::shared_ptr<AdePTTransportInterface> CreateAdePTInstance(unsigned int nThread);

// Temporary
std::string GetVecGeomGDML() { return fVecGeomGDML; }

private:
bool fTrackInAllRegions{false};
bool fAdePTActivated{true};
int fNumThreads;
int fRandomSeed;
int fVerbosity{0};
int fTransportBufferThreshold{200};
Expand Down
8 changes: 5 additions & 3 deletions include/AdePT/core/AdePTTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "CommonStruct.h"
#include <AdePT/core/AdePTScoringTemplate.cuh>
#include <AdePT/core/HostScoringStruct.cuh>
#include <AdePT/core/AdePTConfiguration.hh>

class G4Region;
struct GPUstate;
Expand All @@ -32,7 +33,8 @@ class AdePTTransport : public AdePTTransportInterface {
using TrackBuffer = adeptint::TrackBuffer;
using VolAuxArray = adeptint::VolAuxArray;

AdePTTransport() = default;
// AdePTTransport() = default;
AdePTTransport(AdePTConfiguration &configuration);

~AdePTTransport() { delete fScoring; }

Expand Down Expand Up @@ -76,8 +78,8 @@ class AdePTTransport : public AdePTTransportInterface {

private:
static inline G4HepEmState *fg4hepem_state{nullptr}; ///< The HepEm state singleton
static inline int fCapacity{1024 * 1024}; ///< Track container capacity on GPU
static inline int fHitBufferCapacity{1024 * 1024}; ///< Capacity of hit buffers
int fCapacity{1024 * 1024}; ///< Track container capacity on GPU
int fHitBufferCapacity{1024 * 1024}; ///< Capacity of hit buffers
int fNthreads{0}; ///< Number of cpu threads
int fMaxBatch{0}; ///< Max batch size for allocating GPU memory
int fNumVolumes{0}; ///< Total number of active logical volumes
Expand Down
16 changes: 16 additions & 0 deletions include/AdePT/core/AdePTTransport.icc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ void ShowerGPU(IntegrationLayer &integration, int event, TrackBuffer &buffer, GP

} // namespace adept_impl

template <typename IntegrationLayer>
AdePTTransport<IntegrationLayer>::AdePTTransport(AdePTConfiguration &configuration)
{
fDebugLevel = 0;
fBufferThreshold = configuration.GetTransportBufferThreshold();
fMaxBatch = 2 * configuration.GetTransportBufferThreshold();
fTrackInAllRegions = configuration.GetTrackInAllRegions();
fGPURegionNames = configuration.GetGPURegionNames();
fCUDAStackLimit = configuration.GetCUDAStackLimit();
fCapacity = 1024 * 1024 * configuration.GetMillionsOfTrackSlots() / configuration.GetNumThreads();
fHitBufferCapacity = 1024 * 1024 * configuration.GetMillionsOfHitSlots() / configuration.GetNumThreads();

printf( "AdePT Allocated track capacity: %d tracks\n", fCapacity);
printf( "AdePT Allocated step buffer capacity: %d tracks\n", fHitBufferCapacity);
}

template <typename IntegrationLayer>
bool AdePTTransport<IntegrationLayer>::InitializeField(double bz)
{
Expand Down
3 changes: 2 additions & 1 deletion include/AdePT/integration/AdePTTrackingManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "globals.hh"
#include <AdePT/core/AdePTTransportInterface.hh>
#include <AdePT/core/AdePTTransport.h>
#include "AdePT/copcore/SystemOfUnits.h"
#include <AdePT/integration/AdePTGeant4Integration.hh>
#include <AdePT/core/AdePTConfiguration.hh>
Expand Down Expand Up @@ -49,9 +50,9 @@ private:
/// @brief Steps a track using the Generic G4TrackingManager until it enters a GPU region or stops
void StepInHostRegion(G4Track *aTrack);

static inline int fNumThreads{0};
std::set<G4Region const *> fGPURegions{};
int fVerbosity{0};

std::shared_ptr<AdePTTransportInterface> fAdeptTransport;
AdePTConfiguration *fAdePTConfiguration;
unsigned int fTrackCounter{0};
Expand Down
30 changes: 0 additions & 30 deletions src/AdePTConfiguration.cc

This file was deleted.

13 changes: 9 additions & 4 deletions src/AdePTTrackingManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,25 @@ AdePTTrackingManager::~AdePTTrackingManager()

void AdePTTrackingManager::InitializeAdePT()
{
const auto num_threads = G4RunManager::GetRunManager()->GetNumberOfThreads();

// Check if this is a sequential run
G4RunManager::RMType rmType = G4RunManager::GetRunManager()->GetRunManagerType();
bool sequential = (rmType == G4RunManager::sequentialRM);

// One thread initializes common elements
auto tid = G4Threading::G4GetThreadId();
if (tid < 0) {
// Only the master thread knows the actual number of threads, the worker threads will return "1"
// This value is stored here by the master in a static variable, and used by each thread to pass the
// correct number to their AdePTConfiguration instance
fNumThreads = G4RunManager::GetRunManager()->GetNumberOfThreads();
fAdePTConfiguration->SetNumThreads(fNumThreads);

// Load the VecGeom world in memory
AdePTGeant4Integration::CreateVecGeomWorld(fAdePTConfiguration->GetVecGeomGDML());

// Create an instance of an AdePT transport engine. This can either be one engine per thread or a shared engine for
// all threads.
fAdeptTransport = fAdePTConfiguration->CreateAdePTInstance(num_threads);
fAdeptTransport = std::make_shared<AdePTTransport<AdePTGeant4Integration>>(*fAdePTConfiguration);

// Initialize common data:
// G4HepEM, Upload VecGeom geometry to GPU, Geometry check, Create volume auxiliary data
Expand All @@ -54,7 +58,8 @@ void AdePTTrackingManager::InitializeAdePT()
} else {
// Create an instance of an AdePT transport engine. This can either be one engine per thread or a shared engine for
// all threads.
fAdeptTransport = fAdePTConfiguration->CreateAdePTInstance(num_threads);
fAdePTConfiguration->SetNumThreads(fNumThreads);
fAdeptTransport = std::make_shared<AdePTTransport<AdePTGeant4Integration>>(*fAdePTConfiguration);
// Initialize per-thread data
fAdeptTransport->Initialize();
}
Expand Down
File renamed without changes.
37 changes: 0 additions & 37 deletions src/AdePTTransport.cc

This file was deleted.

0 comments on commit c135a2f

Please sign in to comment.