Re: [eigen] Alignment issues (was: Taking advantage of C++11 features in Eigen) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Alignment issues (was: Taking advantage of C++11 features in Eigen)
- From: Nicola Gigante <nicola.gigante@xxxxxxxxx>
- Date: Thu, 13 Feb 2014 14:42:52 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=eDk++tayQWOFfZefgt7u85fhDLC7JeXiiiPhAzHP7pw=; b=KqsIT2BZ1OVo8NSllKDt9f85HH8tTxQuDOkUkOsnzydgqqx6lhBonIUBvIHBYRfWTt Y50hMK8mn4wVWzTQOXNbhe86RTMDkLeBgAvO8J6rNxQW6IMy9+gbKZOWYcc+BYjOtFFM 03BUxbFtVelOwfap55VleJJrROHIhhCihAqM20n9vUwIJZ9vEGHGHR8bhet+eWjnbp5I hedqep4I5Da1kKaKvBT2io2gPx0/oNWJ21jWIoJz7CTIApglc1oOyjacaeHS/6oCHLkf ztY2K4dNjqjo26Npii+rrqPqFYacnaMny3uaCurxXyLELRZGNqvOMcwcFT4VGw9Wl//Y aFGw==
Il giorno 13/feb/2014, alle ore 10:25, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> ha scritto:
> Hi,
>
> I'm not a C++11 expert but let chime in.
>
> I agree with Nicola that the case of the Tensor module and adding C++11 support are very different.
>
> In the former case, we have en entire module that makes use of C++11 features without any fallback to C++03. From the user point of view, the use of C++11 is completely transparent, so it is important make it clear it requires C++11. Here we are talking about adding more compatibility/support for key C++11 features. I think such additions can be silently enabled if the following criteria are met:
> - it does not introduce a new feature, it must strictly be about C++11 compatibility.
> - it does not change the performance of Eigen itself.
> - it has a favorable code maintenance cost versus user benefits ratio.
>
Of course
> This is clearly the case of move semantics (as long as Eigen does not make use of it itself), static assertions, support for C++11 functors, or support for C++11 allocator.
>
> The support for simple initializer lists (i.e., with scalar values only) is certainly fine too. For more sophisticated initializer lists, then we cannot know the code overhead without trying it.
>
I think I’ll try and we’ll see what happens :)
> Regarding alignment, I'm afraid the C++11 alignas does not bring any improvement since, AFAIK the practical difficulties are the same as with the respective compiler extensions (http://eigen.tuxfamily.org/dox/group__DenseMatrixManipulation__Alignement..html)
>
Maybe I’m missing something. I don’t know precisely the semantics of the gcc attribute, but why doesn’t your current technique work?
i.e. attaching the aligned(16) attribute to the data member of internal::plain_array and let the compiler do the rest.
class plain_array {
alignas(16) char data[42];
};
class vector {
plain_array a;
};
int main()
{
std::cout << alignof(vector) << "\n";
return 0;
}
With the latest clang this piece of code prints “16” as expected (instead of 1 without the attribute). Then, in theory, default operator new (and all the rest of the language, by the way), should obey that, in the same way that it works for other default alignment requirements…
In fact, code that you warn the user about in the documentation seems to actually work in the same way:
class B {
char c;
Vector4f a;
};
int main()
{
std::cout << alignof(B) << "\n";
return 0;
}
Here it correctly prints “16” again, and if you compile with -Wpadded you get the warning "Padding class 'B' with 15 bytes to align ‘a’"
so alignment requirements are correct, and again operator new should obey them.
So, besides C++11, it’s not clear in which cases you’re suggesting that this doesn’t work and especially why. AFAIK this
is the intended meaning of these attributes, so if it’s a matter of bugs of specific compilers out there (or older versions), simply let me know.
> cheers,
> gael
>
Greetings,
Nicola