From 2e050e4231e725e1dff80e801f663fd1f71645a3 Mon Sep 17 00:00:00 2001 From: Rainer Kuemmerle Date: Sun, 6 Aug 2023 14:20:10 +0200 Subject: [PATCH] Fix compile errors for the benchmarks Fix #708 --- CMakeLists.txt | 8 +-- benchmarks/CMakeLists.txt | 5 ++ benchmarks/jacobian_timing_tests.cpp | 78 ++++++++++++++-------------- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fefcc402..c3b6ab5f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -526,6 +526,9 @@ if(BUILD_UNITTESTS) add_subdirectory(unit_test) endif() +# Include the subdirectories +add_subdirectory(g2o) + # Benchmarks option(G2O_BUILD_BENCHMARKS "build benchmarks" OFF) if(G2O_BUILD_BENCHMARKS) @@ -533,9 +536,6 @@ if(G2O_BUILD_BENCHMARKS) if(${benchmark_FOUND}) add_subdirectory(benchmarks) else() - message(WARNING G2O_BUILD_BENCHMARKS was set to true, but the benchmark library cannot be found) + message(WARNING "G2O_BUILD_BENCHMARKS was set to true, but the benchmark library cannot be found") endif() endif() - -# Include the subdirectories -add_subdirectory(g2o) diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index dc78dccc4..89a2612ff 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -1,2 +1,7 @@ add_executable(benchmark_jacobian_timing jacobian_timing_tests.cpp) + +target_include_directories(benchmark_jacobian_timing PUBLIC + "$" +) + target_link_libraries(benchmark_jacobian_timing benchmark::benchmark ${G2O_EIGEN3_EIGEN_TARGET}) diff --git a/benchmarks/jacobian_timing_tests.cpp b/benchmarks/jacobian_timing_tests.cpp index afbf04e3c..1ae7d320c 100644 --- a/benchmarks/jacobian_timing_tests.cpp +++ b/benchmarks/jacobian_timing_tests.cpp @@ -6,10 +6,10 @@ // Test several different ways of evaluating Jacobians to see the impact of // different ways of implementing stuff. -template +template void BM_FixedArray(benchmark::State& state) { while (state.KeepRunning()) { - double add_vi[D] = {}; + Number add_vi[D] = {}; for (int i = 0; i < D; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); benchmark::DoNotOptimize(add_vi[i] = -1); @@ -18,11 +18,11 @@ void BM_FixedArray(benchmark::State& state) { } } -template +template void BM_FixedArrayPointer(benchmark::State& state) { while (state.KeepRunning()) { - double add_vi[D] = {}; - double* v = &add_vi[0]; + Number add_vi[D] = {}; + Number* v = &add_vi[0]; for (int i = 0; i < D; ++i) { benchmark::DoNotOptimize((*v) = 1); benchmark::DoNotOptimize((*v) = -1); @@ -31,12 +31,12 @@ void BM_FixedArrayPointer(benchmark::State& state) { } } -template +template void BM_VariableArray(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - double add_vi[d]; + Number add_vi[d]; // std::fill(add_vi, add_vi + d, double(0.0)); for (int i = 0; i < d; ++i) { @@ -51,15 +51,15 @@ void BM_VariableArray(benchmark::State& state) { } } -template +template void BM_VariableArrayPointer(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - double add_vi[d]; + Number add_vi[d]; - std::fill(add_vi, add_vi + d, double(0.0)); + std::fill(add_vi, add_vi + d, Number(0.0)); - double* v = &add_vi[0]; + Number* v = &add_vi[0]; for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize((*v) = 1); @@ -69,10 +69,10 @@ void BM_VariableArrayPointer(benchmark::State& state) { } } -template +template void BM_StaticEigenMatrix(benchmark::State& state) { while (state.KeepRunning()) { - Eigen::Matrix add_vi = Eigen::Matrix::Zero(); + Eigen::Matrix add_vi = Eigen::Matrix::Zero(); for (int i = 0; i < D; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); benchmark::DoNotOptimize(add_vi[i] = -1); @@ -81,11 +81,11 @@ void BM_StaticEigenMatrix(benchmark::State& state) { } } -template +template void BM_StaticEigenMatrixPointer(benchmark::State& state) { while (state.KeepRunning()) { - Eigen::Matrix add_vi = Eigen::Matrix::Zero(); - double* v = add_vi.data(); + Eigen::Matrix add_vi = Eigen::Matrix::Zero(); + Number* v = add_vi.data(); for (int i = 0; i < D; ++i) { benchmark::DoNotOptimize((*v) = 1); benchmark::DoNotOptimize((*v) = -1); @@ -94,11 +94,11 @@ void BM_StaticEigenMatrixPointer(benchmark::State& state) { } } -template +template void BM_DynamicEigenMatrix(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - Eigen::Matrix add_vi(d); + Eigen::Matrix add_vi(d); add_vi.setZero(); for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); @@ -108,13 +108,13 @@ void BM_DynamicEigenMatrix(benchmark::State& state) { } } -template +template void BM_DynamicEigenMatrixPointer(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - Eigen::Matrix add_vi(d); + Eigen::Matrix add_vi(d); add_vi.setZero(); - double* v = add_vi.data(); + Number* v = add_vi.data(); for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize((*v) = 1); benchmark::DoNotOptimize((*v) = -1); @@ -123,13 +123,13 @@ void BM_DynamicEigenMatrixPointer(benchmark::State& state) { } } -template +template void BM_DynamicAlignedBuffer(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - static g2o::dynamic_aligned_buffer buffer{size_t(d)}; - double* add_vi = buffer.request(d); - std::fill(add_vi, add_vi + d, double(0.0)); + static g2o::dynamic_aligned_buffer buffer{size_t(d)}; + Number* add_vi = buffer.request(d); + std::fill(add_vi, add_vi + d, Number(0.0)); for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); benchmark::DoNotOptimize(add_vi[i] = -1); @@ -138,14 +138,14 @@ void BM_DynamicAlignedBuffer(benchmark::State& state) { } } -template +template void BM_DynamicAlignedBufferPointer(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - static g2o::dynamic_aligned_buffer buffer{size_t(d)}; - double* add_vi = buffer.request(d); - std::fill(add_vi, add_vi + d, double(0.0)); - double* v = add_vi; + static g2o::dynamic_aligned_buffer buffer{size_t(d)}; + Number* add_vi = buffer.request(d); + std::fill(add_vi, add_vi + d, Number(0.0)); + Number* v = add_vi; for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize((*v) = 1); @@ -155,21 +155,21 @@ void BM_DynamicAlignedBufferPointer(benchmark::State& state) { } } -template +template void BM_StaticDynamicDynamicAlignedBufferHybrid(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); if (d <= 10) { - double add_vi[10] = {}; + Number add_vi[10] = {}; for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); benchmark::DoNotOptimize(add_vi[i] = -1); benchmark::DoNotOptimize(add_vi[i] = 0); } } else { - static g2o::dynamic_aligned_buffer buffer{size_t(d)}; - double* add_vi = buffer.request(d); - std::fill(add_vi, add_vi + d, double(0.0)); + static g2o::dynamic_aligned_buffer buffer{size_t(d)}; + Number* add_vi = buffer.request(d); + std::fill(add_vi, add_vi + d, Number(0.0)); for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); benchmark::DoNotOptimize(add_vi[i] = -1); @@ -179,10 +179,10 @@ void BM_StaticDynamicDynamicAlignedBufferHybrid(benchmark::State& state) { } } -template +template void BM_ClassFixedArrayStatic(benchmark::State& state) { while (state.KeepRunning()) { - ceres::internal::FixedArray add_vi(D); + g2o::ceres::internal::FixedArray add_vi(D); add_vi.fill(0.); for (int i = 0; i < D; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1); @@ -192,11 +192,11 @@ void BM_ClassFixedArrayStatic(benchmark::State& state) { } } -template +template void BM_ClassFixedArrayDynamic(benchmark::State& state) { while (state.KeepRunning()) { const int d = state.range(0); - ceres::internal::FixedArray add_vi(d); + g2o::ceres::internal::FixedArray add_vi(d); add_vi.fill(0.); for (int i = 0; i < d; ++i) { benchmark::DoNotOptimize(add_vi[i] = 1);