This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Alignment bug in ICC and VC2008 (debug mode)

Tags: None
(comma "," separated)
cfp
Registered Member
Posts
12
Karma
0
I was getting repeated "access violation reading 0x0000000000000000", but when I checked it was clear it wasn't actually trying to read 0 at all. Instead it seems like a MOVAPS instruction isn't getting aligned properly.

See the following disassembly:

Code: Select all
template<> EIGEN_STRONG_INLINE Packet4f ei_pload<float>(const float*    from) { return _mm_load_ps(from); }
000000013FF2E4A0  push        rbp 
000000013FF2E4A1  sub         rsp,20h
000000013FF2E4A5  lea         rbp,[rsp+20h]
000000013FF2E4AA  mov         qword ptr [rsp],rax
000000013FF2E4AE  mov         rax,8
000000013FF2E4B5  mov         dword ptr [rsp+rax],0CCCCCCCCh
000000013FF2E4BC  add         rax,4
000000013FF2E4C0  cmp         rax,20h
000000013FF2E4C4  jne         Eigen::ei_pload+15h (13FF2E4B5h)
000000013FF2E4C6  mov         rax,qword ptr [rsp]
000000013FF2E4CA  mov         dword ptr [rsp],0CCCCCCCCh
000000013FF2E4D1  mov         dword ptr [rsp+4],0CCCCCCCCh
000000013FF2E4D9  mov         qword ptr [from],rcx
000000013FF2E4DD  mov         rax,qword ptr [from]
000000013FF2E4E1  movaps      xmm0,xmmword ptr [rax]
000000013FF2E4E4  lea         rsp,[rbp]
000000013FF2E4E8  pop         rbp 
000000013FF2E4E9  ret             


The error is always on the movaps instruction, which I believe needs a 16 byte aligned pointer. However, rax = 0x00000000001B9FD8.

I'm using the latest eigen from Mercurial.

Am I doing something stupid, or is this a bug?

Thanks,

Tom
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Have you tried your program in debug mode ? if not please do, and you will likely get this assertion:
[...] && "this assertion is explained here: http://eigen.tuxfamily.org/dox/Unaligne ... ssert.html
READ THIS WEB PAGE !!! ****"' failed.

So please have a look at this page:
http://eigen.tuxfamily.org/api/Unaligne ... ssert.html

If you still have this problem, then get back to us with more details (e.g., the piece of your responsible for that crash)
cfp
Registered Member
Posts
12
Karma
0
That was in debug mode. And there was no assert triggered. (And I checked that ei_assert is indeed getting defined.)

The line triggering the error is:
Code: Select all
lmfKalmanGain = ( lmfObservationBlock.transpose( ) * lmfEstimatedCovarianceSubBlock * lmfObservationBlock + lmfObservationCovariance ).inverse( ) * lmfObservationBlock.transpose( ) * lmfKalmanGain;


where the types are as follows:

Code: Select all
Matrix4f lmfEstimatedCovarianceSubBlock;
MatrixXf lmfKalmanGain( 4, skunNumStates );
Matrix< float, 4, 2 > lmfObservationBlock;
Matrix2f lmfObservationCovariance;


They're all local variables (not array members or anything). And I get the same error with both ICC and VC2008.
cfp
Registered Member
Posts
12
Karma
0
Interestingly, if I rewrite the line as:

Code: Select all
Matrix< float, 2, 4 > lmfTemp = ( lmfObservationBlock.transpose( ) * lmfEstimatedCovarianceSubBlock * lmfObservationBlock + lmfObservationCovariance ).inverse( ) * lmfObservationBlock.transpose( );

lmfKalmanGain = lmfTemp * lmfKalmanGain;


then it works fine.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
indeed, a hit a very bad bug in Eigen.

a simpler code to reproduce it is:

Code: Select all
MatrixXf lmfKalmanGain( 4, skunNumStates );
Matrix< float, 2, 4 > lmfTemp;

lmfKalmanGain = lmfTemp * lmfKalmanGain;


I'll see what I can do when I'll have time...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm... actually the problem is that you have:

A = B * A;

where the size of B*A is different that A, and so Eigen first resize A, and then evaluate B * A into a temporary object T, and then does A = T. So actually we have to find a way to delay the resizing that might not be so trivial to implement...
cfp
Registered Member
Posts
12
Karma
0
Ahha. Strangely I do get an assert (on the assignment) from the following very similar code:

Code: Select all
MatrixXf lmfPH( skunNumStates, 4 );
lmfPH *= lmfObservationBlock;


where again:

Code: Select all
Matrix< float, 4, 2 > lmfObservationBlock;


(which again should work fine in theory).
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
problem fixed in both the devel and stable branches

(not tested with MSVC yet)
cfp
Registered Member
Posts
12
Karma
0
Great thanks. Will test it when I get the chance.
FMD
Registered Member
Posts
25
Karma
0
FYI: I've tested your fix (Rev 1271, default) by cdash testbatch in my MSVC-setup:
Some Warning, no Errors, every test successfull.
Thank you very much!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]