Skip to content

Commit 0377312

Browse files
committed
Small improvements in dataspace and remove user defined defaulted copy
constructors
1 parent d7929e1 commit 0377312

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

include/pmacc/dimensions/DataSpace.hpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "pmacc/math/Vector.hpp"
2626
#include "pmacc/types.hpp"
2727

28+
#include <alpaka/core/Common.hpp>
29+
2830
#include <type_traits>
2931

3032
namespace pmacc
@@ -65,19 +67,15 @@ namespace pmacc
6567
{
6668
}
6769

68-
constexpr DataSpace(DataSpace const&) = default;
69-
70-
HDINLINE constexpr DataSpace& operator=(DataSpace const&) = default;
71-
7270
/** constructor.
7371
*
7472
* Sets size of all dimensions from alpaka.
73+
* Reverses (permutes) the order of the dimensions.
7574
*/
7675
template<typename T_MemberType>
77-
HDINLINE explicit DataSpace(alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const& value)
76+
HDINLINE explicit constexpr DataSpace(alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const& value)
77+
: BaseType(makeReversedArgs(value, std::make_index_sequence<T_dim>{}))
7878
{
79-
for(uint32_t i = 0u; i < T_dim; i++)
80-
(*this)[T_dim - 1 - i] = value[i];
8179
}
8280

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

99-
HDINLINE DataSpace(math::Size_t<T_dim> const& vec)
98+
// constructor to convert from size_t vector to int dataspace
99+
HDINLINE constexpr DataSpace(math::Size_t<T_dim> const& vec) : BaseType(vec)
100100
{
101-
for(uint32_t i = 0; i < T_dim; ++i)
102-
{
103-
(*this)[i] = vec[i];
104-
}
105101
}
106102

107103
/**
@@ -110,14 +106,10 @@ namespace pmacc
110106
* @param value value which is setfor all dimensions
111107
* @return the new DataSpace
112108
*/
113-
HDINLINE static DataSpace<T_dim> create(int value = 1)
109+
HDINLINE static constexpr DataSpace<T_dim> create(int value = 1) noexcept
114110
{
115-
DataSpace<T_dim> tmp;
116-
for(uint32_t i = 0; i < T_dim; ++i)
117-
{
118-
tmp[i] = value;
119-
}
120-
return tmp;
111+
return [value]<std::size_t... Is>(std::index_sequence<Is...>)
112+
{ return DataSpace<T_dim>((static_cast<void>(Is), value)...); }(std::make_index_sequence<T_dim>{});
121113
}
122114

123115
/**
@@ -136,22 +128,25 @@ namespace pmacc
136128
* @param other DataSpace to compare with
137129
* @return true if one dimension is greater, false otherwise
138130
*/
139-
HINLINE bool isOneDimensionGreaterThan(MemSpace<T_dim> const& other) const
131+
HINLINE constexpr bool isOneDimensionGreaterThan(MemSpace<T_dim> const& other) const
140132
{
141-
for(uint32_t i = 0; i < T_dim; ++i)
142-
{
143-
if((*this)[i] > other[i])
144-
return true;
145-
}
146-
return false;
133+
return [this, other]<std::size_t... Is>(std::index_sequence<Is...>)
134+
{ return (((*this)[Is] > other[Is]) || ...); }(std::make_index_sequence<T_dim>{});
147135
}
148136

149137
HDINLINE operator math::Size_t<T_dim>() const
150138
{
151-
math::Size_t<T_dim> result;
152-
for(uint32_t i = 0; i < T_dim; i++)
153-
result[i] = static_cast<size_t>((*this)[i]);
154-
return result;
139+
return [this]<std::size_t... Is>(std::index_sequence<Is...>) -> math::Size_t<T_dim>
140+
{ return {static_cast<std::size_t>((*this)[Is])...}; }(std::make_index_sequence<T_dim>{});
141+
}
142+
143+
private:
144+
template<typename T_MemberType, std::size_t... Is>
145+
static constexpr ALPAKA_FN_INLINE BaseType makeReversedArgs(
146+
alpaka::Vec<::alpaka::DimInt<T_dim>, T_MemberType> const& value,
147+
std::index_sequence<Is...>) noexcept
148+
{
149+
return {static_cast<int>(value[T_dim - 1 - Is])...};
155150
}
156151
};
157152

include/pmacc/mappings/simulation/Selection.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ namespace pmacc
5050
}
5151
}
5252

53-
/**
54-
* Copy constructor
55-
*/
56-
HDINLINE constexpr Selection(Selection const&) = default;
57-
5853
/**
5954
* Constructor
6055
* Offset is initialized to 0.

0 commit comments

Comments
 (0)