Skip to content

Commit

Permalink
extract caching of E-Field
Browse files Browse the repository at this point in the history
removes the code duplciation of caching the EField

ci: picongpu
  • Loading branch information
BrianMarre committed Nov 15, 2024
1 parent 07f6746 commit 0c9ebfe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 42 deletions.
11 changes: 8 additions & 3 deletions include/picongpu/particles/atomicPhysics/EFieldCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,26 @@
// need unit.param for normalisation and units, memory.param for SuperCellSize and dim.param for simDim
#include "picongpu/defines.hpp"

#include <pmacc/dimensions/DataSpace.hpp>
#include <pmacc/dimensions/SuperCellDescription.hpp>
#include <pmacc/mappings/threads/ThreadCollective.hpp>
#include <pmacc/math/operation/Assign.hpp>
#include <pmacc/memory/boxes/CachedBox.hpp>

namespace picongpu::particles::atomicPhysics
{
struct EFieldCache
{
//! @attention collective Method, before first access of cache values a thread synchronize is required!
template<typename T_Worker, typename T_EFieldDataBox>
template<uint32_t T_id, typename T_Worker, typename T_EFieldDataBox>
HDINLINE static auto get(
T_Worker const& worker,
pmacc::DataSpace<picongpu::simDim> const superCellIndex,
T_EFieldDataBox const eFieldBox)
{
using SuperCellBlock = pmacc::SuperCellDescription<typename picongpu::SuperCellSize>;
/// @note cache is unique for kernel call by id and dataType, and thereby shared between workers
auto eFieldCache
= CachedBox::create<__COUNTER__, typename T_EFieldDataBox::ValueType>(worker, SuperCellBlock());
auto eFieldCache = CachedBox::create<T_id, typename T_EFieldDataBox::ValueType>(worker, SuperCellBlock());

pmacc::DataSpace<picongpu::simDim> const superCellCellOffset
= superCellIndex * picongpu::SuperCellSize::toRT();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "picongpu/particles/atomicPhysics/CheckForInvalidChooseTransitionGroup.hpp"
#include "picongpu/particles/atomicPhysics/CheckSetOfAtomicDataBoxes.hpp"
#include "picongpu/particles/atomicPhysics/ConvertEnum.hpp"
#include "picongpu/particles/atomicPhysics/EFieldCache.hpp"
#include "picongpu/particles/atomicPhysics/KernelIndexation.hpp"
#include "picongpu/particles/atomicPhysics/enums/ChooseTransitionGroup.hpp"
#include "picongpu/particles/atomicPhysics/enums/ProcessClass.hpp"
Expand Down Expand Up @@ -62,25 +63,6 @@ namespace picongpu::particles::atomicPhysics::kernel
{
using VectorIdx = pmacc::DataSpace<picongpu::simDim>;

private:
//! @attention this is a collective method and implicitly synchronises
template<typename BlockDescription, typename T_Worker, typename T_EFieldBox, typename T_EfieldCache>
HDINLINE void initEFieldCache(
T_Worker const& worker,
VectorIdx const& superCellCellOffset,
T_EFieldBox const eFieldBox,
T_EfieldCache& eFieldCache) const
{
auto fieldEBlockToCache = eFieldBox.shift(superCellCellOffset);

pmacc::math::operation::Assign assign;
auto collective = makeThreadCollective<BlockDescription>();

collective(worker, assign, eFieldCache, fieldEBlockToCache);
worker.sync();
}

public:
/** call operator
*
* called by ChooseTransition atomic physics sub-stage
Expand Down Expand Up @@ -146,13 +128,8 @@ namespace picongpu::particles::atomicPhysics::kernel
if((timeRemaining <= 0._X) || (!forEachLocalIonBoxEntry.hasParticles()))
return;

using SuperCellBlock = pmacc::SuperCellDescription<typename picongpu::SuperCellSize>;
VectorIdx const superCellSize = picongpu::SuperCellSize::toRT();
/// @note cache is unique for kernel call by id and dataType, and thereby shared between workers
auto eFieldCache
= CachedBox::create</* Id */ 0u, typename T_EFieldBox::ValueType>(worker, SuperCellBlock());
VectorIdx const superCellCellOffset = superCellIdx * superCellSize;
initEFieldCache<SuperCellBlock>(worker, superCellCellOffset, eFieldBox, eFieldCache);
auto eFieldCache = EFieldCache::get<__COUNTER__>(worker, superCellIdx, eFieldBox);
worker.sync();

auto rngGeneratorFloat = rngFactoryFloat(worker, superCellFieldIdx);
auto& rateCache = rateCacheBox(superCellFieldIdx);
Expand All @@ -177,7 +154,7 @@ namespace picongpu::particles::atomicPhysics::kernel
auto const atomicStateCollectionIndex = ion[atomicStateCollectionIndex_];

VectorIdx const localCellIndex
= pmacc::math::mapToND(superCellSize, static_cast<int>(ion[localCellIdx_]));
= pmacc::math::mapToND(picongpu::SuperCellSize::toRT(), static_cast<int>(ion[localCellIdx_]));
// unit: unit_eField
float_X eFieldNormCell = pmacc::math::l2norm(eFieldCache(localCellIndex));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@
#include "picongpu/particles/creation/SpawnFromSourceSpeciesModuleInterfaces.hpp"

#include <pmacc/dimensions/DataSpace.hpp>
#include <pmacc/dimensions/SuperCellDescription.hpp>
#include <pmacc/mappings/threads/ThreadCollective.hpp>
#include <pmacc/math/operation/Assign.hpp>
#include <pmacc/memory/boxes/CachedBox.hpp>
#include <pmacc/memory/boxes/DataBox.hpp>
#include <pmacc/memory/boxes/SharedBox.hpp>

namespace picongpu::particles::atomicPhysics::spawnFromSourceSpeciesModules
{
namespace s_interfaces = picongpu::particles::creation::moduleInterfaces;

//! definition of Modul
template<typename T_IPDModel, typename T_fieldIonizationActive>
template<uint32_t T_id, typename T_IPDModel, typename T_fieldIonizationActive>
struct CacheEFieldForSuperCell
: public s_interfaces::
InitCacheFunctor<pmacc::DataSpace<picongpu::simDim>, T_IPDModel, T_fieldIonizationActive>
Expand Down Expand Up @@ -65,7 +59,7 @@ namespace picongpu::particles::atomicPhysics::spawnFromSourceSpeciesModules
{
if constexpr(T_fieldIonizationActive::value)
{
return EFieldCache::get(worker, superCellIndex, eFieldBox);
return EFieldCache::get<T_id>(worker, superCellIndex, eFieldBox);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions include/picongpu/particles/creation/ModuleConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace picongpu::particles::creation
typename T_KernelStateType,
template<typename... T_KernelConfigOptions>
typename T_InitKernelStateFunctor,
template<typename... T_KernelConfigOptions>
template<uint32_t T_id, typename... T_KernelConfigOptions>
typename T_InitCacheFunctor,
template<typename... T_KernelConfigOptions>
typename T_AdditionalDataIndexFunctor,
Expand Down Expand Up @@ -100,8 +100,8 @@ namespace picongpu::particles::creation
template<typename... T_KernelConfigOptions>
using InitKernelStateFunctor = T_InitKernelStateFunctor<T_KernelConfigOptions...>;

template<typename... T_KernelConfigOptions>
using InitCacheFunctor = T_InitCacheFunctor<T_KernelConfigOptions...>;
template<uint32_t T_id, typename... T_KernelConfigOptions>
using InitCacheFunctor = T_InitCacheFunctor<T_id, T_KernelConfigOptions...>;

template<typename... T_KernelConfigOptions>
using WriteOutKernelStateFunctor = T_WriteOutKernelStateFunctor<T_KernelConfigOptions...>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ namespace picongpu::particles::creation
PMACC_SMEM(worker, sharedKernelState, typename Modules::KernelStateType);

// create cache
auto cache = Modules::template InitCacheFunctor<T_KernelConfigOptions...>::getCache(
auto cache = Modules::template InitCacheFunctor<__COUNTER__, T_KernelConfigOptions...>::getCache(
worker,
superCellIndex,
std::forward<T_AdditionalData>(additonalData)...);
Expand Down

0 comments on commit 0c9ebfe

Please sign in to comment.