Skip to content

Commit d5196ee

Browse files
[mini] Store G4RegionId (#455)
This PR changes the fGPURegion to actually store the G4RegionId. Before, it was 0 for non-GPU and 1 for GPU (should have been a bool), now it actually stores the G4RegionId if it is used on the GPU, otherwise it is set to -1. This is in preparation for Woodcock tracking on the GPU.
1 parent 5e398ae commit d5196ee

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed

include/AdePT/core/AdePTTransport.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ __global__ void InitTracks(adeptint::TrackData *trackinfo, int ntracks, int star
220220
// nextState is initialized as needed.
221221

222222
int lvolID = track.navState.GetLogicalId();
223-
assert(auxDataArray[lvolID].fGPUregion);
223+
assert(auxDataArray[lvolID].fGPUregionId >= 0);
224224
}
225225
}
226226

include/AdePT/core/CommonStruct.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ namespace adeptint {
4343
/// @brief Auxiliary logical volume data. This stores in the same structure the material-cuts couple index,
4444
/// the sensitive volume handler index and the flag if the region is active for AdePT.
4545
struct VolAuxData {
46-
int fSensIndex{-1}; ///< index of handler for sensitive volumes (-1 means non-sensitive)
47-
int fMCIndex{0}; ///< material-cut cuple index in G4HepEm
48-
int fGPUregion{0}; ///< GPU region index (currently 1 or 0, meaning tracked on GPU or not)
46+
int fSensIndex{-1}; ///< index of handler for sensitive volumes (-1 means non-sensitive)
47+
int fMCIndex{0}; ///< material-cut cuple index in G4HepEm
48+
int fGPUregionId{-1}; ///< GPU region index, corresponds to G4Region.instanceID if tracked on GPU, -1 otherwise
4949
};
5050

5151
/// @brief Structure holding the arrays of auxiliary volume data on host and device

include/AdePT/kernels/electrons.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static __device__ __forceinline__ void TransportElectrons(adept::TrackManager<Tr
502502
const int nextlvolID = nextState.GetLogicalId();
503503
VolAuxData const &nextauxData = gVolAuxData[nextlvolID];
504504
// track has left GPU region
505-
if (nextauxData.fGPUregion <= 0) {
505+
if (nextauxData.fGPUregionId < 0) {
506506
// To be safe, just push a bit the track exiting the GPU region to make sure
507507
// Geant4 does not relocate it again inside the same region
508508
pos += kPushDistance * dir;

include/AdePT/kernels/electrons_async.cuh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
7373
// TODO: Why do we have a specific AsyncAdePT VolAuxData?
7474
VolAuxData const &auxData = AsyncAdePT::gVolAuxData[lvolID];
7575

76-
assert(auxData.fGPUregion > 0); // make sure we don't get inconsistent region here
76+
assert(auxData.fGPUregionId >= 0); // make sure we don't get inconsistent region here
7777
SlotManager &slotManager = IsElectron ? *secondaries.electrons.fSlotManager : *secondaries.positrons.fSlotManager;
7878

7979
auto survive = [&](bool leak = false) {
@@ -87,7 +87,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
8787
activeQueue->push_back(slot);
8888
};
8989

90-
if (auxData.fGPUregion == 0) {
90+
if (auxData.fGPUregionId < 0) {
9191
printf(__FILE__ ":%d Error: Should kick particle %d lvol %d (%15.12f %15.12f %15.12f) dir=(%f %f %f) "
9292
"evt=%d thread=%d "
9393
"e=%f safety=%f out of GPU\n",
@@ -337,7 +337,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
337337
const int nextlvolID = navState.GetLogicalId();
338338
#endif
339339
VolAuxData const &nextauxData = AsyncAdePT::gVolAuxData[nextlvolID];
340-
if (nextauxData.fGPUregion > 0)
340+
if (nextauxData.fGPUregionId >= 0)
341341
survive();
342342
else {
343343
// To be safe, just push a bit the track exiting the GPU region to make sure
@@ -386,7 +386,7 @@ static __device__ __forceinline__ void TransportElectrons(Track *electrons, cons
386386
// const auto nextvolume = navState.Top();
387387
// const int nextlvolID = nextvolume->GetLogicalVolume()->id();
388388
// VolAuxData const &nextauxData = AsyncAdePT::gVolAuxData[nextlvolID];
389-
// if (nextauxData.fGPUregion > 0)
389+
// if (nextauxData.fGPUregionId >= 0)
390390
// survive();
391391
// else {
392392
// // To be safe, just push a bit the track exiting the GPU region to make sure

include/AdePT/kernels/electrons_split.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ __global__ void ElectronRelocation(Track *electrons, Track *leaks, G4HepEmElectr
663663
// Check if the next volume belongs to the GPU region and push it to the appropriate queue
664664
const int nextlvolID = currentTrack.navState.GetLogicalId();
665665
VolAuxData const &nextauxData = AsyncAdePT::gVolAuxData[nextlvolID];
666-
if (nextauxData.fGPUregion > 0) {
666+
if (nextauxData.fGPUregionId >= 0) {
667667
theTrack->SetMCIndex(nextauxData.fMCIndex);
668668
survive();
669669
} else {

include/AdePT/kernels/gammas.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ __global__ void TransportGammas(adept::TrackManager<Track> *gammas, Secondaries
236236
const int nextlvolID = nextState.GetLogicalId();
237237
VolAuxData const &nextauxData = gVolAuxData[nextlvolID];
238238

239-
if (nextauxData.fGPUregion > 0) {
239+
if (nextauxData.fGPUregionId >= 0) {
240240
surviveFlag = true;
241241
} else {
242242
// To be safe, just push a bit the track exiting the GPU region to make sure

include/AdePT/kernels/gammas_async.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ __global__ void __launch_bounds__(256, 1)
4242
auto navState = currentTrack.navState;
4343
const auto preStepNavState = navState;
4444
VolAuxData const &auxData = AsyncAdePT::gVolAuxData[currentTrack.navState.Top()->GetLogicalVolume()->id()];
45-
assert(auxData.fGPUregion > 0); // make sure we don't get inconsistent region here
45+
assert(auxData.fGPUregionId >= 0); // make sure we don't get inconsistent region here
4646
auto &slotManager = *secondaries.gammas.fSlotManager;
4747

4848
// Write local variables back into track and enqueue
@@ -115,7 +115,7 @@ __global__ void __launch_bounds__(256, 1)
115115
const auto nextvolume = navState.Top();
116116
const int nextlvolID = nextvolume->GetLogicalVolume()->id();
117117
VolAuxData const &nextauxData = AsyncAdePT::gVolAuxData[nextlvolID];
118-
if (nextauxData.fGPUregion > 0)
118+
if (nextauxData.fGPUregionId >= 0)
119119
survive(activeQueue);
120120
else {
121121
// To be safe, just push a bit the track exiting the GPU region to make sure

include/AdePT/kernels/gammas_split.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ __global__ void GammaRelocation(Track *gammas, Track *leaks, G4HepEmGammaTrack *
313313
// Check if the next volume belongs to the GPU region and push it to the appropriate queue
314314
const int nextlvolID = currentTrack.navState.GetLogicalId();
315315
VolAuxData const &nextauxData = AsyncAdePT::gVolAuxData[nextlvolID];
316-
if (nextauxData.fGPUregion > 0) {
316+
if (nextauxData.fGPUregionId >= 0) {
317317
theTrack->SetMCIndex(nextauxData.fMCIndex);
318318
survive();
319319
} else {

src/AdePTGeant4Integration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,11 @@ void AdePTGeant4Integration::InitVolAuxData(adeptint::VolAuxData *volAuxData, G4
324324
if (!trackInAllRegions) {
325325
for (G4Region *gpuRegion : gpuRegions) {
326326
if (g4_lvol->GetRegion() == gpuRegion) {
327-
volAuxData[vg_lvol->id()].fGPUregion = 1;
327+
volAuxData[vg_lvol->id()].fGPUregionId = g4_lvol->GetRegion()->GetInstanceID();
328328
}
329329
}
330330
} else {
331-
volAuxData[vg_lvol->id()].fGPUregion = 1;
331+
volAuxData[vg_lvol->id()].fGPUregionId = g4_lvol->GetRegion()->GetInstanceID();
332332
}
333333

334334
if (g4_lvol->GetSensitiveDetector() != nullptr) {

0 commit comments

Comments
 (0)