Skip to content

Commit

Permalink
Make num_threads a paramter of the voxel hash map
Browse files Browse the repository at this point in the history
For backwards compatibility, use a default value of "automatic"
  • Loading branch information
nachovizzo committed Feb 11, 2024
1 parent fae5b46 commit 24964c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions cpp/kiss_icp/core/VoxelHashMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ struct ResultTuple {
std::vector<Eigen::Vector3d> target;
};

constexpr int NUM_THREADS_ = 16;

} // namespace

namespace kiss_icp {
Expand Down Expand Up @@ -97,7 +95,7 @@ VoxelHashMap::Vector3dVectorTuple VoxelHashMap::GetCorrespondences(

using points_iterator = std::vector<Eigen::Vector3d>::const_iterator;
ResultTuple correspondences(points.size());
tbb::task_arena limited_arena(NUM_THREADS_);
tbb::task_arena limited_arena(max_threads_);
limited_arena.execute([&]() -> void {
correspondences = tbb::parallel_reduce(
// Range
Expand Down
10 changes: 8 additions & 2 deletions cpp/kiss_icp/core/VoxelHashMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// should at least acknoowledge the work from CT-ICP by giving a star on GitHub
#pragma once

#include <oneapi/tbb/task_arena.h>
#include <tsl/robin_map.h>

#include <Eigen/Core>
Expand All @@ -52,10 +53,14 @@ struct VoxelHashMap {
}
};

explicit VoxelHashMap(double voxel_size, double max_distance, int max_points_per_voxel)
explicit VoxelHashMap(double voxel_size,
double max_distance,
int max_points_per_voxel,
int max_threads = tbb::task_arena::automatic)
: voxel_size_(voxel_size),
max_distance_(max_distance),
max_points_per_voxel_(max_points_per_voxel) {}
max_points_per_voxel_(max_points_per_voxel),
max_threads_(max_threads) {}

Vector3dVectorTuple GetCorrespondences(const Vector3dVector &points,
double max_correspondance_distance) const;
Expand All @@ -70,6 +75,7 @@ struct VoxelHashMap {
double voxel_size_;
double max_distance_;
int max_points_per_voxel_;
int max_threads_;
tsl::robin_map<Voxel, VoxelBlock, VoxelHash> map_;
};
} // namespace kiss_icp

0 comments on commit 24964c8

Please sign in to comment.