Re: [eigen] Alignment issues (was: Taking advantage of C++11 features in Eigen)

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


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


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