Skip to content

Commit

Permalink
Fixes and workaround
Browse files Browse the repository at this point in the history
- shared memory: fix type deduction
- workaround nvcc bugs
  • Loading branch information
psychocoderHPC authored and bernhardmgruber committed Mar 22, 2023
1 parent d924b26 commit 49b7fa9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
8 changes: 6 additions & 2 deletions include/picongpu/plugins/openPMD/openPMDWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
{
private:
using ValueType = typename T_Field::ValueType;
using ComponentType = typename GetComponentsType<ValueType>::type;
using ComponentType =
typename pmacc::traits::GetComponentsType<ValueType>::type; // FIXME(bgruber): pmacc::traits::
// needed because of nvcc 11.0 bug
using UnitType = typename T_Field::UnitValueType;

public:
Expand Down Expand Up @@ -603,7 +605,9 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1.
* `using ComponentType = typename GetComponentsType<ValueType>`
* more info: https://github.com/ComputationalRadiationPhysics/picongpu/pull/4006
*/
using GetComponentsTypeValueType = GetComponentsType<ValueType>;
using GetComponentsTypeValueType
= pmacc::traits::GetComponentsType<ValueType>; // FIXME(bgruber): pmacc::traits:: needed for
// nvcc 11.0
using ComponentType = typename GetComponentsTypeValueType::type;

/** Get the unit for the result from the solver*/
Expand Down
39 changes: 30 additions & 9 deletions include/pmacc/memory/boxes/SharedBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@

namespace pmacc
{
namespace detail
{
template<typename T_Vector, typename T_TYPE>
HDINLINE auto& subscript(T_TYPE* p, int const idx, std::integral_constant<uint32_t, 1>)
{
return p[idx];
}

template<typename T_Vector, typename T_TYPE>
HDINLINE auto* subscript(T_TYPE* p, int const idx, std::integral_constant<uint32_t, 2>)
{
return p + idx * T_Vector::x::value;
}

template<typename T_Vector, typename T_TYPE>
HDINLINE auto* subscript(T_TYPE* p, int const idx, std::integral_constant<uint32_t, 3>)
{
return p + idx * (T_Vector::x::value * T_Vector::y::value);
}
} // namespace detail

/** create shared memory on gpu
*
* @tparam T_TYPE type of memory objects
Expand All @@ -52,16 +73,16 @@ namespace pmacc

HDINLINE SharedBox(SharedBox const&) = default;

HDINLINE decltype(auto) operator[](const int idx) const
using ReducedType1D = T_TYPE&;
using ReducedType2D = SharedBox<T_TYPE, typename math::CT::shrinkTo<T_Vector, 1>::type, T_id>;
using ReducedType3D = SharedBox<T_TYPE, typename math::CT::shrinkTo<T_Vector, 2>::type, T_id>;
using ReducedType
= std::conditional_t<Dim == 1, ReducedType1D, std::conditional_t<Dim == 2, ReducedType2D, ReducedType3D>>;

HDINLINE ReducedType operator[](const int idx) const
{
if constexpr(Dim == 1)
return fixedPointer[idx];
else if constexpr(Dim == 2)
return SharedBox<T_TYPE, math::CT::Int<T_Vector::x::value>, T_id>{
fixedPointer + idx * T_Vector::x::value};
else if constexpr(Dim == 3)
return SharedBox<T_TYPE, math::CT::Int<T_Vector::x::value, T_Vector::y::value>, T_id>{
fixedPointer + idx * (T_Vector::x::value * T_Vector::y::value)};
///@todo(bgruber): inline and replace this by if constexpr in C++17
return {detail::subscript<T_Vector>(fixedPointer, idx, std::integral_constant<uint32_t, T_dim>{})};
}

/*!return the first value in the box (list)
Expand Down
11 changes: 7 additions & 4 deletions include/pmacc/meta/GetKeyFromAlias.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,28 @@ namespace pmacc
struct GetKeyFromAlias
{
private:
// FIXME(bgruber): all the boost::mp11:: qualifications inside this class work around nvcc 11.0 not finding the
// mp_* templates

using KeyNotFoundPolicy = T_KeyNotFoundPolicy;
/*create a map where Key is a undeclared alias and value is real type*/
using AliasMap = typename SeqToMap<T_MPLSeq, TypeToAliasPair<boost::mpl::_1>>::type;
/*create a map where Key and value is real type*/
using KeyMap = typename SeqToMap<T_MPLSeq, TypeToPair<boost::mpl::_1>>::type;
/*combine both maps*/
using FullMap = mp_fold<AliasMap, KeyMap, mp_map_insert>;
using FullMap = boost::mp11::mp_fold<AliasMap, KeyMap, boost::mp11::mp_map_insert>;
/* search for given key,
* - we get the real type if key found
* - else we get boost::mpl::void_
*/
using MapType = mp_map_find<FullMap, T_Key>;
using MapType = boost::mp11::mp_map_find<FullMap, T_Key>;

public:
/* Check for KeyNotFound and calculate final type. (Uses lazy evaluation) */
using type = typename mp_if<
using type = typename boost::mp11::mp_if<
std::is_same<MapType, void>,
boost::mpl::apply<KeyNotFoundPolicy, T_MPLSeq, T_Key>,
mp_defer<mp_second, MapType>>::type;
boost::mp11::mp_defer<boost::mp11::mp_second, MapType>>::type;
};

} // namespace pmacc
3 changes: 2 additions & 1 deletion include/pmacc/meta/conversion/RemoveFromSeq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace pmacc
struct RemoveFromSeq
{
template<typename T_Value>
using hasId = mp_contains<T_MPLSeqObjectsToRemove, T_Value>;
using hasId = boost::mp11::mp_contains<T_MPLSeqObjectsToRemove, T_Value>; // FIXME(bgruber): boost::mp11::
// needed for nvcc 11.0

using type = mp_remove_if<T_MPLSeqSrc, hasId>;
};
Expand Down
8 changes: 4 additions & 4 deletions include/pmacc/particles/memory/dataTypes/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ namespace pmacc
using DestTypeSeq = typename Dest::ValueTypeSeq;
using SrcTypeSeq = typename Src::ValueTypeSeq;

/* create sequences with disjunct attributes from `DestTypeSeq` */
using UniqueInDestTypeSeq = mp_set_difference<DestTypeSeq, SrcTypeSeq>;

/* create attribute list with a subset of common attributes in two sequences
* mp_contains has lower complexity than traits::HasIdentifier
* and was used for this reason
*/
using CommonTypeSeq = mp_set_intersection<DestTypeSeq, SrcTypeSeq>;

/* create sequences with disjunct attributes from `DestTypeSeq` */
using UniqueInDestTypeSeq = mp_set_difference<DestTypeSeq, SrcTypeSeq>;
using CommonTypeSeq = mp_set_difference<DestTypeSeq, UniqueInDestTypeSeq>;

/** Assign particle attributes
*
Expand Down
3 changes: 2 additions & 1 deletion include/pmacc/particles/memory/frames/Frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ namespace pmacc
*/
using SolvedAliasName = typename GetKeyFromAlias<ValueTypeSeq, T_IdentifierName>::type;

using type = mp_contains<ValueTypeSeq, SolvedAliasName>;
using type = boost::mp11::mp_contains<ValueTypeSeq, SolvedAliasName>; // FIXME(bgruber): boost::mp11::
// needed because of nvcc 11.0 bug
};

template<typename T_IdentifierName, typename T_CreatePairOperator, typename T_ParticleDescription>
Expand Down

0 comments on commit 49b7fa9

Please sign in to comment.