Reply to topic

Crash while using Map

eranb
Registered Member
Posts
6
Karma
0

Crash while using Map

Tue Nov 12, 2013 8:06 am
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)
User avatar ggael
Moderator
Posts
2195
Karma
15
OS

Re: Crash while using Map

Tue Nov 12, 2013 10:57 pm
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.
eranb
Registered Member
Posts
6
Karma
0

Re: Crash while using Map

Thu Nov 14, 2013 8:55 am
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?
User avatar ggael
Moderator
Posts
2195
Karma
15
OS

Re: Crash while using Map

Thu Nov 14, 2013 2:33 pm
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.
eranb
Registered Member
Posts
6
Karma
0

Re: Crash while using Map

Sun Nov 17, 2013 9:14 am
Yep, it's working...
changed arch\SSE\PacketMath.h in packet_traits<double> to:
Code: Select all
#if defined(_WIN32) && !defined(_M_X64)
 AlignedOnScalar = 0 ,
#else
 AlignedOnScalar = 1 ,
#endif


In the future, when compilers will implement alignof() as within the c++11 spec., the definition can be :
Code: Select all
 AlignedOnScalar = alignof(double)<sizeof(double)?0:1 ,

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 !
User avatar ggael
Moderator
Posts
2195
Karma
15
OS

Re: Crash while using Map

Mon Nov 18, 2013 10:35 am
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?
eranb
Registered Member
Posts
6
Karma
0

Re: Crash while using Map

Tue Nov 19, 2013 9:06 am
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

 
Reply to topic

Bookmarks



Who is online

Registered users: atrox, Baidu [Spider], bcooksley, Bing [Bot], bshah, Exabot [Bot], garthecho, Google [Bot], ingwa, ken300, koriun, Majestic-12 [Bot], normcross, ooker, pholmes, TheraHedwig, vascobasque, Yahoo [Bot]