diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp index d70622cfab5..c33762dc1d5 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_executable_network.cpp @@ -18,6 +18,10 @@ #include #include #include +#include +#include +#include +#include "../../../ngraph/core/include/openvino/core/interval.hpp" using namespace InferenceEngine; @@ -72,8 +76,40 @@ ExecutableNetwork::ExecutableNetwork( _config.get(), consoleOutput()); + ie::CNNNetwork copyNetwork = network; + if (copyNetwork.getFunction() && copyNetwork.getFunction()->is_dynamic()) { + copyNetwork = InferenceEngine::details::cloneNetwork(network); + auto function = copyNetwork.getFunction(); + for (const auto& input : function->get_parameters()) { + if (input->get_partial_shape().is_dynamic()) { + auto inputShape = input->get_partial_shape(); + const auto inDataParam = std::make_shared( + input->get_output_element_type(0), inputShape.get_max_shape()); + const auto inDataShapeParam = std::make_shared( + ngraph::element::i32, ov::Shape{inputShape.get_max_shape().size()}); + inDataShapeParam->set_friendly_name(input->get_friendly_name()+"_real_shape"); + inDataParam->set_friendly_name(input->get_friendly_name()); + inDataParam->get_output_tensor(0).set_names(input->get_output_tensor(0).get_names()); + const auto dsr = std::make_shared( + inDataParam, inDataShapeParam, ngraph::vpu::op::DynamicShapeResolverMode::INFER_DYNAMIC_SHAPE); + function->replace_node(input, dsr); + function->remove_parameter(input); + function->add_parameters({inDataShapeParam, inDataParam}); + } + } + copyNetwork = ie::CNNNetwork(function); + for (const auto& inputInf : network.getInputsInfo()) { + auto& copyInput = copyNetwork.getInputsInfo()[inputInf.first]; + copyInput->setPrecision(inputInf.second->getPrecision()); + copyInput->setLayout(inputInf.second->getLayout()); + copyInput->getPreProcess() = inputInf.second->getPreProcess(); + } + for (const auto& outputInf : network.getOutputsInfo()) { + *copyNetwork.getOutputsInfo()[outputInf.first].get() = *outputInf.second.get(); + } + } auto compiledGraph = compileNetwork( - network, + copyNetwork, _config, compilerLog, _core); diff --git a/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp b/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp index 73d13b699e4..1ffdc0a4fad 100644 --- a/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp +++ b/inference-engine/src/vpu/myriad_plugin/myriad_infer_request.cpp @@ -166,6 +166,17 @@ void MyriadInferRequest::InferAsync() { } else { MEMCPY(&inputBuffer[offset], blob->buffer().as(), byteSize); } + const auto offsetShape = inputInfo.offset.find(name+"_real_shape"); + if (offsetShape == inputInfo.offset.end()) { + continue; + } + auto dimSize = sizeof(int32_t); + const auto offsetDims = (offsetShape->second) / dimSize; + const auto blobDims = blob->getTensorDesc().getDims(); + for (size_t i = 0; i < blobDims.size(); ++i) { + int32_t dim = static_cast(blobDims[i]); + reinterpret_cast(inputBuffer.data())[offsetDims + i] = dim; + } } _executor->queueInference(_graphDesc, inputBuffer.data(), diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request_dynamic.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request_dynamic.cpp new file mode 100644 index 00000000000..a7558eebe09 --- /dev/null +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/behavior/infer_request_dynamic.cpp @@ -0,0 +1,88 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "behavior/ov_infer_request/infer_request_dynamic.hpp" +#include +#include +#include +#include + +using namespace ov::test::behavior; + +namespace { + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP16 +}; + +const std::vector> configs = { + {} +}; + +const std::vector> HeteroConfigs = { + {{"TARGET_FALLBACK", CommonTestUtils::DEVICE_CPU}} +}; + +std::shared_ptr getFunction1() { + const std::vector inputShape = {1, 4, 20, 20}; + const ngraph::element::Type_t ngPrc = ngraph::element::Type_t::f32; + + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + params.front()->set_friendly_name("Param_1"); + params.front()->get_output_tensor(0).set_names({"input_tensor"}); + + auto in2add = ngraph::builder::makeConstant(ngPrc, {1, 4, 1, 1}, std::vector{}, true); + auto add = ngraph::builder::makeEltwise(params[0], in2add, ngraph::helpers::EltwiseTypes::ADD); + auto relu1 = std::make_shared(add->output(0)); + relu1->get_output_tensor(0).set_names({"relu1"}); + + ngraph::NodeVector results{relu1}; + return std::make_shared(results, params, "AddOneOutputEdge"); +} + +std::shared_ptr getFunction2() { + const std::vector inputShape = {1, 4, 20, 20}; + const ngraph::element::Type_t ngPrc = ngraph::element::Type_t::f32; + + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + params.front()->set_friendly_name("Param_1"); + params.front()->get_output_tensor(0).set_names({"input_tensor"}); + auto split = ngraph::builder::makeSplit(params[0], ngPrc, 2, 1); + + auto in2add = ngraph::builder::makeConstant(ngPrc, {1, 2, 1, 1}, std::vector{}, true); + auto add = ngraph::builder::makeEltwise(split->output(0), in2add, ngraph::helpers::EltwiseTypes::ADD); + auto relu1 = std::make_shared(add); + + auto in2mult = ngraph::builder::makeConstant(ngPrc, {1, 2, 1, 1}, std::vector{}, true); + auto mult = ngraph::builder::makeEltwise(split->output(1), in2mult, ngraph::helpers::EltwiseTypes::MULTIPLY); + auto relu2 = std::make_shared(mult); + + auto concat = std::make_shared(ngraph::OutputVector{relu1->output(0), relu2->output(0)}, 3); + concat->get_output_tensor(0).set_names({"concat"}); + + return std::make_shared(concat, params, "SplitAddConcat"); +} + +INSTANTIATE_TEST_SUITE_P(smoke_BehaviorTests_1, OVInferRequestDynamicTests, + ::testing::Combine( + ::testing::Values(getFunction1()), + ::testing::Values(std::vector, std::vector>>{ + {{1, 4, 20, 20}, {1, 4, 20, 20}}, + {{2, 4, 20, 20}, {2, 4, 20, 20}}}), + ::testing::Values(CommonTestUtils::DEVICE_MYRIAD), + ::testing::ValuesIn(configs)), + OVInferRequestDynamicTests::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_Hetero_BehaviorTests, OVInferRequestDynamicTests, + ::testing::Combine( + ::testing::Values(getFunction2()), + ::testing::Values(std::vector, std::vector>>{ + {{1, 4, 20, 20}, {1, 2, 20, 40}}, + {{2, 4, 20, 20}, {2, 2, 20, 40}}}), + ::testing::Values(CommonTestUtils::DEVICE_HETERO), + ::testing::ValuesIn(HeteroConfigs)), + OVInferRequestDynamicTests::getTestCaseName); +} // namespace diff --git a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp index 020d914713b..5b131794b61 100644 --- a/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp +++ b/inference-engine/tests/functional/plugin/myriad/shared_tests_instances/skip_tests_config.cpp @@ -15,6 +15,15 @@ std::vector disabledTestPatterns() { ".*ActivationLayerTest\\.CompareWithRefs/Log.*netPRC=FP32.*", ".*ActivationLayerTest\\.CompareWithRefs/Sigmoid.*netPRC=FP32.*", ".*ActivationLayerTest\\.CompareWithRefs/Relu.*netPRC=FP32.*", + // Not supported dynamic shapes without upper bound + ".*InferDynamicNetworkWithGetTensor2times.function.*", + ".*InferFullyDynamicNetworkWithGetTensor.function.*", + ".*InferDynamicNetworkWithGetTensor.function.*", + ".*InferDynamicNetworkWithoutSetShape.function.*", + ".*InferFullyDynamicNetworkWithSetTensor/function.*", + ".*InferDynamicNetworkWithSetTensor2times.*", + ".*InferRequestDynamicTests.GetSameTensor2times.*", + ".*InferRequestDynamicTests.InferDynamicNetworkWithSetTensor.*", // TODO: Issue: 26268 ".*ConcatLayerTest.*axis=0.*", // TODO: Issue 31197