From 1cc0bd83e9dd5173e42d034ce26e391cb11b8dfa Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Tue, 29 Jun 2021 10:18:41 -0500 Subject: [PATCH] Tensor: refactor constructor and assignment operator guards * 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 --- include/deal.II/base/tensor.h | 159 +++++++++++++++++++--------------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 003b90da86..89c4a04df3 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -166,30 +166,18 @@ public: 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 /** @@ -249,6 +237,27 @@ public: 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. @@ -560,28 +569,16 @@ public: constexpr operator Tensor<1, dim, Tensor>() const; -#if __GNUC__ >= 11 || defined __INTEL_COMPILER +#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG /** * Copy constructor */ constexpr Tensor(const Tensor &); - /** - * Copy assignment operator - */ - constexpr Tensor & - operator=(const Tensor &); - /** * Move constructor */ constexpr Tensor(Tensor &&) noexcept; - - /** - * Move assignment operator - */ - constexpr Tensor & - operator=(Tensor &&) noexcept; #endif /** @@ -653,6 +650,20 @@ public: constexpr Tensor & operator=(const Number &d); +#ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG + /** + * Copy assignment operator + */ + constexpr Tensor & + operator=(const Tensor &); + + /** + * Move assignment operator + */ + constexpr Tensor & + operator=(Tensor &&) noexcept; +#endif + /** * Test for equality of two tensors. */ @@ -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 constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV Tensor<0, dim, Number>::Tensor(const Tensor<0, dim, Number> &other) @@ -932,35 +942,14 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV -template -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 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 -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 inline Number * Tensor<0, dim, Number>::begin_raw() @@ -1034,6 +1023,29 @@ constexpr inline DEAL_II_ALWAYS_INLINE } +# if defined(__INTEL_COMPILER) || defined(DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG) +template +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 +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 template constexpr inline DEAL_II_ALWAYS_INLINE @@ -1264,6 +1276,7 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV {} + template template constexpr DEAL_II_ALWAYS_INLINE @@ -1273,6 +1286,7 @@ Tensor::Tensor( {} + template template constexpr DEAL_II_ALWAYS_INLINE Tensor:: @@ -1282,7 +1296,7 @@ constexpr DEAL_II_ALWAYS_INLINE Tensor:: } -# if __GNUC__ >= 11 || defined __INTEL_COMPILER +# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG template constexpr DEAL_II_ALWAYS_INLINE Tensor::Tensor(const Tensor &other) @@ -1292,15 +1306,6 @@ Tensor::Tensor(const Tensor &other) } -template -constexpr DEAL_II_ALWAYS_INLINE Tensor & -Tensor::operator=(const Tensor &other) -{ - for (unsigned int i = 0; i < dim; ++i) - values[i] = other.values[i]; - return *this; -} - template constexpr DEAL_II_ALWAYS_INLINE @@ -1309,17 +1314,6 @@ Tensor::Tensor(Tensor &&other) noexcept for (unsigned int i = 0; i < dim; ++i) values[i] = other.values[i]; } - - -template -constexpr DEAL_II_ALWAYS_INLINE Tensor & - Tensor:: - operator=(Tensor &&other) noexcept -{ - for (unsigned int i = 0; i < dim; ++i) - values[i] = other.values[i]; - return *this; -} # endif @@ -1478,6 +1472,7 @@ Tensor::operator=(const Tensor &t) } + template constexpr inline DEAL_II_ALWAYS_INLINE Tensor & Tensor::operator=(const Number &d) @@ -1491,6 +1486,30 @@ Tensor::operator=(const Number &d) } +# ifdef DEAL_II_DELETED_MOVE_CONSTRUCTOR_BUG +template +constexpr DEAL_II_ALWAYS_INLINE Tensor & +Tensor::operator=(const Tensor &other) +{ + for (unsigned int i = 0; i < dim; ++i) + values[i] = other.values[i]; + return *this; +} + + + +template +constexpr DEAL_II_ALWAYS_INLINE Tensor & + Tensor:: + operator=(Tensor &&other) noexcept +{ + for (unsigned int i = 0; i < dim; ++i) + values[i] = other.values[i]; + return *this; +} +# endif + + template template constexpr inline bool -- 2.39.5