Skip to content
Draft
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
57 changes: 26 additions & 31 deletions include/pmacc/dimensions/DataSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "pmacc/math/Vector.hpp"
#include "pmacc/types.hpp"

#include <alpaka/core/Common.hpp>

#include <type_traits>

namespace pmacc
Expand Down Expand Up @@ -65,19 +67,15 @@ namespace pmacc
{
}

constexpr DataSpace(DataSpace const&) = default;

HDINLINE constexpr DataSpace& operator=(DataSpace const&) = default;

/** constructor.
*
* Sets size of all dimensions from alpaka.
* Reverses (permutes) the order of the dimensions.
*/
template<typename T_MemberType>
HDINLINE explicit DataSpace(alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const& value)
HDINLINE explicit constexpr DataSpace(alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const& value)
: BaseType(makeReversedArgs(value, std::make_index_sequence<T_dim>{}))
{
for(uint32_t i = 0u; i < T_dim; i++)
(*this)[T_dim - 1 - i] = value[i];
}

/** Constructor for N-dimensional DataSpace.
Expand All @@ -86,7 +84,8 @@ namespace pmacc
*
* @param args size of each dimension, x,y,z,...
*/
template<typename... T_Args, typename = std::enable_if_t<(std::is_convertible_v<T_Args, int> && ...)>>
template<std::convertible_to<int>... T_Args>
requires(sizeof...(T_Args) == T_dim)
constexpr DataSpace(T_Args&&... args) : BaseType(std::forward<T_Args>(args)...)
{
static_assert(sizeof...(T_Args) == T_dim, "Number of arguments must be equal to the DataSpace dimension.");
Expand All @@ -96,12 +95,9 @@ namespace pmacc
{
}

HDINLINE DataSpace(math::Size_t<T_dim> const& vec)
// constructor to convert from size_t vector to int dataspace
HDINLINE constexpr DataSpace(math::Size_t<T_dim> const& vec) : BaseType(vec)
{
for(uint32_t i = 0; i < T_dim; ++i)
{
(*this)[i] = vec[i];
}
}

/**
Expand All @@ -110,14 +106,10 @@ namespace pmacc
* @param value value which is setfor all dimensions
* @return the new DataSpace
*/
HDINLINE static DataSpace<T_dim> create(int value = 1)
HDINLINE static constexpr DataSpace<T_dim> create(int value = 1) noexcept
{
DataSpace<T_dim> tmp;
for(uint32_t i = 0; i < T_dim; ++i)
{
tmp[i] = value;
}
return tmp;
return [value]<std::size_t... Is>(std::index_sequence<Is...>)
{ return DataSpace<T_dim>((static_cast<void>(Is), value)...); }(std::make_index_sequence<T_dim>{});
}

/**
Expand All @@ -136,22 +128,25 @@ namespace pmacc
* @param other DataSpace to compare with
* @return true if one dimension is greater, false otherwise
*/
HINLINE bool isOneDimensionGreaterThan(MemSpace<T_dim> const& other) const
HINLINE constexpr bool isOneDimensionGreaterThan(MemSpace<T_dim> const& other) const
{
for(uint32_t i = 0; i < T_dim; ++i)
{
if((*this)[i] > other[i])
return true;
}
return false;
return [this, other]<std::size_t... Is>(std::index_sequence<Is...>)
{ return (((*this)[Is] > other[Is]) || ...); }(std::make_index_sequence<T_dim>{});
}

HDINLINE operator math::Size_t<T_dim>() const
{
math::Size_t<T_dim> result;
for(uint32_t i = 0; i < T_dim; i++)
result[i] = static_cast<size_t>((*this)[i]);
return result;
return [this]<std::size_t... Is>(std::index_sequence<Is...>) -> math::Size_t<T_dim>
{ return {static_cast<std::size_t>((*this)[Is])...}; }(std::make_index_sequence<T_dim>{});
}

private:
template<typename T_MemberType, std::size_t... Is>
ALPAKA_FN_INLINE static constexpr BaseType makeReversedArgs(
alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const& value,
std::index_sequence<Is...>) noexcept
{
return {static_cast<int>(value[T_dim - 1 - Is])...};
}
};

Expand Down
5 changes: 0 additions & 5 deletions include/pmacc/mappings/simulation/Selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ namespace pmacc
}
}

/**
* Copy constructor
*/
HDINLINE constexpr Selection(Selection const&) = default;

/**
* Constructor
* Offset is initialized to 0.
Expand Down