mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-31 17:22:07 +08:00
Fix 128bit packet size assumptions in unit tests.
This commit is contained in:
parent
a7d20038df
commit
2606abed53
@ -105,6 +105,8 @@ public:
|
|||||||
EIGEN_DEBUG_VAR(DstIsAligned)
|
EIGEN_DEBUG_VAR(DstIsAligned)
|
||||||
EIGEN_DEBUG_VAR(SrcIsAligned)
|
EIGEN_DEBUG_VAR(SrcIsAligned)
|
||||||
EIGEN_DEBUG_VAR(JointAlignment)
|
EIGEN_DEBUG_VAR(JointAlignment)
|
||||||
|
EIGEN_DEBUG_VAR(Derived::SizeAtCompileTime)
|
||||||
|
EIGEN_DEBUG_VAR(OtherDerived::CoeffReadCost)
|
||||||
EIGEN_DEBUG_VAR(InnerSize)
|
EIGEN_DEBUG_VAR(InnerSize)
|
||||||
EIGEN_DEBUG_VAR(InnerMaxSize)
|
EIGEN_DEBUG_VAR(InnerMaxSize)
|
||||||
EIGEN_DEBUG_VAR(PacketSize)
|
EIGEN_DEBUG_VAR(PacketSize)
|
||||||
|
@ -66,8 +66,7 @@ template<typename Lhs, typename Rhs> struct product_type
|
|||||||
MaxDepth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::MaxColsAtCompileTime,
|
MaxDepth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::MaxColsAtCompileTime,
|
||||||
_Rhs::MaxRowsAtCompileTime),
|
_Rhs::MaxRowsAtCompileTime),
|
||||||
Depth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::ColsAtCompileTime,
|
Depth = EIGEN_SIZE_MIN_PREFER_FIXED(_Lhs::ColsAtCompileTime,
|
||||||
_Rhs::RowsAtCompileTime),
|
_Rhs::RowsAtCompileTime)
|
||||||
LargeThreshold = EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// the splitting into different lines of code here, introducing the _select enums and the typedef below,
|
// the splitting into different lines of code here, introducing the _select enums and the typedef below,
|
||||||
|
@ -10,11 +10,13 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
#if EIGEN_ALIGN
|
#if EIGEN_ALIGN
|
||||||
#define ALIGNMENT 16
|
#define ALIGNMENT EIGEN_ALIGN_BYTES
|
||||||
#else
|
#else
|
||||||
#define ALIGNMENT 1
|
#define ALIGNMENT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef Matrix<float,8,1> Vector8f;
|
||||||
|
|
||||||
void check_handmade_aligned_malloc()
|
void check_handmade_aligned_malloc()
|
||||||
{
|
{
|
||||||
for(int i = 1; i < 1000; i++)
|
for(int i = 1; i < 1000; i++)
|
||||||
@ -68,7 +70,7 @@ struct MyStruct
|
|||||||
{
|
{
|
||||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||||
char dummychar;
|
char dummychar;
|
||||||
Vector4f avec;
|
Vector8f avec;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyClassA
|
class MyClassA
|
||||||
@ -76,15 +78,19 @@ class MyClassA
|
|||||||
public:
|
public:
|
||||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||||
char dummychar;
|
char dummychar;
|
||||||
Vector4f avec;
|
Vector8f avec;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> void check_dynaligned()
|
template<typename T> void check_dynaligned()
|
||||||
{
|
{
|
||||||
|
// TODO have to be updated once we support multiple alignment values
|
||||||
|
if(T::SizeAtCompileTime % ALIGNMENT == 0)
|
||||||
|
{
|
||||||
T* obj = new T;
|
T* obj = new T;
|
||||||
VERIFY(T::NeedsToAlign==1);
|
VERIFY(T::NeedsToAlign==1);
|
||||||
VERIFY(size_t(obj)%ALIGNMENT==0);
|
VERIFY(size_t(obj)%ALIGNMENT==0);
|
||||||
delete obj;
|
delete obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_dynalloc()
|
void test_dynalloc()
|
||||||
@ -102,6 +108,7 @@ void test_dynalloc()
|
|||||||
CALL_SUBTEST(check_dynaligned<Matrix4f>() );
|
CALL_SUBTEST(check_dynaligned<Matrix4f>() );
|
||||||
CALL_SUBTEST(check_dynaligned<Vector4d>() );
|
CALL_SUBTEST(check_dynaligned<Vector4d>() );
|
||||||
CALL_SUBTEST(check_dynaligned<Vector4i>() );
|
CALL_SUBTEST(check_dynaligned<Vector4i>() );
|
||||||
|
CALL_SUBTEST(check_dynaligned<Vector8f>() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// check static allocation, who knows ?
|
// check static allocation, who knows ?
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
typedef Matrix<float,8,1> Vector8f;
|
||||||
|
|
||||||
struct TestNew1
|
struct TestNew1
|
||||||
{
|
{
|
||||||
MatrixXd m; // good: m will allocate its own array, taking care of alignment.
|
MatrixXd m; // good: m will allocate its own array, taking care of alignment.
|
||||||
@ -69,7 +71,7 @@ void construct_at_boundary(int boundary)
|
|||||||
{
|
{
|
||||||
char buf[sizeof(T)+256];
|
char buf[sizeof(T)+256];
|
||||||
size_t _buf = reinterpret_cast<size_t>(buf);
|
size_t _buf = reinterpret_cast<size_t>(buf);
|
||||||
_buf += (16 - (_buf % 16)); // make 16-byte aligned
|
_buf += (EIGEN_ALIGN_BYTES - (_buf % EIGEN_ALIGN_BYTES)); // make 16/32-byte aligned
|
||||||
_buf += boundary; // make exact boundary-aligned
|
_buf += boundary; // make exact boundary-aligned
|
||||||
T *x = ::new(reinterpret_cast<void*>(_buf)) T;
|
T *x = ::new(reinterpret_cast<void*>(_buf)) T;
|
||||||
x[0].setZero(); // just in order to silence warnings
|
x[0].setZero(); // just in order to silence warnings
|
||||||
@ -85,18 +87,18 @@ void unalignedassert()
|
|||||||
construct_at_boundary<Vector4f>(16);
|
construct_at_boundary<Vector4f>(16);
|
||||||
construct_at_boundary<Matrix2f>(16);
|
construct_at_boundary<Matrix2f>(16);
|
||||||
construct_at_boundary<Matrix3f>(4);
|
construct_at_boundary<Matrix3f>(4);
|
||||||
construct_at_boundary<Matrix4f>(16);
|
construct_at_boundary<Matrix4f>(EIGEN_ALIGN_BYTES);
|
||||||
|
|
||||||
construct_at_boundary<Vector2d>(16);
|
construct_at_boundary<Vector2d>(16);
|
||||||
construct_at_boundary<Vector3d>(4);
|
construct_at_boundary<Vector3d>(4);
|
||||||
construct_at_boundary<Vector4d>(16);
|
construct_at_boundary<Vector4d>(EIGEN_ALIGN_BYTES);
|
||||||
construct_at_boundary<Matrix2d>(16);
|
construct_at_boundary<Matrix2d>(EIGEN_ALIGN_BYTES);
|
||||||
construct_at_boundary<Matrix3d>(4);
|
construct_at_boundary<Matrix3d>(4);
|
||||||
construct_at_boundary<Matrix4d>(16);
|
construct_at_boundary<Matrix4d>(EIGEN_ALIGN_BYTES);
|
||||||
|
|
||||||
construct_at_boundary<Vector2cf>(16);
|
construct_at_boundary<Vector2cf>(16);
|
||||||
construct_at_boundary<Vector3cf>(4);
|
construct_at_boundary<Vector3cf>(4);
|
||||||
construct_at_boundary<Vector2cd>(16);
|
construct_at_boundary<Vector2cd>(EIGEN_ALIGN_BYTES);
|
||||||
construct_at_boundary<Vector3cd>(16);
|
construct_at_boundary<Vector3cd>(16);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -110,14 +112,21 @@ void unalignedassert()
|
|||||||
check_unalignedassert_good<Depends<true> >();
|
check_unalignedassert_good<Depends<true> >();
|
||||||
|
|
||||||
#if EIGEN_ALIGN_STATICALLY
|
#if EIGEN_ALIGN_STATICALLY
|
||||||
|
if(EIGEN_ALIGN_BYTES==16)
|
||||||
|
{
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4f>(8));
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4f>(8));
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4f>(8));
|
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2d>(8));
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2d>(8));
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4d>(8));
|
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix2d>(8));
|
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4d>(8));
|
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cf>(8));
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cf>(8));
|
||||||
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cd>(8));
|
}
|
||||||
|
for(int b=8; b<EIGEN_ALIGN_BYTES; b+=8)
|
||||||
|
{
|
||||||
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector8f>(b));
|
||||||
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4f>(b));
|
||||||
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector4d>(b));
|
||||||
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix2d>(b));
|
||||||
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Matrix4d>(b));
|
||||||
|
VERIFY_RAISES_ASSERT(construct_at_boundary<Vector2cd>(b));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ template<typename Scalar, bool Enable = internal::packet_traits<Scalar>::Vectori
|
|||||||
typedef Matrix<Scalar,2*PacketSize,2*PacketSize> Matrix22;
|
typedef Matrix<Scalar,2*PacketSize,2*PacketSize> Matrix22;
|
||||||
typedef Matrix<Scalar,(Matrix11::Flags&RowMajorBit)?16:4*PacketSize,(Matrix11::Flags&RowMajorBit)?4*PacketSize:16> Matrix44;
|
typedef Matrix<Scalar,(Matrix11::Flags&RowMajorBit)?16:4*PacketSize,(Matrix11::Flags&RowMajorBit)?4*PacketSize:16> Matrix44;
|
||||||
typedef Matrix<Scalar,(Matrix11::Flags&RowMajorBit)?16:4*PacketSize,(Matrix11::Flags&RowMajorBit)?4*PacketSize:16,DontAlign|EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION> Matrix44u;
|
typedef Matrix<Scalar,(Matrix11::Flags&RowMajorBit)?16:4*PacketSize,(Matrix11::Flags&RowMajorBit)?4*PacketSize:16,DontAlign|EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION> Matrix44u;
|
||||||
typedef Matrix<Scalar,4*PacketSize,16,ColMajor> Matrix44c;
|
typedef Matrix<Scalar,4*PacketSize,4*PacketSize,ColMajor> Matrix44c;
|
||||||
typedef Matrix<Scalar,4*PacketSize,16,RowMajor> Matrix44r;
|
typedef Matrix<Scalar,4*PacketSize,4*PacketSize,RowMajor> Matrix44r;
|
||||||
|
|
||||||
typedef Matrix<Scalar,
|
typedef Matrix<Scalar,
|
||||||
(PacketSize==8 ? 4 : PacketSize==4 ? 2 : PacketSize==2 ? 1 : /*PacketSize==1 ?*/ 1),
|
(PacketSize==8 ? 4 : PacketSize==4 ? 2 : PacketSize==2 ? 1 : /*PacketSize==1 ?*/ 1),
|
||||||
@ -156,8 +156,8 @@ template<typename Scalar, bool Enable = internal::packet_traits<Scalar>::Vectori
|
|||||||
VERIFY(test_assign(Matrix<Scalar,17,17>(),Matrix<Scalar,17,17>()+Matrix<Scalar,17,17>(),
|
VERIFY(test_assign(Matrix<Scalar,17,17>(),Matrix<Scalar,17,17>()+Matrix<Scalar,17,17>(),
|
||||||
LinearTraversal,NoUnrolling));
|
LinearTraversal,NoUnrolling));
|
||||||
|
|
||||||
VERIFY(test_assign(Matrix11(),Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(2,3)+Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(10,4),
|
VERIFY(test_assign(Matrix11(),Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(2,3)+Matrix<Scalar,17,17>().template block<PacketSize,PacketSize>(8,4),
|
||||||
DefaultTraversal,CompleteUnrolling));
|
DefaultTraversal,PacketSize>4?InnerUnrolling:CompleteUnrolling));
|
||||||
}
|
}
|
||||||
|
|
||||||
VERIFY(test_redux(Matrix3(),
|
VERIFY(test_redux(Matrix3(),
|
||||||
@ -181,11 +181,12 @@ template<typename Scalar, bool Enable = internal::packet_traits<Scalar>::Vectori
|
|||||||
>(InnerVectorizedTraversal,CompleteUnrolling)));
|
>(InnerVectorizedTraversal,CompleteUnrolling)));
|
||||||
|
|
||||||
VERIFY((test_assign<
|
VERIFY((test_assign<
|
||||||
Map<Matrix22, Aligned, InnerStride<3*PacketSize> >,
|
Map<Matrix<Scalar,EIGEN_PLAIN_ENUM_MAX(2,PacketSize),EIGEN_PLAIN_ENUM_MAX(2,PacketSize)>, Aligned, InnerStride<3*PacketSize> >,
|
||||||
Matrix22
|
Matrix<Scalar,EIGEN_PLAIN_ENUM_MAX(2,PacketSize),EIGEN_PLAIN_ENUM_MAX(2,PacketSize)>
|
||||||
>(DefaultTraversal,CompleteUnrolling)));
|
>(DefaultTraversal,CompleteUnrolling)));
|
||||||
|
|
||||||
VERIFY((test_assign(Matrix11(), Matrix11()*Matrix11(), InnerVectorizedTraversal, CompleteUnrolling)));
|
VERIFY((test_assign(Matrix11(), Matrix<Scalar,PacketSize,EIGEN_PLAIN_ENUM_MIN(2,PacketSize)>()*Matrix<Scalar,EIGEN_PLAIN_ENUM_MIN(2,PacketSize),PacketSize>(),
|
||||||
|
PacketSize>=EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD?DefaultTraversal:InnerVectorizedTraversal, CompleteUnrolling)));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VERIFY(test_assign(MatrixXX(10,10),MatrixXX(20,20).block(10,10,2,3),
|
VERIFY(test_assign(MatrixXX(10,10),MatrixXX(20,20).block(10,10,2,3),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user