diff --git a/unit_tests/operator/Test_PadImpl.cpp b/unit_tests/operator/Test_PadImpl.cpp index 5efc5bd36fb582cb2cf27ba739064fbd410a0751..904fab596a938e53134dae4b09dce099a7f9bb7d 100644 --- a/unit_tests/operator/Test_PadImpl.cpp +++ b/unit_tests/operator/Test_PadImpl.cpp @@ -14,6 +14,7 @@ #include <aidge/utils/Types.h> #include <memory> +#include <catch2/benchmark/catch_benchmark.hpp> #include <catch2/catch_test_macros.hpp> #include "aidge/backend/cpu/data/TensorImpl.hpp" @@ -714,5 +715,74 @@ TEST_CASE("[cpu/operator] Pad(forward)", "[Pad][CPU]") { {-2, 2, 2, -2, 2, 2, -2}}}}}})); CHECK(approxEq<float>(*padOp->getOutput(0), expectedOutput)); } + SECTION("Benchmark test") { + Log::setConsoleLevel(Log::Level::Error); + constexpr DimSize_t batch = 1; + constexpr DimSize_t channel = 1; + constexpr std::array<DimSize_t, DIM> inDataSize = {3, 3, 3}; + constexpr std::array<DimSize_t, 2 * DIM> beginEndBorder = + {1, 1, 1, 1, 1, 1}; + constexpr std::array<DimSize_t, DIM> outDataSize = { + inDataSize[0] + beginEndBorder[0] + beginEndBorder[3], + inDataSize[1] + beginEndBorder[1] + beginEndBorder[4], + inDataSize[2] + beginEndBorder[2] + beginEndBorder[5]}; + auto input = std::make_shared<Tensor>(Array5D<float, + batch, + channel, + inDataSize[0], + inDataSize[1], + inDataSize[2]>( + {{{{{{1., 2., 3.}, {4., 5., 6.}, {7., 8., 9.}}, + + {{10., 11., 12.}, {13., 14., 15.}, {16., 17., 18.}}, + + {{19., 20., 21.}, {22., 23., 24.}, {25., 26., 27.}}}}}})); + auto padOp = setupTestPad<DIM>(beginEndBorder, + input, + PadBorderType::Reflect, + 0); + + BENCHMARK("Padding 3D") { + REQUIRE_NOTHROW(padOp->forward()); + return; + }; + + Tensor expectedOutput( + Array5D<float, + batch, + channel, + outDataSize[0], + outDataSize[1], + outDataSize[2]>({{{{{{14., 13., 14., 15., 14.}, + {11., 10., 11., 12., 11.}, + {14., 13., 14., 15., 14.}, + {17., 16., 17., 18., 17.}, + {14., 13., 14., 15., 14.}}, + + {{5., 4., 5., 6., 5.}, + {2., 1., 2., 3., 2.}, + {5., 4., 5., 6., 5.}, + {8., 7., 8., 9., 8.}, + {5., 4., 5., 6., 5.}}, + + {{14., 13., 14., 15., 14.}, + {11., 10., 11., 12., 11.}, + {14., 13., 14., 15., 14.}, + {17., 16., 17., 18., 17.}, + {14., 13., 14., 15., 14.}}, + + {{23., 22., 23., 24., 23.}, + {20., 19., 20., 21., 20.}, + {23., 22., 23., 24., 23.}, + {26., 25., 26., 27., 26.}, + {23., 22., 23., 24., 23.}}, + + {{14., 13., 14., 15., 14.}, + {11., 10., 11., 12., 11.}, + {14., 13., 14., 15., 14.}, + {17., 16., 17., 18., 17.}, + {14., 13., 14., 15., 14.}}}}}})); + CHECK(approxEq<float>(*padOp->getOutput(0), expectedOutput)); + } } }