From 670d56441cbf115652630c890bac1ba41cd20106 Mon Sep 17 00:00:00 2001 From: Mark D Ryan Date: Tue, 13 Nov 2018 16:15:08 +0100 Subject: PR 544: Set requestedAlignment correctly for SliceVectorizedTraversals Commit aa110e681b8b2237757a652ba47da49e1fbd2cd6 optimised the multiplication of small dyanmically sized matrices by restricting the packet size to a maximum of 4, increasing the chances that SIMD instructions are used in the computation. However, it introduced a mismatch between the packet size and the requestedAlignment. This mismatch can lead to crashes when the destination is not aligned. This patch fixes the issue by ensuring that the AssignmentTraits are correctly computed when using a restricted packet size. * * * Bind LinearPacketType to MaxPacketSize This commit applies any packet size limit specified when instantiating copy_using_evaluator_traits to the LinearPacketType, providing that the size of the destination is not known at compile time. * * * Add unit test for restricted packet assignment A new unit test is added to check that multiplication of small dynamically sized matrices works correctly when the packet size is restricted to 4 and the destination is unaligned. --- test/evaluators.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/evaluators.cpp') diff --git a/test/evaluators.cpp b/test/evaluators.cpp index f4fdaf053..ec000f1eb 100644 --- a/test/evaluators.cpp +++ b/test/evaluators.cpp @@ -90,6 +90,12 @@ namespace Eigen { { call_assignment_no_alias(dst.expression(), src, func); } + + template class StorageBase, typename Src, typename Func> + EIGEN_DEVICE_FUNC void call_restricted_packet_assignment(const NoAlias& dst, const Src& src, const Func& func) + { + call_restricted_packet_assignment_no_alias(dst.expression(), src, func); + } } } @@ -496,4 +502,23 @@ EIGEN_DECLARE_TEST(evaluators) VERIFY_IS_EQUAL( get_cost(a*(a+b)), 1); VERIFY_IS_EQUAL( get_cost(a.lazyProduct(a+b)), 15); } + + { + // test restricted_packet_assignment with an unaligned destination + const size_t M = 2; + const size_t K = 2; + const size_t N = 5; + float *destMem = new float[(M*N) + 1]; + float *dest = (internal::UIntPtr(destMem)%EIGEN_MAX_ALIGN_BYTES) == 0 ? destMem+1 : destMem; + + const Matrix a = Matrix::Random(M, K); + const Matrix b = Matrix::Random(K, N); + + Map > z(dest, M, N);; + Product, Matrix, LazyProduct> tmp(a,b); + internal::call_restricted_packet_assignment(z.noalias(), tmp.derived(), internal::assign_op()); + + VERIFY_IS_APPROX(z, a*b); + delete[] destMem; + } } -- cgit v1.2.3