Skip to content

Commit

Permalink
Tensor: refactor constructor and assignment operator guards
Browse files Browse the repository at this point in the history
 * This commit guards some constructors and copy/move assignment
   operators that are necessary to work around a gcc 11 regression with
   DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG.

 * Add back explicitly guarded constructor working around a code
   generation issue with intel compilers
  • Loading branch information
tamiko committed Jun 29, 2021
1 parent 394044b commit 1cc0bd8
Showing 1 changed file with 89 additions and 70 deletions.
159 changes: 89 additions & 70 deletions include/deal.II/base/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,18 @@ class Tensor<0, dim, Number>
constexpr DEAL_II_CUDA_HOST_DEV
Tensor(const OtherNumber &initializer);

#if __GNUC__ >= 11 || defined __INTEL_COMPILER
#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
/**
* Copy constructor
*/
constexpr DEAL_II_CUDA_HOST_DEV
Tensor(const Tensor<0, dim, Number> &other);

/**
* Copy assignment operator
*/
constexpr DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
operator=(const Tensor<0, dim, Number> &other);

/**
* Move constructor
*/
constexpr DEAL_II_CUDA_HOST_DEV
Tensor(Tensor<0, dim, Number> &&other) noexcept;

/**
* Move assignment operator
*/
constexpr DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
operator=(Tensor<0, dim, Number> &&other) noexcept;
#endif

/**
Expand Down Expand Up @@ -249,6 +237,27 @@ class Tensor<0, dim, Number>
constexpr DEAL_II_CUDA_HOST_DEV Tensor &
operator=(const Tensor<0, dim, OtherNumber> &rhs);

#if defined(__INTEL_COMPILER) || defined(DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG)
/**
* Assignment from tensors with same underlying scalar type.
* This is needed for ICC15 because it can't generate a suitable
* copy constructor for Sacado::Rad::ADvar types automatically.
* See https://github.com/dealii/dealii/pull/5865.
*
* @note This function can also be used in CUDA device code.
*/
constexpr DEAL_II_CUDA_HOST_DEV Tensor &
operator=(const Tensor<0, dim, Number> &rhs);
#endif

#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
/**
* Move assignment operator
*/
constexpr DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
operator=(Tensor<0, dim, Number> &&other) noexcept;
#endif

/**
* This operator assigns a scalar to a tensor. This obviously requires
* that the @p OtherNumber type is convertible to @p Number.
Expand Down Expand Up @@ -560,28 +569,16 @@ class Tensor
constexpr
operator Tensor<1, dim, Tensor<rank_ - 1, dim, OtherNumber>>() const;

#if __GNUC__ >= 11 || defined __INTEL_COMPILER
#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
/**
* Copy constructor
*/
constexpr Tensor(const Tensor<rank_, dim, Number> &);

/**
* Copy assignment operator
*/
constexpr Tensor<rank_, dim, Number> &
operator=(const Tensor<rank_, dim, Number> &);

/**
* Move constructor
*/
constexpr Tensor(Tensor<rank_, dim, Number> &&) noexcept;

/**
* Move assignment operator
*/
constexpr Tensor<rank_, dim, Number> &
operator=(Tensor<rank_, dim, Number> &&) noexcept;
#endif

/**
Expand Down Expand Up @@ -653,6 +650,20 @@ class Tensor
constexpr Tensor &
operator=(const Number &d);

#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
/**
* Copy assignment operator
*/
constexpr Tensor<rank_, dim, Number> &
operator=(const Tensor<rank_, dim, Number> &);

/**
* Move assignment operator
*/
constexpr Tensor<rank_, dim, Number> &
operator=(Tensor<rank_, dim, Number> &&) noexcept;
#endif

/**
* Test for equality of two tensors.
*/
Expand Down Expand Up @@ -922,8 +933,7 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
{}



# if __GNUC__ >= 11 || defined __INTEL_COMPILER
# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
template <int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
Tensor<0, dim, Number>::Tensor(const Tensor<0, dim, Number> &other)
Expand All @@ -932,35 +942,14 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV



