Re: [eigen] Map alignedStart issue |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Hi Gael,I run valgrind, and the only error that occurs is the invalid write that causes segfault. (see valgrind log below).
I tryed to investigate more with gdb and see what happens when calling setZero. The problem seems located between Eigen/src/core/Assign.h:414 and Eigen/src/Core/util/Memory.h:412
The "size" parameter which is passed to the "first_aligned" function is converted or casted during function call. It equals 12 in Eigen/src/core/Assign.h:414, and -1075916728 in Eigen/src/Core/util/Memory.h:412.
This big negative value is always selected by the std::min function and so first_aligned returns an incorrect index.
Does anyone have an idea ? thanks in advance ++ benoit --------------------------- ==909== Memcheck, a memory error detector. ==909== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al. ==909== Using LibVEX rev 1854, a library for dynamic binary translation. ==909== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.==909== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation framework.
==909== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al. ==909== For more details, rerun with: -v ==909== ==909== My PID = 909, parent PID = 606. Prog and args are: ==909== yaafe-engine ==909== -c ==909== yaflow ==909== test_small_mono.wav ==909== ==909== Invalid write of size 8==909== at 0x4CF09A0: void Eigen::internal::pstore<double, __vector double>(double*, __vector double const&) (emmintrin.h:150) ==909== by 0x4CF1705: void Eigen::internal::pstoret<double, __vector double, 1>(double*, __vector double const&) (GenericPacketMath.h:280) ==909== by 0x4CF713F: void Eigen::MapBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1>::writePacket<1>(int, __vector double const&) (MapBase.h:235) ==909== by 0x4D090A4: void Eigen::DenseCoeffsBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1>::copyPacket<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >, 1, 0>(int, Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > > const&) (DenseCoeffsBase.h:541) ==909== by 0x4D09168: Eigen::internal::assign_impl<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >, 3, 0>::run(Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >&, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > const&) (Assign.h:422) ==909== by 0x4D09259: Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >& Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::lazyAssign<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > >(Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > > const&) (Assign.h:511) ==909== by 0x4D092CB: Eigen::internal::assign_selector<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >, false, false>::run(Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >&, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > const&) (Assign.h:534) ==909== by 0x4D0931B: Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >& Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::operator=<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > >(Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > > const&) (Assign.h:555) ==909== by 0x4D09396: Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::setConstant(double const&) (CwiseNullaryOp.h:341) ==909== by 0x4D093D6: Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::setZero() (CwiseNullaryOp.h:490) ==909== by 0x4D03C89: YAAFE_EXT::Chroma2ChordDict::Dict::fillPattern(std::vector<int, std::allocator<int> > const&, int, double*) (Chroma2ChordDict.cpp:96) ==909== by 0x4D0407E: YAAFE_EXT::Chroma2ChordDict::Dict::populate(std::string const&, int) (Chroma2ChordDict.cpp:75)
==909== Address 0xfd1cca30 is not stack'd, malloc'd or (recently) free'd ==909== ==909== Process terminating with default action of signal 11 (SIGSEGV) ==909== Access not within mapped region at address 0xFD1CCA38==909== at 0x4CF09A0: void Eigen::internal::pstore<double, __vector double>(double*, __vector double const&) (emmintrin.h:150) ==909== by 0x4CF1705: void Eigen::internal::pstoret<double, __vector double, 1>(double*, __vector double const&) (GenericPacketMath.h:280) ==909== by 0x4CF713F: void Eigen::MapBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1>::writePacket<1>(int, __vector double const&) (MapBase.h:235) ==909== by 0x4D090A4: void Eigen::DenseCoeffsBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1>::copyPacket<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >, 1, 0>(int, Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > > const&) (DenseCoeffsBase.h:541) ==909== by 0x4D09168: Eigen::internal::assign_impl<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >, 3, 0>::run(Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >&, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > const&) (Assign.h:422) ==909== by 0x4D09259: Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >& Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::lazyAssign<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > >(Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > > const&) (Assign.h:511) ==909== by 0x4D092CB: Eigen::internal::assign_selector<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >, false, false>::run(Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >&, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > const&) (Assign.h:534) ==909== by 0x4D0931B: Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >& Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::operator=<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > >(Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > > > const&) (Assign.h:555) ==909== by 0x4D09396: Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::setConstant(double const&) (CwiseNullaryOp.h:341) ==909== by 0x4D093D6: Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::setZero() (CwiseNullaryOp.h:490) ==909== by 0x4D03C89: YAAFE_EXT::Chroma2ChordDict::Dict::fillPattern(std::vector<int, std::allocator<int> > const&, int, double*) (Chroma2ChordDict.cpp:96) ==909== by 0x4D0407E: YAAFE_EXT::Chroma2ChordDict::Dict::populate(std::string const&, int) (Chroma2ChordDict.cpp:75)
==909== ==909== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 87 from 2) ==909== malloc/free: in use at exit: 2,473,055 bytes in 1,372 blocks.==909== malloc/free: 100,026 allocs, 98,654 frees, 181,553,718 bytes allocated.
==909== For counts of detected errors, rerun with: -v ==909== searching for pointers to 1,372 not-freed blocks. ==909== checked 2,460,860 bytes. ==909== ==909== LEAK SUMMARY: ==909== definitely lost: 0 bytes in 0 blocks. ==909== possibly lost: 1,544 bytes in 77 blocks. ==909== still reachable: 2,471,511 bytes in 1,295 blocks. ==909== suppressed: 0 bytes in 0 blocks. ==909== Rerun with --leak-check=full to see details of leaked memory. On 01/26/11 22:33, Gael Guennebaud wrote:
Hi I'd suggest you to run your code under valgrind. Under linux simply do: $ valgrind ./your_exec this will detect bad reads and writes and many other stuffs. gael On Wed, Jan 26, 2011 at 7:23 PM, Benoit Mathieu <benoit.mathieu@xxxxxxxxxxxxxxxxxxxx> wrote:Hi all, I get a strange bug in my application that I cannot reproduce in a small test case. Somewhere in my code I have: void myfunction(double* pattern) { Map<ArrayXd> pVec(pattern,12); pVec.setZero(); // ... } The problem is that when SSE2 is enabled, I get a segfault on the setZero() call. (If I don't activate sse2, no problems). The double* pattern pointer is NOT necessarily aligned. Please find the backtrace at the end of this message. The problem seems that Eigen start finding the first aligned index where to start vectorization, and it get -1075572760. Accessing this index causes the segfault. As I said, I cannot reproduce this bug in a small test case, so it may comes from a mistake in my code, but I have no idea where to look at. If I avoid the setZero call with a basic for loop, the same kind of problem appear later in a pVec.sum() call. I'm using the last version of eigen in the development branch, gcc 4.3.2 on debian with -msse2 -mstackrealign flags. Is anybody have an idea of what happen ? or where to look ? Any help is appreciated. ++ Benoit ---------------------------- (gdb) bt #0 0xb53869a0 in Eigen::internal::pstore<double, double __vector> ( to=0x8c52df0, from=@0xbfe40df0) at /usr/lib/gcc/i486-linux-gnu/4.3.2/include/emmintrin.h:150 #1 0xb5387706 in Eigen::internal::pstoret<double, double __vector, 1> ( to=0x8c52df0, from=@0xbfe40df0) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/GenericPacketMath.h:280 #2 0xb538d140 in Eigen::MapBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1>::writePacket<1> (this=0xbfe40fe8, index=-1075572760, x=@0xbfe40df0) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/MapBase.h:235 #3 0xb539f0a5 in Eigen::DenseCoeffsBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1>::copyPacket<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 1, 0> (this=0xbfe40fe8,index=-1075572760, other=@0xbfe40f38) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/DenseCoeffsBase.h:541 #4 0xb539f169 in Eigen::internal::assign_impl<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, 3, 0>::run (dst=@0xbfe40fe8, src=@0xbfe40f38)at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/Assign.h:422 #5 0xb539f25a in Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >::lazyAssign<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>,Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >(this=0xbfe40fe8, other=@0xbfe40f38)at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/Assign.h:511 #6 0xb539f2cc in Eigen::internal::assign_selector<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >, false, false>::run (dst=@0xbfe40fe8,other=@0xbfe40f38) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/Assign.h:534 #7 0xb539f31c in Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> >::operator=<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>,Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >(this=0xbfe40fe8, other=@0xbfe40f38)at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/Assign.h:555 #8 0xb539f397 in Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::setConstant (this=0xbfe40fe8, value=@0xbfe40f88) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/CwiseNullaryOp.h:341 #9 0xb539f3d7 in Eigen::DenseBase<Eigen::Map<Eigen::Array<double, -1, 1, 0, -1, 1>, 0, Eigen::Stride<0, 0> > >::setZero (this=0x8c52df0) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/externals/eigen/Eigen/src/Core/CwiseNullaryOp.h:490 #10 0xb5399c8a in YAAFE_EXT::Chroma2ChordDict::Dict::fillPattern ( this=0x9a44250, notes=@0x9a4c310, nbHarmo=1, pattern=0x9a4aeb0) at /amd/asansol.enst.fr/home/bmathieu/data/workspace/yaafe-extension/tp-yaafe-extension/components/Chroma2ChordDict.cpp:96
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |