From 874193310e1331bee7089fec3afa65a898c0ba73 Mon Sep 17 00:00:00 2001 From: Anton Voronov Date: Tue, 13 Apr 2021 04:50:37 +0300 Subject: [PATCH 1/2] [CPU] [TESTS] cpu tests improvements 1. extended cpu specific tests to support int8 presision 2. added int8 deconvolution fusing tests --- .../cpu/single_layer_tests/convolution.cpp | 211 +++++++------ .../convolution_backprop_data.cpp | 181 +++++++++-- .../single_layer_tests/group_convolution.cpp | 139 ++++++++- .../group_convolution_backprop_data.cpp | 289 +++++++++++++++--- .../cpu/test_utils/convolution_params.hpp | 4 + .../plugin/cpu/test_utils/cpu_test_utils.cpp | 7 + .../plugin/cpu/test_utils/cpu_test_utils.hpp | 5 + .../cpu/test_utils/fusing_test_utils.cpp | 2 +- .../base/layer_test_utils.hpp | 2 + .../src/base/layer_test_utils.cpp | 3 + .../ngraph_functions/CMakeLists.txt | 1 + .../include/ngraph_functions/builders.hpp | 47 +++ .../ngraph_functions/src/convolution.cpp | 29 ++ .../src/convolution_backprop_data.cpp | 31 +- .../src/group_convolution.cpp | 37 ++- .../src/group_convolution_backprop_data.cpp | 36 ++- 16 files changed, 861 insertions(+), 163 deletions(-) diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp index b8d447d5a2737f..e148a972bfc8b2 100755 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp @@ -77,7 +77,17 @@ class ConvolutionLayerCPUTest : public testing::WithParamInterface padBegin, padEnd; size_t convOutChannels; std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, padType) = convParams; - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + auto ngPrc = (inPrc == Precision::BF16) + ? FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32) + : FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrc); - auto inputParams = ngraph::builder::makeParams(ngraph::element::f32, { inputShape }); - auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(inputParams)); + auto inputParams = builder::makeParams(ngPrc, { inputShape }); + auto paramOuts = helpers::convert2OutputVector(helpers::castOps2Nodes(inputParams)); - auto convolutionNode = ngraph::builder::makeConvolution(paramOuts.front(), ngPrc, kernel, stride, padBegin, + auto weiPrc = (ngPrc == element::u8) ? element::i8 : ngPrc; + auto convolutionNode = builder::makeConvolutionRelaxed(paramOuts.front(), weiPrc, kernel, stride, padBegin, padEnd, dilation, padType, convOutChannels); - function = makeNgraphFunction(ngPrc, inputParams, convolutionNode, "Convolution"); + if (inPrc == Precision::U8 || inPrc == Precision::I8) { + threshold = 1.001f; + outElemType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + quantizeInHigh = calculateQuantizeInHigh(kernel, inputShape[1]); + additionalPasses.push_back(std::make_shared>()); + additionalPasses.push_back(std::make_shared>()); + } + + function = makeNgraphFunction(element::f32, inputParams, convolutionNode, "Convolution"); } }; @@ -179,7 +201,7 @@ const std::map cpuEmptyPluginConfig; const std::map cpuBF16PluginConfig = { { PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES } }; /* ============= Convolution params (GEMM layout) ============= */ -const SizeVector numOutChannels_Gemm = {6 }; +const SizeVector numOutChannels_Gemm = { 6 }; /* ============= Convolution params (blocked and nspc layout) ============= */ const SizeVector numOutChannels = { 64, 63 }; @@ -252,21 +274,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_GEMM_BF16, ConvolutionLayerCPUTest, ::testing::Values(cpuBF16PluginConfig)), ConvolutionLayerCPUTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_GEMM_I8, ConvolutionLayerCPUTest, - ::testing::Combine( - ::testing::Combine( - convParams_ExplicitPadding_GEMM_2D, - ::testing::Values(Precision::FP32), - ::testing::Values(Precision::I8), - ::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(CPUParams_GEMM_2D)), - ::testing::Values(fusingSum), - ::testing::Values(cpuEmptyPluginConfig)), - ConvolutionLayerCPUTest::getTestCaseName); /* ============= Convolution (GEMM 3D) ============= */ const auto convParams_ExplicitPadding_GEMM_3D = ::testing::Combine( @@ -316,22 +323,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Conv_3D_GEMM_BF16, ConvolutionLayerCPUTest, ::testing::Values(cpuBF16PluginConfig)), ConvolutionLayerCPUTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_Conv_3D_GEMM_I8, ConvolutionLayerCPUTest, - ::testing::Combine( - ::testing::Combine( - convParams_ExplicitPadding_GEMM_3D, - ::testing::Values(Precision::FP32), - ::testing::Values(Precision::I8), - ::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(CPUParams_GEMM_3D)), - ::testing::Values(fusingSum), - ::testing::Values(cpuEmptyPluginConfig)), - ConvolutionLayerCPUTest::getTestCaseName); - /* ============= Convolution (2D) ============= */ const auto convParams_ExplicitPadding_2D = ::testing::Combine( ::testing::ValuesIn(kernels2d), @@ -384,21 +375,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_BF16, ConvolutionLayerCPUTest, ::testing::Values(cpuBF16PluginConfig)), ConvolutionLayerCPUTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_I8, ConvolutionLayerCPUTest, - ::testing::Combine( - ::testing::Combine( - convParams_ExplicitPadding_2D, - ::testing::Values(Precision::FP32), - ::testing::Values(Precision::I8), - ::testing::Values(Precision::UNSPECIFIED), - ::testing::Values(Layout::ANY), - ::testing::Values(Layout::ANY), - ::testing::ValuesIn(inputShapes2d), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), - ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D)), - ::testing::Values(fusingSum), - ::testing::Values(cpuEmptyPluginConfig)), - ConvolutionLayerCPUTest::getTestCaseName); const std::vector CPUParams_2D_plain_to_blocked = { conv_sse42_plain_to_blocked_2D, @@ -489,22 +465,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Conv_3D_BF16, ConvolutionLayerCPUTest, ::testing::Values(cpuBF16PluginConfig)), ConvolutionLayerCPUTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_Conv_3D_I8, ConvolutionLayerCPUTest, - ::testing::Combine( - ::testing::Combine( - convParams_ExplicitPadding_3D, - ::testing::Values(Precision::FP32), - ::testing::Values(Precision::I8), - ::testing::Values(Precision::UNSPECIFIED), - ::testing::Values(Layout::ANY), - ::testing::Values(Layout::ANY), - ::testing::ValuesIn(inputShapes3d), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), - ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_3D)), - ::testing::Values(fusingSum), - ::testing::Values(cpuEmptyPluginConfig)), - ConvolutionLayerCPUTest::getTestCaseName); - const std::vector CPUParams_3D_plain_to_blocked = { conv_avx2_plain_to_blocked_3D, conv_avx512_plain_to_blocked_3D, @@ -595,22 +555,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_1x1_BF16, ConvolutionLayerCPUTest, ::testing::Values(cpuBF16PluginConfig)), ConvolutionLayerCPUTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_1x1_I8, ConvolutionLayerCPUTest, - ::testing::Combine( - ::testing::Combine( - convParams_ExplicitPadding_1x1_2D, - ::testing::Values(Precision::FP32), - ::testing::Values(Precision::I8), - ::testing::Values(Precision::UNSPECIFIED), - ::testing::Values(Layout::ANY), - ::testing::Values(Layout::ANY), - ::testing::ValuesIn(inputShapes2d), - ::testing::Values(CommonTestUtils::DEVICE_CPU)), - ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_1x1_2D)), - ::testing::Values(fusingSum), - ::testing::Values(cpuEmptyPluginConfig)), - ConvolutionLayerCPUTest::getTestCaseName); - /* ============= Convolution (1D) ============= */ /* ============= Convolution params (1D) ============= */ const std::vector kernels1d = { {3} }; @@ -770,4 +714,91 @@ INSTANTIATE_TEST_SUITE_P(smoke_Conv_winograd, ConvolutionLayerCPUTest, } // namespace winograd +/* ============= U8/I8 Convolution ============= */ +namespace int8 { + +const std::vector fusingParamsSetI8{ + emptyFusingSpec, +// // activations + fusingElu, + fusingSigmoid, + fusingPReluPerChannel, + fusingSwish, + fusingMish, +// // other patterns + fusingSumEluFQ, + fusingSum, + fusingAddPerChannel +}; + +const std::vector CPUParams_2D_I8 = { + conv_gemm_2D_nspc, + conv_sse42_2D_nspc, + conv_avx2_2D_nspc, + conv_avx512_2D_nspc +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_I8, ConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_GEMM_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), // i8 primitives are disabled in oneDNN fork + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + ConvolutionLayerCPUTest::getTestCaseName); + +const std::vector CPUParams_3D_I8 = { + conv_gemm_3D_nspc, + conv_sse42_3D_nspc, + conv_avx2_3D_nspc, + conv_avx512_3D_nspc +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Conv_3D_I8, ConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_GEMM_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), // i8 primitives are disabled in oneDNN fork + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::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(CPUParams_3D_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + ConvolutionLayerCPUTest::getTestCaseName); + +const std::vector CPUParams_1x1_2D_I8 = { + conv_sse42_2D_1x1_nspc, + conv_avx2_2D_1x1_nspc, + conv_avx512_2D_1x1_nspc +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Conv_2D_1x1_I8, ConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_1x1_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), // i8 primitives are disabled in oneDNN fork + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7 })), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_1x1_2D_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + ConvolutionLayerCPUTest::getTestCaseName); + +} // namespace int8 + } // namespace CPULayerTestsDefinitions 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 index df0fdc1e2abb98..d52b536ad49f58 100755 --- 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 @@ -51,7 +51,17 @@ class DeconvolutionLayerCPUTest : public testing::WithParamInterface padBegin, padEnd, outPadding; size_t convOutChannels; std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, padType, outPadding) = 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, false, outPadding); - - if (!outputShape.empty()) { - auto outShape = ngraph::opset3::Constant::create(ngraph::element::i64, {outputShape.size()}, outputShape); - deconvolutionNode = ngraph::builder::makeConvolutionBackpropData(paramOuts.front(), outShape, ngPrc, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels); + auto inElementType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrc); + auto outElementType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + if (inPrc == Precision::BF16) + inElementType = element::f32; + if (outPrc == Precision::BF16) + outElementType = element::f32; + + auto inputParams = builder::makeParams(inElementType, { inputShape }); + auto paramOuts = helpers::convert2OutputVector(helpers::castOps2Nodes(inputParams)); + + auto weiPrc = (inElementType == element::u8) ? element::i8 : inElementType; + + auto deconvolutionNode = builder::makeConvolutionBackpropDataRelaxed(paramOuts.front(), weiPrc, + kernel, stride, padBegin, padEnd, dilation, padType, convOutChannels); + + if (inPrc == Precision::U8 || inPrc == Precision::I8) { + threshold = 1.001f; + outElemType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + quantizeInHigh = calculateQuantizeInHigh(kernel, inputShape[1]); + additionalPasses.push_back(std::make_shared>()); + additionalPasses.push_back(std::make_shared>()); } - function = makeNgraphFunction(ngPrc, inputParams, deconvolutionNode, "convolutionBackpropData"); + function = makeNgraphFunction(element::f32, inputParams, deconvolutionNode, "convolutionBackpropData"); } }; @@ -186,7 +210,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Deconv_2D_Planar_BF16, DeconvolutionLayerCPUTest, ::testing::Values(cpuBF16PluginConfig)), DeconvolutionLayerCPUTest::getTestCaseName); -/* ============= GroupDeconvolution (Planar 3D) ============= */ +/* ============= Deconvolution (Planar 3D) ============= */ const auto convParams_ExplicitPadding_Planar_3D = ::testing::Combine( ::testing::ValuesIn(kernels3d), ::testing::ValuesIn(strides3d), @@ -374,4 +398,127 @@ INSTANTIATE_TEST_SUITE_P(smoke_Deconv_2D_1x1_BF16, DeconvolutionLayerCPUTest, /* ========= */ } // namespace + +/* ============= U8/I8 Deconvolution ============= */ +namespace int8 { + +/* ============= Deconvolution params I8 (2D) ============= */ +const std::vector kernels2di8 = { {3, 3} }; +const std::vector strides2di8 = { {1, 1}, {2, 2} }; +const std::vector> padBegins2di8 = { {0, 0}, {1, 1} }; +const std::vector> padEnds2di8 = { {0, 0}, {1, 1} }; +const std::vector dilations2di8 = { {1, 1}/*, {2, 2}*/ }; + +const auto deconvParams_2D_I8 = ::testing::Combine( + ::testing::ValuesIn(kernels2di8), + ::testing::ValuesIn(strides2di8), + ::testing::ValuesIn(padBegins2di8), + ::testing::ValuesIn(padEnds2di8), + ::testing::ValuesIn(dilations2di8), + ::testing::ValuesIn(numOutChannels_Planar), + ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::ValuesIn(emptyOutputPadding) +); + +const std::vector fusingParamsSetI8{ + emptyFusingSpec, +// // activations + fusingElu, + fusingSigmoid, + fusingPReluPerChannel, + fusingSwish, + fusingMish, +// // other patterns + fusingAddPerChannel +}; + +const std::vector CPUParams_2D_I8 = { + conv_sse42_2D_nspc, + conv_avx2_2D_nspc, + conv_avx512_2D_nspc +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Deconv_2D_I8, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + deconvParams_2D_I8, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8, Precision::I8), + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7 })), + ::testing::ValuesIn(emptyOutputShape), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +// temporarily disabled support for 3D cases in the plug-in +/* ============= Deconvolution params I8 (3D) ============= */ +//const std::vector kernels3di8 = { {3, 3, 3} }; +//const std::vector strides3di8 = { {1, 1, 1}, {2, 2, 2} }; +//const std::vector> padBegins3di8 = { {0, 0, 0}, {1, 1, 1} }; +//const std::vector> padEnds3di8 = { {0, 0, 0}, {1, 1, 1} }; +//const std::vector dilations3di8 = { {1, 1, 1}/*, {2, 2, 2}*/ }; +// +//const auto deconvParams_3D_I8 = ::testing::Combine( +// ::testing::ValuesIn(kernels3di8), +// ::testing::ValuesIn(strides3di8), +// ::testing::ValuesIn(padBegins3di8), +// ::testing::ValuesIn(padEnds3di8), +// ::testing::ValuesIn(dilations3di8), +// ::testing::ValuesIn(numOutChannels_Planar), +// ::testing::Values(ngraph::op::PadType::EXPLICIT), +// ::testing::ValuesIn(emptyOutputPadding) +//); +// +//const std::vector CPUParams_3D_I8 = { +// conv_sse42_3D_nspc, +// conv_avx2_3D_nspc, +// conv_avx512_3D_nspc +//}; +// +//INSTANTIATE_TEST_CASE_P(smoke_Deconv_3D_I8, DeconvolutionLayerCPUTest, +// ::testing::Combine( +// ::testing::Combine( +// deconvParams_3D_I8, +// ::testing::Values(Precision::FP32), +// ::testing::Values(Precision::U8, Precision::I8), +// ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), +// ::testing::Values(Layout::ANY), +// ::testing::Values(Layout::ANY), +// ::testing::Values(std::vector({ 2, 12, 7, 7, 7 })), +// ::testing::ValuesIn(emptyOutputShape), +// ::testing::Values(CommonTestUtils::DEVICE_CPU)), +// ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_3D_I8)), +// ::testing::ValuesIn(fusingParamsSetI8), +// ::testing::Values(cpuEmptyPluginConfig)), +// DeconvolutionLayerCPUTest::getTestCaseName); + +const std::vector CPUParams_2D_1x1_I8 = { + conv_sse42_2D_1x1_nspc, + conv_avx2_2D_1x1_nspc, + conv_avx512_2D_1x1_nspc +}; + +INSTANTIATE_TEST_CASE_P(smoke_Deconv_2D_1x1_I8, DeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + convParams_ExplicitPadding_1x1_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8, Precision::I8), + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 12, 7, 7 })), + ::testing::ValuesIn(emptyOutputShape), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_1x1_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + DeconvolutionLayerCPUTest::getTestCaseName); + +} // namespace int8 } // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp index 814db862ed0bd1..b5d1671237adf5 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp @@ -67,7 +67,18 @@ class GroupConvolutionLayerCPUTest : public testing::WithParamInterface padBegin, padEnd; size_t convOutChannels, numGroups; std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, numGroups, padType) = groupConvParams; - if (inPrc == Precision::UNSPECIFIED) { - selectedType += std::string("_") + Precision(Precision::FP32).name(); + if (inPrc == Precision::UNSPECIFIED) + inPrc = Precision::FP32; + + if (inPrc == Precision::U8) { + selectedType += std::string("_") + Precision(Precision::I8).name(); } else { selectedType += std::string("_") + inPrc.name(); } - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); - auto paramOuts = ngraph::helpers::convert2OutputVector( - ngraph::helpers::castOps2Nodes(params)); - auto groupConv = std::dynamic_pointer_cast( - ngraph::builder::makeGroupConvolution(paramOuts[0], ngPrc, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, numGroups)); - function = makeNgraphFunction(ngPrc, params, groupConv, "groupConvolution"); + auto ngPrc = (inPrc == Precision::BF16) + ? FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(Precision::FP32) + : FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrc); + + auto params = builder::makeParams(ngPrc, {inputShape}); + auto paramOuts = helpers::convert2OutputVector(helpers::castOps2Nodes(params)); + + auto weiPrc = (ngPrc == element::u8) ? element::i8 : ngPrc; + auto groupConv = builder::makeGroupConvolutionRelaxed(paramOuts[0], weiPrc, kernel, stride, padBegin, + padEnd, dilation, padType, convOutChannels, numGroups); + + if (inPrc == Precision::U8 || inPrc == Precision::I8) { + threshold = 1.001f; + outElemType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + quantizeInHigh = calculateQuantizeInHigh(kernel, inputShape[1], numGroups); + additionalPasses.push_back(std::make_shared>()); + additionalPasses.push_back(std::make_shared>()); + } + + function = makeNgraphFunction(element::f32, params, groupConv, "groupConvolution"); } }; @@ -877,4 +903,95 @@ INSTANTIATE_TEST_SUITE_P(smoke_GroupConv_1D, GroupConvolutionLayerCPUTest, } // namespace +/* ============= U8/I8 Convolution ============= */ +namespace int8 { + +const std::vector fusingParamsSetI8{ + emptyFusingSpec, +// // activations + fusingElu, + fusingSigmoid, + fusingPReluPerChannel, + fusingSwish, + fusingMish, +// // other patterns + fusingSumEluFQ, + fusingSum, + fusingAddPerChannel +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GroupConv_2D_Gemm_I8, GroupConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupConvParams_ExplicitPadding_Gemm_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), // i8 primitives are disabled in oneDNN fork + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({2, 12, 7, 7})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_gemm_2D_nspc})), + ::testing::ValuesIn(fusingParamsSetI8)), + GroupConvolutionLayerCPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_GroupConv_3D_Gemm_I8, GroupConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupConvParams_ExplicitPadding_Gemm_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), // i8 primitives are disabled in oneDNN fork + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({2, 12, 7, 7, 7})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice({conv_gemm_3D_nspc})), + ::testing::ValuesIn(fusingParamsSetI8)), + GroupConvolutionLayerCPUTest::getTestCaseName); + +const std::vector CPUParams_2D_I8 = { + conv_sse42_2D_nspc, + conv_avx2_2D_nspc, + conv_avx512_2D_nspc +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GroupConv_2D_I8, GroupConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupConvParams_ExplicitPadding_2D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), // i8 primitives are disabled in oneDNN fork + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({2, 64, 7, 7})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_I8)), + ::testing::ValuesIn(fusingParamsSetI8)), + GroupConvolutionLayerCPUTest::getTestCaseName); + +const std::vector CPUParams_3D_I8 = { + conv_sse42_3D_nspc, + conv_avx2_3D_nspc, + conv_avx512_3D_nspc +}; + +INSTANTIATE_TEST_SUITE_P(smoke_GroupConv_3D_I8, GroupConvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupConvParams_ExplicitPadding_3D, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8 /*, Precision::I8*/), + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), // i8 primitives are disabled in oneDNN fork + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({2, 64, 7, 7, 7})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_3D_I8)), + ::testing::ValuesIn(fusingParamsSetI8)), + GroupConvolutionLayerCPUTest::getTestCaseName); + +} // namespace int8 + } // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp index 1f50a43b80d178..3001e97fdcf311 100755 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp @@ -49,7 +49,18 @@ class GroupDeconvolutionLayerCPUTest : public testing::WithParamInterface padBegin, padEnd, outputPadding; size_t convOutChannels, numGroups; std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, numGroups, padType, outputPadding) = groupConvParams; - - auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); - auto paramOuts = ngraph::helpers::convert2OutputVector( - ngraph::helpers::castOps2Nodes(params)); - std::shared_ptr groupConv; - if (!outputShape.empty()) { - auto outShape = ngraph::opset3::Constant::create(ngraph::element::i64, {outputShape.size()}, outputShape); - groupConv = std::dynamic_pointer_cast( - ngraph::builder::makeGroupConvolutionBackpropData(paramOuts[0], outShape, ngPrc, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, numGroups, false, outputPadding)); - } else { - groupConv = std::dynamic_pointer_cast( - ngraph::builder::makeGroupConvolutionBackpropData(paramOuts[0], ngPrc, kernel, stride, padBegin, - padEnd, dilation, padType, convOutChannels, numGroups, false, outputPadding)); + auto inElementType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inPrc); + auto outElementType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + if (inPrc == Precision::BF16) + inElementType = element::f32; + if (outPrc == Precision::BF16) + outElementType = element::f32; + + auto inputParams = builder::makeParams(inElementType, { inputShape }); + auto paramOuts = helpers::convert2OutputVector(helpers::castOps2Nodes(inputParams)); + + auto weiPrc = (inElementType == element::u8) ? element::i8 : inElementType; + + auto groupConv = ngraph::builder::makeGroupConvolutionBackpropDataRelaxed(paramOuts[0], weiPrc, kernel, + stride, padBegin, padEnd, dilation, padType, convOutChannels, numGroups); + + if (inPrc == Precision::U8 || inPrc == Precision::I8) { + threshold = 1.001f; + outElemType = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(outPrc); + quantizeInHigh = calculateQuantizeInHigh(kernel, inputShape[1], numGroups); + additionalPasses.push_back(std::make_shared>()); + additionalPasses.push_back(std::make_shared>()); } - function = makeNgraphFunction(ngPrc, params, groupConv, "groupConvolutionBackpropData"); + + function = makeNgraphFunction(element::f32, inputParams, groupConv, "groupConvolutionBackpropData"); } }; @@ -106,28 +129,6 @@ TEST_P(GroupDeconvolutionLayerCPUTest, CompareWithRefs) { namespace { -/* GROUP CONV TEST UTILS */ -std::vector filterParamsSetForDevice(std::vector paramsSet) { - std::vector resParamsSet; - const int cpuParamsIndex = 1; - const int selectedTypeIndex = 3; - - for (auto param : paramsSet) { - auto cpuParams = std::get(param); - auto selectedTypeStr = std::get(cpuParams); - - if (selectedTypeStr.find("jit") != std::string::npos && !with_cpu_x86_sse42()) - continue; - if (selectedTypeStr.find("avx512") != std::string::npos && !with_cpu_x86_avx512f()) - continue; - - resParamsSet.push_back(param); - } - - return resParamsSet; -} -/* ===================== */ - /* COMMON PARAMS */ std::vector fusingParamsSet { emptyFusingSpec, @@ -404,4 +405,210 @@ INSTANTIATE_TEST_SUITE_P(smoke_GroupDeconv_2D_DW_BF16, GroupDeconvolutionLayerCP GroupDeconvolutionLayerCPUTest::getTestCaseName); } // namespace +/* ============= U8/I8 Deconvolution ============= */ +namespace int8 { + +const std::vector kernels2di8 = { {3, 3} }; +const std::vector strides2di8 = { {1, 1}, {2, 2} }; +const std::vector> padBegins2di8 = { {0, 0}, {1, 1} }; +const std::vector> padEnds2di8 = { {0, 0}, {1, 1} }; +const std::vector dilations2di8 = { {1, 1}/*, {2, 2}*/ }; + +const auto groupDeconvParams_2D_I8 = ::testing::Combine( + ::testing::ValuesIn(kernels2di8), + ::testing::ValuesIn(strides2di8), + ::testing::ValuesIn(padBegins2di8), + ::testing::ValuesIn(padEnds2di8), + ::testing::ValuesIn(dilations2di8), + ::testing::ValuesIn(numOutChannels_Blocked), + ::testing::ValuesIn(numGroups_Blocked), + ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::ValuesIn(emptyOutputPadding) +); + +const std::vector fusingParamsSetI8{ + emptyFusingSpec, +// // activations + fusingElu, + fusingSigmoid, + fusingPReluPerChannel, + fusingSwish, + fusingMish, +// // other patterns + fusingAddPerChannel +}; + +const std::vector CPUParams_2D_I8 = { + conv_sse42_2D_nspc, + conv_avx2_2D_nspc, + conv_avx512_2D_nspc +}; + +INSTANTIATE_TEST_CASE_P(smoke_GroupDeconv_2D_I8, GroupDeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupDeconvParams_2D_I8, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8, Precision::I8), + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7 })), + ::testing::ValuesIn(emptyOutputShape), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + GroupDeconvolutionLayerCPUTest::getTestCaseName); + +// temporarily disabled support for 3D cases in the plug-in +/* ============= GroupDeconvolution params I8 (3D) ============= */ +//const std::vector kernels3di8 = { {3, 3, 3} }; +//const std::vector strides3di8 = { {1, 1, 1}, {2, 2, 2} }; +//const std::vector> padBegins3di8 = { {0, 0, 0}, {1, 1, 1} }; +//const std::vector> padEnds3di8 = { {0, 0, 0}, {1, 1, 1} }; +//const std::vector dilations3di8 = { {1, 1, 1}/*, {2, 2, 2}*/ }; +// +//const auto groupDeconvParams_3D_I8 = ::testing::Combine( +// ::testing::ValuesIn(kernels3di8), +// ::testing::ValuesIn(strides3di8), +// ::testing::ValuesIn(padBegins3di8), +// ::testing::ValuesIn(padEnds3di8), +// ::testing::ValuesIn(dilations3di8), +// ::testing::ValuesIn(numOutChannels_Blocked), +// ::testing::ValuesIn(numGroups_Blocked), +// ::testing::Values(ngraph::op::PadType::EXPLICIT), +// ::testing::ValuesIn(emptyOutputPadding) +//); +// +//const std::vector CPUParams_3D_I8 = { +// conv_sse42_3D_nspc, +// conv_avx2_3D_nspc, +// conv_avx512_3D_nspc +//}; +// +//INSTANTIATE_TEST_CASE_P(smoke_GroupDeconv_3D_I8, GroupDeconvolutionLayerCPUTest, +// ::testing::Combine( +// ::testing::Combine( +// groupDeconvParams_3D_I8, +// ::testing::Values(Precision::FP32), +// ::testing::Values(Precision::U8, Precision::I8), +// ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), +// ::testing::Values(Layout::ANY), +// ::testing::Values(Layout::ANY), +// ::testing::Values(std::vector({ 2, 64, 7, 7, 7 })), +// ::testing::ValuesIn(emptyOutputShape), +// ::testing::Values(CommonTestUtils::DEVICE_CPU)), +// ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_3D_I8)), +// ::testing::ValuesIn(fusingParamsSetI8), +// ::testing::Values(cpuEmptyPluginConfig)), +// GroupDeconvolutionLayerCPUTest::getTestCaseName); + +/* ============= GroupDeconvolution params 1x1 I8 (2D) ============= */ +const auto groupDeconvParams_1x1_2D_I8 = ::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::ValuesIn(numGroups_Blocked), + ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::ValuesIn(emptyOutputPadding) +); + +const std::vector CPUParams_2D_1x1_I8 = { + // not supported 1x1 grouped conv for avx2/sse41 isa + // conv_sse42_2D_1x1_I8, + // conv_avx2_2D_1x1_I8, + conv_avx512_2D_1x1_nspc +}; + +INSTANTIATE_TEST_CASE_P(smoke_GroupDeconv_1x1_2D_I8, GroupDeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupDeconvParams_1x1_2D_I8, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8, Precision::I8), + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 64, 7, 7 })), + ::testing::ValuesIn(emptyOutputShape), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_1x1_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + GroupDeconvolutionLayerCPUTest::getTestCaseName); + +// temporarily disabled support for 3D cases in the plug-in +/* ============= GroupDeconvolution params 1x1 I8 (3D) ============= */ +//const auto groupDeconvParams_1x1_3D_I8 = ::testing::Combine( +// ::testing::Values(SizeVector({1, 1, 1})), +// ::testing::Values(SizeVector({1, 1, 1})), +// ::testing::Values(std::vector({0, 0, 0})), +// ::testing::Values(std::vector({0, 0, 0})), +// ::testing::Values(SizeVector({1, 1, 1})), +// ::testing::ValuesIn(numOutChannels_Blocked), +// ::testing::ValuesIn(numGroups_Blocked), +// ::testing::Values(ngraph::op::PadType::EXPLICIT), +// ::testing::ValuesIn(emptyOutputPadding) +//); +// +//const std::vector CPUParams_3D_1x1_I8 = { +// // not supported 1x1 grouped conv for avx2/sse41 isa +// // conv_sse42_3D_1x1_I8, +// // conv_avx2_3D_1x1_I8, +// conv_avx512_3D_1x1_nspc +//}; +// +//INSTANTIATE_TEST_CASE_P(smoke_GroupDeconv_1x1_3D_I8, GroupDeconvolutionLayerCPUTest, +// ::testing::Combine( +// ::testing::Combine( +// groupDeconvParams_1x1_3D_I8, +// ::testing::Values(Precision::FP32), +// ::testing::Values(Precision::U8, Precision::I8), +// ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), +// ::testing::Values(Layout::ANY), +// ::testing::Values(Layout::ANY), +// ::testing::Values(std::vector({ 2, 64, 7, 7, 7 })), +// ::testing::ValuesIn(emptyOutputShape), +// ::testing::Values(CommonTestUtils::DEVICE_CPU)), +// ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_3D_1x1_I8)), +// ::testing::ValuesIn(fusingParamsSetI8), +// ::testing::Values(cpuEmptyPluginConfig)), +// GroupDeconvolutionLayerCPUTest::getTestCaseName); + +/* ============= GroupDeconvolution params I8 (DW 2D) ============= */ +const auto groupDeconvParams_DW_2D_I8 = ::testing::Combine( + ::testing::ValuesIn(kernels2di8), + ::testing::ValuesIn(strides2di8), + ::testing::ValuesIn(padBegins2di8), + ::testing::ValuesIn(padEnds2di8), + ::testing::ValuesIn(dilations2di8), + ::testing::ValuesIn(numOutChannels_DW), + ::testing::ValuesIn(numGroups_DW), + ::testing::Values(ngraph::op::PadType::EXPLICIT), + ::testing::ValuesIn(emptyOutputPadding) +); + +INSTANTIATE_TEST_CASE_P(smoke_GroupDeconv_2D_DW_I8, GroupDeconvolutionLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + groupDeconvParams_DW_2D_I8, + ::testing::Values(Precision::FP32), + ::testing::Values(Precision::U8), // I8 and 3D DW deconvolution not supported in oneDNN + ::testing::Values(Precision::FP32, Precision::U8, Precision::I8), + ::testing::Values(Layout::ANY), + ::testing::Values(Layout::ANY), + ::testing::Values(std::vector({ 2, 32, 7, 7 })), + ::testing::ValuesIn(emptyOutputShape), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(filterCPUInfoForDevice(CPUParams_2D_I8)), + ::testing::ValuesIn(fusingParamsSetI8), + ::testing::Values(cpuEmptyPluginConfig)), + GroupDeconvolutionLayerCPUTest::getTestCaseName); + +} // namespace int8 + } // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/convolution_params.hpp b/inference-engine/tests/functional/plugin/cpu/test_utils/convolution_params.hpp index 762b19ed4a78ee..f7f7d8adef29a2 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/convolution_params.hpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/convolution_params.hpp @@ -71,5 +71,9 @@ namespace CPUTestUtils { const auto conv_avx2_2D_1x1_nspc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_avx2_1x1"}, "jit_avx2_1x1"}; const auto conv_avx512_2D_1x1_nspc = CPUSpecificParams{{nhwc}, {nhwc}, {"jit_avx512_1x1"}, "jit_avx512_1x1"}; + const auto conv_sse42_3D_1x1_nspc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_sse42_1x1"}, "jit_sse42_1x1"}; + const auto conv_avx2_3D_1x1_nspc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_avx2_1x1"}, "jit_avx2_1x1"}; + const auto conv_avx512_3D_1x1_nspc = CPUSpecificParams{{ndhwc}, {ndhwc}, {"jit_avx512_1x1"}, "jit_avx512_1x1"}; + const auto conv_winograd = CPUSpecificParams{{nChw16c}, {nChw16c}, {"jit_avx512_winograd"}, "jit_avx512_winograd"}; } // namespace CPUTestUtils diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp index dba15ff1d48eba..52195926952a62 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.cpp @@ -4,6 +4,7 @@ #include "cpu_test_utils.hpp" #include "utils/rt_info/memory_formats_attribute.hpp" +#include "ngraph_functions/builders.hpp" namespace CPUTestUtils { @@ -269,6 +270,12 @@ CPUTestsBase::makeNgraphFunction(const ngraph::element::Type &ngPrc, ngraph::Par auto newLastNode = modifyGraph(ngPrc, params, lastNode); ngraph::ResultVector results; + if (outElemType == ngraph::element::u8) { + newLastNode = ngraph::builder::makeFakeQuantize(newLastNode, ngPrc, 256, {1, 1, 1, 1}, {0}, {static_cast(quantizeInHigh)}, {0}, {255}); + } else if (outElemType == ngraph::element::i8) { + newLastNode = ngraph::builder::makeFakeQuantize(newLastNode, ngPrc, 255, {1, 1, 1, 1}, {0}, {static_cast(quantizeInHigh)}, {-127}, {127}); + } + for (int i = 0; i < newLastNode->get_output_size(); i++) results.push_back(std::make_shared(newLastNode->output(i))); diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp index f6b89c6ee5499e..14a0854d0446f2 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/cpu_test_utils.hpp @@ -10,6 +10,7 @@ #include "shared_test_classes/base/layer_test_utils.hpp" #include #include "ie_system_conf.h" +#include "ngraph_ops/type_relaxed.hpp" namespace CPUTestUtils { typedef enum { @@ -151,6 +152,10 @@ class CPUTestsBase { std::vector inFmts, outFmts; std::vector priority; std::string selectedType; + + ngraph::element::Type outElemType = ngraph::element::f32; + // only for int8 testing + int quantizeInHigh = 1; }; const auto emptyCPUSpec = CPUSpecificParams{{}, {}, {}, {}}; diff --git a/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp b/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp index d0b4441dfdf81e..af85a2f41c2a5a 100644 --- a/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp +++ b/inference-engine/tests/functional/plugin/cpu/test_utils/fusing_test_utils.cpp @@ -103,7 +103,7 @@ std::string postNodesMgr::getFusedOpsNames() const { const char* separator = ""; for (const auto& item : _postNodes) { result << separator << item.name; - separator = ","; + separator = ":"; } return result.str(); } diff --git a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp index 9140f970cff7ca..7d3760352b9aa5 100644 --- a/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp +++ b/inference-engine/tests/functional/shared_test_classes/include/shared_test_classes/base/layer_test_utils.hpp @@ -153,6 +153,8 @@ class LayerTestsCommon : public CommonTestUtils::TestsCommon { InferenceEngine::InferRequest inferRequest; + std::vector> additionalPasses; + private: RefMode refMode = RefMode::INTERPRETER; }; diff --git a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp index b9f679cb2a9a93..fd3bb0858113bb 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp @@ -354,6 +354,9 @@ std::vector>> LayerTe ngraph::pass::ConvertPrecision().run_on_function(function); ngraph::pass::ConvertPrecision().run_on_function(function); + for (const auto &pass : additionalPasses) + pass->run_on_function(function); + function->validate_nodes_and_infer_types(); auto referenceInputs = std::vector>(inputs.size()); diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/CMakeLists.txt b/inference-engine/tests/ngraph_helpers/ngraph_functions/CMakeLists.txt index e63b455218a4e8..4f4f7fd3a7ed3d 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/CMakeLists.txt +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/CMakeLists.txt @@ -13,6 +13,7 @@ addIeTarget( INCLUDES PUBLIC ${PUBLIC_HEADERS_DIR} + ${IE_MAIN_SOURCE_DIR}/src/transformations/include ADDITIONAL_SOURCE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src LINK_LIBRARIES diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp index 8e70dfdc6d82aa..e3683ffeffb090 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/builders.hpp @@ -17,6 +17,7 @@ #include #include "ngraph_functions/utils/data_utils.hpp" +#include "ngraph_ops/type_relaxed.hpp" namespace ngraph { namespace builder { @@ -91,6 +92,17 @@ std::shared_ptr makeConvolution(const ngraph::Output &in, const std::vector &filterWeights = {}, const std::vector &biasesWeights = {}); +std::shared_ptr makeConvolutionRelaxed(const ngraph::Output &in, + const element::Type &type, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + const std::vector &filterWeights = {}); + std::shared_ptr makeGroupConvolution(const ngraph::Output &in, const element::Type &type, const std::vector &filterSize, @@ -116,6 +128,18 @@ std::shared_ptr makeGroupConvolution(const ngraph::Output &i bool addBiases = false, const std::vector &biasesWeights = {}); +std::shared_ptr makeGroupConvolutionRelaxed(const ngraph::Output &in, + const element::Type &type, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + size_t numGroups, + const std::vector &filterWeights = {}); + std::shared_ptr makeConvolutionBackpropData(const ngraph::Output &in, const element::Type &type, const std::vector &filterSize, @@ -157,6 +181,17 @@ std::shared_ptr makeConvolutionBackpropData(const ngraph::Output &filterWeights = {}, const std::vector &biasesWeights = {}); +std::shared_ptr makeConvolutionBackpropDataRelaxed(const ngraph::Output &in, + const element::Type &weiType, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + const std::vector &filterWeights = {}); + std::shared_ptr makeCTCGreedyDecoder( const ngraph::Output& inputData, const bool mergeRepeated); @@ -229,6 +264,18 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ngraph::Out const std::vector &filterWeights = {}, const std::vector &biasesWeights = {}); +std::shared_ptr makeGroupConvolutionBackpropDataRelaxed(const ngraph::Output &in, + const element::Type &weiType, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + size_t numGroups, + const std::vector &filterWeights = {}); + std::shared_ptr makeBinaryConvolution(const ngraph::Output &in, const std::vector &filterSize, const std::vector &strides, diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution.cpp index 43ca5522cf8782..29946d06d935ce 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution.cpp @@ -39,5 +39,34 @@ std::shared_ptr makeConvolution(const ngraph::Output &in, } } +std::shared_ptr makeConvolutionRelaxed(const ngraph::Output &in, + const element::Type &type, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + const std::vector &filterWeights) { + auto inputParamsFP32 = ngraph::builder::makeParams(ngraph::element::f32, { in.get_shape() }); + auto paramOutsFP32 = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(inputParamsFP32)); + + auto convolutionNodeRelaxed = std::make_shared>( + *as_type_ptr(ngraph::builder::makeConvolution( + paramOutsFP32.front(), ngraph::element::f32, filterSize, strides, padsBegin, padsEnd, dilations, autoPad, numOutChannels)), + element::f32); + + bool randomFilterWeights = filterWeights.empty(); + auto shape = in.get_shape(); + std::vector filterWeightsShape = {numOutChannels, shape[1]}; + filterWeightsShape.insert(filterWeightsShape.end(), filterSize.begin(), filterSize.end()); + auto filterWeightsNode = makeConstant(type, filterWeightsShape, filterWeights, randomFilterWeights); + + auto newConvolution = convolutionNodeRelaxed->copy_with_new_inputs({in, filterWeightsNode}); + + return newConvolution; +} + } // namespace builder } // namespace ngraph diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution_backprop_data.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution_backprop_data.cpp index 91d6c0fc0852e6..08118e35b06058 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution_backprop_data.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/convolution_backprop_data.cpp @@ -96,5 +96,34 @@ std::shared_ptr makeConvolutionBackpropData(const ngraph::Output &in } } +std::shared_ptr makeConvolutionBackpropDataRelaxed(const ngraph::Output &in, + const element::Type &weiType, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + const std::vector &filterWeights) { + auto inputParamsFP32 = ngraph::builder::makeParams(ngraph::element::f32, { in.get_shape() }); + auto paramOutsFP32 = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(inputParamsFP32)); + + auto deconvolutionNodeRelaxed = std::make_shared>( + *as_type_ptr(ngraph::builder::makeConvolutionBackpropData( + paramOutsFP32.front(), ngraph::element::f32, filterSize, strides, padsBegin, padsEnd, dilations, autoPad, numOutChannels)), + element::f32); + + bool randomFilterWeights = filterWeights.empty(); + auto shape = in.get_shape(); + std::vector filterWeightsShape = {shape[1], numOutChannels}; + filterWeightsShape.insert(filterWeightsShape.end(), filterSize.begin(), filterSize.end()); + auto filterWeightsNode = makeConstant(weiType, filterWeightsShape, filterWeights, randomFilterWeights); + + auto newDeconvolution = deconvolutionNodeRelaxed->copy_with_new_inputs({in, filterWeightsNode}); + + return newDeconvolution; +} + } // namespace builder -} // namespace ngraph \ No newline at end of file +} // namespace ngraph diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution.cpp index 07df7d0f481e29..dca4092532a3b9 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution.cpp @@ -58,5 +58,40 @@ std::shared_ptr makeGroupConvolution(const ngraph::Output &in, } } +std::shared_ptr makeGroupConvolutionRelaxed(const ngraph::Output &in, + const element::Type &type, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + size_t numGroups, + const std::vector &filterWeights) { + auto inputParamsFP32 = ngraph::builder::makeParams(ngraph::element::f32, { in.get_shape() }); + auto paramOutsFP32 = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(inputParamsFP32)); + + auto groupConvolutionNodeRelaxed = std::make_shared>( + *as_type_ptr(ngraph::builder::makeGroupConvolution( + paramOutsFP32.front(), ngraph::element::f32, filterSize, strides, padsBegin, padsEnd, dilations, autoPad, numOutChannels, numGroups)), + element::f32); + + bool randomFilterWeights = filterWeights.empty(); + auto shape = in.get_shape(); + std::vector filterWeightsShape = {numOutChannels, shape[1]}; + if (filterWeightsShape[0] % numGroups || filterWeightsShape[1] % numGroups) + throw std::runtime_error("incorrected shape for GroupConvolution"); + filterWeightsShape[0] /= numGroups; + filterWeightsShape[1] /= numGroups; + filterWeightsShape.insert(filterWeightsShape.begin(), numGroups); + filterWeightsShape.insert(filterWeightsShape.end(), filterSize.begin(), filterSize.end()); + auto filterWeightsNode = makeConstant(type, filterWeightsShape, filterWeights, randomFilterWeights); + + auto newGroupConvolution = groupConvolutionNodeRelaxed->copy_with_new_inputs({in, filterWeightsNode}); + + return newGroupConvolution; +} + } // namespace builder -} // namespace ngraph \ No newline at end of file +} // namespace ngraph diff --git a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution_backprop_data.cpp b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution_backprop_data.cpp index 84c141f8a20ca5..6e740f1a691ac9 100644 --- a/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution_backprop_data.cpp +++ b/inference-engine/tests/ngraph_helpers/ngraph_functions/src/group_convolution_backprop_data.cpp @@ -108,5 +108,39 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ngraph::Output makeGroupConvolutionBackpropDataRelaxed(const ngraph::Output &in, + const element::Type &weiType, + const std::vector &filterSize, + const std::vector &strides, + const std::vector &padsBegin, + const std::vector &padsEnd, + const std::vector &dilations, + const op::PadType &autoPad, + size_t numOutChannels, + size_t numGroups, + const std::vector &filterWeights) { + auto inputParamsFP32 = ngraph::builder::makeParams(ngraph::element::f32, { in.get_shape() }); + auto paramOutsFP32 = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(inputParamsFP32)); + + auto groupDeconvolutionNodeRelaxed = std::make_shared>( + *as_type_ptr(ngraph::builder::makeGroupConvolutionBackpropData( + paramOutsFP32.front(), ngraph::element::f32, filterSize, strides, padsBegin, padsEnd, dilations, autoPad, + numOutChannels, numGroups)), + element::f32); + + bool randomFilterWeights = filterWeights.empty(); + auto shape = in.get_shape(); + std::vector filterWeightsShape = {shape[1], numOutChannels}; + filterWeightsShape[0] /= numGroups; + filterWeightsShape[1] /= numGroups; + filterWeightsShape.insert(filterWeightsShape.begin(), numGroups); + filterWeightsShape.insert(filterWeightsShape.end(), filterSize.begin(), filterSize.end()); + auto filterWeightsNode = makeConstant(weiType, filterWeightsShape, filterWeights, randomFilterWeights); + + auto newGroupDeconvolution = groupDeconvolutionNodeRelaxed->copy_with_new_inputs({in, filterWeightsNode}); + + return newGroupDeconvolution; +} + } // namespace builder -} // namespace ngraph \ No newline at end of file +} // namespace ngraph From 65d5691571eb08bca0f8fc9f6b570c4e817442aa Mon Sep 17 00:00:00 2001 From: Anton Voronov Date: Tue, 24 Aug 2021 15:40:43 +0300 Subject: [PATCH 2/2] some fixes --- .../functional/plugin/cpu/single_layer_tests/convolution.cpp | 5 ++++- .../cpu/single_layer_tests/convolution_backprop_data.cpp | 5 ++++- .../plugin/cpu/single_layer_tests/group_convolution.cpp | 5 ++++- .../single_layer_tests/group_convolution_backprop_data.cpp | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp index e148a972bfc8b2..790fab29bc17b3 100755 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/convolution.cpp @@ -132,10 +132,13 @@ class ConvolutionLayerCPUTest : public testing::WithParamInterface>()); additionalPasses.push_back(std::make_shared>()); } 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 index d52b536ad49f58..317c22d6478a18 100755 --- 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 @@ -110,10 +110,13 @@ class DeconvolutionLayerCPUTest : public testing::WithParamInterface>()); additionalPasses.push_back(std::make_shared>()); } diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp index b5d1671237adf5..42cf9a33911a73 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution.cpp @@ -121,10 +121,13 @@ class GroupConvolutionLayerCPUTest : public testing::WithParamInterface>()); additionalPasses.push_back(std::make_shared>()); } diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp index 3001e97fdcf311..0fa37686263775 100755 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/group_convolution_backprop_data.cpp @@ -108,10 +108,13 @@ class GroupDeconvolutionLayerCPUTest : public testing::WithParamInterface>()); additionalPasses.push_back(std::make_shared>()); }