From 3055e3a7c213e7f1337cdc43d5b1953acd013897 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Wed, 8 Aug 2018 11:19:02 +0100 Subject: [PATCH 01/25] Creating a pointer type in TensorCustomOp.h --- .../Eigen/CXX11/src/Tensor/TensorCustomOp.h | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index 47b5a5a5e..87d84a311 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -88,6 +88,7 @@ struct TensorEvaluator, Devi typedef typename internal::remove_const::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; + typedef typename internal::remove_all::PointerType>::type * PointerType; enum { IsAligned = false, @@ -106,7 +107,7 @@ struct TensorEvaluator, Devi EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType* data) { + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(PointerType data) { if (data) { evalTo(data); return false; @@ -139,23 +140,22 @@ struct TensorEvaluator, Devi return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize); } - EIGEN_DEVICE_FUNC typename Eigen::internal::traits::PointerType data() const { return m_result; } + EIGEN_DEVICE_FUNC PointerType data() const { return m_result; } #ifdef EIGEN_USE_SYCL EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Device& device() const { return m_device; } #endif protected: - EIGEN_DEVICE_FUNC void evalTo(Scalar* data) { - TensorMap > result( - data, m_dimensions); + EIGEN_DEVICE_FUNC void evalTo(PointerType data) { + TensorMap > result(data, m_dimensions); m_op.func().eval(m_op.expression(), result, m_device); } Dimensions m_dimensions; const ArgType m_op; const Device& m_device; - CoeffReturnType* m_result; + PointerType m_result; }; @@ -250,6 +250,7 @@ struct TensorEvaluator::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; + typedef typename internal::remove_all::PointerType>::type * PointerType; enum { IsAligned = false, @@ -268,12 +269,12 @@ struct TensorEvaluator(m_device.allocate_temp(dimensions().TotalSize() * sizeof(Scalar))); + m_result = static_cast(m_device.allocate_temp(dimensions().TotalSize() * sizeof(CoeffReturnType))); evalTo(m_result); return true; } @@ -300,22 +301,22 @@ struct TensorEvaluator::PointerType data() const { return m_result; } + EIGEN_DEVICE_FUNC PointerType data() const { return m_result; } #ifdef EIGEN_USE_SYCL EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Device& device() const { return m_device; } #endif protected: - EIGEN_DEVICE_FUNC void evalTo(Scalar* data) { - TensorMap > result(data, m_dimensions); + EIGEN_DEVICE_FUNC void evalTo(PointerType data) { + TensorMap > result(data, m_dimensions); m_op.func().eval(m_op.lhsExpression(), m_op.rhsExpression(), result, m_device); } Dimensions m_dimensions; const XprType m_op; const Device& m_device; - CoeffReturnType* m_result; + PointerType m_result; }; From 8c083bfd0e975fc2592ced1a066e1796550338a2 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 9 Aug 2018 13:57:43 +0100 Subject: [PATCH 02/25] Properly fixing the PointerType for TensorCustomOp.h. As the output type here should be based on CoeffreturnType not the Scalar type. Therefore, Similar to reduction and evalTo function, it should have its own MakePointer class. In this case, for other device the type is defaulted to CoeffReturnType and no changes is required on users' code. However, in SYCL, on the device, we can recunstruct the device Type. --- .../Eigen/CXX11/src/Tensor/TensorCustomOp.h | 77 +++++++++++-------- .../src/Tensor/TensorForwardDeclarations.h | 4 +- 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index 87d84a311..39410e63d 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -20,8 +20,8 @@ namespace Eigen { * */ namespace internal { -template -struct traits > +template class MakePointer_> +struct traits > { typedef typename XprType::Scalar Scalar; typedef typename XprType::StorageKind StorageKind; @@ -30,27 +30,35 @@ struct traits > typedef typename remove_reference::type _Nested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; - typedef typename traits::PointerType PointerType; + + template struct MakePointer { + // Intermediate typedef to workaround MSVC issue. + typedef MakePointer_ MakePointerT; + typedef typename MakePointerT::Type Type; + typedef typename MakePointerT::RefType RefType; + typedef typename MakePointerT::ScalarType ScalarType; + }; + typedef typename MakePointer::type>::Type PointerType; }; -template -struct eval, Eigen::Dense> +template class MakePointer_> +struct eval, Eigen::Dense> { - typedef const TensorCustomUnaryOp& type; + typedef const TensorCustomUnaryOp& type; }; -template -struct nested > +template class MakePointer_> +struct nested > { - typedef TensorCustomUnaryOp type; + typedef TensorCustomUnaryOp type; }; } // end namespace internal -template -class TensorCustomUnaryOp : public TensorBase, ReadOnlyAccessors> +template class MakePointer_> +class TensorCustomUnaryOp : public TensorBase, ReadOnlyAccessors> { public: typedef typename internal::traits::Scalar Scalar; @@ -77,10 +85,10 @@ class TensorCustomUnaryOp : public TensorBase -struct TensorEvaluator, Device> +template class MakePointer_, typename Device> +struct TensorEvaluator, Device> { - typedef TensorCustomUnaryOp ArgType; + typedef TensorCustomUnaryOp ArgType; typedef typename internal::traits::Index Index; static const int NumDims = internal::traits::NumDimensions; typedef DSizes Dimensions; @@ -88,7 +96,7 @@ struct TensorEvaluator, Devi typedef typename internal::remove_const::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; - typedef typename internal::remove_all::PointerType>::type * PointerType; + typedef typename Eigen::internal::traits::PointerType PointerType; enum { IsAligned = false, @@ -112,7 +120,7 @@ struct TensorEvaluator, Devi evalTo(data); return false; } else { - m_result = static_cast( + m_result = static_cast( m_device.allocate_temp(dimensions().TotalSize() * sizeof(Scalar))); evalTo(m_result); return true; @@ -168,8 +176,8 @@ struct TensorEvaluator, Devi * */ namespace internal { -template -struct traits > +template class MakePointer_> +struct traits > { typedef typename internal::promote_storage_type::ret Scalar; @@ -185,28 +193,35 @@ struct traits > typedef typename remove_reference::type _RhsNested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; - typedef typename conditional::val, - typename traits::PointerType, typename traits::PointerType>::type PointerType; + + template struct MakePointer { + // Intermediate typedef to workaround MSVC issue. + typedef MakePointer_ MakePointerT; + typedef typename MakePointerT::Type Type; + typedef typename MakePointerT::RefType RefType; + typedef typename MakePointerT::ScalarType ScalarType; + }; + typedef typename MakePointer::Type PointerType; }; -template -struct eval, Eigen::Dense> +template class MakePointer_> +struct eval, Eigen::Dense> { typedef const TensorCustomBinaryOp& type; }; -template -struct nested > +template class MakePointer_> +struct nested > { - typedef TensorCustomBinaryOp type; + typedef TensorCustomBinaryOp type; }; } // end namespace internal -template -class TensorCustomBinaryOp : public TensorBase, ReadOnlyAccessors> +template class MakePointer_> +class TensorCustomBinaryOp : public TensorBase, ReadOnlyAccessors> { public: typedef typename internal::traits::Scalar Scalar; @@ -239,10 +254,10 @@ class TensorCustomBinaryOp : public TensorBase -struct TensorEvaluator, Device> +template class MakePointer_, typename Device> +struct TensorEvaluator, Device> { - typedef TensorCustomBinaryOp XprType; + typedef TensorCustomBinaryOp XprType; typedef typename internal::traits::Index Index; static const int NumDims = internal::traits::NumDimensions; typedef DSizes Dimensions; @@ -250,7 +265,7 @@ struct TensorEvaluator::type CoeffReturnType; typedef typename PacketType::type PacketReturnType; static const int PacketSize = PacketType::size; - typedef typename internal::remove_all::PointerType>::type * PointerType; + typedef typename Eigen::internal::traits::PointerType PointerType; enum { IsAligned = false, diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h b/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h index 0dd524a30..da0751039 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h @@ -89,8 +89,8 @@ template class TensorAssignOp; template class TensorScanOp; template class TensorTraceOp; -template class TensorCustomUnaryOp; -template class TensorCustomBinaryOp; +template class MakePointer_ = MakePointer> class TensorCustomUnaryOp; +template class MakePointer_ = MakePointer> class TensorCustomBinaryOp; template class MakePointer_ = MakePointer> class TensorEvalToOp; template class TensorForcedEvalOp; From aebdb0642402e49ded58db98dd29c67cd76d204a Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Tue, 14 Aug 2018 12:06:39 -0700 Subject: [PATCH 03/25] Fix a few compiler warnings in CXX11 tests. --- unsupported/test/cxx11_tensor_contraction.cpp | 4 +-- unsupported/test/cxx11_tensor_convolution.cpp | 2 +- unsupported/test/cxx11_tensor_index_list.cpp | 1 - unsupported/test/kronecker_product.cpp | 27 ++++++++++--------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/unsupported/test/cxx11_tensor_contraction.cpp b/unsupported/test/cxx11_tensor_contraction.cpp index d4cfbd0da..2e918eb30 100644 --- a/unsupported/test/cxx11_tensor_contraction.cpp +++ b/unsupported/test/cxx11_tensor_contraction.cpp @@ -471,7 +471,7 @@ static void test_tensor_product() mat1.setRandom(); mat2.setRandom(); - Tensor result = mat1.contract(mat2, Eigen::array{{}}); + Tensor result = mat1.contract(mat2, Eigen::array{}); VERIFY_IS_EQUAL(result.dimension(0), 2); VERIFY_IS_EQUAL(result.dimension(1), 3); @@ -553,7 +553,7 @@ static void test_large_contraction_with_output_kernel() { m_result = m_left * m_right; - for (size_t i = 0; i < t_result.dimensions().TotalSize(); i++) { + for (std::ptrdiff_t i = 0; i < t_result.dimensions().TotalSize(); i++) { VERIFY(&t_result.data()[i] != &m_result.data()[i]); VERIFY_IS_APPROX(t_result.data()[i], std::sqrt(m_result.data()[i])); } diff --git a/unsupported/test/cxx11_tensor_convolution.cpp b/unsupported/test/cxx11_tensor_convolution.cpp index 01bc77bc1..9fe980648 100644 --- a/unsupported/test/cxx11_tensor_convolution.cpp +++ b/unsupported/test/cxx11_tensor_convolution.cpp @@ -25,7 +25,7 @@ static void test_evals() Tensor result(2,3); result.setZero(); - Eigen::array::Index, 1> dims3{{0}}; + Eigen::array::Index, 1> dims3{0}; typedef TensorEvaluator Evaluator; Evaluator eval(input.convolve(kernel, dims3), DefaultDevice()); diff --git a/unsupported/test/cxx11_tensor_index_list.cpp b/unsupported/test/cxx11_tensor_index_list.cpp index e81fa5e40..294677a4d 100644 --- a/unsupported/test/cxx11_tensor_index_list.cpp +++ b/unsupported/test/cxx11_tensor_index_list.cpp @@ -170,7 +170,6 @@ static void test_type2indexpair_list() typedef Eigen::IndexPairList, Eigen::IndexPair, Eigen::type2indexpair<2,12>> Dims2_b; typedef Eigen::IndexPairList, Eigen::type2indexpair<1,11>, Eigen::IndexPair> Dims2_c; - Dims0 d0; Dims2_a d2_a; Dims2_b d2_b; diff --git a/unsupported/test/kronecker_product.cpp b/unsupported/test/kronecker_product.cpp index 4f143b6de..1a936ed25 100644 --- a/unsupported/test/kronecker_product.cpp +++ b/unsupported/test/kronecker_product.cpp @@ -9,6 +9,9 @@ // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "main.h" + #ifdef EIGEN_TEST_PART_1 #include "sparse.h" @@ -95,7 +98,7 @@ EIGEN_DECLARE_TEST(kronecker_product) SM_a.insert(1,0) = DM_a.coeffRef(1,0) = -0.9076572187376921; SM_a.insert(1,1) = DM_a.coeffRef(1,1) = 0.6469156566545853; SM_a.insert(1,2) = DM_a.coeffRef(1,2) = -0.3658010398782789; - + MatrixXd DM_b(3,2); SparseMatrix SM_b(3,2); SM_b.insert(0,0) = DM_b.coeffRef(0,0) = 0.9004440976767099; @@ -165,7 +168,7 @@ EIGEN_DECLARE_TEST(kronecker_product) SM_a.insert(0,3) = -0.2; SM_a.insert(2,4) = 0.3; SM_a.finalize(); - + SM_b.insert(0,0) = 0.4; SM_b.insert(2,1) = -0.5; SM_b.finalize(); @@ -183,7 +186,7 @@ EIGEN_DECLARE_TEST(kronecker_product) DM_b2.resize(4,8); DM_ab2 = kroneckerProduct(DM_a2,DM_b2); CALL_SUBTEST(check_dimension(DM_ab2,10*4,9*8)); - + for(int i = 0; i < g_repeat; i++) { double density = Eigen::internal::random(0.01,0.5); @@ -196,35 +199,35 @@ EIGEN_DECLARE_TEST(kronecker_product) MatrixXf dA(ra,ca), dB(rb,cb), dC; initSparse(density, dA, sA); initSparse(density, dB, sB); - + sC = kroneckerProduct(sA,sB); dC = kroneckerProduct(dA,dB); VERIFY_IS_APPROX(MatrixXf(sC),dC); - + sC = kroneckerProduct(sA.transpose(),sB); dC = kroneckerProduct(dA.transpose(),dB); VERIFY_IS_APPROX(MatrixXf(sC),dC); - + sC = kroneckerProduct(sA.transpose(),sB.transpose()); dC = kroneckerProduct(dA.transpose(),dB.transpose()); VERIFY_IS_APPROX(MatrixXf(sC),dC); - + sC = kroneckerProduct(sA,sB.transpose()); dC = kroneckerProduct(dA,dB.transpose()); VERIFY_IS_APPROX(MatrixXf(sC),dC); - + sC2 = kroneckerProduct(sA,sB); dC = kroneckerProduct(dA,dB); VERIFY_IS_APPROX(MatrixXf(sC2),dC); - + sC2 = kroneckerProduct(dA,sB); dC = kroneckerProduct(dA,dB); VERIFY_IS_APPROX(MatrixXf(sC2),dC); - + sC2 = kroneckerProduct(sA,dB); dC = kroneckerProduct(dA,dB); VERIFY_IS_APPROX(MatrixXf(sC2),dC); - + sC2 = kroneckerProduct(2*sA,sB); dC = kroneckerProduct(2*dA,dB); VERIFY_IS_APPROX(MatrixXf(sC2),dC); @@ -236,8 +239,6 @@ EIGEN_DECLARE_TEST(kronecker_product) #ifdef EIGEN_TEST_PART_2 // simply check that for a dense kronecker product, sparse module is not needed - -#include "main.h" #include EIGEN_DECLARE_TEST(kronecker_product) From ab3f481141a6bc72d2bbdc6300fb9dc157029ea9 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 14 Aug 2018 14:05:46 -0700 Subject: [PATCH 04/25] Cleaned up the code and make it compile with more compilers --- .../Eigen/CXX11/src/Tensor/TensorBlock.h | 76 ++++++++----------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h index 322260011..24a6343e8 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h @@ -91,7 +91,7 @@ EIGEN_STRONG_INLINE void MergeResourceRequirements( *block_total_size = resources[0].block_total_size; for (std::vector::size_type i = 1; i < resources.size(); ++i) { if (resources[i].block_shape == kSkewedInnerDims && - *block_shape ! kSkewedInnerDims) { + *block_shape != kSkewedInnerDims) { *block_shape = kSkewedInnerDims; } *block_total_size = @@ -152,11 +152,11 @@ struct TensorBlockCopyOp { const Scalar* src_base = &src_data[src_index]; Scalar* dst_base = &dst_data[dst_index]; - typedef const Eigen::Array Src; - typedef Eigen::Array Dst; + typedef const Array Src; + typedef Array Dst; - typedef Eigen::Map > SrcMap; - typedef Eigen::Map > DstMap; + typedef Map > SrcMap; + typedef Map > DstMap; const SrcMap src(src_base, num_coeff_to_copy, InnerStride<>(src_stride)); DstMap dst(dst_base, num_coeff_to_copy, InnerStride<>(dst_stride)); @@ -178,10 +178,8 @@ template class TensorBlockIO { public: - typedef typename TensorBlock - TensorBlock; - typedef typename TensorBlockCopyOp - TensorBlockCopyOp; + typedef TensorBlock Block; + typedef TensorBlockCopyOp BlockCopyOp; protected: struct BlockIteratorState { @@ -194,7 +192,7 @@ class TensorBlockIO { }; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Copy( - const TensorBlock& block, StorageIndex first_coeff_index, + const Block& block, StorageIndex first_coeff_index, const array& tensor_to_block_dim_map, const array& tensor_strides, const Scalar* src_data, Scalar* dst_data) { @@ -290,8 +288,8 @@ class TensorBlockIO { const StorageIndex block_total_size = NumDims == 0 ? 1 : block.block_sizes().TotalSize(); for (StorageIndex i = 0; i < block_total_size; i += block_inner_dim_size) { - TensorBlockCopyOp::Run(block_inner_dim_size, outputIndex, output_stride, - dst_data, inputIndex, input_stride, src_data); + BlockCopyOp::Run(block_inner_dim_size, outputIndex, output_stride, + dst_data, inputIndex, input_stride, src_data); // Update index. for (int j = 0; j < num_squeezed_dims; ++j) { if (++block_iter_state[j].count < block_iter_state[j].size) { @@ -320,13 +318,11 @@ template class TensorBlockReader : public TensorBlockIO { public: - typedef typename TensorBlock - TensorBlock; - typedef TensorBlockIO - Base; + typedef TensorBlock Block; + typedef TensorBlockIO Base; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - TensorBlock* block, const Scalar* src_data) { + Block* block, const Scalar* src_data) { array tensor_to_block_dim_map; for (int i = 0; i < NumDims; ++i) { tensor_to_block_dim_map[i] = i; @@ -336,7 +332,7 @@ class TensorBlockReader : public TensorBlockIO& tensor_to_block_dim_map, const array& tensor_strides, const Scalar* src_data) { Base::Copy(*block, first_coeff_index, tensor_to_block_dim_map, @@ -357,13 +353,11 @@ template class TensorBlockWriter : public TensorBlockIO { public: - typedef typename TensorBlock - TensorBlock; - typedef TensorBlockIO - Base; + typedef TensorBlock Block; + typedef TensorBlockIO Base; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run( - const TensorBlock& block, Scalar* dst_data) { + const Block& block, Scalar* dst_data) { array tensor_to_block_dim_map; for (int i = 0; i < NumDims; ++i) { tensor_to_block_dim_map[i] = i; @@ -373,7 +367,7 @@ class TensorBlockWriter : public TensorBlockIO& tensor_to_block_dim_map, const array& tensor_strides, Scalar* dst_data) { Base::Copy(block, first_coeff_index, tensor_to_block_dim_map, @@ -401,13 +395,13 @@ struct TensorBlockCwiseBinaryOp { const StorageIndex left_stride, const LeftScalar* left_data, const StorageIndex right_index, const StorageIndex right_stride, const RightScalar* right_data) { - typedef const Eigen::Array Lhs; - typedef const Eigen::Array Rhs; - typedef Eigen::Array Out; + typedef const Array Lhs; + typedef const Array Rhs; + typedef Array Out; - typedef Eigen::Map > LhsMap; - typedef Eigen::Map > RhsMap; - typedef Eigen::Map > OutMap; + typedef Map > LhsMap; + typedef Map > RhsMap; + typedef Map > OutMap; const LeftScalar* lhs_base = &left_data[left_index]; const RightScalar* rhs_base = &right_data[right_index]; @@ -417,8 +411,7 @@ struct TensorBlockCwiseBinaryOp { const RhsMap rhs(rhs_base, num_coeff, InnerStride<>(right_stride)); OutMap out(out_base, num_coeff, InnerStride<>(output_stride)); - out = - Eigen::CwiseBinaryOp(lhs, rhs, functor); + out = CwiseBinaryOp(lhs, rhs, functor); } }; @@ -434,8 +427,7 @@ struct TensorBlockCwiseBinaryOp { template struct TensorBlockCwiseBinaryIO { - typedef typename TensorBlock::Dimensions Dimensions; + typedef typename TensorBlock::Dimensions Dimensions; struct BlockIteratorState { StorageIndex output_stride, output_span; @@ -627,8 +619,7 @@ struct TensorBlockView { template class TensorBlockMapper { public: - typedef typename TensorBlock - TensorBlock; + typedef TensorBlock Block; typedef DSizes Dimensions; TensorBlockMapper(const Dimensions& dims, @@ -663,7 +654,7 @@ class TensorBlockMapper { } } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block GetBlockForIndex(StorageIndex block_index, Scalar* data) const { StorageIndex first_coeff_index = 0; DSizes coords; @@ -711,8 +702,7 @@ class TensorBlockMapper { } } - return TensorBlock(first_coeff_index, sizes, strides, m_tensor_strides, - data); + return Block(first_coeff_index, sizes, strides, m_tensor_strides, data); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex total_block_count() const { @@ -818,8 +808,7 @@ class TensorBlockMapper { template class TensorSliceBlockMapper { public: - typedef typename TensorBlock - TensorBlock; + typedef TensorBlock Block; typedef DSizes Dimensions; TensorSliceBlockMapper(const Dimensions& tensor_dims, @@ -860,7 +849,7 @@ class TensorSliceBlockMapper { } } - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block GetBlockForIndex(StorageIndex block_index, Scalar* data) const { StorageIndex first_coeff_index = 0; DSizes coords; @@ -917,8 +906,7 @@ class TensorSliceBlockMapper { } } - return TensorBlock(first_coeff_index, sizes, strides, m_tensor_strides, - data); + return Block(first_coeff_index, sizes, strides, m_tensor_strides, data); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex total_block_count() const { From 43ec0082a6ca5e6098bdca1728094b0b7ce550c4 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 14 Aug 2018 14:08:36 -0700 Subject: [PATCH 05/25] Made the kronecker_product test compile again --- unsupported/test/kronecker_product.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unsupported/test/kronecker_product.cpp b/unsupported/test/kronecker_product.cpp index 1a936ed25..b5b764c65 100644 --- a/unsupported/test/kronecker_product.cpp +++ b/unsupported/test/kronecker_product.cpp @@ -10,8 +10,6 @@ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#include "main.h" - #ifdef EIGEN_TEST_PART_1 #include "sparse.h" @@ -239,6 +237,7 @@ EIGEN_DECLARE_TEST(kronecker_product) #ifdef EIGEN_TEST_PART_2 // simply check that for a dense kronecker product, sparse module is not needed +#include "main.h" #include EIGEN_DECLARE_TEST(kronecker_product) From 6bb3f1b43ecad440fb7ad172657f0f7a0c804d29 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 14 Aug 2018 14:26:59 -0700 Subject: [PATCH 06/25] Made the tensor_block_access test compile again --- .../test/cxx11_tensor_block_access.cpp | 120 +++++++++--------- 1 file changed, 58 insertions(+), 62 deletions(-) diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 6feeff231..2631767e2 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -10,6 +10,8 @@ #include "main.h" +#include +#include #include #include @@ -19,17 +21,16 @@ using Eigen::Index; using Eigen::RowMajor; using Eigen::ColMajor; -using internal::TensorBlockShapeType; template static const T& choose(int layout, const T& col, const T& row) { return layout == ColMajor ? col : row; } -static const TensorBlockShapeType RandomShape() { +static internal::TensorBlockShapeType RandomShape() { return internal::random() - ? internal::TensorBlockShapeType::kUniformAllDims - : internal::TensorBlockShapeType::kSkewedInnerDims; + ? internal::kUniformAllDims + : internal::kSkewedInnerDims; } template @@ -44,7 +45,7 @@ static DSizes RandomDims() { dims[i] = internal::random(1, 20); } return DSizes(dims); -}; +} /** Dummy data type to test TensorBlock copy ops. */ struct Data { @@ -91,21 +92,19 @@ static void Debug(DSizes dims) { template static void test_block_mapper_sanity() { - using T = int; - using TensorBlock = internal::TensorBlock; - using TensorBlockMapper = internal::TensorBlockMapper; + typedef internal::TensorBlockMapper TensorBlockMapper; DSizes tensor_dims(100, 100); // Test uniform blocks. TensorBlockMapper uniform_block_mapper( - tensor_dims, internal::TensorBlockShapeType::kUniformAllDims, 100); + tensor_dims, internal::kUniformAllDims, 100); VERIFY_IS_EQUAL(uniform_block_mapper.total_block_count(), 100); VERIFY_IS_EQUAL(uniform_block_mapper.block_dims_total_size(), 100); // 10x10 blocks - auto uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, nullptr); + auto uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(0), 10); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(1), 10); // Depending on a layout we stride by cols rows. @@ -117,13 +116,13 @@ static void test_block_mapper_sanity() // Test skewed to inner dims blocks. TensorBlockMapper skewed_block_mapper( - tensor_dims, internal::TensorBlockShapeType::kSkewedInnerDims, 100); + tensor_dims, internal::kSkewedInnerDims, 100); VERIFY_IS_EQUAL(skewed_block_mapper.total_block_count(), 100); VERIFY_IS_EQUAL(skewed_block_mapper.block_dims_total_size(), 100); // 1x100 (100x1) rows/cols depending on a tensor layout. - auto skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, nullptr); + auto skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(0), choose(Layout, 100, 1)); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(1), choose(Layout, 1, 100)); // Depending on a layout we stride by cols rows. @@ -171,7 +170,7 @@ static void test_block_mapper_maps_every_element() { TensorBlockMapper block_mapper(dims, RandomShape(), RandomTargetSize(dims)); for (int i = 0; i < block_mapper.total_block_count(); ++i) { - TensorBlock block = block_mapper.GetBlockForIndex(i, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(i, NULL); UpdateCoeffSet(block, block.first_coeff_index(), choose(Layout, NumDims - 1, 0), &coeff_set); @@ -219,7 +218,7 @@ static void test_slice_block_mapper_maps_every_element() { DimensionList()); for (int i = 0; i < block_mapper.total_block_count(); ++i) { - TensorBlock block = block_mapper.GetBlockForIndex(i, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(i, NULL); UpdateCoeffSet(block, block.first_coeff_index(), choose(Layout, NumDims - 1, 0), &coeff_set); @@ -647,17 +646,16 @@ static void test_block_cwise_binary_io_zero_strides() { template static void test_uniform_block_shape() { - using T = int; - typedef internal::TensorBlock TensorBlock; - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorBlockMapper TensorBlockMapper; { // Test shape 'UniformAllDims' with uniform 'max_coeff count'. DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 5 * 5 * 5 * 5 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); for (int i = 0; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); } @@ -669,9 +667,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 7 * 5 * 5 * 5 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -680,9 +678,9 @@ static void test_uniform_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 5 * 5 * 5 * 5 * 6; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(6, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -695,9 +693,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 5 * 5 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -706,9 +704,9 @@ static void test_uniform_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 5 * 5 * 5 * 5 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(5, block.block_sizes()[i]); @@ -721,9 +719,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); const size_t max_coeff_count = 7 * 5 * 6 * 7 * 5; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -733,9 +731,9 @@ static void test_uniform_block_shape() } else { DSizes dims(7, 5, 6, 9, 7); const size_t max_coeff_count = 5 * 5 * 5 * 6 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(6, block.block_sizes()[3]); VERIFY_IS_EQUAL(5, block.block_sizes()[2]); @@ -748,9 +746,9 @@ static void test_uniform_block_shape() if (Layout == ColMajor) { DSizes dims(7, 5, 6, 17, 7); const size_t max_coeff_count = 7 * 5 * 6 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -760,9 +758,9 @@ static void test_uniform_block_shape() } else { DSizes dims(7, 5, 6, 9, 7); const size_t max_coeff_count = 7 * 5 * 6 * 9 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kUniformAllDims, + TensorBlockMapper block_mapper(dims, internal::kUniformAllDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(9, block.block_sizes()[3]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -783,9 +781,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 10 * 1 * 1 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(10, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -794,9 +792,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 1 * 1 * 6; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(6, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -808,9 +806,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 1 * 1 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); for (int i = 1; i < 5; ++i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -819,9 +817,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 1 * 1 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); for (int i = 3; i >= 0; --i) { VERIFY_IS_EQUAL(1, block.block_sizes()[i]); @@ -834,9 +832,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 3 * 1 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); VERIFY_IS_EQUAL(3, block.block_sizes()[1]); for (int i = 2; i < 5; ++i) { @@ -846,9 +844,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 1 * 15 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(15, block.block_sizes()[3]); for (int i = 2; i >= 0; --i) { @@ -862,9 +860,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 5 * 1 * 1; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(5, block.block_sizes()[2]); @@ -875,9 +873,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 1 * 1 * 5 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(17, block.block_sizes()[3]); VERIFY_IS_EQUAL(5, block.block_sizes()[2]); @@ -891,9 +889,9 @@ static void test_skewed_inner_dim_block_shape() if (Layout == ColMajor) { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 6 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(11, block.block_sizes()[0]); VERIFY_IS_EQUAL(5, block.block_sizes()[1]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -903,9 +901,9 @@ static void test_skewed_inner_dim_block_shape() } else { DSizes dims(11, 5, 6, 17, 7); const size_t max_coeff_count = 11 * 5 * 6 * 17 * 7; - TensorBlockMapper block_mapper(dims, TensorBlockShapeType::kSkewedInnerDims, + TensorBlockMapper block_mapper(dims, internal::kSkewedInnerDims, max_coeff_count); - TensorBlock block = block_mapper.GetBlockForIndex(0, nullptr); + TensorBlock block = block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(7, block.block_sizes()[4]); VERIFY_IS_EQUAL(17, block.block_sizes()[3]); VERIFY_IS_EQUAL(6, block.block_sizes()[2]); @@ -918,15 +916,13 @@ static void test_skewed_inner_dim_block_shape() template static void test_empty_dims(const internal::TensorBlockShapeType block_shape) { - using T = int; - // Test blocking of tensors with zero dimensions: // - we must not crash on asserts and divisions by zero // - we must not return block with zero dimensions // (recipe for overflows/underflows, divisions by zero and NaNs later) // - total block count must be zero { - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlockMapper TensorBlockMapper; DSizes dims(0); for (int max_coeff_count = 0; max_coeff_count < 2; ++max_coeff_count) { TensorBlockMapper block_mapper(dims, block_shape, max_coeff_count); @@ -936,7 +932,7 @@ static void test_empty_dims(const internal::TensorBlockShapeType block_shape) } { - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlockMapper TensorBlockMapper; for (int dim1 = 0; dim1 < 3; ++dim1) { for (int dim2 = 0; dim2 < 3; ++dim2) { DSizes dims(dim1, dim2); @@ -987,9 +983,9 @@ EIGEN_DECLARE_TEST(cxx11_tensor_block_access) { TEST_LAYOUTS(test_block_cwise_binary_io_zero_strides); TEST_LAYOUTS(test_uniform_block_shape); TEST_LAYOUTS(test_skewed_inner_dim_block_shape); - TEST_LAYOUTS_WITH_ARG(test_empty_dims, TensorBlockShapeType::kUniformAllDims); - TEST_LAYOUTS_WITH_ARG(test_empty_dims, TensorBlockShapeType::kSkewedInnerDims); + TEST_LAYOUTS_WITH_ARG(test_empty_dims, internal::kUniformAllDims); + TEST_LAYOUTS_WITH_ARG(test_empty_dims, internal::kSkewedInnerDims); } #undef TEST_LAYOUTS -#undef TEST_LAYOUTS_WITH_ARG \ No newline at end of file +#undef TEST_LAYOUTS_WITH_ARG From fbb834144df6190a93757098d097f230b167edc5 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 15 Aug 2018 08:52:58 -0700 Subject: [PATCH 07/25] Fixed more compilation errors --- unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h index 0cefe42dd..676645b0c 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h @@ -132,7 +132,7 @@ class TensorExecutor resources; evaluator.getResourceRequirements(&resources); @@ -272,7 +272,7 @@ class TensorExecutor resources; From b6f96cf7dd616ed1604919892f68f5b94d31fa5e Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 15 Aug 2018 08:54:31 -0700 Subject: [PATCH 08/25] Removed dependencies on cxx11 language features from the tensor_block_access test --- unsupported/test/cxx11_tensor_block_access.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 2631767e2..417b72201 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -157,9 +157,8 @@ static void UpdateCoeffSet( template static void test_block_mapper_maps_every_element() { - using TensorBlock = internal::TensorBlock; - using TensorBlockMapper = - internal::TensorBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorBlockMapper TensorBlockMapper; DSizes dims = RandomDims(); @@ -186,9 +185,8 @@ static void test_block_mapper_maps_every_element() { template static void test_slice_block_mapper_maps_every_element() { - using TensorBlock = internal::TensorBlock; - using TensorSliceBlockMapper = - internal::TensorSliceBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorSliceBlockMapper TensorSliceBlockMapper; DSizes tensor_dims = RandomDims(); DSizes tensor_slice_offsets = RandomDims(); @@ -773,9 +771,8 @@ static void test_uniform_block_shape() template static void test_skewed_inner_dim_block_shape() { - using T = int; - typedef internal::TensorBlock TensorBlock; - typedef internal::TensorBlockMapper TensorBlockMapper; + typedef internal::TensorBlock TensorBlock; + typedef internal::TensorBlockMapper TensorBlockMapper; // Test shape 'SkewedInnerDims' with partial allocation to inner-most dim. if (Layout == ColMajor) { From 4181556907fd29d6328fb718fa42cf9ce4734133 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 15 Aug 2018 09:34:47 -0700 Subject: [PATCH 09/25] Fixed the tensor contraction code. --- unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h | 10 ++-------- unsupported/test/cxx11_tensor_contraction.cpp | 2 +- unsupported/test/cxx11_tensor_thread_pool.cpp | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h index a023718c6..5d619efd8 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h @@ -152,13 +152,7 @@ struct TensorContractionParams { // 1. Elementwise Relu transformation following Conv2D. // 2. AddBias to the Conv2D output channels dimension. // -// See expected implementation in NoOpOutputKernel. -struct OutputKernel { - template - typedef internal::blas_data_mapper OutputMapper; -}; - -// Output kernel that does absolutely nothing. +// The NoOpOutputKernel implements an output kernel that does absolutely nothing. struct NoOpOutputKernel { /** * Tensor contraction evaluator calls this kernel after finishing each block @@ -177,7 +171,7 @@ struct NoOpOutputKernel { */ template EIGEN_ALWAYS_INLINE void operator()( - const OutputKernel::OutputMapper& /*output_mapper*/, + const internal::blas_data_mapper& /*output_mapper*/, const TensorContractionParams& /*params*/, Index /*i*/, Index /*j*/, Index /*num_rows*/, Index /*num_cols*/) const {} }; diff --git a/unsupported/test/cxx11_tensor_contraction.cpp b/unsupported/test/cxx11_tensor_contraction.cpp index 2e918eb30..928d20f6e 100644 --- a/unsupported/test/cxx11_tensor_contraction.cpp +++ b/unsupported/test/cxx11_tensor_contraction.cpp @@ -514,7 +514,7 @@ static void test_const_inputs() struct SqrtOutputKernel { template EIGEN_ALWAYS_INLINE void operator()( - const OutputKernel::OutputMapper& output_mapper, + const internal::blas_data_mapper& output_mapper, const TensorContractionParams&, Index, Index, Index num_rows, Index num_cols) const { for (int i = 0; i < num_rows; ++i) { diff --git a/unsupported/test/cxx11_tensor_thread_pool.cpp b/unsupported/test/cxx11_tensor_thread_pool.cpp index dd163c18a..7606b0abf 100644 --- a/unsupported/test/cxx11_tensor_thread_pool.cpp +++ b/unsupported/test/cxx11_tensor_thread_pool.cpp @@ -255,7 +255,7 @@ void test_multithread_contraction_agrees_with_singlethread() { struct SqrtOutputKernel { template EIGEN_ALWAYS_INLINE void operator()( - const OutputKernel::OutputMapper& output_mapper, + const internal::blas_data_mapper& output_mapper, const TensorContractionParams&, Index, Index, Index num_rows, Index num_cols) const { for (int i = 0; i < num_rows; ++i) { From f197c3f55b3a04ab24dfee8057b1d510c7483fc3 Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Wed, 15 Aug 2018 11:24:57 -0700 Subject: [PATCH 10/25] Removed an used variable (PacketSize) from TensorExecutor --- unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h index 676645b0c..9b9587de5 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h @@ -229,10 +229,6 @@ class TensorExecutor { Evaluator evaluator(expr, device); const bool needs_assign = evaluator.evalSubExprsIfNeeded(NULL); if (needs_assign) { - const StorageIndex PacketSize = - Vectorizable - ? unpacket_traits::size - : 1; const StorageIndex size = array_prod(evaluator.dimensions()); device.parallelFor(size, evaluator.costPerCoeff(Vectorizable), EvalRange::alignBlockSize, From d0b01ebbf63f0594760b6e1568bec0228987157a Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 16 Aug 2018 13:21:36 +0100 Subject: [PATCH 11/25] Reverting the unitended delete from the code. --- unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index ab5990c14..dde1b449e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -30,6 +30,7 @@ struct traits > typedef typename remove_reference::type _Nested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; + typedef typename traits::PointerType PointerType; }; @@ -185,6 +186,8 @@ struct traits > typedef typename remove_reference::type _RhsNested; static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; + typedef typename conditional::val, + typename traits::PointerType, typename traits::PointerType>::type PointerType; }; From 80f1a76dec9a5fbe4305633ab0c8797a876e4ab5 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 16 Aug 2018 13:33:24 +0100 Subject: [PATCH 12/25] removing the noises. --- unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h index dde1b449e..cbec5e9b4 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorCustomOp.h @@ -31,7 +31,6 @@ struct traits > static const int NumDimensions = traits::NumDimensions; static const int Layout = traits::Layout; typedef typename traits::PointerType PointerType; - }; template @@ -188,7 +187,6 @@ struct traits > static const int Layout = traits::Layout; typedef typename conditional::val, typename traits::PointerType, typename traits::PointerType>::type PointerType; - }; template From e23c8c294e57d6600086ede5480c2e6c89db56ec Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 16 Aug 2018 10:41:01 -0700 Subject: [PATCH 13/25] Use actual types instead of the auto keyword to make the code more portable --- unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h index 5d619efd8..2ca91709f 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h @@ -660,7 +660,7 @@ struct TensorContractionEvaluatorBase // call gebp (matrix kernel) // The parameters here are copied from Eigen's GEMM implementation - const auto output_mapper = output.getSubMapper(i2, j2); + const OutputMapper output_mapper = output.getSubMapper(i2, j2); gebp(output_mapper, blockA, blockB, actual_mc, actual_kc, actual_nc, Scalar(1), -1, -1, 0, 0); From ede580ccdac3b964bdfcf12d55560a268c366c3c Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 16 Aug 2018 10:49:47 -0700 Subject: [PATCH 14/25] Avoid using the auto keyword to make the tensor block access test more portable --- .../test/cxx11_tensor_block_access.cpp | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 417b72201..da093166b 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -104,7 +104,7 @@ static void test_block_mapper_sanity() VERIFY_IS_EQUAL(uniform_block_mapper.block_dims_total_size(), 100); // 10x10 blocks - auto uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, NULL); + typename TensorBlockMapper::Block uniform_b0 = uniform_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(0), 10); VERIFY_IS_EQUAL(uniform_b0.block_sizes().at(1), 10); // Depending on a layout we stride by cols rows. @@ -122,7 +122,7 @@ static void test_block_mapper_sanity() VERIFY_IS_EQUAL(skewed_block_mapper.block_dims_total_size(), 100); // 1x100 (100x1) rows/cols depending on a tensor layout. - auto skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, NULL); + typename TensorBlockMapper::Block skewed_b0 = skewed_block_mapper.GetBlockForIndex(0, NULL); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(0), choose(Layout, 100, 1)); VERIFY_IS_EQUAL(skewed_b0.block_sizes().at(1), choose(Layout, 1, 100)); // Depending on a layout we stride by cols rows. @@ -203,7 +203,7 @@ static void test_slice_block_mapper_maps_every_element() { // Keep track of elements indices available via block access. std::set coeff_set; - auto total_coeffs = static_cast(tensor_slice_extents.TotalSize()); + int total_coeffs = static_cast(tensor_slice_extents.TotalSize()); // Pick a random dimension sizes for the tensor blocks. DSizes block_sizes; @@ -237,7 +237,7 @@ static void test_block_io_copy_data_from_source_to_target() { TensorBlockWriter; DSizes input_tensor_dims = RandomDims(); - const auto input_tensor_size = input_tensor_dims.TotalSize(); + const Index input_tensor_size = input_tensor_dims.TotalSize(); T* input_data = GenerateRandomData(input_tensor_size); T* output_data = new T[input_tensor_size]; @@ -316,7 +316,7 @@ static void test_block_io_copy_using_reordered_dimensions() { TensorBlockWriter; DSizes input_tensor_dims = RandomDims(); - const auto input_tensor_size = input_tensor_dims.TotalSize(); + const Index input_tensor_size = input_tensor_dims.TotalSize(); // Create a random input tensor. T* input_data = GenerateRandomData(input_tensor_size); @@ -339,8 +339,8 @@ static void test_block_io_copy_using_reordered_dimensions() { TensorBlockMapper block_mapper(output_tensor_dims, RandomShape(), RandomTargetSize(input_tensor_dims)); - auto* block_data = new T[block_mapper.block_dims_total_size()]; - auto* output_data = new T[input_tensor_size]; + T* block_data = new T[block_mapper.block_dims_total_size()]; + T* output_data = new T[input_tensor_size]; array input_tensor_strides = ComputeStrides(input_tensor_dims); @@ -382,8 +382,8 @@ static void test_block_io_zero_stride() input_tensor_dims[0] = 1; input_tensor_dims[2] = 1; input_tensor_dims[4] = 1; - const auto input_tensor_size = input_tensor_dims.TotalSize(); - auto* input_data = GenerateRandomData(input_tensor_size); + const Index input_tensor_size = input_tensor_dims.TotalSize(); + float* input_data = GenerateRandomData(input_tensor_size); DSizes output_tensor_dims = rnd_dims; @@ -424,7 +424,7 @@ static void test_block_io_zero_stride() }; { - auto* output_data = new float[output_tensor_dims.TotalSize()]; + float* output_data = new float[output_tensor_dims.TotalSize()]; TensorBlock read_block(0, output_tensor_dims, output_tensor_strides, input_tensor_strides_with_zeros, output_data); TensorBlockReader::Run(&read_block, input_data); @@ -433,7 +433,7 @@ static void test_block_io_zero_stride() } { - auto* output_data = new float[output_tensor_dims.TotalSize()]; + float* output_data = new float[output_tensor_dims.TotalSize()]; TensorBlock write_block(0, output_tensor_dims, input_tensor_strides_with_zeros, output_tensor_strides, input_data); @@ -456,14 +456,14 @@ static void test_block_io_squeeze_ones() { // Total size > 1. { DSizes block_sizes(1, 2, 1, 2, 1); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensor. - auto* input_data = GenerateRandomData(total_size); + float* input_data = GenerateRandomData(total_size); DSizes strides(ComputeStrides(block_sizes)); { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock read_block(0, block_sizes, strides, strides, output_data); TensorBlockReader::Run(&read_block, input_data); for (int i = 0; i < total_size; ++i) { @@ -473,7 +473,7 @@ static void test_block_io_squeeze_ones() { } { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock write_block(0, block_sizes, strides, strides, input_data); TensorBlockWriter::Run(write_block, output_data); for (int i = 0; i < total_size; ++i) { @@ -486,14 +486,14 @@ static void test_block_io_squeeze_ones() { // Total size == 1. { DSizes block_sizes(1, 1, 1, 1, 1); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensor. - auto* input_data = GenerateRandomData(total_size); + float* input_data = GenerateRandomData(total_size); DSizes strides(ComputeStrides(block_sizes)); { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock read_block(0, block_sizes, strides, strides, output_data); TensorBlockReader::Run(&read_block, input_data); for (int i = 0; i < total_size; ++i) { @@ -503,7 +503,7 @@ static void test_block_io_squeeze_ones() { } { - auto* output_data = new float[block_sizes.TotalSize()]; + float* output_data = new float[block_sizes.TotalSize()]; TensorBlock write_block(0, block_sizes, strides, strides, input_data); TensorBlockWriter::Run(write_block, output_data); for (int i = 0; i < total_size; ++i) { @@ -524,7 +524,7 @@ static void test_block_cwise_binary_io_basic() { DSizes block_sizes = RandomDims(); DSizes strides(ComputeStrides(block_sizes)); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensors. T* left_data = GenerateRandomData(total_size); @@ -553,13 +553,13 @@ static void test_block_cwise_binary_io_squeeze_ones() { DSizes block_sizes(1, 2, 1, 3, 1); DSizes strides(ComputeStrides(block_sizes)); - const auto total_size = block_sizes.TotalSize(); + const Index total_size = block_sizes.TotalSize(); // Create a random input tensors. - auto* left_data = GenerateRandomData(total_size); - auto* right_data = GenerateRandomData(total_size); + float* left_data = GenerateRandomData(total_size); + float* right_data = GenerateRandomData(total_size); - auto* output_data = new float[total_size]; + float* output_data = new float[total_size]; BinaryFunctor functor; TensorBlockCwiseBinaryIO::Run(functor, block_sizes, strides, output_data, strides, left_data, strides, right_data); @@ -600,14 +600,14 @@ static void test_block_cwise_binary_io_zero_strides() { right_strides[3] = 0; // Generate random data. - auto* left_data = GenerateRandomData(left_sizes.TotalSize()); - auto* right_data = GenerateRandomData(right_sizes.TotalSize()); + float* left_data = GenerateRandomData(left_sizes.TotalSize()); + float* right_data = GenerateRandomData(right_sizes.TotalSize()); DSizes output_sizes = rnd_dims; DSizes output_strides(ComputeStrides(output_sizes)); - const auto output_total_size = output_sizes.TotalSize(); - auto* output_data = new float[output_total_size]; + const Index output_total_size = output_sizes.TotalSize(); + float* output_data = new float[output_total_size]; BinaryFunctor functor; TensorBlockCwiseBinaryIO::Run(functor, output_sizes, output_strides, From f641cf1253bc2f7388b632a50b818b9d15b7588d Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Thu, 16 Aug 2018 11:24:37 -0700 Subject: [PATCH 15/25] Adding missing at method in Eigen::array --- unsupported/Eigen/CXX11/src/util/EmulateArray.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unsupported/Eigen/CXX11/src/util/EmulateArray.h b/unsupported/Eigen/CXX11/src/util/EmulateArray.h index d91662d96..32db51592 100644 --- a/unsupported/Eigen/CXX11/src/util/EmulateArray.h +++ b/unsupported/Eigen/CXX11/src/util/EmulateArray.h @@ -25,6 +25,11 @@ template class array { EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator[] (size_t index) const { return values[index]; } + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE T& at(size_t index) { eigen_assert(index < size()); return values[index]; } + EIGEN_DEVICE_FUNC + EIGEN_STRONG_INLINE const T& at(size_t index) const { eigen_assert(index < size()); return values[index]; } + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T& front() { return values[0]; } EIGEN_DEVICE_FUNC From dbdeceabdd115293a2f6a9c17079940cf5b096dd Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 17 Aug 2018 16:26:11 +0200 Subject: [PATCH 16/25] Silence double-promotion warning (when converting double to complex) --- unsupported/Eigen/FFT | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unsupported/Eigen/FFT b/unsupported/Eigen/FFT index 2c45b3999..d8cf3e642 100644 --- a/unsupported/Eigen/FFT +++ b/unsupported/Eigen/FFT @@ -289,6 +289,7 @@ class FFT void inv( MatrixBase & dst, const MatrixBase & src, Index nfft=-1) { typedef typename ComplexDerived::Scalar src_type; + typedef typename ComplexDerived::RealScalar real_type; typedef typename OutputDerived::Scalar dst_type; const bool realfft= (NumTraits::IsComplex == 0); EIGEN_STATIC_ASSERT_VECTOR_ONLY(OutputDerived) @@ -329,9 +330,9 @@ class FFT tmp.head(nhead) = src.head(nhead); tmp.tail(ntail) = src.tail(ntail); if (resize_input<0) { //shrinking -- create the Nyquist bin as the average of the two bins that fold into it - tmp(nhead) = ( src(nfft/2) + src( src.size() - nfft/2 ) )*src_type(.5); + tmp(nhead) = ( src(nfft/2) + src( src.size() - nfft/2 ) )*real_type(.5); }else{ // expanding -- split the old Nyquist bin into two halves - tmp(nhead) = src(nhead) * src_type(.5); + tmp(nhead) = src(nhead) * real_type(.5); tmp(tmp.size()-nhead) = tmp(nhead); } } From c9b25fbefa44f684f76e9a669be217c9d3e7734d Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 17 Aug 2018 16:28:28 +0200 Subject: [PATCH 17/25] Silence unused parameter warning --- unsupported/Eigen/src/BVH/KdBVH.h | 1 + 1 file changed, 1 insertion(+) diff --git a/unsupported/Eigen/src/BVH/KdBVH.h b/unsupported/Eigen/src/BVH/KdBVH.h index 13f792cd0..2d5b76ad0 100644 --- a/unsupported/Eigen/src/BVH/KdBVH.h +++ b/unsupported/Eigen/src/BVH/KdBVH.h @@ -35,6 +35,7 @@ struct get_boxes_helper { { outBoxes.insert(outBoxes.end(), boxBegin, boxEnd); eigen_assert(outBoxes.size() == objects.size()); + EIGEN_ONLY_USED_FOR_DEBUG(objects); } }; From 595cae9b09bf322a747f8ff5aade76448db58a17 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 17 Aug 2018 16:30:32 +0200 Subject: [PATCH 18/25] Silence logical-op-parentheses warning --- Eigen/src/SuperLUSupport/SuperLUSupport.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eigen/src/SuperLUSupport/SuperLUSupport.h b/Eigen/src/SuperLUSupport/SuperLUSupport.h index 4bb95eb8b..354e33de5 100644 --- a/Eigen/src/SuperLUSupport/SuperLUSupport.h +++ b/Eigen/src/SuperLUSupport/SuperLUSupport.h @@ -297,8 +297,8 @@ SluMatrix asSluMatrix(MatrixType& mat) template MappedSparseMatrix map_superlu(SluMatrix& sluMat) { - eigen_assert((Flags&RowMajor)==RowMajor && sluMat.Stype == SLU_NR - || (Flags&ColMajor)==ColMajor && sluMat.Stype == SLU_NC); + eigen_assert(((Flags&RowMajor)==RowMajor && sluMat.Stype == SLU_NR) + || ((Flags&ColMajor)==ColMajor && sluMat.Stype == SLU_NC)); Index outerSize = (Flags&RowMajor)==RowMajor ? sluMat.ncol : sluMat.nrow; From 4713465eefbdb725ee3bb2cc3330bf77f51f1c6b Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 17 Aug 2018 16:39:43 +0200 Subject: [PATCH 19/25] Silence double-promotion warning --- unsupported/Eigen/OpenGLSupport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsupported/Eigen/OpenGLSupport b/unsupported/Eigen/OpenGLSupport index 11d99567e..489fd8354 100644 --- a/unsupported/Eigen/OpenGLSupport +++ b/unsupported/Eigen/OpenGLSupport @@ -184,7 +184,7 @@ inline void glRotate(const Rotation2D& rot) } inline void glRotate(const Rotation2D& rot) { - glRotated(rot.angle()*180.0/EIGEN_PI, 0.0, 0.0, 1.0); + glRotated(rot.angle()*180.0/double(EIGEN_PI), 0.0, 0.0, 1.0); } template void glRotate(const RotationBase& rot) From 41f1cc67b8e55469367416151d6a82e3632cfda8 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Fri, 17 Aug 2018 16:42:53 +0200 Subject: [PATCH 20/25] Assertion depended on a not yet initialized value --- Eigen/src/Core/MapBase.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Eigen/src/Core/MapBase.h b/Eigen/src/Core/MapBase.h index 020f939ad..668922ffc 100644 --- a/Eigen/src/Core/MapBase.h +++ b/Eigen/src/Core/MapBase.h @@ -43,6 +43,7 @@ template class MapBase enum { RowsAtCompileTime = internal::traits::RowsAtCompileTime, ColsAtCompileTime = internal::traits::ColsAtCompileTime, + InnerStrideAtCompileTime = internal::traits::InnerStrideAtCompileTime, SizeAtCompileTime = Base::SizeAtCompileTime }; @@ -187,8 +188,11 @@ template class MapBase void checkSanity(typename internal::enable_if<(internal::traits::Alignment>0),void*>::type = 0) const { #if EIGEN_MAX_ALIGN_BYTES>0 + // innerStride() is not set yet when this function is called, so we optimistically assume the lowest plausible value: + const Index minInnerStride = InnerStrideAtCompileTime == Dynamic ? 1 : Index(InnerStrideAtCompileTime); + EIGEN_ONLY_USED_FOR_DEBUG(minInnerStride); eigen_assert(( ((internal::UIntPtr(m_data) % internal::traits::Alignment) == 0) - || (cols() * rows() * innerStride() * sizeof(Scalar)) < internal::traits::Alignment ) && "data is not aligned"); + || (cols() * rows() * minInnerStride * sizeof(Scalar)) < internal::traits::Alignment ) && "data is not aligned"); #endif } From f76c802973a5e70309eb1d713adf59a5f9711ad1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 17 Aug 2018 17:16:12 +0200 Subject: [PATCH 21/25] Add missing empty line --- test/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/main.h b/test/main.h index de8a4865f..5d550969e 100644 --- a/test/main.h +++ b/test/main.h @@ -845,4 +845,4 @@ int main(int argc, char *argv[]) #ifdef _MSC_VER // 4503 - decorated name length exceeded, name was truncated #pragma warning( disable : 4503) -#endif \ No newline at end of file +#endif From 43d9dd9b2844828de3996b762b2f760749df711b Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 17 Aug 2018 08:49:32 -0700 Subject: [PATCH 22/25] Removed more dependencies on cxx11. --- unsupported/test/cxx11_tensor_block_access.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index da093166b..7bf338522 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -11,7 +11,6 @@ #include "main.h" #include -#include #include #include @@ -49,8 +48,8 @@ static DSizes RandomDims() { /** Dummy data type to test TensorBlock copy ops. */ struct Data { - Data() : Data(0) {} - explicit Data(int v) { value = v; } + Data() : value(0) {} + explicit Data(int v) : value(v) { } int value; }; @@ -324,7 +323,7 @@ static void test_block_io_copy_using_reordered_dimensions() { // Create a random dimension re-ordering/shuffle. std::vector shuffle; for (int i = 0; i < NumDims; ++i) shuffle.push_back(i); - std::shuffle(shuffle.begin(), shuffle.end(), std::mt19937()); + std::random_shuffle(shuffle.begin(), shuffle.end()); DSizes output_tensor_dims; array input_to_output_dim_map; From ff8e0ecc2fa83ca4de14fc2f1049bd48907df3f6 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 17 Aug 2018 15:15:52 -0700 Subject: [PATCH 23/25] Updated one more line of code to avoid making the test dependent on cxx11 features. --- unsupported/test/cxx11_tensor_block_access.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unsupported/test/cxx11_tensor_block_access.cpp b/unsupported/test/cxx11_tensor_block_access.cpp index 7bf338522..f572e496d 100644 --- a/unsupported/test/cxx11_tensor_block_access.cpp +++ b/unsupported/test/cxx11_tensor_block_access.cpp @@ -143,7 +143,8 @@ static void UpdateCoeffSet( for (int i = 0; i < block_sizes[dim_index]; ++i) { if (tensor_strides[dim_index] == 1) { - auto inserted = visited_coeffs->insert(first_coeff_index + i); + typedef std::pair::iterator, bool> ReturnType; + ReturnType inserted = visited_coeffs->insert(first_coeff_index + i); VERIFY_IS_EQUAL(inserted.second, true); } else { int next_dim_index = dim_index + choose(Layout, -1, 1); From 39335cf51e7ea5edfe9113cb91034625a039ccbf Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Thu, 23 Aug 2018 19:37:56 +0200 Subject: [PATCH 24/25] Make MaxSizeVector leak-safe --- .../Eigen/CXX11/src/util/MaxSizeVector.h | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h b/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h index 4bc3dd1ba..bc5b3632c 100644 --- a/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h +++ b/unsupported/Eigen/CXX11/src/util/MaxSizeVector.h @@ -35,7 +35,6 @@ class MaxSizeVector { explicit MaxSizeVector(size_t n) : reserve_(n), size_(0), data_(static_cast(internal::aligned_malloc(n * sizeof(T)))) { - for (size_t i = 0; i < n; ++i) { new (&data_[i]) T; } } // Construct a new MaxSizeVector, reserve and resize to n. @@ -44,35 +43,55 @@ class MaxSizeVector { MaxSizeVector(size_t n, const T& init) : reserve_(n), size_(n), data_(static_cast(internal::aligned_malloc(n * sizeof(T)))) { - for (size_t i = 0; i < n; ++i) { new (&data_[i]) T(init); } + size_t i = 0; + EIGEN_TRY + { + for(; i < size_; ++i) { new (&data_[i]) T(init); } + } + EIGEN_CATCH(...) + { + // Construction failed, destruct in reverse order: + for(; (i+1) > 0; --i) { data_[i-1].~T(); } + internal::aligned_free(data_); + EIGEN_THROW; + } } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~MaxSizeVector() { - for (size_t i = 0; i < size_; ++i) { - data_[i].~T(); + for (size_t i = size_; i > 0; --i) { + data_[i-1].~T(); } internal::aligned_free(data_); } void resize(size_t n) { eigen_assert(n <= reserve_); - for (size_t i = size_; i < n; ++i) { - new (&data_[i]) T; + for (; size_ < n; ++size_) { + new (&data_[size_]) T; } - for (size_t i = n; i < size_; ++i) { - data_[i].~T(); + for (; size_ > n; --size_) { + data_[size_-1].~T(); } - size_ = n; + eigen_assert(size_ == n); } // Append new elements (up to reserved size). EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void push_back(const T& t) { eigen_assert(size_ < reserve_); - data_[size_++] = t; + new (&data_[size_++]) T(t); } + // For C++03 compatibility this only takes one argument + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + void emplace_back(const X& x) { + eigen_assert(size_ < reserve_); + new (&data_[size_++]) T(x); + } + + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T& operator[] (size_t i) const { eigen_assert(i < size_); @@ -99,11 +118,8 @@ class MaxSizeVector { EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void pop_back() { - // NOTE: This does not destroy the value at the end the way - // std::vector's version of pop_back() does. That happens when - // the Vector is destroyed. eigen_assert(size_ > 0); - size_--; + data_[--size_].~T(); } EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE From a709c8efb4927ebac338cb93865e8d0bdfcac85d Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Thu, 23 Aug 2018 19:41:59 +0200 Subject: [PATCH 25/25] Replace pointers by values or unique_ptr for better leak-safety --- .../src/ThreadPool/NonBlockingThreadPool.h | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h b/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h index ecd49f382..a93e22a76 100644 --- a/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h +++ b/unsupported/Eigen/CXX11/src/ThreadPool/NonBlockingThreadPool.h @@ -58,11 +58,9 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { coprimes_.push_back(i); } } + queues_.resize(num_threads_); for (int i = 0; i < num_threads_; i++) { - queues_.push_back(new Queue()); - } - for (int i = 0; i < num_threads_; i++) { - threads_.push_back(env_.CreateThread([this, i]() { WorkerLoop(i); })); + threads_.emplace_back(env_.CreateThread([this, i]() { WorkerLoop(i); })); } } @@ -78,13 +76,12 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { // Since we were cancelled, there might be entries in the queues. // Empty them to prevent their destructor from asserting. for (size_t i = 0; i < queues_.size(); i++) { - queues_[i]->Flush(); + queues_[i].Flush(); } } // Join threads explicitly to avoid destruction order issues. - for (size_t i = 0; i < num_threads_; i++) delete threads_[i]; - for (size_t i = 0; i < num_threads_; i++) delete queues_[i]; + threads_.resize(0); } void Schedule(std::function fn) { @@ -92,13 +89,13 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { PerThread* pt = GetPerThread(); if (pt->pool == this) { // Worker thread of this pool, push onto the thread's queue. - Queue* q = queues_[pt->thread_id]; - t = q->PushFront(std::move(t)); + Queue& q = queues_[pt->thread_id]; + t = q.PushFront(std::move(t)); } else { // A free-standing thread (or worker of another pool), push onto a random // queue. - Queue* q = queues_[Rand(&pt->rand) % queues_.size()]; - t = q->PushBack(std::move(t)); + Queue& q = queues_[Rand(&pt->rand) % queues_.size()]; + t = q.PushBack(std::move(t)); } // Note: below we touch this after making w available to worker threads. // Strictly speaking, this can lead to a racy-use-after-free. Consider that @@ -157,8 +154,8 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { Environment env_; const int num_threads_; const bool allow_spinning_; - MaxSizeVector threads_; - MaxSizeVector queues_; + MaxSizeVector > threads_; + MaxSizeVector queues_; MaxSizeVector coprimes_; MaxSizeVector waiters_; std::atomic blocked_; @@ -173,7 +170,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { pt->pool = this; pt->rand = std::hash()(std::this_thread::get_id()); pt->thread_id = thread_id; - Queue* q = queues_[thread_id]; + Queue& q = queues_[thread_id]; EventCount::Waiter* waiter = &waiters_[thread_id]; // TODO(dvyukov,rmlarsen): The time spent in Steal() is proportional // to num_threads_ and we assume that new work is scheduled at a @@ -189,10 +186,10 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { // counter-productive for the types of I/O workloads the single thread // pools tend to be used for. while (!cancelled_) { - Task t = q->PopFront(); + Task t = q.PopFront(); for (int i = 0; i < spin_count && !t.f; i++) { if (!cancelled_.load(std::memory_order_relaxed)) { - t = q->PopFront(); + t = q.PopFront(); } } if (!t.f) { @@ -206,7 +203,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { } } else { while (!cancelled_) { - Task t = q->PopFront(); + Task t = q.PopFront(); if (!t.f) { t = Steal(); if (!t.f) { @@ -243,7 +240,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { unsigned inc = coprimes_[r % coprimes_.size()]; unsigned victim = r % size; for (unsigned i = 0; i < size; i++) { - Task t = queues_[victim]->PopBack(); + Task t = queues_[victim].PopBack(); if (t.f) { return t; } @@ -270,7 +267,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { if (cancelled_) { return false; } else { - *t = queues_[victim]->PopBack(); + *t = queues_[victim].PopBack(); return true; } } @@ -278,7 +275,8 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { // If we are shutting down and all worker threads blocked without work, // that's we are done. blocked_++; - if (done_ && blocked_ == num_threads_) { + // TODO is blocked_ required to be unsigned? + if (done_ && blocked_ == static_cast(num_threads_)) { ec_.CancelWait(waiter); // Almost done, but need to re-check queues. // Consider that all queues are empty and all worker threads are preempted @@ -311,7 +309,7 @@ class ThreadPoolTempl : public Eigen::ThreadPoolInterface { unsigned inc = coprimes_[r % coprimes_.size()]; unsigned victim = r % size; for (unsigned i = 0; i < size; i++) { - if (!queues_[victim]->Empty()) { + if (!queues_[victim].Empty()) { return victim; } victim += inc;