Skip to content

Commit

Permalink
Merge pull request #3274 from psychocoderHPC/topic-constexprContVecto…
Browse files Browse the repository at this point in the history
…rInstance

refactor `ConstVector`
  • Loading branch information
sbastrakov authored Jun 30, 2020
2 parents 41e6321 + 79616f2 commit fe322db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/pmacc/math/ConstVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace PMACC_JOIN(pmacc_static_const_storage,id) \
namespace PMACC_JOIN(pmacc_static_const_vector_host,id) \
{ \
/* store all values in a const C array on host*/ \
const Type PMACC_JOIN(Name,_data)[]={__VA_ARGS__}; \
constexpr Type PMACC_JOIN(Name,_data)[]={__VA_ARGS__}; \
} /* namespace pmacc_static_const_vector_host + id */ \
/* select host or device namespace depending on __CUDA_ARCH__ compiler flag*/ \
PMACC_USING_STATIC_CONST_VECTOR_NAMESPACE(id); \
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace PMACC_JOIN(pmacc_static_const_storage,id) \
namespace PMACC_JOIN(pmacc_static_const_vector_host,id) \
{ \
/* create const instance on host*/ \
const PMACC_JOIN(Name,_t) Name; \
constexpr PMACC_JOIN(Name,_t) Name; \
} /* namespace pmacc_static_const_vector_host + id */ \
} /* namespace pmacc_static_const_storage + id */

Expand Down
19 changes: 13 additions & 6 deletions include/pmacc/math/vector/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ struct Vector_components
static constexpr int dim = T_Dim;
using type = T_Type;

HDINLINE
constexpr Vector_components()
{}

/*align full vector*/
PMACC_ALIGN(v[dim], type);

Expand Down Expand Up @@ -139,34 +143,36 @@ struct Vector : private T_Storage<T_Type, T_dim>, protected T_Accessor, protecte
using type = const typename F::type&;
};

HDINLINE Vector()
HDINLINE
constexpr Vector()
{}

HDINLINE
Vector(const type x)
constexpr Vector(const type x)
{
PMACC_CASSERT_MSG(math_Vector__constructor_is_only_allowed_for_DIM1,dim == 1);
(*this)[0] = x;
}

HDINLINE
Vector(const type x, const type y)
constexpr Vector(const type x, const type y)
{
PMACC_CASSERT_MSG(math_Vector__constructor_is_only_allowed_for_DIM2,dim == 2);
(*this)[0] = x;
(*this)[1] = y;
}

HDINLINE
Vector(const type x, const type y, const type z)
constexpr Vector(const type x, const type y, const type z)
{
PMACC_CASSERT_MSG(math_Vector__constructor_is_only_allowed_for_DIM3,dim == 3);
(*this)[0] = x;
(*this)[1] = y;
(*this)[2] = z;
}

HDINLINE Vector(const This& other)
HDINLINE
constexpr Vector(const This& other)
{
detail::CopyElementWise<Storage::isConst>()(*this,other);
}
Expand All @@ -176,7 +182,8 @@ struct Vector : private T_Storage<T_Type, T_dim>, protected T_Accessor, protecte
typename T_OtherAccessor,
typename T_OtherNavigator,
template <typename, int> class T_OtherStorage>
HDINLINE explicit Vector(const Vector<
HDINLINE
explicit Vector(const Vector<
T_OtherType,
dim,
T_OtherAccessor,
Expand Down

0 comments on commit fe322db

Please sign in to comment.