tesseract-robotics / tesseract

Motion Planning Environment
http://tesseract-docs.rtfd.io
Other
259 stars 89 forks source link

Why are AVX instructions disabled? #983

Closed rjoomen closed 7 months ago

rjoomen commented 7 months ago

On my Intel Skylake CPU, which has AVX instructions, the option -mno-avx is passed to the compiler, why?

BTW, the result of uname -p is x86_64, but that's not enough information to determine AVX support.

rjoomen commented 7 months ago

Ah, wait, I see: "Add -mno-avx as compile option to fix Eigen Alignment Issues".

Building with AVX first led to Eigen issues when interfacing with KDL (in calcInvKinHelper), as KDL is built without AVX. After solving this with a workaround, Boost serialization produces Eigen issues, after which I gave up.

Levi-Armstrong commented 7 months ago

Yea, we struggled with a lot and eventually just disabled it. If they would ever update the system version of Eigen to the latest this alignment issue should no longer exist.

rjoomen commented 7 months ago

Unfortunately, updating system Eigen is not the solution. I tested this on Jammy, which has Eigen 3.4.0 (i.e. latest). Problems arise when Tesseract is compiled with AVX, but interfaces through Eigen data types with for example system KDL, which is built without AVX. One specific example is this line, where a VectorXd is transferred from Tesseract (AVX-aligned) to KDL (not AVX-aligned). When exiting calcInvKinHelper() this results in a 'double free or corruption' segfault. For an explanation, see here.

An ugly work-around for this specific case was to resize kdl_seed and assign element-wise, i.e. kdl_seed.data[i] = seed[i] in a for loop. But then I ran into Eigen-related issues with Boost serialization and gave up.

Levi-Armstrong commented 7 months ago

Yea, it looks like there is still some edge case which overloading the new operator does not handle. We would have to do as you suggested to address these.