Re: [eigen] How do you link multiple versions (e.g. AVX vs SSE) of the same Eigen code?

[ Thread Index | Date Index | More Archives ]

ah, sorry Christoph, I did not see your reply when replying to Benoit. We are essentially saying the same. To be more concrete we could replace the following two options:



EIGEN_MAX_ALIGN = {0,16,32}


If none of them is defined, then Eigen would automatically define them to the same value depending on the target architecture:

  if x86 but not AVX then 16
  otherwise use the value provided by the respective SIMD layer, currently we have:
     - default = 0
     - SSE*, Altivec, NEON = 16
     - AVX = 32

Recall that those values define maximal bounds. For static allocation, lower values might be used to match the vector/matrix size. Likewise, we could imagine that aligned_malloc automatically reduce alignement requirement if the requested size is lower than the requested alignment. In that case, aligned_free will also need to know the allocated size to use the right strategy.

Internally, we also have to extend the FirstAlignedBit flag to a more general enum allowing to specify the actual alignement 0, 16, 32, etc. This is typically useful for Map.


On Wed, Jan 28, 2015 at 6:03 AM, Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

I thought that we once (informally) agreed on statically aligning to 16 bytes only (also because AVX is a bit more relaxed regarding alignment), but do 32 byte alignment for dynamic objects. Admittedly, that was long time ago before we had a working AVX implementation. Also, I did not yet look much into the details of the current AVX code.

But I agree with Benoit that losing ABI compatibility is severe enough to make 32 byte alignment not the default when compiling for AVX. IMO the best solution would be to define the desired alignment by using an option flag. Then it is still debatable what shall be the default behavior. Requiring 32 byte alignment if the object size is a multiple of 32 can still destroy ABI compatibility, e.g., when having to-be-aligned objects in a struct which requires padding bytes.

Fortunately, so far AVX is only in the devel-branch, so it's not too late to re-discuss any design decisions.


Am 28.01.2015 um 00:30 schrieb Benoit Jacob:

Benoit, Gael, could you confirm that this change is intentional?

   improves perf of certain 4d ops
  - regresses perf of 4f ops, as now Vector4f isn't aligned anymore!!!!
  - breaks long-standing invariant that Eigen ABI is independent of compile


2015-01-27 18:22 GMT-05:00 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:

Ouch... you're right. From Macros.h:

   #if defined(__AVX__)
     #define EIGEN_ALIGN_BYTES 32

2015-01-27 18:19 GMT-05:00 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:

Oh --- I was still living in a world where the Eigen ABI is unaffected by
vectorization, which was the case at least until AVX.

Is alignof(Vector4d) actually 32 with AVX by default? So ABI is now
dependent on compile flags?


2015-01-27 18:17 GMT-05:00 Marc Glisse <marc.glisse@xxxxxxxx>:

On Tue, 27 Jan 2015, Benoit Jacob wrote:

  An approach that works is to #define Eigen EigenAVX, but this is very
annoying because you can't anymore pass around Eigen objects, you have
somehow reinterpret_cast them to EigenAVX objects.

I would expect EigenAVX::Vector4d to have an alignment of 32, and only
16 for EigenSSE::Vector4d (I did not check), which would mean they really
are different types and you cannot pass the second one to a function
expecting the first. So I am not sure how you intend to "pass around Eigen

Marc Glisse

Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252

Mail converted by MHonArc 2.6.19+