From 531ecb4000c6f3f42a9641088b902503af4d9c08 Mon Sep 17 00:00:00 2001 From: Abe Date: Mon, 9 Mar 2015 17:01:47 -0700 Subject: [PATCH 1/2] Get rid of hardcoded path to the internal version of eigen inside gtsam --- CMakeLists.txt | 13 ++++++++++--- gtsam/base/Matrix.cpp | 4 ++-- gtsam/base/Matrix.h | 6 +++--- gtsam/base/OptionalJacobian.h | 2 +- gtsam/base/Vector.h | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38ee89760..0041c4710 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,8 +196,7 @@ endif() ### See: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=704 (Householder QR MKL selection) ### http://eigen.tuxfamily.org/bz/show_bug.cgi?id=705 (Fix MKL LLT return code) ### http://eigen.tuxfamily.org/bz/show_bug.cgi?id=716 (Improved comma initialization) -# option(GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" OFF) -set(GTSAM_USE_SYSTEM_EIGEN OFF) +option(GTSAM_USE_SYSTEM_EIGEN "Find and use system-installed Eigen. If 'off', use the one bundled with GTSAM" OFF) # Switch for using system Eigen or GTSAM-bundled Eigen if(GTSAM_USE_SYSTEM_EIGEN) @@ -207,13 +206,16 @@ if(GTSAM_USE_SYSTEM_EIGEN) find_package(Eigen3 REQUIRED) include_directories(AFTER "${EIGEN3_INCLUDE_DIR}") else() - # Use bundled Eigen include paths e.g. + # Use bundled Eigen include path. set(GTSAM_EIGEN_INCLUDE_PREFIX "gtsam/3rdparty/Eigen/") # Clear any variables set by FindEigen3 if(EIGEN3_INCLUDE_DIR) set(EIGEN3_INCLUDE_DIR NOTFOUND CACHE STRING "" FORCE) endif() + # Add the bundled version of eigen to the include path so that it can still be included + # with #include + include_directories(BEFORE ${GTSAM_EIGEN_INCLUDE_PREFIX}) endif() # Write Eigen include file with the paths for either the system Eigen or the GTSAM-bundled Eigen @@ -389,6 +391,11 @@ if(NOT MSVC AND NOT XCODE_VERSION) message(STATUS " C compilation flags : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${cmake_build_type_toupper}}") message(STATUS " C++ compilation flags : ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${cmake_build_type_toupper}}") endif() +if(GTSAM_USE_SYSTEM_EIGEN) + message(STATUS " Use System Eigen : Yes") +else() + message(STATUS " Use System Eigen : No") +endif() if(GTSAM_USE_TBB) message(STATUS " Use Intel TBB : Yes") elseif(TBB_FOUND) diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 7fa0992ca..a5836a3ac 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -20,8 +20,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index 27b7ec8f7..53b040b9a 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -23,9 +23,9 @@ #pragma once #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/gtsam/base/OptionalJacobian.h b/gtsam/base/OptionalJacobian.h index 2ea9d672e..81bf265a3 100644 --- a/gtsam/base/OptionalJacobian.h +++ b/gtsam/base/OptionalJacobian.h @@ -19,7 +19,7 @@ #pragma once -#include +#include #ifndef OPTIONALJACOBIAN_NOBOOST #include diff --git a/gtsam/base/Vector.h b/gtsam/base/Vector.h index fc543acc3..0869abc16 100644 --- a/gtsam/base/Vector.h +++ b/gtsam/base/Vector.h @@ -26,7 +26,7 @@ #endif #include -#include +#include #include #include From f61e398e2d970cc2d523bb58bff7c52dbf682732 Mon Sep 17 00:00:00 2001 From: cbeall3 Date: Tue, 10 Mar 2015 13:00:28 -0400 Subject: [PATCH 2/2] Deal with patched/un-patched version of householder_qr_inplace_blocked --- CMakeLists.txt | 5 +++++ gtsam/base/Matrix.cpp | 7 +++++++ gtsam/config.h.in | 3 +++ 3 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0041c4710..dd626bde8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,6 +205,11 @@ if(GTSAM_USE_SYSTEM_EIGEN) find_package(Eigen3 REQUIRED) include_directories(AFTER "${EIGEN3_INCLUDE_DIR}") + + # check if MKL is also enabled - can have one or the other, but not both! + if(EIGEN_USE_MKL_ALL) + message(FATAL_ERROR "MKL cannot be used together with system-installed Eigen, as MKL support relies on patches which are not yet in the system-installed Eigen. Disable either GTSAM_USE_SYSTEM_EIGEN or GTSAM_WITH_EIGEN_MKL") + endif() else() # Use bundled Eigen include path. set(GTSAM_EIGEN_INCLUDE_PREFIX "gtsam/3rdparty/Eigen/") diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index a5836a3ac..9e56dfb6c 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -706,6 +706,7 @@ std::string formatMatrixIndented(const std::string& label, const Matrix& matrix, return ss.str(); } +/* ************************************************************************* */ void inplace_QR(Matrix& A){ size_t rows = A.rows(); size_t cols = A.cols(); @@ -716,7 +717,13 @@ void inplace_QR(Matrix& A){ HCoeffsType hCoeffs(size); RowVectorType temp(cols); +#ifdef GTSAM_USE_SYSTEM_EIGEN + // System-Eigen is used, and MKL is off + Eigen::internal::householder_qr_inplace_blocked(A, hCoeffs, 48, temp.data()); +#else + // Patched Eigen is used, and MKL is either on or off Eigen::internal::householder_qr_inplace_blocked::run(A, hCoeffs, 48, temp.data()); +#endif zeroBelowDiagonal(A); } diff --git a/gtsam/config.h.in b/gtsam/config.h.in index 64136511d..8d406e21f 100644 --- a/gtsam/config.h.in +++ b/gtsam/config.h.in @@ -42,6 +42,9 @@ // Whether we are using TBB (if TBB was found and GTSAM_WITH_TBB is enabled in CMake) #cmakedefine GTSAM_USE_TBB +// Whether we are using system-Eigen or our own patched version +#cmakedefine GTSAM_USE_SYSTEM_EIGEN + // Whether Eigen will use MKL (if MKL was found and GTSAM_WITH_EIGEN_MKL is enabled in CMake) #cmakedefine GTSAM_USE_EIGEN_MKL #cmakedefine EIGEN_USE_MKL_ALL // This is also defined in gtsam_eigen_includes.h