Merge branch 'hash' into 'master'

TBB deprecation and other fixes

Closes #8

See merge request basalt/basalt!40
This commit is contained in:
Vladyslav Usenko 2020-06-24 11:08:48 +00:00
commit fda2a31b6a
25 changed files with 42 additions and 68 deletions

View File

@ -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})

View File

@ -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)

View File

@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/calibration/calibration.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
namespace basalt {

View File

@ -72,7 +72,7 @@ class HashBow {
const int64_t* max_t_ns = nullptr) const {
results.clear();
std::unordered_map<TimeCamId, double, tbb::tbb_hash<TimeCamId>> scores;
std::unordered_map<TimeCamId, double> scores;
for (const auto& kv : bow_vector) {
const auto range_it = inverted_index.find(kv.first);

View File

@ -49,8 +49,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/image/image_pyr.h>
#include <basalt/utils/keypoints.h>
#include <tbb/parallel_for.h>
namespace basalt {
template <typename Scalar, template <typename> typename Pattern>

View File

@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unordered_map>
#include <basalt/utils/assert.h>
#include <basalt/utils/hash.h>
#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<int>()(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<KeyT, MatrixX, KeyHash> hash_map;

View File

@ -40,8 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/calibration/calibration.hpp>
#include <basalt/camera/stereographic_param.hpp>
#include <tbb/tbb.h>
namespace basalt {
template <typename Scalar>

View File

@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/optimization/accumulator.h>
#include <tbb/tbb.h>
#include <tbb/blocked_range.h>
namespace basalt {

View File

@ -38,6 +38,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/calibration/calibration_helper.h>
#include <basalt/optimization/poses_linearize.h>
#include <tbb/parallel_reduce.h>
namespace basalt {
class PosesOptimization {
@ -308,7 +310,6 @@ class PosesOptimization {
Eigen::aligned_vector<AprilgridCornersData> aprilgrid_corners_measurements;
Eigen::aligned_vector<Eigen::Vector4d> aprilgrid_corner_pos_3d;
}; // namespace basalt
};
} // namespace basalt

View File

@ -44,7 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/utils/test_utils.h>
#include <tbb/tbb.h>
#include <tbb/blocked_range.h>
#include <tbb/tbb_stddef.h>
namespace basalt {

View File

@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/serialization/headers_serialization.h>
#include <tbb/parallel_reduce.h>
#include <chrono>
namespace basalt {

View File

@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <Eigen/StdVector>
#include <sophus/se3.hpp>
#include <basalt/utils/hash.h>
#include <basalt/utils/sophus_utils.hpp>
namespace basalt {
@ -268,6 +269,7 @@ using ImageProjections = std::map<TimeCamId, ImageProjection>;
/// inlier projections indexed per track
using TrackProjections =
std::unordered_map<TrackId, std::map<TimeCamId, ProjectedLandmarkConstPtr>>;
} // namespace basalt
namespace cereal {
@ -286,20 +288,17 @@ template <class Archive>
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<basalt::TimeCamId> {
size_t operator()(const basalt::TimeCamId& x) const {
size_t seed = 0;
hash_combine(seed, std::hash<int>()(x.frame_id));
hash_combine(seed, std::hash<int>()(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<std::pair<basalt::TimeCamId, basalt::TimeCamId>> {
size_t operator()(
const std::pair<basalt::TimeCamId, basalt::TimeCamId>& x) const {
size_t seed = 0;
hash_combine(seed, std::hash<int>()(x.first.frame_id));
hash_combine(seed, std::hash<int>()(x.first.cam_id));
hash_combine(seed, std::hash<int>()(x.second.frame_id));
hash_combine(seed, std::hash<int>()(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<basalt::TimeCamId> : public std::hash<basalt::TimeCamId> {};
template <>
struct tbb_hash<std::pair<basalt::TimeCamId, basalt::TimeCamId>>
: public std::hash<std::pair<basalt::TimeCamId, basalt::TimeCamId>> {};
} // namespace tbb

View File

@ -35,14 +35,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/calibration/cam_calib.h>
#include <tbb/tbb.h>
#include <CLI/CLI.hpp>
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;

View File

@ -37,14 +37,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/calibration/cam_imu_calib.h>
#include <tbb/tbb.h>
#include <CLI/CLI.hpp>
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;

View File

@ -37,6 +37,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/utils/apriltag.h>
#include <tbb/parallel_for.h>
#include <opengv/absolute_pose/CentralAbsoluteAdapter.hpp>
#include <opengv/absolute_pose/methods.hpp>

View File

@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>

View File

@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>

View File

@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>

View File

@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>

View File

@ -42,8 +42,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <tbb/concurrent_queue.h>
#include <tbb/global_control.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>
@ -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> tbb_global_control;
if (num_threads > 0) {
tbb::task_scheduler_init init(num_threads);
tbb_global_control = std::make_unique<tbb::global_control>(
tbb::global_control::max_allowed_parallelism, num_threads);
}
try {

View File

@ -45,8 +45,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <basalt/utils/filesystem.h>
#include <basalt/calibration/calibration.hpp>
#include <tbb/tbb.h>
#include <CLI/CLI.hpp>
basalt::Calibration<double> 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;

View File

@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <tbb/global_control.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>
@ -222,8 +222,11 @@ int main(int argc, char** argv) {
"Save trajectory. Supported formats <tum, euroc, kitti>");
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> tbb_global_control;
if (num_threads > 0) {
tbb::task_scheduler_init init(num_threads);
tbb_global_control = std::make_unique<tbb::global_control>(
tbb::global_control::max_allowed_parallelism, num_threads);
}
try {

View File

@ -41,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <sophus/se3.hpp>
#include <tbb/concurrent_unordered_map.h>
#include <tbb/tbb.h>
#include <pangolin/display/image_view.h>
#include <pangolin/gl/gldraw.h>

View File

@ -1,5 +1,4 @@
#include <basalt/optimization/spline_optimize.h>
#include <iostream>
@ -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<double> accel_bias_full;

@ -1 +1 @@
Subproject commit b068d7a967af52fb3c8e261829b16a2403845ef8
Subproject commit d6a1bc24376a67b11bd13e44cf75c1e4351f359a