Registered Member
|
I have a problem, using Map of unaligned doubles (x86 compilation, x64 machine, windows7, visual studio 2013) :
The crash is happening in Assign.h line 465, when it's trying to copy the second line of the matrix. When the first loop iteration is being run (copying the first line of the matrix), the alignedStart value is 10, so nothing is vectorized, which is right. But, at the end of the for loop (line 471) the value of alignedStart for the next iteration is being evaluated, alignedStep value is 0 so (alignedStart+alignedStep)&packetSize = (10-0)%2 = 0, and alignedStart of the 2nd line becomes 0, which is wrong. so at the second iteration (copying the 2nd line of the matrix), it's trying to vectorize the copy using aligned opcodes, and crashes. The computation of 2nd alignedStart seems to be wrong. There will be no aligned elements in the whole matrix. Is it a bug ? Note : This happened in my code when a variable on the stack was not aligned to 8 bytes but to 4, this example enforces that situation. |
Moderator
|
This is surprising because Windows impose double to be aligned on a 64 bits boundary, even for 32 bits windows. Therefore, Eigen also assumes that double are aligned a 64 bits boundary on that platform. Looks like your stack has been corrupted.
|
Moderator
|
for the record, a possible workaround would be:
but again, I'm surprised that such a situation occur. |
Registered Member
|
Well... I'm compiling this code (Windows 7_64bit, Visual Studio 2013, compiled for x86 , Debug, created from default console application) :
Running gives "not aligned", sometimes (~20%). This stack cannot be corrupted... Tried in 3 different computers in our company... |
Registered Member
|
From MSDN :
https://msdn.microsoft.com/en-us/library/aa290049%28v=vs.71%29.aspx Well, according to my example the compiler can improve the heuristic... It seems that the compiler may fail to align doubles even with very simple cases. Anyway, Eigen cannot assume that every double is aligned in windows platforms (with visual studio) - sometimes (that are not so rare) the heuristic fails, and doubles are not aligned. |
Moderator
|
What puzzle me is that you are the first one hitting this issue while there are several hundreds of Eigen users on windows. Could you try to run the unit tests? Here is what I use on windows:
this might take about 2 hours. |
Registered Member
|
Iv'e checked the tests. No test checks mapping a double variable on the stack with outer stride, that should use packed elements.
The next small test will crash in x86, debug (when the output is "4", about 20% of the runs) : void foo() { typedef Matrix<double, Dynamic, Dynamic, RowMajor> MatrixType; typedef Map<MatrixType, Unaligned, OuterStride<> > MapType; const int rows(5), cols(5), stride(6); double arrayUnaligned[cols*stride]; std::cout<< (int)arrayUnaligned % 8 << std::endl; MapType map(arrayUnaligned,rows,cols,OuterStride<>(stride)); map *= 2.0; } |
Moderator
|
OuterStride is tested in mapstride.cpp unit test, however, I agree that stack allocated buffers were not tested. Fixed:
https://bitbucket.org/eigen/eigen/commits/dcd97d2510ef/ https://bitbucket.org/eigen/eigen/commits/1990c04fc972/ |
Moderator
|
Let's continue there: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1003
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]