From 6d320d71629027d3b7b9930d5e51fa048cde39cd Mon Sep 17 00:00:00 2001 From: Yury Gaydaychuk Date: Thu, 24 Dec 2020 10:20:44 +0300 Subject: [PATCH] convert to bf is to be inserted only after non-const layer (#3597) --- .../src/mkldnn_plugin/bf16transformer.cpp | 3 ++ .../src/mkldnn_plugin/mkldnn_exec_network.cpp | 2 +- .../cpu/single_layer_tests/interpolate.cpp | 53 ++++++++++++++++--- .../src/single_layer/interpolate.cpp | 5 +- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/inference-engine/src/mkldnn_plugin/bf16transformer.cpp b/inference-engine/src/mkldnn_plugin/bf16transformer.cpp index 6f238d46f78..03fb5001a16 100644 --- a/inference-engine/src/mkldnn_plugin/bf16transformer.cpp +++ b/inference-engine/src/mkldnn_plugin/bf16transformer.cpp @@ -347,6 +347,9 @@ void BF16Transformer::addLayerToCNNNetworkAfterData( void BF16Transformer::insertConvertAfterInput(InferenceEngine::CNNNetwork &network) { auto inputLayers = InferenceEngine::CNNNetGetAllInputLayers(network); for (auto inputIter : inputLayers) { + if (inputIter->type == "Const") { + continue; + } for (size_t o = 0; o < inputIter->outData.size(); o++) { for (auto bfInitIter : getInputTo(inputIter->outData[o])) { if (inputIter->outData[o]->getPrecision() == Precision::BF16) { diff --git a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp index 4ce00d14501..230334bc374 100644 --- a/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp +++ b/inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp @@ -67,7 +67,7 @@ MKLDNNExecNetwork::MKLDNNExecNetwork(const InferenceEngine::ICNNNetwork &network BF16Transformer bf16Transformer; CNNNetwork cnnetwork(_clonedNetwork); // If enforceBF16 flag was set, BF16 transformation applies for all layers supported by CPU plugin. - // Overwise, only layers marked as BF16 in 'cnnetwork' will be performed in bfloat16 mode. + // Otherwise, only layers marked as BF16 in 'cnnetwork' will be performed in bfloat16 mode. // CPU plugin throws an exception, if marked as BF16 layers have not supported by CPU plugin. if (cfg.enforceBF16 == true) bf16Transformer.convertToBFloat16(cnnetwork); diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp index b15ec88e7bb..3d7faa3ec3e 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/interpolate.cpp @@ -12,6 +12,7 @@ namespace CPULayerTestsDefinitions { typedef std::tuple< LayerTestsDefinitions::InterpolateLayerTestParams, + std::map, // Bf16 config CPUSpecificParams> InterpolateLayerCPUTestParamsSet; class InterpolateLayerCPUTest : public testing::WithParamInterface, @@ -20,12 +21,16 @@ public: static std::string getTestCaseName(testing::TestParamInfo obj) { LayerTestsDefinitions::InterpolateLayerTestParams basicParamsSet; CPUSpecificParams cpuParams; - std::tie(basicParamsSet, cpuParams) = obj.param; + std::map bf16config; + std::tie(basicParamsSet, bf16config, cpuParams) = obj.param; std::ostringstream result; result << LayerTestsDefinitions::InterpolateLayerTest::getTestCaseName(testing::TestParamInfo( basicParamsSet, 0)); + result << "bf16Enforce=" << (bf16config.count(InferenceEngine::PluginConfigParams::KEY_ENFORCE_BF16) ? + bf16config.at(InferenceEngine::PluginConfigParams::KEY_ENFORCE_BF16) : InferenceEngine::PluginConfigParams::NO); + result << CPUTestsBase::getTestCaseName(cpuParams); return result.str(); @@ -35,14 +40,15 @@ protected: void SetUp() { LayerTestsDefinitions::InterpolateLayerTestParams basicParamsSet; CPUSpecificParams cpuParams; - std::tie(basicParamsSet, cpuParams) = this->GetParam(); + std::map bf16config; + std::tie(basicParamsSet, bf16config, cpuParams) = this->GetParam(); std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; LayerTestsDefinitions::InterpolateSpecificParams interpolateParams; std::vector inputShape; std::vector targetShape; - auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; + auto netPrecision = InferenceEngine::Precision::UNSPECIFIED; std::tie(interpolateParams, netPrecision, inPrc, outPrc, inLayout, outLayout, inputShape, targetShape, targetDevice) = basicParamsSet; ngraph::op::v4::Interpolate::InterpolateMode mode; @@ -54,9 +60,9 @@ protected: double cubeCoef; std::vector axes; std::vector scales; - std:tie(mode, shapeCalcMode, coordinateTransformMode, nearestMode, antialias, padBegin, padEnd, cubeCoef, axes, scales) = interpolateParams; + std::tie(mode, shapeCalcMode, coordinateTransformMode, nearestMode, antialias, padBegin, padEnd, cubeCoef, axes, scales) = interpolateParams; inPrc = outPrc = netPrecision; - + configuration.insert(bf16config.begin(), bf16config.end()); using ShapeCalcMode = ngraph::op::v4::Interpolate::ShapeCalcMode; auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); @@ -82,7 +88,6 @@ protected: interpolate->get_rt_info() = getCPUInfo(); const ngraph::ResultVector results{std::make_shared(interpolate)}; function = std::make_shared(results, params, "interpolate"); - selectedType = getPrimitiveType() + "_" + inPrc.name(); } }; @@ -203,6 +208,23 @@ const auto interpolateCasesCubic = ::testing::Combine( ::testing::ValuesIn(defaultAxes), ::testing::ValuesIn(defaultScales)); +const auto interpolateCasesBf16Enforced = ::testing::Combine( + ::testing::Values(ngraph::op::v4::Interpolate::InterpolateMode::nearest), + ::testing::Values(ngraph::op::v4::Interpolate::ShapeCalcMode::scales), + ::testing::Values(ngraph::op::v4::Interpolate::CoordinateTransformMode::tf_half_pixel_for_nn), + ::testing::Values(ngraph::op::v4::Interpolate::NearestMode::simple), + ::testing::ValuesIn(antialias), + ::testing::ValuesIn(pads), + ::testing::ValuesIn(pads), + ::testing::ValuesIn(cubeCoefs), + ::testing::ValuesIn(defaultAxes), + ::testing::ValuesIn(defaultScales)); + +std::vector> bf16EnforceFlags = { + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::NO}}, + {{PluginConfigParams::KEY_ENFORCE_BF16, PluginConfigParams::YES}} +}; + INSTANTIATE_TEST_CASE_P(smoke_InterpolateNN_Layout_Test, InterpolateLayerCPUTest, ::testing::Combine( ::testing::Combine( @@ -215,6 +237,7 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateNN_Layout_Test, InterpolateLayerCPUTest ::testing::Values(std::vector({1, 21, 40, 40})), ::testing::Values(std::vector({1, 21, 50, 60})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(std::map {}), ::testing::ValuesIn(filterCPUInfoForDevice())), InterpolateLayerCPUTest::getTestCaseName); @@ -230,6 +253,7 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateLinearOnnx_Layout_Test, InterpolateLaye ::testing::Values(std::vector({1, 21, 40, 40})), ::testing::Values(std::vector({1, 21, 50, 60})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(std::map {}), ::testing::ValuesIn(filterCPUInfoForDevice())), InterpolateLayerCPUTest::getTestCaseName); @@ -245,9 +269,26 @@ INSTANTIATE_TEST_CASE_P(smoke_InterpolateCubic_Layout_Test, InterpolateLayerCPUT ::testing::Values(std::vector({1, 21, 40, 40})), ::testing::Values(std::vector({1, 21, 50, 60})), ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::Values(std::map {}), ::testing::ValuesIn(filterCPUInfoForDevice())), InterpolateLayerCPUTest::getTestCaseName); +INSTANTIATE_TEST_CASE_P(smoke_Interpolate_Enforced_Bf16_Layout_Test, InterpolateLayerCPUTest, + ::testing::Combine( + ::testing::Combine( + interpolateCasesBf16Enforced, + ::testing::Values(InferenceEngine::Precision::BF16), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(std::vector({1, 21, 40, 40})), + ::testing::Values(std::vector({1, 21, 50, 60})), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ::testing::ValuesIn(bf16EnforceFlags), + ::testing::ValuesIn(filterCPUInfoForDevice())), + InterpolateLayerCPUTest::getTestCaseName); + } // namespace } // namespace CPULayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/interpolate.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/interpolate.cpp index 072775a7a2e..9e836b3a296 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/single_layer/interpolate.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/interpolate.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include #include "shared_test_classes/single_layer/interpolate.hpp" #include "ngraph_functions/builders.hpp" #include "ngraph_functions/utils/ngraph_helpers.hpp" @@ -27,7 +28,7 @@ std::string InterpolateLayerTest::getTestCaseName(testing::TestParamInfo