Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for limiting num_threads in tbb task #252

Merged
merged 50 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5e08b68
Add support for limiting num_threads in tbb task
zzodo Nov 2, 2023
fae5b46
Merge remote-tracking branch 'origin/main' into feature/set-num-threads
nachovizzo Feb 11, 2024
24964c8
Make num_threads a paramter of the voxel hash map
nachovizzo Feb 11, 2024
51decb1
This got a bit more hacky but is to avoid hardocding a praamter
nachovizzo Feb 11, 2024
b327258
Propagate max_threads to Python config
nachovizzo Feb 11, 2024
a262e9f
Merge remote-tracking branch 'origin/main' into feature/set-num-threads
nachovizzo Feb 29, 2024
e5044f8
First draft on core library
nachovizzo Mar 1, 2024
6c7e505
Update python API
nachovizzo Mar 1, 2024
80248bb
Rearange
nachovizzo Mar 1, 2024
505ab61
Remove type alias
nachovizzo Mar 1, 2024
1dc13a7
Fix build
nachovizzo Mar 1, 2024
5053877
Wrap constants into a configuration struct
nachovizzo Mar 1, 2024
0e015d9
Split the watters
nachovizzo Mar 1, 2024
d4378b4
It's all about drafts
nachovizzo Mar 1, 2024
ebdfab5
Update python API
nachovizzo Mar 1, 2024
598e1a6
Some renaming just because
nachovizzo Mar 1, 2024
18465fd
Changing names trying to auto-convince myself...
nachovizzo Mar 1, 2024
3606d0c
Fix c++ build
nachovizzo Mar 1, 2024
9fa9f2d
rename function
benemer Mar 4, 2024
ea7b313
renaming variables
benemer Mar 4, 2024
5c8fc25
renaming, should be one neighbor only
benemer Mar 4, 2024
01b11c5
Tizianified a little bit
tizianoGuadagnino Mar 4, 2024
f4a2465
Draft on voxelhashmap
nachovizzo Mar 4, 2024
0cb69a7
Rename
nachovizzo Mar 4, 2024
39e4cbf
Rename Correspondences -> Associations
nachovizzo Mar 4, 2024
b434e04
Move stuff around only
nachovizzo Mar 4, 2024
70a6457
Remove redunant name
nachovizzo Mar 4, 2024
876fedc
They are not there, we need to find them!
nachovizzo Mar 4, 2024
c338afb
Shrink
nachovizzo Mar 4, 2024
2b79370
Tiziano shows to guys -> with for_each
tizianoGuadagnino Mar 4, 2024
d834170
Tiziano shows to guys -> with transform_reduce....sexy
tizianoGuadagnino Mar 4, 2024
b58d352
Merge remote-tracking branch 'origin/nacho/strip_nn_search_from_voxel…
nachovizzo Mar 5, 2024
f88310f
Consistent naming
nachovizzo Mar 5, 2024
8fb80db
Bring comments for readbilty
nachovizzo Mar 5, 2024
f5c1524
rename variable
nachovizzo Mar 5, 2024
318cd86
Sacrifice name for one-liner
nachovizzo Mar 5, 2024
0c823ae
AlignCloudToMap -> AlignPointsToMap
nachovizzo Mar 5, 2024
7a45c9d
Make rename like a book on ProbRob
tizianoGuadagnino Mar 5, 2024
26dd7b0
Revert "Make rename like a book on ProbRob"
nachovizzo Mar 5, 2024
d5a38f4
estimation_threshold -> convergence_criterion
nachovizzo Mar 5, 2024
f2e5d60
Rename threshold also here
benemer Mar 5, 2024
9a80e16
Merge remote-tracking branch 'origin/nacho/strip_nn_search_from_voxel…
nachovizzo Mar 5, 2024
cdafca9
Merge remote-tracking branch 'origin/nacho/strip_nn_search_from_voxel…
nachovizzo Mar 5, 2024
cfadfab
no typos no nacho
nachovizzo Mar 5, 2024
bd063e9
Remove comment
nachovizzo Mar 5, 2024
90e6fc5
Merge remote-tracking branch 'origin/nacho/strip_nn_search_from_voxel…
nachovizzo Mar 5, 2024
cbc831c
Merge remote-tracking branch 'origin/main' into feature/set-num-threads
nachovizzo Mar 5, 2024
af2c31a
reduce diff
nachovizzo Mar 5, 2024
f550a1a
Small improvement. max_num_threads_ always represents what it says
nachovizzo Mar 11, 2024
bb880fd
Remove single letter variable
tizianoGuadagnino Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/advanced.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ adaptive_threshold:
registration:
max_num_iterations: 500 # <- optional
convergence_criterion: 0.0001 # <- optional
max_num_threads: 0 # <- optional, 0 means automatic
13 changes: 13 additions & 0 deletions cpp/kiss_icp/core/Registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "Registration.hpp"

