Fix for alignment asserts from eigen when running with -mnative

441 views
Skip to first unread message

Jorgen Birkler

unread,
Jul 22, 2016, 2:28:38 PM7/22/16
to Ceres Solver
Summary; FixedArray does not consider alignment to the 'T' type and in certain circumstances we got asserts and seg-faults from Eigen because the data was not aligned.

This patch seems to fix the issues.


ceres_eigen_alignment_crash_fix.patch

Sameer Agarwal

unread,
Jul 22, 2016, 2:37:28 PM7/22/16
to ceres-...@googlegroups.com
Jorgen,

Thanks for the patch. Two things.
1. It would be useful to see what kind of errors you are getting and are being fixed by this. I am surprised because we do not put eigen arrays inside FixedArray anywhere in the code.
2. The path needs to be submitted to gerrit after signing a CLA, so that copyrights are handled correctly, following the instructions at 


Sameer



On Fri, Jul 22, 2016 at 11:28 AM Jorgen Birkler <jor...@insidemaps.com> wrote:
Summary; FixedArray does not consider alignment to the 'T' type and in certain circumstances we got asserts and seg-faults from Eigen because the data was not aligned.

This patch seems to fix the issues.


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/01fd9675-fef7-4ad8-951f-9e294ffa74b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jorgen Birkler

unread,
Jul 22, 2016, 6:30:27 PM7/22/16
to Ceres Solver
Thread #1 [interface_tests] 11582 [core: 1] (Suspended : Signal : SIGABRT:Aborted)
__GI_raise() at raise.c:54 0x7f0880940418
__GI_abort() at abort.c:89 0x7f088094201a
__assert_fail_base() at assert.c:92 0x7f0880938bd7
__GI___assert_fail() at assert.c:101 0x7f0880938c82
Eigen::internal::plain_array<double, 24, 0, 32>::plain_array() at DenseStorage.h:128 0x49c795
Eigen::DenseStorage<double, 24, 24, 1, 0>::DenseStorage() at DenseStorage.h:187 0x498b04
Eigen::PlainObjectBase<Eigen::Matrix<double, 24, 1, 0, 24, 1> >::PlainObjectBase() at PlainObjectBase.h:457 0x4954b0
Eigen::Matrix<double, 24, 1, 0, 24, 1>::Matrix() at Matrix.h:259 0x4921aa
ceres::Jet<double, 24>::Jet() at jet.h:182 0x48cd7a
ceres::internal::FixedArray<ceres::Jet<double, 24>, 8l>::InnerContainer::InnerContainer() at fixed_array.h:139 0x4862ba
ceres::internal::FixedArray<ceres::Jet<double, 24>, 8l>::FixedArray() at fixed_array.h:169 0x486344
ceres::internal::AutoDiff<im::InverseDepthAnchor2UVCostFunctor, double, 4, 4, 3, 4, 3, 6, 0, 0, 0, 0>::Differentiate() at autodiff.h:233 0x4807d9
ceres::AutoDiffCostFunction<im::InverseDepthAnchor2UVCostFunctor, 2, 4, 4, 3, 4, 3, 6, 0, 0, 0, 0>::Evaluate() at autodiff_cost_function.h:218 0x47efb7
ceres::internal::ResidualBlock::Evaluate(bool, double*, double*, double**, double*) const at 0x739a14
ceres::internal::ProgramEvaluator<ceres::internal::BlockEvaluatePreparer, ceres::internal::BlockJacobianWriter, ceres::internal::NullJacobianFinalizer>::Evaluate() at 0x7628d3
ceres::internal::TrustRegionMinimizer::Minimize() at 0x78085c
ceres::Solver::Solve() at 0x745e7d
ceres::Solve() at 0x747829
testTrackerBundleAdjusterRandom() at main_test.cpp:624 0x61714e
TestFixture_testTrackerBundleAdjusterMapPointParametrizationRandomNoInit_Test::TestBody() at main_test.cpp:770 0x61995a
<...more frames...>


Yes. I could not understand that either. T is a double. Inside the Jet it creates a Eigen::Matrix which is templated to use NoAlign bit. but it seems that when the constructor is being run the created Matrix is aligned.

Sorry I do not have any minimal test case that provokes the error at the moment.

BTW if we pass 
-march=native => ASSERT triggers
-march=native -mno-avx -mno-avx2  => No assert triggers

I'm on an i7 and 
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



So -march=native will allow Eigen to generate avx vectorization (and eigen does...).

Sameer Agarwal

unread,
Jul 25, 2016, 3:10:38 AM7/25/16
to Ceres Solver
hmm fixed array of jets, I had forgotten about this.
I am guessing you are enabling c++11 when compiling your code, since that is the only path when the Eigen Array inside the Jet is aligned. or is that not the case?
Sameer


Jorgen Birkler

unread,
Jul 25, 2016, 4:02:12 PM7/25/16
to Ceres Solver
Correct. We are using C++11.

Jorgen Birkler

unread,
Jul 26, 2016, 12:33:59 AM7/26/16
to Ceres Solver
Update:
Just got a segfault in the autodiff. 
-mno-avx -mno-avx2 removes the segfault.

So the patch does not seem to cover all the cases.

/Jorgen

Sameer Agarwal

unread,
Jul 27, 2016, 6:35:11 PM7/27/16
to ceres-...@googlegroups.com
I think we have a lead on the fix for this, it will take a bit, will update later next week.

Reply all
Reply to author
Forward
0 new messages