Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions include/AdePT/transport/kernels/electrons.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ __device__ double GetVelocity(double eKin)

namespace adept::transport {

// Compute the physics and geometry step limit, transport the electrons while
// Compute the physics and geometry step limit, transport the electron in the given slot while
// applying the continuous effects and maybe a discrete process that could
// generate secondaries.
// generate secondaries. Does one step of one track; the transport kernels call it per active slot.
template <bool IsElectron, class SteppingActionT>
static __device__ __forceinline__ void TransportElectrons(ParticleManager &particleManager, Stats *InFlightStats,
const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent,
const TransportKernelOptions options)
static __device__ __forceinline__ void ElectronStep(ParticleManager &particleManager,
const SlotManager::value_type slot, Stats *InFlightStats,
const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent,
const TransportKernelOptions options)
{
constexpr unsigned short maxSteps = 10'000;
constexpr int Charge = IsElectron ? -1 : 1;
Expand All @@ -88,9 +89,7 @@ static __device__ __forceinline__ void TransportElectrons(ParticleManager &parti
auto &electronsOrPositrons = (IsElectron ? particleManager.electrons : particleManager.positrons);
SlotManager &slotManager = *electronsOrPositrons.fSlotManager;

const int activeSize = electronsOrPositrons.ActiveSize();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const auto slot = electronsOrPositrons.ActiveAt(i);
{
ChargedTrack &currentTrack = electronsOrPositrons.TrackAt(slot);

// Finish-on-CPU must happen before any interaction can create secondaries on the GPU.
Expand All @@ -102,7 +101,7 @@ static __device__ __forceinline__ void TransportElectrons(ParticleManager &parti

adept_step_recording::RecordFinishOnCPU(currentTrack,
IsElectron ? ParticleType::Electron : ParticleType::Positron);
continue;
return;
}

auto navState = currentTrack.navState;
Expand Down Expand Up @@ -158,7 +157,7 @@ static __device__ __forceinline__ void TransportElectrons(ParticleManager &parti
IsElectron ? ParticleType::Electron : ParticleType::Positron,
kAdePTTransportationProcess, preStepEnergy, eKin, actionEdep);
}
continue;
return;
}
}

Expand Down Expand Up @@ -866,6 +865,22 @@ static __device__ __forceinline__ void TransportElectrons(ParticleManager &parti
secondaryData, // Secondary initialization data
nSecondaries); // Number of secondaries
}
} // end of the step of this track
}

// Transport all active electrons or positrons by one step: grid-stride loop over the active queue.
template <bool IsElectron, class SteppingActionT>
static __device__ __forceinline__ void TransportElectrons(ParticleManager &particleManager, Stats *InFlightStats,
const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent,
const TransportKernelOptions options)
{
auto &electronsOrPositrons = (IsElectron ? particleManager.electrons : particleManager.positrons);
const int activeSize = electronsOrPositrons.ActiveSize();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const auto slot = electronsOrPositrons.ActiveAt(i);
ElectronStep<IsElectron, SteppingActionT>(particleManager, slot, InFlightStats, params, allowFinishOffEvent,
options);
}
}

Expand Down
32 changes: 22 additions & 10 deletions include/AdePT/transport/kernels/gammas.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ using StepActionParam = adept::SteppingAction::Params;
using adept::SteppingAction::SetSecondaryHostData;

namespace adept::transport {
// TransportGammas Interface
// One step of the gamma in the given slot. The transport kernels call it per active slot.
template <class SteppingActionT>
__global__ void __launch_bounds__(256, 1)
TransportGammas(ParticleManager particleManager, Stats *InFlightStats, const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent, const TransportKernelOptions options)
static __device__ __forceinline__ void GammaStep(ParticleManager &particleManager, const SlotManager::value_type slot,
Stats *InFlightStats, const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent,
const TransportKernelOptions options)
{
constexpr unsigned short maxSteps = 10'000;
const bool returnAllSteps = options.returnAllSteps;
const bool returnLastStep = options.returnLastStep;
auto &slotManager = *particleManager.gammas.fSlotManager;
const int activeSize = particleManager.gammas.ActiveSize();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const auto slot = particleManager.gammas.ActiveAt(i);
{
NeutralTrack &currentTrack = particleManager.gammas.TrackAt(slot);

// Finish-on-CPU must happen before any interaction can create secondaries on the GPU.
Expand All @@ -62,7 +61,7 @@ __global__ void __launch_bounds__(256, 1)
slotManager.MarkSlotForFreeing(slot);

adept_step_recording::RecordFinishOnCPU(currentTrack, ParticleType::Gamma);
continue;
return;
}

auto navState = currentTrack.navState;
Expand Down Expand Up @@ -113,7 +112,7 @@ __global__ void __launch_bounds__(256, 1)
adept_step_recording::RecordZeroLengthGPUStep(currentTrack, ParticleType::Gamma, kAdePTTransportationProcess,
preStepEnergy, eKin, edep);
}
continue;
return;
}
}

