diff --git a/CMakeLists.txt b/CMakeLists.txt index 0747331..a6c4683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,6 +209,11 @@ endif() find_package(TBB REQUIRED) include_directories(${TBB_INCLUDE_DIR}) +message(STATUS "TBB_INTERFACE_VERSION: ${TBB_INTERFACE_VERSION}") +if (TBB_INTERFACE_VERSION LESS 11004) + # enable global_control header for earlier TBB versions (Ubuntu 16.04, 18.04) + add_definitions(-DTBB_PREVIEW_GLOBAL_CONTROL) +endif() find_package(OpenCV REQUIRED core imgproc calib3d highgui) include_directories(${OpenCV_INCLUDE_DIR}) diff --git a/cmake_modules/FindTBB.cmake b/cmake_modules/FindTBB.cmake index f9e3e0f..ab95fb5 100644 --- a/cmake_modules/FindTBB.cmake +++ b/cmake_modules/FindTBB.cmake @@ -44,7 +44,7 @@ # TBB_INSTALL_DIR or $ENV{TBB21_INSTALL_DIR} or $ENV{TBB_INSTALL_DIR} # This module defines -# TBB_INCLUDE_DIRS, where to find task_scheduler_init.h, etc. +# TBB_INCLUDE_DIRS, where to find tbb_stddef.h, etc. # TBB_LIBRARY_DIRS, where to find libtbb, libtbbmalloc # TBB_DEBUG_LIBRARY_DIRS, where to find libtbb_debug, libtbbmalloc_debug # TBB_INSTALL_DIR, the base TBB install directory @@ -184,7 +184,7 @@ set (TBB_INC_SEARCH_DIR ${_TBB_INSTALL_DIR}/include) # Jiri: tbbvars now sets the CPATH environment variable to the directory # containing the headers. find_path(TBB_INCLUDE_DIR - tbb/task_scheduler_init.h + tbb/tbb_stddef.h PATHS ${TBB_INC_SEARCH_DIR} ENV CPATH ) mark_as_advanced(TBB_INCLUDE_DIR) diff --git a/include/basalt/calibration/calibration_helper.h b/include/basalt/calibration/calibration_helper.h index dcdf48f..95aac3a 100644 --- a/include/basalt/calibration/calibration_helper.h +++ b/include/basalt/calibration/calibration_helper.h @@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include namespace basalt { diff --git a/include/basalt/hash_bow/hash_bow.h b/include/basalt/hash_bow/hash_bow.h index f2faab3..c034edd 100644 --- a/include/basalt/hash_bow/hash_bow.h +++ b/include/basalt/hash_bow/hash_bow.h @@ -72,7 +72,7 @@ class HashBow { const int64_t* max_t_ns = nullptr) const { results.clear(); - std::unordered_map> scores; + std::unordered_map scores; for (const auto& kv : bow_vector) { const auto range_it = inverted_index.find(kv.first); diff --git a/include/basalt/optical_flow/frame_to_frame_optical_flow.h b/include/basalt/optical_flow/frame_to_frame_optical_flow.h index 5e9c6ef..9fd0814 100644 --- a/include/basalt/optical_flow/frame_to_frame_optical_flow.h +++ b/include/basalt/optical_flow/frame_to_frame_optical_flow.h @@ -49,8 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include - namespace basalt { template typename Pattern> diff --git a/include/basalt/optimization/accumulator.h b/include/basalt/optimization/accumulator.h index 420cc66..94d90b6 100644 --- a/include/basalt/optimization/accumulator.h +++ b/include/basalt/optimization/accumulator.h @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #if defined(BASALT_USE_CHOLMOD) @@ -256,14 +257,10 @@ class SparseHashAccumulator { inline size_t operator()(const KeyT& c) const { size_t seed = 0; for (int i = 0; i < 4; i++) { - hash_combine(seed, std::hash()(c[i])); + hash_combine(seed, c[i]); } return seed; } - - inline void hash_combine(std::size_t& seed, std::size_t value) const { - seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2); - } }; std::unordered_map hash_map; diff --git a/include/basalt/optimization/linearize.h b/include/basalt/optimization/linearize.h index ed06ea4..465886a 100644 --- a/include/basalt/optimization/linearize.h +++ b/include/basalt/optimization/linearize.h @@ -40,8 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include - namespace basalt { template diff --git a/include/basalt/optimization/poses_linearize.h b/include/basalt/optimization/poses_linearize.h index f7c9b47..4cd814d 100644 --- a/include/basalt/optimization/poses_linearize.h +++ b/include/basalt/optimization/poses_linearize.h @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include +#include namespace basalt { diff --git a/include/basalt/optimization/poses_optimize.h b/include/basalt/optimization/poses_optimize.h index b2f2056..a4e32fe 100644 --- a/include/basalt/optimization/poses_optimize.h +++ b/include/basalt/optimization/poses_optimize.h @@ -38,6 +38,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include + namespace basalt { class PosesOptimization { @@ -308,7 +310,6 @@ class PosesOptimization { Eigen::aligned_vector aprilgrid_corners_measurements; Eigen::aligned_vector aprilgrid_corner_pos_3d; - -}; // namespace basalt +}; } // namespace basalt diff --git a/include/basalt/optimization/spline_linearize.h b/include/basalt/optimization/spline_linearize.h index e9e67ab..69722ca 100644 --- a/include/basalt/optimization/spline_linearize.h +++ b/include/basalt/optimization/spline_linearize.h @@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include +#include +#include namespace basalt { diff --git a/include/basalt/optimization/spline_optimize.h b/include/basalt/optimization/spline_optimize.h index 53a62e3..bd0de2c 100644 --- a/include/basalt/optimization/spline_optimize.h +++ b/include/basalt/optimization/spline_optimize.h @@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + #include namespace basalt { diff --git a/include/basalt/utils/common_types.h b/include/basalt/utils/common_types.h index cc0c07e..48678c0 100644 --- a/include/basalt/utils/common_types.h +++ b/include/basalt/utils/common_types.h @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include namespace basalt { @@ -268,6 +269,7 @@ using ImageProjections = std::map; /// inlier projections indexed per track using TrackProjections = std::unordered_map>; + } // namespace basalt namespace cereal { @@ -286,20 +288,17 @@ template void serialize(Archive& ar, basalt::MatchData& c) { ar(c.T_i_j, c.matches, c.inliers); } + } // namespace cereal namespace std { -inline void hash_combine(std::size_t& seed, std::size_t value) { - seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2); -} - template <> struct hash { size_t operator()(const basalt::TimeCamId& x) const { size_t seed = 0; - hash_combine(seed, std::hash()(x.frame_id)); - hash_combine(seed, std::hash()(x.cam_id)); + basalt::hash_combine(seed, x.frame_id); + basalt::hash_combine(seed, x.cam_id); return seed; } }; @@ -309,22 +308,12 @@ struct hash> { size_t operator()( const std::pair& x) const { size_t seed = 0; - hash_combine(seed, std::hash()(x.first.frame_id)); - hash_combine(seed, std::hash()(x.first.cam_id)); - hash_combine(seed, std::hash()(x.second.frame_id)); - hash_combine(seed, std::hash()(x.second.cam_id)); + basalt::hash_combine(seed, x.first.frame_id); + basalt::hash_combine(seed, x.first.cam_id); + basalt::hash_combine(seed, x.second.frame_id); + basalt::hash_combine(seed, x.second.cam_id); return seed; } }; + } // namespace std - -namespace tbb { - -template <> -struct tbb_hash : public std::hash {}; - -template <> -struct tbb_hash> - : public std::hash> {}; - -} // namespace tbb diff --git a/src/calibrate.cpp b/src/calibrate.cpp index d9999ad..1bc5ff1 100644 --- a/src/calibrate.cpp +++ b/src/calibrate.cpp @@ -35,14 +35,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include - #include int main(int argc, char **argv) { - tbb::task_scheduler_init init( - tbb::task_scheduler_init::default_num_threads()); - std::string dataset_path; std::string dataset_type; std::string aprilgrid_path; diff --git a/src/calibrate_imu.cpp b/src/calibrate_imu.cpp index 8588039..cb0f59a 100644 --- a/src/calibrate_imu.cpp +++ b/src/calibrate_imu.cpp @@ -37,14 +37,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include - #include int main(int argc, char **argv) { - tbb::task_scheduler_init init( - tbb::task_scheduler_init::default_num_threads()); - std::string dataset_path; std::string dataset_type; std::string aprilgrid_path; diff --git a/src/calibration/calibraiton_helper.cpp b/src/calibration/calibraiton_helper.cpp index 7a86ce2..4a2879f 100644 --- a/src/calibration/calibraiton_helper.cpp +++ b/src/calibration/calibraiton_helper.cpp @@ -37,6 +37,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include + #include #include diff --git a/src/mapper.cpp b/src/mapper.cpp index 2b5c6ab..d37f7f8 100644 --- a/src/mapper.cpp +++ b/src/mapper.cpp @@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include diff --git a/src/mapper_sim.cpp b/src/mapper_sim.cpp index f1dec05..6d7d793 100644 --- a/src/mapper_sim.cpp +++ b/src/mapper_sim.cpp @@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include diff --git a/src/mapper_sim_naive.cpp b/src/mapper_sim_naive.cpp index 8fad8bc..e186f7a 100644 --- a/src/mapper_sim_naive.cpp +++ b/src/mapper_sim_naive.cpp @@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include diff --git a/src/opt_flow.cpp b/src/opt_flow.cpp index 2ebd769..d95924d 100644 --- a/src/opt_flow.cpp +++ b/src/opt_flow.cpp @@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include diff --git a/src/rs_t265_vio.cpp b/src/rs_t265_vio.cpp index 9a176a7..5b353ea 100644 --- a/src/rs_t265_vio.cpp +++ b/src/rs_t265_vio.cpp @@ -42,8 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#include -#include +#include +#include #include #include @@ -137,8 +137,11 @@ int main(int argc, char** argv) { app.add_option("--num-threads", num_threads, "Number of threads."); app.add_option("--step-by-step", step_by_step, "Path to config file."); + // global thread limit is in effect until global_control object is destroyed + std::unique_ptr tbb_global_control; if (num_threads > 0) { - tbb::task_scheduler_init init(num_threads); + tbb_global_control = std::make_unique( + tbb::global_control::max_allowed_parallelism, num_threads); } try { diff --git a/src/time_alignment.cpp b/src/time_alignment.cpp index 925ca8b..447dc10 100644 --- a/src/time_alignment.cpp +++ b/src/time_alignment.cpp @@ -45,8 +45,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include - #include basalt::Calibration calib; @@ -86,9 +84,6 @@ double compute_error( } int main(int argc, char **argv) { - tbb::task_scheduler_init init( - tbb::task_scheduler_init::default_num_threads()); - std::string dataset_path; std::string calibration_path; std::string mocap_calibration_path; diff --git a/src/vio.cpp b/src/vio.cpp index 048a8ab..90bab30 100644 --- a/src/vio.cpp +++ b/src/vio.cpp @@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include #include @@ -222,8 +222,11 @@ int main(int argc, char** argv) { "Save trajectory. Supported formats "); app.add_option("--use-imu", use_imu, "Use IMU."); + // global thread limit is in effect until global_control object is destroyed + std::unique_ptr tbb_global_control; if (num_threads > 0) { - tbb::task_scheduler_init init(num_threads); + tbb_global_control = std::make_unique( + tbb::global_control::max_allowed_parallelism, num_threads); } try { diff --git a/src/vio_sim.cpp b/src/vio_sim.cpp index bc07bd2..b4c3b34 100644 --- a/src/vio_sim.cpp +++ b/src/vio_sim.cpp @@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include #include #include diff --git a/test/src/test_spline_opt.cpp b/test/src/test_spline_opt.cpp index 08e7c55..6384e10 100644 --- a/test/src/test_spline_opt.cpp +++ b/test/src/test_spline_opt.cpp @@ -1,5 +1,4 @@ - #include #include @@ -8,9 +7,6 @@ #include "test_utils.h" TEST(SplineOpt, SplineOptTest) { - tbb::task_scheduler_init init( - tbb::task_scheduler_init::default_num_threads()); - int num_knots = 15; basalt::CalibAccelBias accel_bias_full; diff --git a/thirdparty/basalt-headers b/thirdparty/basalt-headers index b068d7a..d6a1bc2 160000 --- a/thirdparty/basalt-headers +++ b/thirdparty/basalt-headers @@ -1 +1 @@ -Subproject commit b068d7a967af52fb3c8e261829b16a2403845ef8 +Subproject commit d6a1bc24376a67b11bd13e44cf75c1e4351f359a