bayes-filters-lib icon indicating copy to clipboard operation
bayes-filters-lib copied to clipboard

Fixed-size vectorizable Eigen matrices in WhiteNoiseAcceleration

Open travek opened this issue 6 years ago • 13 comments

Hi!

I'm using MS VS 2015. I compiled example from test_UKF and started running it. On the following line of code from example file: std::unique_ptr<AdditiveStateModel> wna = utils::make_unique<WhiteNoiseAcceleration>(T, tilde_q); I got assert error (from Eigen DenseStorage):

EIGEN_DEVICE_FUNC
plain_array() 
{ 
  EIGEN_MAKE_UNALIGNED_ARRAY_ASSERT(15);
  check_static_allocation_size<T,Size>();
}

Could you advice how to fix example code quickly?

travek avatar May 10 '19 13:05 travek

Hi @travek! Are you compiling 32 or 64 bit?

claudiofantacci avatar May 10 '19 13:05 claudiofantacci

I tried x86 in MS VS

travek avatar May 10 '19 14:05 travek

Can you by chance try to compile it for x64 and let us know? Thanks!

claudiofantacci avatar May 10 '19 18:05 claudiofantacci

@claudiofantacci It works when compiling in x64. Thanks!

Is it possible to have Eigen works correctly in x86 ? Do you know what needs to be changed ?

travek avatar May 11 '19 05:05 travek

@claudiofantacci I tried with preprocessing options, it works with x86, too Thanks

travek avatar May 11 '19 06:05 travek

Hi travek, do you mind giving us details of your findings to have the code compiled under x86? This could be useful to other users as well! Anyway, I’ll add to our pipeline this issue.

claudiofantacci avatar May 11 '19 08:05 claudiofantacci

I compile with this preprocessing definitions: EIGEN_DONT_ALIGN_STATICALLY EIGEN_DONT_VECTORIZE EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT

travek avatar May 11 '19 11:05 travek

A small note: if I am not wrong, compiling a library that uses Eigen classes in its public interfaces changes the ABI of the Eigen classes, that means that it may create run-time crashes if the library is used/linked in a compilation unit that uses Eigen and is not compiled with that options.

traversaro avatar May 11 '19 16:05 traversaro

@traversaro Recommendation is taken from https://eigen.tuxfamily.org/dox/group__TopicUnalignedArrayAssert.html

travek avatar May 13 '19 10:05 travek

The problem is related to the fixed-size Eigen::Matrix4d matrices in WhiteNoiseAcceleration.h header file. This is, of course, an error and I will fix as soon as possible. We are undergoing an heavy maintenence on the library and I plan to fix it within the next release. Thanks for reporting this 👍

claudiofantacci avatar May 13 '19 12:05 claudiofantacci

See this Eigen reference page.

claudiofantacci avatar May 13 '19 12:05 claudiofantacci

@traversaro Recommendation is taken from https://eigen.tuxfamily.org/dox/group__TopicUnalignedArrayAssert.html

Exactly this document explains that defining EIGEN_DONT_ALIGN_STATICALLY: "note that this breaks ABI compatibility with the default behavior of static alignment." This ABI incompatibility is what causes the run-time crashes in the cases I was describing.

traversaro avatar May 13 '19 13:05 traversaro

I changed the implementation of WhiteNoiseAcceleration using the PIMPL pattern and by generalizing it a bit for 1D, 2D and 3D position + velocity state space. You can see the new implementation here. It is still WIP and consequently the implementation may change until it is merged into devel.

claudiofantacci avatar May 30 '19 08:05 claudiofantacci