You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
5.2 KiB

  1. namespace Eigen {
  2. /** \page TopicUnalignedArrayAssert Explanation of the assertion on unaligned arrays
  3. Hello! You are seeing this webpage because your program terminated on an assertion failure like this one:
  4. <pre>
  5. my_program: path/to/eigen/Eigen/src/Core/DenseStorage.h:44:
  6. Eigen::internal::matrix_array<T, Size, MatrixOptions, Align>::internal::matrix_array()
  7. [with T = double, int Size = 2, int MatrixOptions = 2, bool Align = true]:
  8. Assertion `(reinterpret_cast<size_t>(array) & 0xf) == 0 && "this assertion
  9. is explained here: http://eigen.tuxfamily.org/dox/UnalignedArrayAssert.html
  10. **** READ THIS WEB PAGE !!! ****"' failed.
  11. </pre>
  12. There are 4 known causes for this issue. Please read on to understand them and learn how to fix them.
  13. \b Table \b of \b contents
  14. - \ref where
  15. - \ref c1
  16. - \ref c2
  17. - \ref c3
  18. - \ref c4
  19. - \ref explanation
  20. - \ref getrid
  21. \section where Where in my own code is the cause of the problem?
  22. First of all, you need to find out where in your own code this assertion was triggered from. At first glance, the error message doesn't look helpful, as it refers to a file inside Eigen! However, since your program crashed, if you can reproduce the crash, you can get a backtrace using any debugger. For example, if you're using GCC, you can use the GDB debugger as follows:
  23. \code
  24. $ gdb ./my_program # Start GDB on your program
  25. > run # Start running your program
  26. ... # Now reproduce the crash!
  27. > bt # Obtain the backtrace
  28. \endcode
  29. Now that you know precisely where in your own code the problem is happening, read on to understand what you need to change.
  30. \section c1 Cause 1: Structures having Eigen objects as members
  31. If you have code like this,
  32. \code
  33. class Foo
  34. {
  35. //...
  36. Eigen::Vector2d v;
  37. //...
  38. };
  39. //...
  40. Foo *foo = new Foo;
  41. \endcode
  42. then you need to read this separate page: \ref TopicStructHavingEigenMembers "Structures Having Eigen Members".
  43. Note that here, Eigen::Vector2d is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types".
  44. \section c2 Cause 2: STL Containers
  45. If you use STL Containers such as std::vector, std::map, ..., with Eigen objects, or with classes containing Eigen objects, like this,
  46. \code
  47. std::vector<Eigen::Matrix2f> my_vector;
  48. struct my_class { ... Eigen::Matrix2f m; ... };
  49. std::map<int, my_class> my_map;
  50. \endcode
  51. then you need to read this separate page: \ref TopicStlContainers "Using STL Containers with Eigen".
  52. Note that here, Eigen::Matrix2f is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types" and \ref TopicStructHavingEigenMembers "structures having such Eigen objects as member".
  53. \section c3 Cause 3: Passing Eigen objects by value
  54. If some function in your code is getting an Eigen object passed by value, like this,
  55. \code
  56. void func(Eigen::Vector4d v);
  57. \endcode
  58. then you need to read this separate page: \ref TopicPassingByValue "Passing Eigen objects by value to functions".
  59. Note that here, Eigen::Vector4d is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types".
  60. \section c4 Cause 4: Compiler making a wrong assumption on stack alignment (for instance GCC on Windows)
  61. This is a must-read for people using GCC on Windows (like MinGW or TDM-GCC). If you have this assertion failure in an innocent function declaring a local variable like this:
  62. \code
  63. void foo()
  64. {
  65. Eigen::Quaternionf q;
  66. //...
  67. }
  68. \endcode
  69. then you need to read this separate page: \ref TopicWrongStackAlignment "Compiler making a wrong assumption on stack alignment".
  70. Note that here, Eigen::Quaternionf is only used as an example, more generally the issue arises for all \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen types".
  71. \section explanation General explanation of this assertion
  72. \ref TopicFixedSizeVectorizable "fixed-size vectorizable Eigen objects" must absolutely be created at 16-byte-aligned locations, otherwise SIMD instructions adressing them will crash.
  73. Eigen normally takes care of these alignment issues for you, by setting an alignment attribute on them and by overloading their "operator new".
  74. However there are a few corner cases where these alignment settings get overridden: they are the possible causes for this assertion.
  75. \section getrid I don't care about vectorization, how do I get rid of that stuff?
  76. Two possibilities:
  77. <ul>
  78. <li>Define EIGEN_DONT_ALIGN_STATICALLY. That disables all 128-bit static alignment code, while keeping 128-bit heap alignment. This has the effect of
  79. disabling vectorization for fixed-size objects (like Matrix4d) while keeping vectorization of dynamic-size objects
  80. (like MatrixXd). But do note that this breaks ABI compatibility with the default behavior of 128-bit static alignment.</li>
  81. <li>Or define both EIGEN_DONT_VECTORIZE and EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT. This keeps the
  82. 128-bit alignment code and thus preserves ABI compatibility, but completely disables vectorization.</li>
  83. </ul>
  84. For more information, see <a href="http://eigen.tuxfamily.org/index.php?title=FAQ#I_disabled_vectorization.2C_but_I.27m_still_getting_annoyed_about_alignment_issues.21">this FAQ</a>.
  85. */
  86. }