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

Eigen Alignment issue

Tags: None
(comma "," separated)
mustafaf
Registered Member
Posts
4
Karma
0

Eigen Alignment issue

Tue Aug 06, 2013 6:23 pm
Hi, I'm using Eigen 3.1.2 and I am able to build a 64-bit target of my application without any problems. When I build a 32-bit target, I got a lot of "unaligned" asserts. So I followed the workaround by defining EIGEN_MAKE_ALIGNED_OPERATOR_NEW in all my classes, and using Eigen::aligned_allocator for all the STL containers. This seems to have taken care of all the asserts. However, in debug mode, I crash at a certain point. Here is where it crashes:

m_container.resize(N)

This is a resize operation on m_container which is a std::vector<std::vector<std::vector<pFOO> > > (a 3D array of pFOO), where pFOO is a pointer to a FOO object. I'm defining the pointer using a pFOO = std::shared_ptr<FOO>. Also, class FOO has a few Eigen members and I've defined a public EIGEN_MAKE_ALIGNED_OPERATOR_NEW in the class. Will std::shared_ptr<FOO> use the aligned allocator by default? Any reason why it would crash at the resize operation ? What else could I try ?

Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen Alignment issue

Tue Aug 06, 2013 9:40 pm
This is a rather inefficient way to create a 3D structure: std::vector<std::vector<std::vector<pFOO> > >. Better write a small wrapper around a single std::vector<pFOO>. Regarding your issue, please check the backtrace to see where it is really failing. Perhaps std::shared_ptr<FOO> does not use operator new? Does it work if you disable alignment? (-DEIGEN_DONT_ALIGN_STATICALLY)
mustafaf
Registered Member
Posts
4
Karma
0

Re: Eigen Alignment issue

Tue Aug 06, 2013 9:46 pm
The crash happens at std::_Allocate in the following lines:

if (_Count == 0) ;
else if (((size_t)(-1) / sizeof (_Ty) < _Count) || (_Ptr = ::operator new(_Count * sizeof (_Ty))) == 0)
_Xbad_alloc(); // report no memory

It happens at the operator new line. I disabled alignment and it still fails at the same spot. Could you explain what you meant by "writing a small wrapper around std::vector<FOO>" ? Thanks for your time!
mustafaf
Registered Member
Posts
4
Karma
0

Re: Eigen Alignment issue

Wed Aug 07, 2013 5:07 pm
Let me ask a simpler question. Suppose that I have a class FOO which has the EIGEN_MAKE_ALIGNED_OPERATOR_NEW macro declared. In a different class, I am declaring a std::vector<std::vector<std::vector<FOO*> > > and the program crashes during the initial resize operation of this 3d array. What could be wrong? This issue does not exist in 64-bit!!
mustafaf
Registered Member
Posts
4
Karma
0

Re: Eigen Alignment issue

Wed Aug 07, 2013 5:30 pm
Sorry guys, embarrassing to admit but this was a red herring. The crash was related to out of memory issues in 32-bit. Sorry for the bother :S


Bookmarks



Who is online

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