Registered Member
|
The following code crashes sometimes(!) :
const int N = 9; double d[N]; double s = 2.0; for (int n=0;n<N;++n) d[n]=1.0; Map<Matrix<double,Dynamic,Dynamic,RowMajor>,Unaligned,OuterStride<> > map(d,3,3,OuterStride<>(3)); map *= s; why ?? (the crash in somewhere in PacketMath.h) |
Moderator
|
cannot reproduce. Could you provide the backtrace and also check your program with valgrind to see if the problem does not come from another part of the program.
|
Registered Member
|
Tnx for the reply.
I've further investigated the issue, and found the problem: Well, i'm using MSVC2012, on x86, according to : http://msdn.microsoft.com/en-us/library ... 49(v=vs.71).aspx the stack on x86/windows is aligned to 4 bytes only. My crash happened when the pointer-to-double (the d buffer) was not aligned to 8 bytes but to 4. The loop in Assign.h (line 456, run method) assume that even if the object is "unaligned" - it's still aligned to itself size, i.e 8 bytes in my double case, So it try to call the copyPacket method on unaligned data (mm_load_pd) and crash (when the first double is not aligned to 8 bytes - no element in the array will be aligned to 16 bytes...). Because the default in MSVC x86 is non aligned stack, and Eigen::Map may be used for external buffers, i think this situation should be treated inside eigen. Doesn't it? |
Moderator
|
hm, ok so the fix would be to set PacketTraits<double>::AlignedOnScalar to false on windows 32bits. It is strange that we never hit this issue. Our test platforms do include 32bits windows.
|
Registered Member
|
Yep, it's working...
changed arch\SSE\PacketMath.h in packet_traits<double> to:
In the future, when compilers will implement alignof() as within the c++11 spec., the definition can be :
but in the current microsoft's __alignof() implementation, __alignof(double)=8 although when a double is on the stack it may not be aligned to 8bytes. (Maybe that's the reason microsoft didn't renamed the __alignof operator to spec's alignof). Thanks ! |
Moderator
|
hm, that's strange that __alignof(double) returns 8. How are you calling the function that produces the crash? Through a pointer function? Through multi-threading?
|
Registered Member
|
It was a simple main().
About __alignof, I've asked it in stackoverflow forum, and didn't get a complete answer : http://stackoverflow.com/questions/20001135/alignofdouble-in-msvc-win32 |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]