From 8ee263e7fbe61e6964f619ed53a8a5aa5217ec1d Mon Sep 17 00:00:00 2001 From: "Gladilov, Gleb" Date: Fri, 30 Oct 2020 09:12:11 +0300 Subject: [PATCH] [IE][VPU][GT]: Introduce Split by dynamic dimension check (#2802) * [IE][VPU][GT]: Introduce Split by dynamic dimension check At the moment, myriad plugin does not support split operation by dynamic axis. To be sure there is no issue with optimized-out split operation which should have been replaced with copy stage - assertion before DTS transformation is introduced. Check should be performed before loop with DTS transformations because it requires dynamic context (dynamic dimension should be visible as dynamic), otherwise dynamic dimension would be replaced with upper-bound estimation and check will always pass. Signed-off-by: Gladilov, Gleb * [IE][nGraph]: Fixes normalize_axis symbol exporting Signed-off-by: Gladilov, Gleb --- .../dynamic_to_static_shape.cpp | 21 +++++++++++++++++++ .../core/include/ngraph/validation_util.hpp | 1 + 2 files changed, 22 insertions(+) diff --git a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp index 9059e978f85..2f86fd06d9d 100644 --- a/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp +++ b/inference-engine/src/vpu/common/src/ngraph/transformations/dynamic_to_static_shape.cpp @@ -27,6 +27,7 @@ #include "vpu/utils/error.hpp" #include "ngraph/opsets/opset3.hpp" +#include #include "ngraph/opsets/opset5.hpp" namespace vpu { @@ -68,6 +69,23 @@ bool propagateUpperBoundFromExistingDSR(std::shared_ptr& funct return function_changed; } +void validateDynamicFunction(const ngraph::Function& function) { + for (auto const& split : function.get_ordered_ops()) { + if (split->get_type_info() != ngraph::opset5::Split::type_info) { + continue; + } + + VPU_THROW_UNLESS(split->get_input_size() >= 2, "There is Split operation \"{}\" without specified axis", split->get_friendly_name()); + const auto& axis = ngraph::as_type_ptr(split->input_value(1).get_node_shared_ptr()); + VPU_THROW_UNLESS(axis != nullptr, "There is Split operation \"{}\" with dynamic axis \"{}\", but only constant axis is supported", + split->get_friendly_name(), split->input_value(1).get_node_shared_ptr()->get_friendly_name()); + const auto axisValue = ngraph::normalize_axis(split.get(), axis->cast_vector().front(), split->get_input_partial_shape(0).rank()); + VPU_THROW_UNLESS(split->get_input_partial_shape(0)[axisValue].is_static(), + "There is Split operation \"{}\" by dynamic dimension, but only split by static dimension is supported: shape = \"{}\", axis = \"{}\"", + split->get_friendly_name(), split->get_input_partial_shape(0), axisValue); + } +} + const Transformations& getDefaultTransformations() { static const Transformations transformations = { {ngraph::opset3::Add::type_info, dynamicToStaticShapeBinaryEltwise}, @@ -141,6 +159,9 @@ bool DynamicToStaticShape::run_on_function(std::shared_ptr fun // Basically this is possible in test cases, when the function is initially configured with DSR as inputs. function_changed |= propagateUpperBoundFromExistingDSR(function); + // Operation-specific testing that needs to be performed in dynamic context before DSRs are introduced + validateDynamicFunction(*function); + for (const auto& operation : function->get_ordered_ops()) { if (!isDynamic(*operation)) { continue; diff --git a/ngraph/core/include/ngraph/validation_util.hpp b/ngraph/core/include/ngraph/validation_util.hpp index a9415a55830..4c928d8f425 100644 --- a/ngraph/core/include/ngraph/validation_util.hpp +++ b/ngraph/core/include/ngraph/validation_util.hpp @@ -144,6 +144,7 @@ namespace ngraph /// \return Checking if axis is in range [-tensor_rank, tensor_rank-1], otherwise /// returns error. If negative axis, it counts from the last to the first axis, /// by adding tensor_rank to axis. + NGRAPH_API int64_t normalize_axis(const Node* node, std::int64_t axis, const Rank& tensor_rank); /// \brief Handle out of range axes in vector.