stack-of-tasks / pinocchio

A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
http://stack-of-tasks.github.io/pinocchio/
BSD 2-Clause "Simplified" License
1.7k stars 366 forks source link

Memory alignment issue when instantiating Data with AVX2 #2234

Closed duburcqa closed 2 months ago

duburcqa commented 2 months ago

Bug description

Python is crashing when instantiating a Data from Python when pinocchio has been compiled in Debug with AVX2 instruction set enabled.

It is only occurring at Python-side. I have no issue when running a C++ executable that has been compiled with the exact same flags. It also works fine when calling pin.Model().createData() in place of pin.Data(). So it means to be related to some eigenpy memory alignment issue. It is not systematically crashing the first time I try to create Data, sometimes it takes 2 or 3 trials.

I already observed this issue I will ago, and I just decided to ignore it at that time because it was not blocking me. It is still not blocking me but it would be nice if it could be fixed, mainly because I don't understandard what is happening, and I don't like it.

Reproduction steps

First, compile eigenpy and pinocchio with flags BUILD_TYPE="Debug" and CMAKE_CXX_FLAGS="-march=x86-64-v3 -mtune=generic".

Code

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.10.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import pinocchio as pin

In [2]: pin.Data()
Out[2]: <pinocchio.pinocchio_pywrap.Data at 0x7f2370a0f150>

In [3]: pin.Data()
python3: /home/duburcqa/workspace/src/jiminy_2/install/include/eigen3/Eigen/src/Core/DenseStorage.h:128: Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; in
t Size = 36; int MatrixOrArrayOptions = 0]: Assertion `(internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily
.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.
Aborted (core dumped)

System

jcarpent commented 2 months ago

It should be fixed in Pinocchio 3, coming soon.

duburcqa commented 2 months ago

Any chance this could be backported ? I could take care of it eventually if I could understand the issue.

ManifoldFR commented 2 months ago

What is your version of Boost?

duburcqa commented 2 months ago

boost-1.76.0

ManifoldFR commented 2 months ago

Hmm, I'm not sure whether that version works. From what I recall this is Boost.Python + Eigen issue that got patched by Justin a year or so ago in eigenpy.

Last I checked 1.74 and 1.75 still crap out with AVX2 but 1.78 and above work for all versions of eigenpy post-fix.

duburcqa commented 2 months ago

OK I can confirm this. The precompiled version of pinocchio available on robotpkg it is using some boost version older than 1.78.0 as far as I know. Would it be possible to update it in order to maintain consistency with what is considered supported now ?

ManifoldFR commented 2 months ago

I don't know about robotpkg, sorry :/

duburcqa commented 2 months ago

I can confirm that using boost 1.78 is fixing the issue. Thank you for the hint !

duburcqa commented 2 months ago

Currently I am bit stuck on 1.76 because I want to maintain compatibility with robotpkg though... but at least it is good to know that the issue will vanish at some point.

ManifoldFR commented 2 months ago

Yes, this has also been a huge problem for us when using Ros noetic unfortunately...

duburcqa commented 2 months ago

For the record, I can confirm the fix was introduced with boost 1.78.0. https://github.com/boostorg/python/pull/360 is the corresponding PR. Ubuntu 24.04 ships with boost 1.83 but we are out of luck for older releases, even 23.10 surprisingly is shipping with a version released in 2020.

duburcqa commented 2 months ago

I guess we can close this issue since nothing can be done about it except waiting for boost<1.78 to disappear. Thank you again !

nim65s commented 2 months ago

@duburcqa : robotpkg just use the version from your OS, so upgrading your OS will upgrade boost

duburcqa commented 2 months ago

Yes, I figured this out when trying to understand from where it was getting the boost version. That is why I mentioned that it will be fine for Ubuntu 24.04, but we are out of luck for older Ubuntu releases...