Skip to content

Commit c3015ff

Browse files
factor out host WDT data preparation
1 parent 041047e commit c3015ff

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

include/AdePT/core/AsyncAdePTTransport.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public:
9494
std::vector<std::string> const *GetGPURegionNames() { return fGPURegionNames; }
9595
std::vector<std::string> const *GetCPURegionNames() { return fCPURegionNames; }
9696
G4HepEmState *GetHepEmState() const { return fg4hepem_state.get(); }
97-
void CompleteInitialization(adeptint::VolAuxData *auxData, const adeptint::WDTHostRaw &wdtRaw,
97+
void CompleteInitialization(adeptint::VolAuxData *auxData, const adeptint::WDTHostPacked &wdtPacked,
9898
const std::vector<float> &uniformFieldValues);
9999
/// Block until transport of the given event is done.
100100
void Flush(int threadId, int eventId, AdePTGeant4Integration &g4Integration);

include/AdePT/core/AsyncAdePTTransport.icc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,24 @@ inline void AsyncAdePTTransport::Initialize(G4HepEmConfig *hepEmConfig)
202202
}
203203

204204
inline void AsyncAdePTTransport::CompleteInitialization(adeptint::VolAuxData *auxData,
205-
const adeptint::WDTHostRaw &wdtRaw,
205+
const adeptint::WDTHostPacked &wdtPacked,
206206
const std::vector<float> &uniformFieldValues)
207207
{
208+
// This is the second half of the split initialization. A non-zero volume count was already
209+
// required in Initialize() before geometry upload, and it remains a hard precondition here
210+
// before uploading any geometry-derived metadata to the device.
211+
const auto numVolumes = vecgeom::GeoManager::Instance().GetRegisteredVolumesCount();
212+
if (numVolumes == 0)
213+
throw std::runtime_error("AsyncAdePTTransport::CompleteInitialization: Number of geometry volumes is zero.");
214+
208215
// Initialize volume auxiliary data on device
209216
auto &volAuxArray = adeptint::VolAuxArray::GetInstance();
210-
volAuxArray.fNumVolumes = vecgeom::GeoManager::Instance().GetRegisteredVolumesCount();
217+
volAuxArray.fNumVolumes = numVolumes;
211218
volAuxArray.fAuxData = auxData;
212219
AsyncAdePT::InitVolAuxArray(volAuxArray);
213220

214-
// Pack host-side WDT
215-
adeptint::WDTHostPacked wdtPacked = adeptint::PackWDT(wdtRaw);
216-
fHasWDTRegions = !wdtPacked.regions.empty(); // set the flag whether WDT regions are enabled
221+
// The Geant4 side has already packed the host-side WDT metadata before handing it to transport.
222+
fHasWDTRegions = !wdtPacked.regions.empty(); // set the flag whether WDT regions are enabled
217223

218224
// Upload WDT to device
219225
adeptint::WDTDeviceBuffers wdtDev;

src/AdePTTrackingManager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ void AdePTTrackingManager::InitializeSharedAdePTTransport()
7676
fGeant4Integration.InitVolAuxData(auxData, fAdeptTransport->GetHepEmState(), fHepEmTrackingManager.get(),
7777
fAdePTConfiguration->GetTrackInAllRegions(),
7878
fAdePTConfiguration->GetGPURegionNames(), wdtRaw);
79+
adeptint::WDTHostPacked wdtPacked = adeptint::PackWDT(wdtRaw);
7980

8081
// Finish the shared transport initialization by uploading the prepared metadata to the device.
81-
fAdeptTransport->CompleteInitialization(auxData, wdtRaw, uniformFieldValues);
82+
fAdeptTransport->CompleteInitialization(auxData, wdtPacked, uniformFieldValues);
8283
}
8384

8485
void AdePTTrackingManager::InitializeAdePT()

0 commit comments

Comments
 (0)