template <int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
Tensor<0, dim, Number>::operator=(const Tensor<0, dim, Number> &other)
{
value = other.value;
return *this;
}



template <int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
Tensor<0, dim, Number>::Tensor(Tensor<0, dim, Number> &&other) noexcept
: value{std::move(other.value)}
{}



template <int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
Tensor<0, dim, Number>::operator=(Tensor<0, dim, Number> &&other) noexcept
{
value = std::move(other.value);
return *this;
}
# endif



template <int dim, typename Number>
inline Number *
Tensor<0, dim, Number>::begin_raw()
Expand Down Expand Up @@ -1034,6 +1023,29 @@ constexpr inline DEAL_II_ALWAYS_INLINE
}


# if defined(__INTEL_COMPILER) || defined(DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG)
template <int dim, typename Number>
constexpr inline DEAL_II_ALWAYS_INLINE
DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
Tensor<0, dim, Number>::operator=(const Tensor<0, dim, Number> &p)
{
value = p.value;
return *this;
}
# endif

# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
template <int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number> &
Tensor<0, dim, Number>::operator=(Tensor<0, dim, Number> &&other) noexcept
{
value = std::move(other.value);
return *this;
}
# endif



template <int dim, typename Number>
template <typename OtherNumber>
constexpr inline DEAL_II_ALWAYS_INLINE
Expand Down Expand Up @@ -1264,6 +1276,7 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
{}



template <int rank_, int dim, typename Number>
template <typename OtherNumber>
constexpr DEAL_II_ALWAYS_INLINE
Expand All @@ -1273,6 +1286,7 @@ Tensor<rank_, dim, Number>::Tensor(
{}



template <int rank_, int dim, typename Number>
template <typename OtherNumber>
constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number>::
Expand All @@ -1282,7 +1296,7 @@ constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number>::
}


# if __GNUC__ >= 11 || defined __INTEL_COMPILER
# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
template <int rank_, int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE
Tensor<rank_, dim, Number>::Tensor(const Tensor<rank_, dim, Number> &other)
Expand All @@ -1292,15 +1306,6 @@ Tensor<rank_, dim, Number>::Tensor(const Tensor<rank_, dim, Number> &other)
}


template <int rank_, int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::operator=(const Tensor<rank_, dim, Number> &other)
{
for (unsigned int i = 0; i < dim; ++i)
values[i] = other.values[i];
return *this;
}


template <int rank_, int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE
Expand All @@ -1309,17 +1314,6 @@ Tensor<rank_, dim, Number>::Tensor(Tensor<rank_, dim, Number> &&other) noexcept
for (unsigned int i = 0; i < dim; ++i)
values[i] = other.values[i];
}


template <int rank_, int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::
operator=(Tensor<rank_, dim, Number> &&other) noexcept
{
for (unsigned int i = 0; i < dim; ++i)
values[i] = other.values[i];
return *this;
}
# endif


Expand Down Expand Up @@ -1478,6 +1472,7 @@ Tensor<rank_, dim, Number>::operator=(const Tensor<rank_, dim, OtherNumber> &t)
}



template <int rank_, int dim, typename Number>
constexpr inline DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::operator=(const Number &d)
Expand All @@ -1491,6 +1486,30 @@ Tensor<rank_, dim, Number>::operator=(const Number &d)
}


# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG
template <int rank_, int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::operator=(const Tensor<rank_, dim, Number> &other)
{
for (unsigned int i = 0; i < dim; ++i)
values[i] = other.values[i];
return *this;
}



template <int rank_, int dim, typename Number>
constexpr DEAL_II_ALWAYS_INLINE Tensor<rank_, dim, Number> &
Tensor<rank_, dim, Number>::
operator=(Tensor<rank_, dim, Number> &&other) noexcept
{
for (unsigned int i = 0; i < dim; ++i)
values[i] = other.values[i];
return *this;
}
# endif


template <int rank_, int dim, typename Number>
template <typename OtherNumber>
constexpr inline bool
Expand Down

0 comments on commit 1cc0bd8

Please sign in to comment.