Expand Down Expand Up @@ -554,7 +553,20 @@ __global__ void __launch_bounds__(256, 1)
secondaryData, // Secondary initialization data
nSecondaries); // Number of secondaries
}
} // end for loop over tracks
} // end of the step of this track
}

// TransportGammas Interface
template <class SteppingActionT>
__global__ void __launch_bounds__(256, 1)
TransportGammas(ParticleManager particleManager, Stats *InFlightStats, const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent, const TransportKernelOptions options)
{
const int activeSize = particleManager.gammas.ActiveSize();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const auto slot = particleManager.gammas.ActiveAt(i);
GammaStep<SteppingActionT>(particleManager, slot, InFlightStats, params, allowFinishOffEvent, options);
}
}

} // namespace adept::transport
35 changes: 24 additions & 11 deletions include/AdePT/transport/kernels/gammasWDT.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ using StepActionParam = adept::SteppingAction::Params;
using adept::SteppingAction::SetSecondaryHostData;

namespace adept::transport {
// TransportGammasWoodcock Interface
// One Woodcock-tracking step of the gamma in the given slot. The transport kernels call it per active slot.
template <class SteppingActionT>
__global__ void __launch_bounds__(256, 1)
TransportGammasWoodcock(ParticleManager particleManager, Stats *InFlightStats, const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent, const TransportKernelOptions options)
static __device__ __forceinline__ void GammaWDTStep(ParticleManager &particleManager,
const SlotManager::value_type slot, Stats *InFlightStats,
const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent,
const TransportKernelOptions options)
{
// Implementation of the gamma transport using Woodcock tracking. The implementation is taken from
// Mihaly Novak's G4HepEm (https://github.com/mnovak42/g4hepem), see G4HepEmWoodcockHelper.hh/cc and
Expand All @@ -52,9 +54,7 @@ __global__ void __launch_bounds__(256, 1)
const bool returnAllSteps = options.returnAllSteps;
const bool returnLastStep = options.returnLastStep;
auto &slotManager = *particleManager.gammasWDT.fSlotManager;
const int activeSize = particleManager.gammasWDT.ActiveSize();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const auto slot = particleManager.gammasWDT.ActiveAt(i);
{
NeutralTrack &currentTrack = particleManager.gammasWDT.TrackAt(slot);

// Finish-on-CPU must happen before any interaction can create secondaries on the GPU.
Expand All @@ -65,7 +65,7 @@ __global__ void __launch_bounds__(256, 1)
slotManager.MarkSlotForFreeing(slot);

adept_step_recording::RecordFinishOnCPU(currentTrack, ParticleType::Gamma);
continue;
return;
}

// Find the Woodcock tracking region index and root volume index
Expand All @@ -79,7 +79,7 @@ __global__ void __launch_bounds__(256, 1)
if (!particleManager.gammas.EnqueueNext(slot)) {
COPCORE_EXCEPTION("WDT fallback could not enqueue gamma");
}
continue;
return;
}

// Setup of the advanced debug printouts
Expand Down Expand Up @@ -135,7 +135,7 @@ __global__ void __launch_bounds__(256, 1)
adept_step_recording::RecordZeroLengthGPUStep(currentTrack, ParticleType::Gamma, kAdePTTransportationProcess,
preStepEnergy, eKin, edep);
}
continue;
return;
}
}

Expand Down Expand Up @@ -751,7 +751,20 @@ __global__ void __launch_bounds__(256, 1)
secondaryData, // Secondary initialization data
nSecondaries); // Number of secondaries
}
} // end for loop over tracks
} // end of the step of this track
}

// TransportGammasWoodcock Interface
template <class SteppingActionT>
__global__ void __launch_bounds__(256, 1)
TransportGammasWoodcock(ParticleManager particleManager, Stats *InFlightStats, const StepActionParam params,
AllowFinishOffEventArray allowFinishOffEvent, const TransportKernelOptions options)
{
const int activeSize = particleManager.gammasWDT.ActiveSize();
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < activeSize; i += blockDim.x * gridDim.x) {
const auto slot = particleManager.gammasWDT.ActiveAt(i);
GammaWDTStep<SteppingActionT>(particleManager, slot, InFlightStats, params, allowFinishOffEvent, options);
}
}

} // namespace adept::transport
Loading