diff --git a/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/merge_subsequent_dsr_operations.cpp b/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/merge_subsequent_dsr_operations.cpp new file mode 100644 index 00000000000..1c04279f9af --- /dev/null +++ b/inference-engine/tests/functional/plugin/myriad/ngraph/transformations/merge_subsequent_dsr_operations.cpp @@ -0,0 +1,169 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include + +#include "ngraph/ngraph.hpp" +#include "ngraph/opsets/opset4.hpp" + +#include "vpu/ngraph/operations/dynamic_shape_resolver.hpp" +#include "vpu/ngraph/transformations/merge_subsequent_dsr_operations.hpp" + +namespace { + +TEST(MergeSubsequentDSROperations, SingleDSRFunction) { + // shape + // \ + // dsr + // / + // data + + const auto inputType = ngraph::element::f16; + const auto inputShape = ngraph::Shape{1}; + + const auto data = std::make_shared(inputType, inputShape); + const auto shape = std::make_shared(ngraph::element::i64, ngraph::Shape{inputShape.size()}); + + const auto dsr = std::make_shared(data, shape); + const auto reference = std::make_shared( + ngraph::NodeVector{dsr}, + ngraph::ParameterVector{data, shape}, + "SingleDSRFunction"); + auto actual = ngraph::clone_function(*reference); + + vpu::MergeSubsequentDSROperations().run_on_function(actual); + + ASSERT_NO_THROW(ngraph::helpers::CompareFunctions(*reference, *actual)); +} + +TEST(MergeSubsequentDSROperations, DSR_ReLU_DSR_ReLU_DSR) { + // one_1 + // \ + // one_0 sum_1 - - - - - - - - - - dsr_2 + // \ / / + // shape - sum_0 - - - - - dsr_1 - relu_1 - + // \ / + // dsr_0 - relu_0 + // / + // data - + // + + const auto inputType = ngraph::element::f16; + const auto inputShape = ngraph::Shape{1}; + + const auto data = std::make_shared(inputType, inputShape); + const auto shape = std::make_shared(ngraph::element::i64, ngraph::Shape{inputShape.size()}); + const auto dsr_0 = std::make_shared(data, shape); + + const auto relu_0 = std::make_shared(dsr_0); + + // emulates shape subgraph for operation ReLU + const auto one_0 = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, std::vector{1}); + const auto sum_0 = std::make_shared(shape, one_0); + + const auto dsr_1 = std::make_shared(relu_0, sum_0); + + const auto relu_1 = std::make_shared(dsr_1); + + // emulates shape subgraph for operation ReLU + const auto one_1 = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, std::vector{1}); + const auto sum_1 = std::make_shared(sum_0, one_1); + + const auto dsr_2 = std::make_shared(relu_1, sum_1); + + const auto reference = std::make_shared( + ngraph::NodeVector{dsr_2}, + ngraph::ParameterVector{data, shape}, + "DSR_ReLU_DSR_ReLU_DSR"); + auto actual = ngraph::clone_function(*reference); + + vpu::MergeSubsequentDSROperations().run_on_function(actual); + + ASSERT_NO_THROW(ngraph::helpers::CompareFunctions(*reference, *actual)); +} + +TEST(MergeSubsequentDSROperations, DSR_ReLU_DSR_DSR) { + // Before: + // one_1 + // \ + // one_0 sum_1 - - - - - - dsr_2 + // \ / / + // shape - sum_0 - - - - - dsr_1 - + // \ / + // dsr_0 - relu_0 + // / + // data - + // + // After: + // one_1 + // \ + // one_0 sum_1 - - - - - - dsr_2 + // \ / / + // shape - sum_0 / + // \ / + // dsr_0 - relu_0 - - - - + // / + // data - + + const auto inputType = ngraph::element::f16; + const auto inputShape = ngraph::Shape{1}; + + std::shared_ptr actual; + { + const auto data = std::make_shared(inputType, inputShape); + const auto shape = std::make_shared(ngraph::element::i64, ngraph::Shape{inputShape.size()}); + const auto dsr_0 = std::make_shared(data, shape); + + const auto relu_0 = std::make_shared(dsr_0); + + // emulates shape subgraph for operation ReLU + const auto one_0 = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, std::vector{1}); + const auto sum_0 = std::make_shared(shape, one_0); + + const auto dsr_1 = std::make_shared(relu_0, sum_0); + + // emulates shape subgraph for operation ReLU + const auto one_1 = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, std::vector{1}); + const auto sum_1 = std::make_shared(sum_0, one_1); + + const auto dsr_2 = std::make_shared(dsr_1, sum_1); + + actual = std::make_shared( + ngraph::NodeVector{dsr_2}, + ngraph::ParameterVector{data, shape}, + "DSR_ReLU_DSR_DSR"); + } + + std::shared_ptr reference; + { + const auto data = std::make_shared(inputType, inputShape); + const auto shape = std::make_shared(ngraph::element::i64, ngraph::Shape{inputShape.size()}); + const auto dsr_0 = std::make_shared(data, shape); + + const auto relu_0 = std::make_shared(dsr_0); + + // emulates shape subgraph for operation ReLU + const auto one_0 = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, std::vector{1}); + const auto sum_0 = std::make_shared(shape, one_0); + + // emulates shape subgraph for operation ReLU + const auto one_1 = std::make_shared(ngraph::element::i64, ngraph::Shape{1}, std::vector{1}); + const auto sum_1 = std::make_shared(sum_0, one_1); + + const auto dsr_2 = std::make_shared(relu_0, sum_1); + + reference = std::make_shared( + ngraph::NodeVector{dsr_2}, + ngraph::ParameterVector{data, shape}, + "DSR_ReLU_DSR_DSR"); + } + + vpu::MergeSubsequentDSROperations().run_on_function(actual); + + ASSERT_NO_THROW(ngraph::helpers::CompareFunctions(*reference, *actual)); +} + +} //namespace