I am building an application with ETL and Eigen. The actual application is of course more complex, but this representative example shows that using list_ext and generic_pool together causes memory to be allocated in places that do not conform with the requested memory alignment.
As you can see, neither of those pointers are 32 byte aligned.
The reason the byte alignment is important in this case is because of Eigen's optimizations for vector arithmetic:
A Eigen::Vector4d consists of 4 doubles, which is 256 bits. This is exactly the size of an AVX register, which makes it possible to use AVX for all sorts of operations on this vector. But AVX instructions (at least the ones that Eigen uses, which are the fast ones) require 256-bit alignment. Otherwise you get a segmentation fault.
For this reason, Eigen takes care by itself to require 256-bit alignment for Eigen::Vector4d, by doing two things:\
Eigen requires 256-bit alignment for the Eigen::Vector4d's array (of 4 doubles). With [c++11] this is done with the [alignas] keyword, or compiler's extensions for c++98/03.
Eigen overloads the operator new of Eigen::Vector4d so it will always return 256-bit aligned pointers. (removed in [c++17])
I'm a bit unsure on how to debug this issue myself further, but I have a feeling it might have to do with this function:
I am building an application with ETL and Eigen. The actual application is of course more complex, but this representative example shows that using
list_ext
andgeneric_pool
together causes memory to be allocated in places that do not conform with the requested memory alignment.Running this code, I get the following output:
The first line is printed from this line I added to
ilist::emplace_back
:As you can see, neither of those pointers are 32 byte aligned.
The reason the byte alignment is important in this case is because of Eigen's optimizations for vector arithmetic:
I'm a bit unsure on how to debug this issue myself further, but I have a feeling it might have to do with this function:
I'm not sure if the subclass routine is called or the parent class routine is called, and whether this affects whether alignment is respected or not.
Thanks for the help and the useful library!