From 72f802f282afd5a172c427668411e1ae839a78fa Mon Sep 17 00:00:00 2001 From: Maxim Andronov Date: Wed, 30 Mar 2022 10:20:52 +0300 Subject: [PATCH] [CPU] Fix Parameter -> Result model for dynamic case (#10764) --- src/plugins/intel_cpu/src/infer_request.cpp | 38 +++++++++++------- .../subgraph_tests/parameter_result.cpp | 22 +++++++++-- .../src/param_result_custom_blob.cpp | 22 ++++++----- .../subgraph_tests/parameter_result.cpp | 16 ++++++-- .../skip_tests_config.cpp | 3 ++ .../subgraph_tests/parameter_result.cpp | 12 +++++- .../subgraph_tests/parameter_result.hpp | 6 ++- .../subgraph/parameter_result.hpp | 26 +++++++++---- .../src/subgraph/parameter_result.cpp | 39 +++++++++++++++---- 9 files changed, 138 insertions(+), 46 deletions(-) diff --git a/src/plugins/intel_cpu/src/infer_request.cpp b/src/plugins/intel_cpu/src/infer_request.cpp index fef83221c9c..a0c932dd695 100644 --- a/src/plugins/intel_cpu/src/infer_request.cpp +++ b/src/plugins/intel_cpu/src/infer_request.cpp @@ -642,11 +642,11 @@ void InferRequest::initBlobs() { void InferRequest::SetBatch(int new_batch) { if (!graph->getProperty().batchLimit || modelInputsMap.begin()->second->get_output_partial_shape(0).is_static()) { - IE_THROW() << "Can't SetBatch for model that can't be executed via legacy dynamic batch or for static model"; + IE_THROW() << "Can't set batch for model that can't be executed via legacy dynamic batch or for static model"; } if (new_batch < 1 || new_batch > graph->getProperty().batchLimit) { - IE_THROW() << "Can't set batch that more than upper bound"; + IE_THROW() << "Can't set batch that is bigger than upper bound"; } m_curBatch = new_batch; @@ -671,16 +671,16 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob: if (inputNodeItr != modelInputsMap.end()) { if (!inputNodeItr->second) { - IE_THROW() << "Can't SetBlob with name: " << name << ", because has null pointer to input node"; + IE_THROW() << "Can't set blob with name: " << name << ", because has null pointer to input node"; } isInput = true; } else if (outputNodeItr != modelOutputsMap.end()) { if (!outputNodeItr->second) { - IE_THROW() << "Can't SetBlob with name: " << name << ", because has null pointer to output node"; + IE_THROW() << "Can't set blob with name: " << name << ", because has null pointer to output node"; } isInput = false; } else { - IE_THROW(NotFound) << "Can't SetBlob with name: " << name << ", because input/output with this name doesn't exist"; + IE_THROW(NotFound) << "Can't set blob with name: " << name << ", because input/output with this name doesn't exist"; } const bool compoundBlobPassed = data->is(); @@ -699,13 +699,14 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob: const auto shape = inputNodeItr->second->get_output_partial_shape(0); const bool isDynamic = shape.is_dynamic(); if (!shape.compatible(ov::PartialShape(data->getTensorDesc().getDims()))) { - IE_THROW() << "Can't SetBlob with name: " << name + IE_THROW() << "Can't set input blob with name: " << name << ", because model input (shape=" << shape << ") and blob (shape=" << vec2str(data->getTensorDesc().getDims()) << ") are incompatible"; } if (!isDynamic && ngraph::shape_size(shape.to_shape()) != data->size()) { - IE_THROW() << "Can't SetBlob with name: " << name << ", because model input and blob have different size"; + IE_THROW() << "Can't set input blob with name: " << name << ", because model input size = " << ngraph::shape_size(shape.to_shape()) + << " and blob size = " << data->size() << " are different."; } MemoryDescPtr actualDesc = graph->getInputNodeByName(name)->getBaseMemDescAtOutputPort(0); @@ -725,7 +726,7 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob: _inputs[name] = data; } else { if (compoundBlobPassed) { - IE_THROW(NotImplemented) << "cannot set compound blob: supported only for input pre-processing"; + IE_THROW(NotImplemented) << "Can't set compound blob: supported only for input pre-processing"; } const auto netOutPrc = InferenceEngine::details::convertPrecision(outputNodeItr->second->get_input_element_type(0)); if (netOutPrc != blobDesc.getPrecision()) { @@ -737,11 +738,14 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob: const bool isDynamic = shape.is_dynamic(); if (!shape.compatible(ov::PartialShape(data->getTensorDesc().getDims()))) { - IE_THROW() << "Can't SetBlob with name: " << name << ", because model output and blob are incompatible"; + IE_THROW() << "Can't set output blob with name: " << name + << ", because model output (shape=" << shape + << ") and blob (shape=" << vec2str(data->getTensorDesc().getDims()) << ") are incompatible"; } if (!isDynamic && ngraph::shape_size(shape.to_shape()) != data->size()) { - IE_THROW() << "Can't SetBlob with name: " << name << ", because model output and blob have different size"; + IE_THROW() << "Can't set output blob with name: " << name << ", because model output size = " << ngraph::shape_size(shape.to_shape()) + << " and blob size = " << data->size() << " are different."; } const auto &desc = graph->getOutputNodeByName(name)->getParentEdgesAtPort(0)[0]->getMemory().getDesc(); @@ -769,7 +773,7 @@ InferenceEngine::Blob::Ptr InferRequest::GetBlob(const std::string& name) { auto inputNode = modelInputsMap.find(name); if (inputNode != modelInputsMap.end()) { if (!inputNode->second) { - IE_THROW() << "Can't GetBlob with name: " << name << ", because has null pointer to input node"; + IE_THROW() << "Can't get blob with name: " << name << ", because has null pointer to input node"; } const auto shape = inputNode->second->get_output_partial_shape(0); @@ -822,8 +826,16 @@ InferenceEngine::Blob::Ptr InferRequest::GetBlob(const std::string& name) { data = make_blob_with_precision(desc); data->allocate(); } else { - if (!shape.compatible(ov::PartialShape(data->getTensorDesc().getDims()))) { - IE_THROW(ParameterMismatch) << "Network input and output use the same name: " << name << ", but expect blobs with different shapes."; + const auto& blobDims = data->getTensorDesc().getDims(); + // in static shape case is enough information that shapes are incompatible to throw exception + // but in dynamic shape case we also need to handle following corner case: + // on blob initialization stage we create empty blob with dimensions equal 0 + // so if we have blob with all zero dimension we mustn't throw exception + if (!shape.compatible(ov::PartialShape(blobDims)) && (!isDynamic || blobDims.size() != shape.rank().get_length() || + std::any_of(blobDims.begin(), blobDims.end(), [](const size_t& dims) { return dims != 0; } ))) { + IE_THROW(ParameterMismatch) << "Network input and output use the same name: " << name + << ", but expect blobs with different shapes. Input shape: " + << ov::PartialShape(blobDims) << ", output shape: " << shape; } const auto netOutPrc = InferenceEngine::details::convertPrecision(outputNode->second->get_input_element_type(0)); diff --git a/src/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/parameter_result.cpp b/src/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/parameter_result.cpp index 2e566cabfb6..4b8fc805fa9 100644 --- a/src/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/parameter_result.cpp +++ b/src/tests/functional/plugin/cpu/shared_tests_instances/subgraph_tests/parameter_result.cpp @@ -8,7 +8,23 @@ using namespace SubgraphTestsDefinitions; namespace { - INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest, - ::testing::Values(CommonTestUtils::DEVICE_CPU), - ParameterResultSubgraphTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTestLegacyApi, + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ParameterResultSubgraphTestBase::getTestCaseName); + +const std::vector inputShapes = { + ov::test::InputShape{{1, 3, 10, 10}, {{ 1, 3, 10, 10}, { 1, 3, 10, 10}}}, + ov::test::InputShape{{-1, -1, -1, -1}, {{ 1, 3, 10, 10}, { 2, 5, 3, 10}, { 1, 3, 10, 10}, { 1, 3, 10, 10}}}, + ov::test::InputShape{{{1, 10}, {1, 10}, {1, 10}, {1, 10}}, {{ 1, 3, 10, 10}, { 2, 5, 3, 10}, { 1, 3, 10, 10}, { 1, 3, 10, 10}}}, +}; + +INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest, + ::testing::Combine( + ::testing::ValuesIn(inputShapes), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ParameterResultSubgraphTestBase::getTestCaseName); + } // namespace diff --git a/src/tests/functional/plugin/cpu/subgraph_tests/src/param_result_custom_blob.cpp b/src/tests/functional/plugin/cpu/subgraph_tests/src/param_result_custom_blob.cpp index 26ea21827c1..2fe0804c225 100644 --- a/src/tests/functional/plugin/cpu/subgraph_tests/src/param_result_custom_blob.cpp +++ b/src/tests/functional/plugin/cpu/subgraph_tests/src/param_result_custom_blob.cpp @@ -10,7 +10,7 @@ using namespace InferenceEngine; namespace CPULayerTestsDefinitions { -class ParameterResultCustomBlobTest : public ParameterResultSubgraphTest { +class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyApi { protected: void Infer() override { constexpr size_t inferIterations = 10lu; @@ -34,7 +34,7 @@ class ParameterResultCustomBlobTest : public ParameterResultSubgraphTest { inferRequest.Infer(); - ParameterResultSubgraphTest::Validate(); + ParameterResultSubgraphTestLegacyApi::Validate(); } } void Validate() override { @@ -54,18 +54,20 @@ TEST_P(ParameterResultCustomBlobTest, CompareWithRefs) { } namespace { INSTANTIATE_TEST_SUITE_P(smoke_Check_Custom_Blob, ParameterResultCustomBlobTest, - ::testing::Values(CommonTestUtils::DEVICE_CPU), - ParameterResultSubgraphTest::getTestCaseName); + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{}}}), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ParameterResultSubgraphTestBase::getTestCaseName); } // namespace -class ParameterResultSameBlobTest : public ParameterResultSubgraphTest { +class ParameterResultSameBlobTest : public ParameterResultSubgraphTestLegacyApi { protected: void Infer() override { constexpr size_t inferIterations = 10lu; for (size_t i = 0; i < inferIterations; ++i) { - ParameterResultSubgraphTest::Infer(); - ParameterResultSubgraphTest::Validate(); + ParameterResultSubgraphTestLegacyApi::Infer(); + ParameterResultSubgraphTestLegacyApi::Validate(); } } void Validate() override { @@ -80,7 +82,9 @@ TEST_P(ParameterResultSameBlobTest, CompareWithRefs) { } namespace { INSTANTIATE_TEST_SUITE_P(smoke_Check_Same_Blob, ParameterResultSameBlobTest, - ::testing::Values(CommonTestUtils::DEVICE_CPU), - ParameterResultSubgraphTest::getTestCaseName); + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{}}}), + ::testing::Values(CommonTestUtils::DEVICE_CPU)), + ParameterResultSubgraphTestBase::getTestCaseName); } // namespace } // namespace CPULayerTestsDefinitions \ No newline at end of file diff --git a/src/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/parameter_result.cpp b/src/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/parameter_result.cpp index 712dc9e157a..54119876895 100644 --- a/src/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/parameter_result.cpp +++ b/src/tests/functional/plugin/gpu/shared_tests_instances/subgraph_tests/parameter_result.cpp @@ -10,7 +10,17 @@ using namespace SubgraphTestsDefinitions; namespace { - INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest, - ::testing::Values(CommonTestUtils::DEVICE_GPU), - ParameterResultSubgraphTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTestLegacyApi, + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}), + ::testing::Values(CommonTestUtils::DEVICE_GPU)), + ParameterResultSubgraphTestBase::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest, + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{1, 3, 10, 10}}}), + ::testing::Values(CommonTestUtils::DEVICE_GPU)), + ParameterResultSubgraphTestBase::getTestCaseName); + } // namespace diff --git a/src/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp b/src/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp index fe1719ecf35..3c63ab772b9 100644 --- a/src/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp +++ b/src/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp @@ -87,5 +87,8 @@ std::vector disabledTestPatterns() { R"(.*MultithreadingTests.*canRun.*RequestsConsistentlyFromThreads.*MYRIAD.*)", // TODO: CVS-82012 R"(.*StridedSliceLayerTest\.CompareWithRefs/inShape=\(1\.12\.100\).*)", + + // Issue: 81016 + R"(.*ParameterResultSubgraphTest\.CompareWithRefs.*)", }; } diff --git a/src/tests/functional/plugin/myriad/subgraph_tests/parameter_result.cpp b/src/tests/functional/plugin/myriad/subgraph_tests/parameter_result.cpp index 720f985706e..0317a91f1cf 100644 --- a/src/tests/functional/plugin/myriad/subgraph_tests/parameter_result.cpp +++ b/src/tests/functional/plugin/myriad/subgraph_tests/parameter_result.cpp @@ -8,8 +8,16 @@ using namespace SubgraphTestsDefinitions; namespace { +INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTestLegacyApi, + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}), + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)), + ParameterResultSubgraphTestBase::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest, - ::testing::Values(CommonTestUtils::DEVICE_MYRIAD), - ParameterResultSubgraphTest::getTestCaseName); + ::testing::Combine( + ::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{1, 3, 10, 10}}}), + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD)), + ParameterResultSubgraphTestBase::getTestCaseName); } // namespace diff --git a/src/tests/functional/plugin/shared/include/subgraph_tests/parameter_result.hpp b/src/tests/functional/plugin/shared/include/subgraph_tests/parameter_result.hpp index 586f5e57149..f19ee4b991a 100644 --- a/src/tests/functional/plugin/shared/include/subgraph_tests/parameter_result.hpp +++ b/src/tests/functional/plugin/shared/include/subgraph_tests/parameter_result.hpp @@ -8,8 +8,12 @@ namespace SubgraphTestsDefinitions { -TEST_P(ParameterResultSubgraphTest, CompareWithRefs) { +TEST_P(ParameterResultSubgraphTestLegacyApi, CompareWithRefs) { Run(); } +TEST_P(ParameterResultSubgraphTest, CompareWithRefs) { + run(); +} + } // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/parameter_result.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/parameter_result.hpp index 6c3a62d30c8..3a73c13821b 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/parameter_result.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/parameter_result.hpp @@ -10,19 +10,31 @@ #include #include "shared_test_classes/base/layer_test_utils.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" #include "ngraph_functions/builders.hpp" namespace SubgraphTestsDefinitions { -typedef std::tuple< - std::string // Device name -> parameterResultParams; +using parameterResultParams = std::tuple; // Device name -class ParameterResultSubgraphTest : public testing::WithParamInterface, - virtual public LayerTestsUtils::LayerTestsCommon { -public: - static std::string getTestCaseName(const testing::TestParamInfo& obj); +class ParameterResultSubgraphTestBase : public testing::WithParamInterface { + public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + protected: + std::shared_ptr createModel(const ov::PartialShape& shape); +}; + +class ParameterResultSubgraphTestLegacyApi : public ParameterResultSubgraphTestBase, + virtual public LayerTestsUtils::LayerTestsCommon { protected: void SetUp() override; }; + +class ParameterResultSubgraphTest : public ParameterResultSubgraphTestBase, + virtual public ov::test::SubgraphBaseTest { +protected: + void SetUp() override; +}; + } // namespace SubgraphTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/subgraph/parameter_result.cpp b/src/tests/functional/shared_test_classes/src/subgraph/parameter_result.cpp index bb35be6a7d4..05d757b4428 100644 --- a/src/tests/functional/shared_test_classes/src/subgraph/parameter_result.cpp +++ b/src/tests/functional/shared_test_classes/src/subgraph/parameter_result.cpp @@ -6,22 +6,45 @@ namespace SubgraphTestsDefinitions { -std::string ParameterResultSubgraphTest::getTestCaseName(const testing::TestParamInfo& obj) { +std::string ParameterResultSubgraphTestBase::getTestCaseName(const testing::TestParamInfo& obj) { + ov::test::InputShape inShape; std::string targetDevice; - std::tie(targetDevice) = obj.param; + std::tie(inShape, targetDevice) = obj.param; std::ostringstream result; + result << "IS="; + result << CommonTestUtils::partialShape2str({inShape.first}) << "_"; + result << "TS="; + for (const auto& shape : inShape.second) { + result << CommonTestUtils::vec2str(shape) << "_"; + } result << "TargetDevice=" << targetDevice; return result.str(); } -void ParameterResultSubgraphTest::SetUp() { - InferenceEngine::SizeVector inputShapes; - std::tie(targetDevice) = this->GetParam(); - - auto parameter = std::make_shared(ngraph::element::Type_t::f32, ngraph::Shape{1, 3, 10, 10}); +std::shared_ptr ParameterResultSubgraphTestBase::createModel(const ov::PartialShape& shape) { + auto parameter = std::make_shared(ov::element::f32, shape); const ngraph::ResultVector results{std::make_shared(parameter)}; ngraph::ParameterVector params = {parameter}; - function = std::make_shared(results, params, "ParameterResult"); + auto model = std::make_shared(results, params, "ParameterResult"); + return model; +} + +void ParameterResultSubgraphTestLegacyApi::SetUp() { + ov::test::InputShape inShape; + std::tie(inShape, targetDevice) = this->GetParam(); + + IE_ASSERT(inShape.first.is_static()); + + function = createModel(inShape.first); +} + +void ParameterResultSubgraphTest::SetUp() { + ov::test::InputShape inShape; + std::tie(inShape, targetDevice) = this->GetParam(); + + init_input_shapes({inShape}); + + function = createModel(inShape.first); } } // namespace SubgraphTestsDefinitions