Skip to content

Commit 2d7ebf1

Browse files
mviethlarshg
andauthored
Add google benchmark for NormalEstimation (#4506)
* Add google benchmark for NormalEstimation * Add benchmarks step to ubuntu and windows ci * Suggested changes. * More suggestions. * Add NormalEstimationOMP * Make cmake set lowercase * Change macro to function * Fix unit test->benchmark Co-authored-by: Lars Glud <[email protected]> * Restructure benchmarks * Add more benchmark variants for NormalEstimation * Correct use of ArgumentWarningShown * Hopefully fix build error on 18.04 GCC * Improve formatting * Fix Windows tests/benchmarks * Do not run benchmarks on CIs Co-authored-by: Lars Glud <[email protected]>
1 parent b29cab8 commit 2d7ebf1

File tree

7 files changed

+133
-2
lines changed

7 files changed

+133
-2
lines changed

.ci/azure-pipelines/build/macos.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ steps:
33
# find the commit hash on a quick non-forced update too
44
fetchDepth: 10
55
- script: |
6-
brew install cmake pkg-config boost eigen flann glew libusb qhull vtk glew qt5 libpcap libomp
6+
brew install cmake pkg-config boost eigen flann glew libusb qhull vtk glew qt5 libpcap libomp google-benchmark
77
brew install brewsci/science/openni
88
git clone https://github.com/abseil/googletest.git $GOOGLE_TEST_DIR # the official endpoint changed to abseil/googletest
99
cd $GOOGLE_TEST_DIR && git checkout release-1.8.1
@@ -20,6 +20,7 @@ steps:
2020
-DPCL_ONLY_CORE_POINT_TYPES=ON \
2121
-DBUILD_simulation=ON \
2222
-DBUILD_global_tests=ON \
23+
-DBUILD_benchmarks=ON \
2324
-DBUILD_examples=ON \
2425
-DBUILD_tools=ON \
2526
-DBUILD_apps=ON \

.ci/azure-pipelines/build/ubuntu.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ steps:
1414
-DBUILD_simulation=ON \
1515
-DBUILD_surface_on_nurbs=ON \
1616
-DBUILD_global_tests=ON \
17+
-DBUILD_benchmarks=ON \
1718
-DBUILD_examples=ON \
1819
-DBUILD_tools=ON \
1920
-DBUILD_apps=ON \

.ci/azure-pipelines/build/windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ steps:
1414
-DPCL_BUILD_WITH_FLANN_DYNAMIC_LINKING_WIN32=ON ^
1515
-DPCL_BUILD_WITH_QHULL_DYNAMIC_LINKING_WIN32=ON ^
1616
-DBUILD_global_tests=ON ^
17+
-DBUILD_benchmarks=ON ^
1718
-DBUILD_tools=OFF ^
1819
-DBUILD_surface_on_nurbs=ON ^
1920
-DPCL_DISABLE_VISUALIZATION_TESTS=ON

.dev/format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
format() {
1010
# don't use a directory with whitespace
11-
local whitelist="apps/3d_rec_framework apps/include apps/modeler apps/src 2d geometry ml octree simulation stereo tracking registration gpu/containers"
11+
local whitelist="apps/3d_rec_framework apps/include apps/modeler apps/src benchmarks 2d geometry ml octree simulation stereo tracking registration gpu/containers"
1212

1313
local PCL_DIR="${2}"
1414
local formatter="${1}"

benchmarks/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(SUBSYS_NAME benchmarks)
2+
set(SUBSYS_DESC "Point cloud library benchmarks")
3+
set(SUBSYS_DEPS common features search kdtree io)
4+
set(DEFAULT OFF)
5+
set(build TRUE)
6+
set(REASON "Disabled by default")
7+
PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ${DEFAULT} "${REASON}")
8+
PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS})
9+
if(NOT build)
10+
return()
11+
endif()
12+
13+
find_package(benchmark REQUIRED)
14+
add_custom_target(run_benchmarks)
15+
16+
PCL_ADD_BENCHMARK(features_normal_3d FILES features/normal_3d.cpp
17+
LINK_WITH pcl_io pcl_search pcl_features
18+
ARGUMENTS "${PCL_SOURCE_DIR}/test/table_scene_mug_stereo_textured.pcd"
19+
"${PCL_SOURCE_DIR}/test/milk_cartoon_all_small_clorox.pcd")

