Remove aligned-on-scalar assert and fallback to non vectorized path at runtime (first_aligned already had this runtime guard)

This commit is contained in:
Gael Guennebaud 2015-06-14 15:04:07 +02:00
parent e5b490b654
commit 972a535288
3 changed files with 35 additions and 19 deletions

View File

@ -471,18 +471,25 @@ struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling>
{
EIGEN_DEVICE_FUNC static inline void run(Kernel &kernel)
{
typedef packet_traits<typename Kernel::Scalar> PacketTraits;
typedef typename Kernel::Scalar Scalar;
typedef packet_traits<Scalar> PacketTraits;
enum {
packetSize = PacketTraits::size,
alignable = PacketTraits::AlignedOnScalar,
dstAlignment = alignable ? Aligned : int(Kernel::AssignmentTraits::DstIsAligned)
dstIsAligned = Kernel::AssignmentTraits::DstIsAligned,
dstAlignment = alignable ? Aligned : int(dstIsAligned)
};
const Scalar *dst_ptr = &kernel.dstEvaluator().coeffRef(0,0);
if((!bool(dstIsAligned)) && (Index(dst_ptr) % sizeof(Scalar))>0)
{
// the pointer is not aligend-on scalar, so alignment is not possible
return dense_assignment_loop<Kernel,DefaultTraversal,NoUnrolling>::run(kernel);
}
const Index packetAlignedMask = packetSize - 1;
const Index innerSize = kernel.innerSize();
const Index outerSize = kernel.outerSize();
const Index alignedStep = alignable ? (packetSize - kernel.outerStride() % packetSize) & packetAlignedMask : 0;
Index alignedStart = ((!alignable) || Kernel::AssignmentTraits::DstIsAligned) ? 0
: internal::first_aligned(&kernel.dstEvaluator().coeffRef(0,0), innerSize);
Index alignedStart = ((!alignable) || bool(dstIsAligned)) ? 0 : internal::first_aligned(dst_ptr, innerSize);
for(Index outer = 0; outer < outerSize; ++outer)
{

View File

@ -124,7 +124,6 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma
: Base(cast_to_pointer_type(dataPtr)), m_stride(stride)
{
PlainObjectType::Base::_check_template_params();
checkPointer(dataPtr);
}
/** Constructor in the dynamic-size vector case.
@ -138,7 +137,6 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma
: Base(cast_to_pointer_type(dataPtr), size), m_stride(stride)
{
PlainObjectType::Base::_check_template_params();
checkPointer(dataPtr);
}
/** Constructor in the dynamic-size matrix case.
@ -153,24 +151,11 @@ template<typename PlainObjectType, int MapOptions, typename StrideType> class Ma
: Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride)
{
PlainObjectType::Base::_check_template_params();
checkPointer(dataPtr);
}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
protected:
static void checkPointer(const Scalar* dataPtr)
{
enum {
MightTryToAlignOnScalar = internal::packet_traits<Scalar>::AlignedOnScalar
&& bool(internal::traits<Map>::Flags&PacketAccessBit)
&& internal::is_lvalue<Map>::value
};
eigen_assert(EIGEN_IMPLIES(bool(MightTryToAlignOnScalar), (size_t(dataPtr) % sizeof(Scalar)) == 0)
&& "input pointer is not aligned on scalar boundary, e.g., use \"EIGEN_ALIGN8 T ptr[N];\" for double or complex<float>");
}
StrideType m_stride;
};

View File

@ -159,6 +159,28 @@ template<typename PlainObjectType> void check_const_correctness(const PlainObjec
VERIFY( !(Map<ConstPlainObjectType, Aligned>::Flags & LvalueBit) );
}
template<typename Scalar>
void map_not_aligned_on_scalar()
{
typedef Matrix<Scalar,Dynamic,Dynamic> MatrixType;
typedef typename MatrixType::Index Index;
Index size = 11;
Scalar* array1 = internal::aligned_new<Scalar>((size+1)*(size+1)+1);
Scalar* array2 = reinterpret_cast<Scalar*>(sizeof(Scalar)/2+std::size_t(array1));
Map<MatrixType,0,OuterStride<> > map2(array2, size, size, OuterStride<>(size+1));
MatrixType m2 = MatrixType::Random(size,size);
map2 = m2;
VERIFY_IS_EQUAL(m2, map2);
typedef Matrix<Scalar,Dynamic,1> VectorType;
Map<VectorType> map3(array2, size);
MatrixType v3 = VectorType::Random(size);
map3 = v3;
VERIFY_IS_EQUAL(v3, map3);
internal::aligned_delete(array1, (size+1)*(size+1)+1);
}
void test_mapped_matrix()
{
for(int i = 0; i < g_repeat; i++) {
@ -183,5 +205,7 @@ void test_mapped_matrix()
CALL_SUBTEST_8( map_static_methods(RowVector3d()) );
CALL_SUBTEST_9( map_static_methods(VectorXcd(8)) );
CALL_SUBTEST_10( map_static_methods(VectorXf(12)) );
CALL_SUBTEST_11( map_not_aligned_on_scalar<double>() );
}
}