From 702397cfbac51495631e6ff8014784a33eda828e Mon Sep 17 00:00:00 2001 From: BrianMarre Date: Wed, 13 Nov 2024 19:45:56 +0100 Subject: [PATCH] extract caching of E-Field removes the code duplciation of caching the EField ci: picongpu --- .../particles/atomicPhysics/EFieldCache.hpp | 11 +++++-- .../ChooseTransition_FieldBoundFree.kernel | 31 +++---------------- .../CacheEFieldForSuperCell.hpp | 10 ++---- .../particles/creation/ModuleConfig.hpp | 6 ++-- .../creation/SpawnFromSourceSpecies.kernel | 2 +- 5 files changed, 18 insertions(+), 42 deletions(-) diff --git a/include/picongpu/particles/atomicPhysics/EFieldCache.hpp b/include/picongpu/particles/atomicPhysics/EFieldCache.hpp index e6de4cbfea..dc8213b26f 100644 --- a/include/picongpu/particles/atomicPhysics/EFieldCache.hpp +++ b/include/picongpu/particles/atomicPhysics/EFieldCache.hpp @@ -22,12 +22,18 @@ // need unit.param for normalisation and units, memory.param for SuperCellSize and dim.param for simDim #include "picongpu/defines.hpp" +#include +#include +#include +#include +#include + namespace picongpu::particles::atomicPhysics { struct EFieldCache { //! @attention collective Method, before first access of cache values a thread synchronize is required! - template + template HDINLINE static auto get( T_Worker const& worker, pmacc::DataSpace const superCellIndex, @@ -35,8 +41,7 @@ namespace picongpu::particles::atomicPhysics { using SuperCellBlock = pmacc::SuperCellDescription; /// @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(worker, SuperCellBlock()); pmacc::DataSpace const superCellCellOffset = superCellIndex * picongpu::SuperCellSize::toRT(); diff --git a/include/picongpu/particles/atomicPhysics/kernel/ChooseTransition_FieldBoundFree.kernel b/include/picongpu/particles/atomicPhysics/kernel/ChooseTransition_FieldBoundFree.kernel index 8528375018..5bdb74380e 100644 --- a/include/picongpu/particles/atomicPhysics/kernel/ChooseTransition_FieldBoundFree.kernel +++ b/include/picongpu/particles/atomicPhysics/kernel/ChooseTransition_FieldBoundFree.kernel @@ -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" @@ -62,25 +63,6 @@ namespace picongpu::particles::atomicPhysics::kernel { using VectorIdx = pmacc::DataSpace; - private: - //! @attention this is a collective method and implicitly synchronises - template - 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(); - - collective(worker, assign, eFieldCache, fieldEBlockToCache); - worker.sync(); - } - - public: /** call operator * * called by ChooseTransition atomic physics sub-stage @@ -146,13 +128,8 @@ namespace picongpu::particles::atomicPhysics::kernel if((timeRemaining <= 0._X) || (!forEachLocalIonBoxEntry.hasParticles())) return; - using SuperCellBlock = pmacc::SuperCellDescription; - 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(worker, SuperCellBlock()); - VectorIdx const superCellCellOffset = superCellIdx * superCellSize; - initEFieldCache(worker, superCellCellOffset, eFieldBox, eFieldCache); + auto eFieldCache = EFieldCache::get<__COUNTER__>(worker, superCellIdx, eFieldBox); + worker.sync(); auto rngGeneratorFloat = rngFactoryFloat(worker, superCellFieldIdx); auto& rateCache = rateCacheBox(superCellFieldIdx); @@ -177,7 +154,7 @@ namespace picongpu::particles::atomicPhysics::kernel auto const atomicStateCollectionIndex = ion[atomicStateCollectionIndex_]; VectorIdx const localCellIndex - = pmacc::math::mapToND(superCellSize, static_cast(ion[localCellIdx_])); + = pmacc::math::mapToND(picongpu::SuperCellSize::toRT(), static_cast(ion[localCellIdx_])); // unit: unit_eField float_X eFieldNormCell = pmacc::math::l2norm(eFieldCache(localCellIndex)); diff --git a/include/picongpu/particles/atomicPhysics/spawnFromSourceSpeciesModules/CacheEFieldForSuperCell.hpp b/include/picongpu/particles/atomicPhysics/spawnFromSourceSpeciesModules/CacheEFieldForSuperCell.hpp index 8eca755696..a15e3bb301 100644 --- a/include/picongpu/particles/atomicPhysics/spawnFromSourceSpeciesModules/CacheEFieldForSuperCell.hpp +++ b/include/picongpu/particles/atomicPhysics/spawnFromSourceSpeciesModules/CacheEFieldForSuperCell.hpp @@ -25,19 +25,13 @@ #include "picongpu/particles/creation/SpawnFromSourceSpeciesModuleInterfaces.hpp" #include -#include -#include -#include -#include -#include -#include namespace picongpu::particles::atomicPhysics::spawnFromSourceSpeciesModules { namespace s_interfaces = picongpu::particles::creation::moduleInterfaces; //! definition of Modul - template + template struct CacheEFieldForSuperCell : public s_interfaces:: InitCacheFunctor, T_IPDModel, T_fieldIonizationActive> @@ -65,7 +59,7 @@ namespace picongpu::particles::atomicPhysics::spawnFromSourceSpeciesModules { if constexpr(T_fieldIonizationActive::value) { - return EFieldCache::get(worker, superCellIndex, eFieldBox); + return EFieldCache::get(worker, superCellIndex, eFieldBox); } else { diff --git a/include/picongpu/particles/creation/ModuleConfig.hpp b/include/picongpu/particles/creation/ModuleConfig.hpp index ed70ac8fbf..5568a830cc 100644 --- a/include/picongpu/particles/creation/ModuleConfig.hpp +++ b/include/picongpu/particles/creation/ModuleConfig.hpp @@ -66,7 +66,7 @@ namespace picongpu::particles::creation typename T_KernelStateType, template typename T_InitKernelStateFunctor, - template + template typename T_InitCacheFunctor, template typename T_AdditionalDataIndexFunctor, @@ -100,8 +100,8 @@ namespace picongpu::particles::creation template using InitKernelStateFunctor = T_InitKernelStateFunctor; - template - using InitCacheFunctor = T_InitCacheFunctor; + template + using InitCacheFunctor = T_InitCacheFunctor; template using WriteOutKernelStateFunctor = T_WriteOutKernelStateFunctor; diff --git a/include/picongpu/particles/creation/SpawnFromSourceSpecies.kernel b/include/picongpu/particles/creation/SpawnFromSourceSpecies.kernel index 8ec873a785..c19b2e96a8 100644 --- a/include/picongpu/particles/creation/SpawnFromSourceSpecies.kernel +++ b/include/picongpu/particles/creation/SpawnFromSourceSpecies.kernel @@ -157,7 +157,7 @@ namespace picongpu::particles::creation PMACC_SMEM(worker, sharedKernelState, typename Modules::KernelStateType); // create cache - auto cache = Modules::template InitCacheFunctor::getCache( + auto cache = Modules::template InitCacheFunctor<__COUNTER__, T_KernelConfigOptions...>::getCache( worker, superCellIndex, std::forward(additonalData)...);