benchmarks/features/normal_3d.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <pcl/features/normal_3d.h> // for NormalEstimation
2+
#include <pcl/features/normal_3d_omp.h> // for NormalEstimationOMP
3+
#include <pcl/io/pcd_io.h> // for PCDReader
4+
5+
#include <benchmark/benchmark.h>
6+
7+
static void
8+
BM_NormalEstimation(benchmark::State& state, const std::string& file)
9+
{
10+
// Perform setup here
11+
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
12+
pcl::PCDReader reader;
13+
reader.read(file, *cloud);
14+
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
15+
ne.setInputCloud(cloud);
16+
ne.setKSearch(state.range(0));
17+
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);
18+
for (auto _ : state) {
19+
// This code gets timed
20+
ne.compute(*cloud_normals);
21+
}
22+
}
23+
24+
#ifdef _OPENMP
25+
static void
26+
BM_NormalEstimationOMP(benchmark::State& state, const std::string& file)
27+
{
28+
// Perform setup here
29+
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
30+
pcl::PCDReader reader;
31+
reader.read(file, *cloud);
32+
pcl::NormalEstimationOMP<pcl::PointXYZ, pcl::Normal> ne;
33+
ne.setInputCloud(cloud);
34+
ne.setKSearch(100);
35+
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);
36+
for (auto _ : state) {
37+
// This code gets timed
38+
ne.compute(*cloud_normals);
39+
}
40+
}
41+
#endif
42+
43+
int
44+
main(int argc, char** argv)
45+
{
46+
if (argc < 3) {
47+
std::cerr
48+
<< "No test files given. Please download `table_scene_mug_stereo_textured.pcd` "
49+
"and `milk_cartoon_all_small_clorox.pcd`, and pass their paths to the test."
50+
<< std::endl;
51+
return (-1);
52+
}
53+
benchmark::RegisterBenchmark("BM_NormalEstimation_mug", &BM_NormalEstimation, argv[1])
54+
->Arg(50)
55+
->Arg(100)
56+
->Unit(benchmark::kMillisecond);
57+
benchmark::RegisterBenchmark(
58+
"BM_NormalEstimation_milk", &BM_NormalEstimation, argv[2])
59+
->Arg(50)
60+
->Arg(100)
61+
->Unit(benchmark::kMillisecond);
62+
#ifdef _OPENMP
63+
benchmark::RegisterBenchmark(
64+
"BM_NormalEstimationOMP", &BM_NormalEstimationOMP, argv[1])
65+
->Unit(benchmark::kMillisecond);
66+
#endif
67+
benchmark::Initialize(&argc, argv);
68+
benchmark::RunSpecifiedBenchmarks();
69+
}

cmake/pcl_targets.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,46 @@ macro(PCL_ADD_TEST _name _exename)
411411
add_dependencies(tests ${_exename})
412412
endmacro()
413413

414+
###############################################################################
415+
# Add a benchmark target.
416+
# _name The benchmark name.
417+
# ARGN :
418+
# FILES the source files for the benchmark
419+
# ARGUMENTS Arguments for benchmark executable
420+
# LINK_WITH link benchmark executable with libraries
421+
function(PCL_ADD_BENCHMARK _name)
422+
set(options)
423+
set(oneValueArgs)
424+
set(multiValueArgs FILES ARGUMENTS LINK_WITH)
425+
cmake_parse_arguments(PCL_ADD_BENCHMARK "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
426+
427+
add_executable(benchmark_${_name} ${PCL_ADD_BENCHMARK_FILES})
428+
set_target_properties(benchmark_${_name} PROPERTIES FOLDER "Benchmarks")
429+
target_link_libraries(benchmark_${_name} benchmark::benchmark ${PCL_ADD_BENCHMARK_LINK_WITH})
430+
set_target_properties(benchmark_${_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
431+
432+
#Only applies to MSVC
433+
if(MSVC)
434+
#Requires CMAKE version 3.13.0
435+
get_target_property(BenchmarkArgumentWarningShown run_benchmarks PCL_BENCHMARK_ARGUMENTS_WARNING_SHOWN)
436+
if(CMAKE_VERSION VERSION_LESS "3.13.0" AND (NOT BenchmarkArgumentWarningShown))
437+
message(WARNING "Arguments for benchmark projects are not added - this requires at least CMake 3.13. Can be added manually in \"Project settings -> Debugging -> Command arguments\"")
438+
set_target_properties(run_benchmarks PROPERTIES PCL_BENCHMARK_ARGUMENTS_WARNING_SHOWN TRUE)
439+
else()
440+
#Only add if there are arguments to test
441+
if(PCL_ADD_BENCHMARK_ARGUMENTS)
442+
string (REPLACE ";" " " PCL_ADD_BENCHMARK_ARGUMENTS_STR "${PCL_ADD_BENCHMARK_ARGUMENTS}")
443+
set_target_properties(benchmark_${_name} PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS ${PCL_ADD_BENCHMARK_ARGUMENTS_STR})
444+
endif()
445+
endif()
446+
endif()
447+
448+
add_custom_target(run_benchmark_${_name} benchmark_${_name} ${PCL_ADD_BENCHMARK_ARGUMENTS})
449+
set_target_properties(run_benchmark_${_name} PROPERTIES FOLDER "Benchmarks")
450+
451+
add_dependencies(run_benchmarks run_benchmark_${_name})
452+
endfunction()
453+
414454
###############################################################################
415455
# Add an example target.
416456
# _name The example name.

0 commit comments

Comments
 (0)