Skip to content

Commit

Permalink
Refactor Seq meta algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Mar 23, 2023
1 parent 4291dea commit d45c46e
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 135 deletions.
4 changes: 2 additions & 2 deletions include/picongpu/particles/Manipulate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace picongpu
uint32_t T_area = CORE + BORDER>
inline void manipulate(uint32_t const currentStep)
{
using SpeciesSeq = typename pmacc::ToSeq<T_Species>::type;
using SpeciesSeq = pmacc::ToSeq<T_Species>;
using Functor
= Manipulate<T_Manipulator, boost::mpl::_1, T_Filter, std::integral_constant<uint32_t, T_area>>;
pmacc::meta::ForEach<SpeciesSeq, Functor> forEach;
Expand All @@ -155,7 +155,7 @@ namespace picongpu
typename T_Filter = filter::All>
inline void manipulate(uint32_t const currentStep, T_AreaMapperFactory const& areaMapperFactory)
{
using SpeciesSeq = typename pmacc::ToSeq<T_Species>::type;
using SpeciesSeq = pmacc::ToSeq<T_Species>;
using Functor = Manipulate<T_Manipulator, boost::mpl::_1, T_Filter>;
pmacc::meta::ForEach<SpeciesSeq, Functor> forEach;
forEach(currentStep, areaMapperFactory);
Expand Down
2 changes: 1 addition & 1 deletion include/picongpu/particles/collision/Collider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace picongpu
{
void operator()(std::shared_ptr<DeviceHeap> const& deviceHeap, uint32_t currentStep)
{
using SpeciesPairList = typename pmacc::ToSeq<typename T_Collider::SpeciesPairs>::type;
using SpeciesPairList = pmacc::ToSeq<typename T_Collider::SpeciesPairs>;
constexpr size_t numPairs = pmacc::mp_size<SpeciesPairList>::value;
std::make_index_sequence<numPairs> index{};
detail::CallColliderForAPair<SpeciesPairList, T_Collider, colliderId>{}(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace picongpu
struct CreateEligible
{
// wrap single arguments to sequence
using SeqSpecies = typename pmacc::ToSeq<T_SeqSpecies>::type;
using SeqSpecies = pmacc::ToSeq<T_SeqSpecies>;
using FilteredAttribute = FilteredDerivedAttribute<T_DerivedAttribute, T_Filter>;

using type = typename traits::GenerateSolversIfSpeciesEligible<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace picongpu
struct GenerateSolversIfSpeciesEligible
{
// wrap single arguments to sequence
using SeqSpecies = typename pmacc::ToSeq<T_SeqSpecies>::type;
using SeqSpecies = pmacc::ToSeq<T_SeqSpecies>;

// unspecialized solver
using Solver = T_Solver;
Expand Down
3 changes: 1 addition & 2 deletions include/picongpu/plugins/BinEnergyParticles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ namespace picongpu
// find all valid filter for the current used species
template<typename T>
using Op = typename particles::traits::GenerateSolversIfSpeciesEligible<T, ParticlesType>::type;
using EligibleFilters =
typename MakeSeqFromNestedSeq<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>::type;
using EligibleFilters = pmacc::mp_flatten<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>;

//! periodicity of computing the particle energy
plugins::multi::Option<std::string> notifyPeriod = {"period", "enable plugin [for each n-th step]"};
Expand Down
3 changes: 1 addition & 2 deletions include/picongpu/plugins/Emittance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ namespace picongpu
// find all valid filter for the current used species
template<typename T>
using Op = typename particles::traits::GenerateSolversIfSpeciesEligible<T, ParticlesType>::type;
using EligibleFilters =
typename MakeSeqFromNestedSeq<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>::type;
using EligibleFilters = pmacc::mp_flatten<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>;

//! periodicity of computing the particle energy
plugins::multi::Option<std::string> notifyPeriod
Expand Down
3 changes: 1 addition & 2 deletions include/picongpu/plugins/EnergyParticles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ namespace picongpu
// find all valid filter for the current used species
template<typename T>
using Op = typename particles::traits::GenerateSolversIfSpeciesEligible<T, ParticlesType>::type;
using EligibleFilters =
typename MakeSeqFromNestedSeq<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>::type;
using EligibleFilters = pmacc::mp_flatten<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>;

//! periodicity of computing the particle energy
plugins::multi::Option<std::string> notifyPeriod
Expand Down
3 changes: 1 addition & 2 deletions include/picongpu/plugins/PhaseSpace/PhaseSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ namespace picongpu
// find all valid filter for the current used species
template<typename T>
using Op = typename particles::traits::GenerateSolversIfSpeciesEligible<T, Species>::type;
using EligibleFilters =
typename MakeSeqFromNestedSeq<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>::type;
using EligibleFilters = pmacc::mp_flatten<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>;

//! periodicity of computing the particle energy
plugins::multi::Option<std::string> notifyPeriod = {"period", "notify period"};
Expand Down
1 change: 0 additions & 1 deletion include/picongpu/plugins/PluginController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@

#include <pmacc/mappings/kernel/MappingDescription.hpp>
#include <pmacc/meta/AllCombinations.hpp>
#include <pmacc/meta/SeqToList.hpp>

#include <list>
#include <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ namespace picongpu
// find all valid filter for the current used species
template<typename T>
using Op = typename particles::traits::GenerateSolversIfSpeciesEligible<T, ParticlesType>::type;
using EligibleFilters =
typename MakeSeqFromNestedSeq<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>::type;
using EligibleFilters = pmacc::mp_flatten<pmacc::mp_transform<Op, particles::filter::AllParticleFilters>>;

//! periodicity of computing the particle energy
plugins::multi::Option<std::string> notifyPeriod = {"period", "enable plugin [for each n-th step]"};
Expand Down
11 changes: 4 additions & 7 deletions include/pmacc/meta/ForEach.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#pragma once

#include "pmacc/meta/SeqToList.hpp"
#include "pmacc/meta/accessors/Identity.hpp"

#include <boost/mpl/apply.hpp>
Expand All @@ -32,29 +31,27 @@ namespace pmacc::meta
{
/** Compile-Time for each for Boost::MPL Type Lists
*
* @tparam T_MPLSeq A mpl sequence that can be accessed by mpl::begin, mpl::end, mpl::next
* @tparam List An mp_list.
* @tparam T_Functor An unary lambda functor with a HDINLINE void operator()(...) method
* _1 is substituted by Accessor's result using boost::mpl::apply with elements from T_MPLSeq.
* The maximum number of parameters for the operator() is limited by
* PMACC_MAX_FUNCTOR_OPERATOR_PARAMS
* @tparam T_Accessor An unary lambda operation
*
* Example:
* MPLSeq = pmacc::mp_list<int,float>
* List = pmacc::mp_list<int,float>
* Functor = any unary lambda functor
* Accessor = lambda operation identity
*
* definition: F(X) means boost::apply<F,X>
*
* call: ForEach<MPLSeq,Functor,Accessor>()(42);
* call: ForEach<List,Functor,Accessor>()(42);
* unrolled code: Functor(Accessor(int))(42);
* Functor(Accessor(float))(42);
*/
template<typename T_MPLSeq, typename T_Functor, typename T_Accessor = meta::accessors::Identity<>>
template<typename List, typename T_Functor, typename T_Accessor = meta::accessors::Identity<>>
struct ForEach
{
using List = detail::SeqToList<T_MPLSeq>;

template<typename X>
using ReplacePlaceholder =
typename boost::mpl::apply1<T_Functor, typename boost::mpl::apply1<T_Accessor, X>::type>::type;
Expand Down
38 changes: 0 additions & 38 deletions include/pmacc/meta/SeqToList.hpp

This file was deleted.

10 changes: 5 additions & 5 deletions include/pmacc/meta/conversion/MakeSeq.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2013-2022 Rene Widera
/* Copyright 2013-2022 Rene Widera, Bernhard Manfred Gruber
*
* This file is part of PMacc.
*
Expand All @@ -22,12 +22,12 @@

#pragma once

#include "pmacc/meta/conversion/MakeSeqFromNestedSeq.hpp"
#include "pmacc/meta/Mp11.hpp"

namespace pmacc
{
/** short hand definition for @see MakeSeqFromNestedSeq<> */
/** Makes an mp_list from T_Args. If any type in T_Args is a list itself, it will be unwrapped.
*/
template<typename... T_Args>
using MakeSeq_t = typename MakeSeqFromNestedSeq<mp_list<T_Args...>>::type;

using MakeSeq_t = mp_flatten<mp_list<T_Args...>>;
} // namespace pmacc
43 changes: 0 additions & 43 deletions include/pmacc/meta/conversion/MakeSeqFromNestedSeq.hpp

This file was deleted.

9 changes: 4 additions & 5 deletions include/pmacc/meta/conversion/SeqToMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,30 @@

#pragma once

#include "pmacc/meta/SeqToList.hpp"
#include "pmacc/meta/accessors/Identity.hpp"
#include "pmacc/types.hpp"

#include <boost/mpl/apply.hpp>

namespace pmacc
{
/** convert boost mp11 list to a map
/** convert a list to a map
*
* @tparam T_MPLSeq any boost mp11 list
* @tparam T_List an mp_list.
* @tparam T_UnaryOperator unary operator to translate type from the sequence
* to a mpl pair
* @tparam T_Accessor An unary lambda operator which is used before the type
* from the sequence is passed to T_UnaryOperator
* @return ::type mpl map
*/
template<typename T_MPLSeq, typename T_UnaryOperator, typename T_Accessor = meta::accessors::Identity<>>
template<typename T_List, typename T_UnaryOperator, typename T_Accessor = meta::accessors::Identity<>>
struct SeqToMap
{
template<typename X>
using Op =
typename boost::mpl::apply1<T_UnaryOperator, typename boost::mpl::apply1<T_Accessor, X>::type>::type;

using ListOfTuples = mp_transform<Op, meta::detail::SeqToList<T_MPLSeq>>;
using ListOfTuples = mp_transform<Op, T_List>;
using type = mp_fold<ListOfTuples, mp_list<>, mp_map_insert>;
};
} // namespace pmacc
32 changes: 18 additions & 14 deletions include/pmacc/meta/conversion/ToSeq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@

#pragma once

#include "pmacc/types.hpp"
#include "pmacc/meta/Mp11.hpp"

namespace pmacc
{
/** cast type to boost mpl vector
* @return ::type if T_Type is sequence then identity of T_Type
* else mp_list<T_Type>
*/
template<typename T_Type>
struct ToSeq
namespace detail
{
using type = mp_list<T_Type>;
};
template<typename T_Type>
struct ToSeq
{
using type = mp_list<T_Type>;
};

template<typename... Ts>
struct ToSeq<mp_list<Ts...>>
{
using type = mp_list<Ts...>;
};
template<typename... Ts>
struct ToSeq<mp_list<Ts...>>
{
using type = mp_list<Ts...>;
};
} // namespace detail

/** If T_Type is an mp_list, return it. Otherwise wrap it in an mp_list.
*/
template<typename T_Type>
using ToSeq = typename detail::ToSeq<T_Type>::type;
} // namespace pmacc
12 changes: 6 additions & 6 deletions include/pmacc/particles/ParticleDescription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ namespace pmacc
{
using Name = T_Name;
using SuperCellSize = T_SuperCellSize;
using ValueTypeSeq = typename ToSeq<T_ValueTypeSeq>::type;
using FlagsList = typename ToSeq<T_Flags>::type;
using ValueTypeSeq = ToSeq<T_ValueTypeSeq>;
using FlagsList = ToSeq<T_Flags>;
using HandleGuardRegion = T_HandleGuardRegion;
using MethodsList = typename ToSeq<T_MethodsList>::type;
using FrameExtensionList = typename ToSeq<T_FrameExtensionList>::type;
using MethodsList = ToSeq<T_MethodsList>;
using FrameExtensionList = ToSeq<T_FrameExtensionList>;
using ThisType = ParticleDescription<
Name,
SuperCellSize,
Expand Down Expand Up @@ -100,7 +100,7 @@ namespace pmacc
using type = ParticleDescription<
typename OldParticleDescription::Name,
typename OldParticleDescription::SuperCellSize,
typename ToSeq<T_NewValueTypeSeq>::type,
ToSeq<T_NewValueTypeSeq>,
typename OldParticleDescription::FlagsList,
typename OldParticleDescription::HandleGuardRegion,
typename OldParticleDescription::MethodsList,
Expand All @@ -124,7 +124,7 @@ namespace pmacc
typename OldParticleDescription::FlagsList,
typename OldParticleDescription::HandleGuardRegion,
typename OldParticleDescription::MethodsList,
typename ToSeq<T_FrameExtensionSeq>::type>;
ToSeq<T_FrameExtensionSeq>>;
};

} // namespace pmacc
2 changes: 1 addition & 1 deletion include/pmacc/particles/operations/Deselect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace pmacc
template<typename T_Exclude, typename T_Object>
HDINLINE decltype(auto) deselect(T_Object& object)
{
using DeselectSeq = typename ToSeq<T_Exclude>::type;
using DeselectSeq = ToSeq<T_Exclude>;
using BaseType = detail::Deselect<DeselectSeq, T_Object>;

return BaseType()(object);
Expand Down

0 comments on commit d45c46e

Please sign in to comment.