#include <tbb/blocked_range.h>
#include <tbb/global_control.h>
#include <tbb/info.h>
#include <tbb/parallel_reduce.h>

#include <algorithm>
Expand Down Expand Up @@ -142,6 +144,17 @@ LinearSystem BuildLinearSystem(const Associations &associations, double kernel)

namespace kiss_icp {

Registration::Registration(int max_num_iteration, double convergence_criterion, int max_num_threads)
: max_num_iterations_(max_num_iteration),
convergence_criterion_(convergence_criterion),
// Only manipulate the number of threads if the user specifies something greater than 0
max_num_threads_(max_num_threads > 0 ? max_num_threads : tbb::info::default_concurrency()) {
// This global variable requires static duration storage to be able to manipulate the max
// concurrency from TBB across the entire class
static const auto tbb_control_settings = tbb::global_control(
tbb::global_control::max_allowed_parallelism, static_cast<size_t>(max_num_threads_));
}

Sophus::SE3d Registration::AlignPointsToMap(const std::vector<Eigen::Vector3d> &frame,
const VoxelHashMap &voxel_map,
const Sophus::SE3d &initial_guess,
Expand Down
4 changes: 2 additions & 2 deletions cpp/kiss_icp/core/Registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
namespace kiss_icp {

struct Registration {
explicit Registration(int max_num_iteration, double convergence_criterion)
: max_num_iterations_(max_num_iteration), convergence_criterion_(convergence_criterion) {}
explicit Registration(int max_num_iteration, double convergence_criterion, int max_num_threads);

Sophus::SE3d AlignPointsToMap(const std::vector<Eigen::Vector3d> &frame,
const VoxelHashMap &voxel_map,
Expand All @@ -42,5 +41,6 @@ struct Registration {

int max_num_iterations_;
double convergence_criterion_;
int max_num_threads_;
};
} // namespace kiss_icp
4 changes: 3 additions & 1 deletion cpp/kiss_icp/pipeline/KissICP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct KISSConfig {
// registration params
int max_num_iterations = 500;
double convergence_criterion = 0.0001;
int max_num_threads = 0;

// Motion compensation
bool deskew = false;
Expand All @@ -59,7 +60,8 @@ class KissICP {
public:
explicit KissICP(const KISSConfig &config)
: config_(config),
registration_(config.max_num_iterations, config.convergence_criterion),
registration_(
config.max_num_iterations, config.convergence_criterion, config.max_num_threads),
local_map_(config.voxel_size, config.max_range, config.max_points_per_voxel),
adaptive_threshold_(config.initial_threshold, config.min_motion_th, config.max_range) {}

Expand Down
1 change: 1 addition & 0 deletions python/kiss_icp/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MappingConfig(BaseModel):
class RegistrationConfig(BaseModel):
max_num_iterations: Optional[int] = 500
convergence_criterion: Optional[float] = 0.0001
max_num_threads: Optional[int] = 0 # 0 means automatic


class AdaptiveThresholdConfig(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion python/kiss_icp/pybind/kiss_icp_pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ PYBIND11_MODULE(kiss_icp_pybind, m) {
// Point Cloud registration
py::class_<Registration> internal_registration(m, "_Registration", "Don't use this");
internal_registration
.def(py::init<int, double>(), "max_num_iterations"_a, "convergence_criterion"_a)
.def(py::init<int, double, int>(), "max_num_iterations"_a, "convergence_criterion"_a,
"max_num_threads"_a)
.def(
"_align_points_to_map",
[](Registration &self, const std::vector<Eigen::Vector3d> &points,
Expand Down
9 changes: 8 additions & 1 deletion python/kiss_icp/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ def get_registration(config: KISSConfig):
return Registration(
max_num_iterations=config.registration.max_num_iterations,
convergence_criterion=config.registration.convergence_criterion,
max_num_threads=config.registration.max_num_threads,
)


class Registration:
def __init__(self, max_num_iterations: int, convergence_criterion: float):
def __init__(
self,
max_num_iterations: int,
convergence_criterion: float,
max_num_threads: int = 0,
):
self._registration = kiss_icp_pybind._Registration(
max_num_iterations=max_num_iterations,
convergence_criterion=convergence_criterion,
max_num_threads=max_num_threads,
)

def align_points_to_map(
Expand Down
Loading