Skip to content

Commit

Permalink
Fix IPP benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebionne committed Jul 28, 2023
1 parent 2c2fb7a commit 30d6c6c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 25 deletions.
8 changes: 8 additions & 0 deletions benchmark/google/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ endforeach()
unset(_benchmarks)
unset(_benchmark)


#-----------------------------------------------------------------------------
# Options
#-----------------------------------------------------------------------------
option(BOOST_GIL_BUILD_BENCHMARKS_OPENCV "Builds all OpenCV benchmarks" OFF)
option(BOOST_GIL_BUILD_BENCHMARKS_BLAZE "Builds all BLAZE benchmarks" OFF)
option(BOOST_GIL_BUILD_BENCHMARKS_IPP "Builds all IPP benchmarks" OFF)

if(BOOST_GIL_BUILD_BENCHMARKS_OPENCV)
add_subdirectory(opencv)
endif()
Expand Down
12 changes: 12 additions & 0 deletions benchmark/google/ipp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ add_library(ipp::ipp INTERFACE IMPORTED)
target_include_directories(ipp::ipp INTERFACE ${IPP_INCLUDE_DIR})
target_link_libraries(ipp::ipp INTERFACE ${IPP_LIB_CORE} ${IPP_LIB_I})

#-----------------------------------------------------------------------------
# Build benchmarks
#-----------------------------------------------------------------------------
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
file(GLOB _benchmarks ${CMAKE_CURRENT_LIST_DIR}/*.cpp CONFIGURE_DEPEND)
else()
file(GLOB _benchmarks ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
endif()

foreach(_benchmark ${_benchmarks})
get_filename_component(_name ${_benchmark} NAME_WE)
set(_target benchmark_google_ipp_${_name})
Expand All @@ -31,3 +40,6 @@ foreach(_benchmark ${_benchmarks})
gil_googlebenchmark
ipp::ipp)
endforeach()

unset(_benchmarks)
unset(_benchmark)
60 changes: 43 additions & 17 deletions benchmark/google/ipp/view_flip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <boost/gil.hpp>

inline bool is_odd(benchmark::IterationCount cnt) { return (cnt % 2); }

static void ipp_flip_left_right(benchmark::State& state)
{
using namespace boost::gil;
Expand All @@ -24,11 +26,14 @@ static void ipp_flip_left_right(benchmark::State& state)

for (auto _ : state) {
// The code to benchmark
ippiMirror_8u_C1R(
boost::gil::interleaved_view_get_raw_data(const_view(in)), (int) in.width(),
boost::gil::interleaved_view_get_raw_data(view(out)), (int) out.width(),
auto res = ippiMirror_8u_C1R(
boost::gil::interleaved_view_get_raw_data(const_view(in)), (int)const_view(in).pixels().row_size(),
boost::gil::interleaved_view_get_raw_data(view(out)), (int)view(in).pixels().row_size(),
srcRoi,
ippAxsVertical);

if (res != ippStsNoErr)
state.SkipWithError("ipp_flip_left_right failed");
}

if (!equal_pixels(flipped_left_right_view(const_view(in)), const_view(out)))
Expand All @@ -50,14 +55,23 @@ static void ipp_flip_left_right_inplace(benchmark::State& state)

for (auto _ : state) {
// The code to benchmark
ippiMirror_8u_C1IR(
boost::gil::interleaved_view_get_raw_data(view(in)), (int) in.width(),
auto res = ippiMirror_8u_C1IR(
boost::gil::interleaved_view_get_raw_data(view(in)), (int)view(in).pixels().row_size(),
srcRoi,
ippAxsVertical);

if (res != ippStsNoErr)
state.SkipWithError("ipp_flip_left_right_inplace failed");
}

if (is_odd(state.iterations())) {
if (!equal_pixels(flipped_left_right_view(const_view(in_ref)), const_view(in)))
state.SkipWithError("ipp_flip_left_right_inplace wrong result");
}
else {
if (!equal_pixels(const_view(in_ref), const_view(in)))
state.SkipWithError("ipp_flip_left_right_inplace wrong result");
}

if (!equal_pixels(flipped_left_right_view(const_view(in)), const_view(in_ref)))
state.SkipWithError("ipp_flip_left_right_inplace wrong result");
}
BENCHMARK(ipp_flip_left_right_inplace)->RangeMultiplier(2)->Range(256, 8 << 10);

Expand All @@ -75,15 +89,24 @@ static void ipp_flip_up_down(benchmark::State& state)

for (auto _ : state) {
// The code to benchmark
ippiMirror_8u_C1R(
boost::gil::interleaved_view_get_raw_data(const_view(in)), (int) in.width(),
boost::gil::interleaved_view_get_raw_data(view(out)), (int) out.width(),
auto res = ippiMirror_8u_C1R(
boost::gil::interleaved_view_get_raw_data(const_view(in)), (int)const_view(in).pixels().row_size(),
boost::gil::interleaved_view_get_raw_data(view(out)), (int)view(out).pixels().row_size(),
srcRoi,
ippAxsHorizontal);

if (res != ippStsNoErr)
state.SkipWithError("ipp_flip_up_down failed");
}

if (is_odd(state.iterations())) {
if (!equal_pixels(flipped_up_down_view(const_view(in)), const_view(out)))
state.SkipWithError("ipp_flip_up_down wrong result");
}
else {
if (!equal_pixels(const_view(in), const_view(out)))
state.SkipWithError("ipp_flip_up_down wrong result");
}

if (!equal_pixels(flipped_left_right_view(const_view(in)), const_view(out)))
state.SkipWithError("ipp_flip_up_down wrong result");
}
BENCHMARK(ipp_flip_up_down)->RangeMultiplier(2)->Range(256, 8 << 10);

Expand All @@ -101,13 +124,16 @@ static void ipp_flip_up_down_inplace(benchmark::State& state)

for (auto _ : state) {
// The code to benchmark
ippiMirror_8u_C1IR(
boost::gil::interleaved_view_get_raw_data(view(in)), (int) in.width(),
auto res = ippiMirror_8u_C1IR(
boost::gil::interleaved_view_get_raw_data(view(in)), (int)view(in).pixels().row_size(),
srcRoi,
ippAxsHorizontal);

if (res != ippStsNoErr)
state.SkipWithError("ipp_flip_up_down_inplace failed");
}

if (!equal_pixels(flipped_left_right_view(const_view(in)), const_view(in_ref)))
if (!equal_pixels(flipped_up_down_view(const_view(in_ref)), const_view(in)))
state.SkipWithError("ipp_flip_up_down_inplace wrong result");
}
BENCHMARK(ipp_flip_up_down_inplace)->RangeMultiplier(2)->Range(256, 8 << 10);
Expand Down
33 changes: 25 additions & 8 deletions benchmark/google/ipp/view_transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <boost/gil.hpp>

inline bool is_odd(benchmark::IterationCount cnt) { return (cnt % 2); }

static void ipp_transpose(benchmark::State& state)
{
using namespace boost::gil;
Expand All @@ -24,10 +26,13 @@ static void ipp_transpose(benchmark::State& state)

for (auto _ : state) {
// The code to benchmark
ippiTranspose_8u_C1R(
boost::gil::interleaved_view_get_raw_data(const_view(in)), (int) in.width(),
boost::gil::interleaved_view_get_raw_data(view(out)), (int) out.width(),
auto res = ippiTranspose_8u_C1R(
boost::gil::interleaved_view_get_raw_data(const_view(in)), (int) const_view(in).pixels().row_size(),
boost::gil::interleaved_view_get_raw_data(view(out)), (int)const_view(out).pixels().row_size(),
srcRoi);

if (res != ippStsNoErr)
state.SkipWithError("ipp_transpose_inplace failed");
}

if (!equal_pixels(transposed_view(const_view(in)), const_view(out)))
Expand All @@ -45,17 +50,29 @@ static void ipp_transpose_inplace(benchmark::State& state)
generate_pixels(view(in), [i = 0]() mutable -> std::uint8_t { return ++i; });
gray8_image_t in_ref(in);

if (!equal_pixels(const_view(in_ref), const_view(in)))
state.SkipWithError("ipp_transpose_inplace wrong init");

IppiSize srcRoi = { dim, dim };

for (auto _ : state) {
// The code to benchmark
ippiTranspose_8u_C1IR(
boost::gil::interleaved_view_get_raw_data(view(in)), (int) in.width(),
auto res = ippiTranspose_8u_C1IR(
boost::gil::interleaved_view_get_raw_data(view(in)), (int)const_view(in).pixels().row_size(),
srcRoi);

if (res != ippStsNoErr)
state.SkipWithError("ipp_transpose_inplace failed");
}

if (is_odd(state.iterations())) {
if (!equal_pixels(transposed_view(const_view(in_ref)), const_view(in)))
state.SkipWithError("ipp_transpose_inplace wrong result");
}
else {
if (!equal_pixels(const_view(in_ref), const_view(in)))
state.SkipWithError("ipp_transpose_inplace wrong result");
}

if (!equal_pixels(transposed_view(const_view(in_ref)), const_view(in)))
state.SkipWithError("ipp_transpose_inplace wrong result");
}
BENCHMARK(ipp_transpose_inplace)->RangeMultiplier(2)->Range(256, 8 << 10);

Expand Down

0 comments on commit 30d6c6c

Please sign in to comment.