Re: [eigen] STL Vectors and Alignment |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: Re: [eigen] STL Vectors and Alignment*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Wed, 26 Nov 2014 22:43:27 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=WTYWKtymFNf4e8QlOl7gisma0VjB72eCiD1DmDDlYr8=; b=Tl+WbmW/KjCfMTDzEN6rRFcK5Et3q5Uxa+Exe4zvU8UjLGyDGrljs+py/7zgf2OcAk lpCOgAxCEvZ5XlA7YXguBWEMUX6VjqNlkIaxQ//1ewJ2dntEZCgo3FUpa7lyYRE5+SS0 4qMXeYF5yBLMtH6CmtmvIcgTZmOQUPwzY5uqnrlWxDoEZ/vOeFEEFehZn7QpB6FlHmcj nFSANV/XPNHQWnluiGBK8ibTh1JvK1WNs+cbvtZ0jxIjf2IN+BMLS9AQjYASh0OuClxi R11Ab1WoS8dTCorTquuoh9bt6jmArqWNep+IF17ihUwfEtWy8wRSj+NiOw2t4HRlAa9o lZYQ==

On Wed, Nov 26, 2014 at 10:12 PM, Gabriel <gnuetzi@xxxxxxxxx> wrote:

These examples and answers should actually go into the Documentation, that would help a lot for inexperienced users :-) :-)

Documentations are best written by users, so feel free to compile them in the respective .dox file and propose us a patch ;)

cheers,

gael

Thanks for the help!!

On 11/26/2014 09:40 PM, Christoph Hertzberg wrote:

On 26.11.2014 17:39, Gabriel wrote:

Thanks for the answer!

Sorry again for my unclear phrasing!

Just to be absolutely sure:

Lets say we have:

struct A{

Eigen::Vector2d t;

};

If we use A locally:

A a;

a.t

is a.t aligned on the Stack, (how does alignment work on the stack)

Yes, that is aligned on the stack. Also, if you wrote, e.g.

struct A{

char dummy; // compiler will add filling bytes after this

Eigen::Vector2d t;

};

a.t will be aligned on the stack.

The data member of Vector2d has a compiler attribute which tells it to always have it aligned.

If we use A on the heap:

A * a = new A;

then as "a" is not aligned , also a.t is not aligned

It is not guaranteed to be aligned. It is, however, aligned on most (all?) 64bit systems.

If we use EIGEN_MAKE_ALLOCATOR_NEW inside A , then "a" is aligned , and

Yes.

BUT what happens in this example:

struct B{

A a;

};

struct C{

B b;

};

std::vector< C , Eigen::aligned_allocator<C> > vec(1);

Is vec[0].b.a.t now aligned in memory? which does *NOT*

result in a segfault if Eigen uses SIMD internally?

Yes.

If we use locally lets say:

C c;

c.b.a.t do something with t

is c.b.a.t aligned on the Stack?

Yes.

Or on the heap:

C * c = new C;

c might not be aligned => c.b might not be aligned => c.b.a => might

not bealigned => c.b.a.t might not be aligned => SEGFAULT for usage of

c.b.a.t

Correct. c is not guaranteed to be aligned (except on most 64 bit systems ....)

How do I need to correct the above example such that in the cases above,

vector A::t is always aligned to 16bytes?

To make the only not yet working case work, you need to add an

EIGEN_MAKE_ALIGNED_OPERATOR_NEW

into struct C. It would not hurt to add it into A and B, as well.

Christoph

**References**:**[eigen] Block sparse matrices and std vector compilation error***From:*Hilario Tomé

**[eigen] STL Vectors and Alignment***From:*Gabriel

**[eigen] STL Vectors and Alignment***From:*Gabriel

**Re: [eigen] STL Vectors and Alignment***From:*Christoph Hertzberg

**Re: [eigen] STL Vectors and Alignment***From:*Gabriel

**Re: [eigen] STL Vectors and Alignment***From:*Christoph Hertzberg

**Re: [eigen] STL Vectors and Alignment***From:*Gabriel

**Re: [eigen] STL Vectors and Alignment***From:*Christoph Hertzberg

**Re: [eigen] STL Vectors and Alignment***From:*Gabriel

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] STL Vectors and Alignment** - Next by Date:
**Re: [eigen] Block sparse matrices and std vector compilation error** - Previous by thread:
**Re: [eigen] STL Vectors and Alignment** - Next by thread:
**Re: [eigen] STL Vectors and Alignment**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |