From 42d59a7b26e5518b693a203e703f7554c3ef73b8 Mon Sep 17 00:00:00 2001 From: alexey-varyzgin Date: Thu, 28 Jan 2021 21:12:18 +0300 Subject: [PATCH] Deconvolution tests were added --- .../convolution_backprop_data.cpp | 378 ++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100755 inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution_backprop_data.cpp diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution_backprop_data.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution_backprop_data.cpp new file mode 100755 index 00000000000000..4ad39dcb60a8fb --- /dev/null +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution_backprop_data.cpp @@ -0,0 +1,378 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "test_utils/cpu_test_utils.hpp" +#include "test_utils/fusing_test_utils.hpp" +#include "shared_test_classes/base/layer_test_utils.hpp" +#include "ngraph_functions/utils/ngraph_helpers.hpp" +#include "ngraph_functions/builders.hpp" +#include + + +using namespace InferenceEngine; +using namespace CPUTestUtils; + +namespace CPULayerTestsDefinitions { +using LayerTestsDefinitions::convBackpropDataSpecificParams; +using LayerTestsDefinitions::convBackpropDataLayerTestParamsSet; + +typedef std::tuple< + convBackpropDataLayerTestParamsSet, + CPUSpecificParams, + fusingSpecificParams, + std::map > deconvLayerCPUTestParamsSet; + +class DeconvolutionLayerCPUTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon, public CpuTestWithFusing { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + convBackpropDataLayerTestParamsSet basicParamsSet; + CPUSpecificParams cpuParams; + fusingSpecificParams fusingParams; + std::map additionalConfig; + std::tie(basicParamsSet, cpuParams, fusingParams, additionalConfig) = obj.param; + + std::ostringstream result; + result << LayerTestsDefinitions::ConvolutionBackpropDataLayerTest::getTestCaseName(testing::TestParamInfo( + basicParamsSet, 0)); + + result << CPUTestsBase::getTestCaseName(cpuParams); + result << CpuTestWithFusing::getTestCaseName(fusingParams); + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto& item : additionalConfig) { + result << "_" << item.first << "=" << item.second; + } + } + + return result.str(); + } +protected: + void SetUp() override { + convBackpropDataLayerTestParamsSet basicParamsSet; + CPUSpecificParams cpuParams; + fusingSpecificParams fusingParams; + std::map additionalConfig; + std::tie(basicParamsSet, cpuParams, fusingParams, additionalConfig) = this->GetParam(); + + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; + std::tie(postOpMgrPtr, fusedOps) = fusingParams; + + convBackpropDataSpecificParams convParams; + std::vector inputShape; + auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; + std::tie(convParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetDevice) = basicParamsSet; + + if (inPrc == Precision::UNSPECIFIED) { + selectedType += std::string("_") + Precision(Precision::FP32).name(); + } else { + selectedType += std::string("_") + inPrc.name(); + } + + ngraph::op::PadType padType; + InferenceEngine::SizeVector kernel, stride, dilation; + std::vector padBegin, padEnd; + size_t convOutChannels; + std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, padType) = convParams; + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + + auto inputParams = ngraph::builder::makeParams(ngraph::element::f32, { inputShape }); + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(inputParams)); + + auto deconvolutionNode = ngraph::builder::makeConvolutionBackpropData(paramOuts.front(), ngPrc, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels); +threshold = 0.1f; + function = makeNgraphFunction(ngPrc, inputParams, deconvolutionNode, "convolutionBackpropData"); + } +}; + +TEST_P(DeconvolutionLayerCPUTest, CompareWithRefs) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + + Run(); +// CheckPluginRelatedResults(executableNetwork, "Deconvolution"); +} + +namespace { + +/* COMMON PARAMS */ +const std::vector fusingParamsSet{ + emptyFusingSpec, + // activations + fusingRelu, + fusingElu, + fusingSigmoid, + fusingClamp, + fusingPRelu, + fusingSwish, + // other patterns + fusingReluScaleShift, + fusingFakeQuantizePerTensorRelu, + fusingFakeQuantizePerChannelRelu, + fusingSumEluFQ, + fusingSum +}; + +const std::vector fusingParamsSetBF16{ + emptyFusingSpec, + // activations + fusingRelu, + fusingElu, + fusingSigmoid, + fusingClamp, + fusingPRelu, + fusingSwish, + // other patterns + fusingReluScaleShift, + fusingSum +}; + +const std::map cpuEmptyPluginConfig; +const std::map cpuBF16PluginConfig = { { PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES } }; + +/* ============= Deconvolution params (planar layout) ============= */ +const SizeVector numOutChannels_Planar = { 6 }; + +/* ============= Deconvolution params (blocked layout) ============= */ +const SizeVector numOutChannels_Blocked = { 64 }; + +/* ============= Deconvolution params (2D) ============= */ +const std::vector kernels2d = { {3, 3}, {1, 1} }; +const std::vector strides2d = { {1, 1}, {2, 2} }; +const std::vector> padBegins2d = { {0, 0} }; +const std::vector> padEnds2d = { {0, 0} }; +const std::vector dilations2d = { {1, 1} }; + +/* ============= Deconvolution params (3D) ============= */ +const std::vector kernels3d = { {3, 3, 3}, {1, 1, 1} }; +const std::vector strides3d = { {1, 1, 1}, {2, 2, 2} }; +const std::vector> padBegins3d = { {0, 0, 0} }; +const std::vector> padEnds3d = { {0, 0, 0} }; +const std::vector dilations3d = { {1, 1, 1} }; +/* ============= */ + +/* INSTANCES */ +/* ============= Deconvolution (Planar 2D) ============= */ +const auto convParams_ExplicitPadding_Planar_2D = ::testing::Combine( + ::testing::ValuesIn(kernels2d), + ::testing::ValuesIn(strides2d), + ::testing::ValuesIn(padBegins2d), + ::testing::ValuesIn(padEnds2d), + ::testing::ValuesIn(dilations2d), + ::testing::ValuesIn(numOutChannels_Planar), + ::testing::Values(ngraph::op::PadType::EXPLICIT) +); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_Planar_FP32, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Planar_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_gemm_2D})), + ::testing::ValuesIn(fusingParamsSet), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_Planar_BF16, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Planar_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::BF16), + ::testing::Values(Precision::BF16), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_gemm_2D})), + ::testing::ValuesIn(fusingParamsSetBF16), + ::testing::Values(cpuBF16PluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +/* ============= GroupDeconvolution (Planar 3D) ============= */ +const auto convParams_ExplicitPadding_Planar_3D = ::testing::Combine( + ::testing::ValuesIn(kernels3d), + ::testing::ValuesIn(strides3d), + ::testing::ValuesIn(padBegins3d), + ::testing::ValuesIn(padEnds3d), + ::testing::ValuesIn(dilations3d), + ::testing::ValuesIn(numOutChannels_Planar), + ::testing::Values(ngraph::op::PadType::EXPLICIT) +); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_3D_Planar_FP32, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Planar_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_gemm_3D})), + ::testing::ValuesIn(fusingParamsSet), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_3D_Planar_BF16, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Planar_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::BF16), + ::testing::Values(Precision::BF16), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_gemm_3D})), + ::testing::ValuesIn(fusingParamsSetBF16), + ::testing::Values(cpuBF16PluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +/* ============= GroupDeconvolution (Blocked 2D) ============= */ +const auto convParams_ExplicitPadding_Blocked_2D = ::testing::Combine( + ::testing::ValuesIn(kernels2d), + ::testing::ValuesIn(strides2d), + ::testing::ValuesIn(padBegins2d), + ::testing::ValuesIn(padEnds2d), + ::testing::ValuesIn(dilations2d), + ::testing::ValuesIn(numOutChannels_Blocked), + ::testing::Values(ngraph::op::PadType::EXPLICIT) +); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_Blocked_FP32, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Blocked_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_avx512_2D})), + ::testing::ValuesIn(fusingParamsSet), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_Blocked_BF16, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Blocked_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::BF16), + ::testing::Values(Precision::BF16), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_avx512_2D})), + ::testing::ValuesIn(fusingParamsSetBF16), + ::testing::Values(cpuBF16PluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +/* ============= GroupDeconvolution (Blocked 3D) ============= */ +const auto convParams_ExplicitPadding_Blocked_3D = ::testing::Combine( + ::testing::ValuesIn(kernels3d), + ::testing::ValuesIn(strides3d), + ::testing::ValuesIn(padBegins3d), + ::testing::ValuesIn(padEnds3d), + ::testing::ValuesIn(dilations3d), + ::testing::ValuesIn(numOutChannels_Blocked), + ::testing::Values(ngraph::op::PadType::EXPLICIT) +); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_3D_Blocked_FP32, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Blocked_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_avx512_3D})), + ::testing::ValuesIn(fusingParamsSet), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_3D_Blocked_BF16, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_Blocked_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::BF16), + ::testing::Values(Precision::BF16), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_avx512_3D})), + ::testing::ValuesIn(fusingParamsSetBF16), + ::testing::Values(cpuBF16PluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +/* ============= Kernel_1x1 (2D) ============= */ + +const auto convParams_ExplicitPadding_1x1_2D = ::testing::Combine( + ::testing::Values(SizeVector({1, 1})), + ::testing::Values(SizeVector({1, 1})), + ::testing::Values(std::vector({0, 0})), + ::testing::Values(std::vector({0, 0})), + ::testing::Values(SizeVector({1, 1})), + ::testing::ValuesIn(numOutChannels_Blocked), + ::testing::Values(ngraph::op::PadType::EXPLICIT) +); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_1x1_FP32, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_1x1_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Precision::UNSPECIFIED), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_avx512_2D_1x1})), + ::testing::ValuesIn(fusingParamsSet), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_1x1_BF16, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_1x1_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::BF16), + ::testing::Values(Precision::BF16), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_avx512_2D_1x1})), + ::testing::ValuesIn(fusingParamsSetBF16), + ::testing::Values(cpuBF16PluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +/* ========= */ + +} // namespace +} // namespace CPULayerTestsDefinitions