From c0f3a78529da6abfeb9793400f7eed7ac15e5ef1 Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 13 Jul 2021 12:21:05 +0300 Subject: [PATCH 01/21] Add multisubgraph --- .../include/ngraph/op/tensor_iterator.hpp | 8 +- .../ngraph/op/util/multi_subgraph_base.hpp | 289 ++++++++++++++++++ .../include/ngraph/op/util/sub_graph_base.hpp | 157 ++-------- ngraph/core/src/op/loop.cpp | 54 ++-- ngraph/core/src/op/tensor_iterator.cpp | 51 ++-- .../core/src/op/util/multi_subgraph_base.cpp | 124 ++++++++ ngraph/core/src/op/util/sub_graph_base.cpp | 69 ++--- 7 files changed, 524 insertions(+), 228 deletions(-) create mode 100644 ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp create mode 100644 ngraph/core/src/op/util/multi_subgraph_base.cpp diff --git a/ngraph/core/include/ngraph/op/tensor_iterator.hpp b/ngraph/core/include/ngraph/op/tensor_iterator.hpp index de44f4b638edeb..6c751fb45f95c8 100644 --- a/ngraph/core/include/ngraph/op/tensor_iterator.hpp +++ b/ngraph/core/include/ngraph/op/tensor_iterator.hpp @@ -20,8 +20,8 @@ namespace ngraph class NGRAPH_API TensorIterator : public op::util::SubGraphOp { public: - NGRAPH_RTTI_DECLARATION; - + static constexpr NodeTypeInfo type_info{"TensorIterator", 0}; + const NodeTypeInfo& get_type_info() const override { return type_info; } bool visit_attributes(AttributeVisitor& visitor) override; TensorIterator() = default; @@ -30,9 +30,9 @@ namespace ngraph std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; /// \return the body of the iteration - std::shared_ptr get_body() const { return m_body; } + std::shared_ptr get_body() const { return m_bodies[0]; } /// \param body set the body of the iteration - void set_body(const std::shared_ptr& body) { m_body = body; } + void set_body(const std::shared_ptr& body) { m_bodies[0] = body; } void validate_and_infer_types() override; void revalidate_and_infer_types_for_body_ops(); /// \return the body of the iteration diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp new file mode 100644 index 00000000000000..4273f66ddc99f3 --- /dev/null +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -0,0 +1,289 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include "ngraph/op/op.hpp" + +namespace ngraph +{ + namespace op + { + namespace util + { + /// \brief Abstract base class for sub-graph based ops, i.e ops that have some + /// sub-graphs + /// + class NGRAPH_API MultiSubGraphOp : public Op + { + public: + NGRAPH_RTTI_DECLARATION; + /// \brief Abstract class describes a connection between a MultiSubGraphOp input and + /// the body. + class InputDescription + { + protected: + /// + /// \brief Constructs a new instance. + /// + /// \param input_index Position of the MultiSubGraphOp input + /// \param body_parameter_index Body parameter to receive input + /// + InputDescription(uint64_t input_index, uint64_t body_parameter_index); + InputDescription() = default; + + public: + using type_info_t = DiscreteTypeInfo; + virtual ~InputDescription() = default; + virtual std::shared_ptr copy() const = 0; + + virtual const type_info_t& get_type_info() const = 0; + + uint64_t m_input_index{0}; + uint64_t m_body_parameter_index{0}; + }; + + /// \brief Abstract class describes how a MultiSubGraphOp output is produced from + /// the body. + class OutputDescription + { + protected: + /// + /// \brief Constructs a new instance. + /// + /// \param body_value_index A body value that produces the output + /// \param output_index The MultiSubGraphOp output index + /// + OutputDescription(uint64_t body_value_index, uint64_t output_index); + OutputDescription() = default; + + public: + using type_info_t = DiscreteTypeInfo; + virtual ~OutputDescription() = default; + virtual std::shared_ptr copy() const = 0; + virtual const type_info_t& get_type_info() const = 0; + + uint64_t m_body_value_index{0}; + uint64_t m_output_index{0}; + }; + /// \brief Produces an input + class NGRAPH_API InvariantInputDescription : public InputDescription + { + public: + static constexpr type_info_t type_info{"InvariantInputDescription", 0}; + const type_info_t& get_type_info() const override { return type_info; } + /// + /// \brief Constructs a new instance. + /// + /// \param input_index Position of the MultiSubGraphOp input + /// \param body_parameter_index Body parameter to receive input + /// + InvariantInputDescription(uint64_t input_index, uint64_t body_parameter_index); + InvariantInputDescription() = default; + std::shared_ptr copy() const override; + }; + + /// \brief Produces an output + class NGRAPH_API BodyOutputDescription : public OutputDescription + { + public: + static constexpr type_info_t type_info{"BodyOutputDescription", 0}; + const type_info_t& get_type_info() const override { return type_info; } + /// + /// \brief Constructs a new instance. + /// + /// \param body_value_index A body value that produces the output + /// \param output_index The MultiSubGraphOp output index + /// + BodyOutputDescription(uint64_t body_value_index, uint64_t output_index); + BodyOutputDescription() = default; + std::shared_ptr copy() const override; + }; + using MultiSubgraphInputDescriptionPtr = + std::shared_ptr; + using MultiSubgraphOutputDescriptionPtr = + std::shared_ptr; + using MultiSubgraphInputDescriptionVector = + std::vector; + using MultiSubgraphOutputDescriptionVector = + std::vector; + + /// \brief Gets internal sub-graph by index in MultiSubGraphOp + /// + /// \param index sub-graph's index in op + /// \return pointer to ngraph::Function with sub-graph + virtual std::shared_ptr get_function(int index) + { + return m_bodies[index]; + }; + /// \brief Gets internal sub-graph by index in MultiSubGraphOp + /// + /// \param index sub-graph's index in op + /// \return pointer to ngraph::Function with sub-graph + virtual std::shared_ptr get_function(int index) const + { + return m_bodies[index]; + }; + /// \brief Adds sub-graph to MultiSubGraphOp + /// + /// \param func new sub_graph as ngraph::Function + virtual void add_function(const std::shared_ptr& func) + { + m_bodies.push_back(func); + } + /// \brief Adds sub-graph to MultiSubGraphOp + /// + /// \param index index of new sub-graph + /// \param func func new sub_graph as ngraph::Function + virtual void set_function(int index, const std::shared_ptr& func) + { + m_bodies[index] = func; + } + /// \brief Gets vector with connections beewtwen operation inputs + /// and internal sub-graph parameters + /// + /// \param index index of internal sub-graph + /// \return vector of input descriptions + const MultiSubgraphInputDescriptionVector& get_input_descriptions(int index) const + { + return m_input_descriptions[index]; + } + /// \brief Gets vector with connections beewtwen operation inputs + /// and internal sub-graph parameters + /// + /// \param index index of internal sub-graph + /// \return vector of input descriptions + MultiSubgraphInputDescriptionVector& get_input_descriptions(int index) + { + return m_input_descriptions[index]; + } + /// \brief Gets vector with connections beewtwen operation outputs + /// and internal sub-graph results + /// + /// \param index index of internal sub-graph + /// \return vector of output descriptions + const MultiSubgraphOutputDescriptionVector& get_output_descriptions(int index) const + { + return m_output_descriptions[index]; + } + /// \brief Gets vector with connections beewtwen operation outputs + /// and internal sub-graph results + /// + /// \param index index of internal sub-graph + /// \return vector of output descriptions + MultiSubgraphOutputDescriptionVector& get_output_descriptions(int index) + { + return m_output_descriptions[index]; + } + + /// \brief Sets vector with connections beewtwen operation inputs + /// and internal sub-graph parameters + /// + /// \param index index of internal sub-graph + /// \param inputs vector of input descriptions + void set_input_descriptions(int index, MultiSubgraphInputDescriptionVector inputs) + { + m_input_descriptions[index] = inputs; + } + + /// \brief Sets vector with connections beewtwen operation outputs + /// and internal sub-graph results + /// + /// \param index index of internal sub-graph + /// \param outputs vector of input descriptions + void set_output_descriptions(int index, + MultiSubgraphOutputDescriptionVector outputs) + { + m_output_descriptions[index] = outputs; + } + + /// + /// \brief Set input decriptions for MultiSubGraphOp input. + /// + /// \param value The value supplied as an input to the block. + /// \param bodies_parameters vector of bodies parameters. + virtual void set_invariant_inputs(const Output& value, + const ParameterVector bodies_parameters); + /// + /// \brief Set output decriptions for MultiSubGraphOp output. + /// + /// \param bodies_results vector of bodies results for one output. + /// \return value Output node for bodies_results. + virtual Output set_body_outputs(ResultVector bodies_results); + + MultiSubGraphOp(const MultiSubGraphOp&) = delete; + MultiSubGraphOp(MultiSubGraphOp&&) = default; + + MultiSubGraphOp& operator=(const MultiSubGraphOp&) = delete; + MultiSubGraphOp& operator=(MultiSubGraphOp&&) = default; + MultiSubGraphOp::MultiSubGraphOp(size_t bodies_index); + protected: + // Find an input corresponding to value, adding one if necessary. + Input input_for_value(const Output& value); + + MultiSubGraphOp() = default; + MultiSubGraphOp(const OutputVector& args, size_t bodies_index); + explicit MultiSubGraphOp(const OutputVector& args); + + std::vector> m_bodies; + std::vector m_input_descriptions; + std::vector m_output_descriptions; + }; + using MultiSubgraphInputDescriptionPtr = + util::MultiSubGraphOp::MultiSubgraphInputDescriptionPtr; + using MultiSubgraphOutputDescriptionPtr = + util::MultiSubGraphOp::MultiSubgraphOutputDescriptionPtr; + using MultiSubgraphInputDescriptionVector = + util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector; + using MultiSubgraphOutputDescriptionVector = + util::MultiSubGraphOp::MultiSubgraphOutputDescriptionVector; + + } // namespace util + } // namespace op + + template <> + class NGRAPH_API AttributeAdapter< + std::vector>> + : public DirectValueAccessor< + std::vector>> + { + public: + AttributeAdapter( + std::vector>& + value) + : DirectValueAccessor>>(value) + { + } + + static constexpr DiscreteTypeInfo type_info{ + "AttributeAdapter>>", + 0}; + const DiscreteTypeInfo& get_type_info() const override { return type_info; } + }; + + template <> + class NGRAPH_API AttributeAdapter< + std::vector>> + : public DirectValueAccessor< + std::vector>> + { + public: + AttributeAdapter( + std::vector>& + value) + : DirectValueAccessor>>(value) + { + } + + static constexpr DiscreteTypeInfo type_info{ + "AttributeAdapter>>", + 0}; + const DiscreteTypeInfo& get_type_info() const override { return type_info; } + }; +} // namespace ngraph diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index a44c830b78c6c9..5ab16b2e1a829b 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -5,7 +5,7 @@ #pragma once #include -#include "ngraph/op/op.hpp" +#include "ngraph/op/util/multi_subgraph_base.hpp" namespace ngraph { @@ -15,39 +15,16 @@ namespace ngraph { /// \brief Abstract base class for sub-graph based ops, i.e ops that have sub-graph /// - class NGRAPH_API SubGraphOp : public Op + class NGRAPH_API SubGraphOp : public MultiSubGraphOp { public: NGRAPH_RTTI_DECLARATION; - /// \brief Describes a connection between a SubGraphOp input and the body. - class InputDescription - { - protected: - /// - /// \brief Constructs a new instance. - /// - /// \param input_index Position of the SubGraphOp input - /// \param body_parameter_index Body parameter to receive input - /// - InputDescription(uint64_t input_index, uint64_t body_parameter_index); - InputDescription() = default; - - public: - using type_info_t = DiscreteTypeInfo; - virtual ~InputDescription() = default; - virtual std::shared_ptr copy() const = 0; - - virtual const type_info_t& get_type_info() const = 0; - - uint64_t m_input_index{0}; - uint64_t m_body_parameter_index{0}; - }; /// /// \brief Describes a body input formed from slices of an input to /// SubGraphOp. /// - class NGRAPH_API SliceInputDescription : public InputDescription + class NGRAPH_API SliceInputDescription : public MultiSubGraphOp::InputDescription { public: static constexpr type_info_t type_info{"SliceInputDescription", 0}; @@ -71,7 +48,7 @@ namespace ngraph int64_t end, int64_t axis); SliceInputDescription() = default; - std::shared_ptr copy() const override; + std::shared_ptr copy() const override; int64_t m_start{0}; int64_t m_stride{0}; int64_t m_part_size{0}; @@ -83,7 +60,7 @@ namespace ngraph /// \brief Describes a body input initialized from a SubGraphOp input on /// the first iteration, and then a body output thereafter. /// - class NGRAPH_API MergedInputDescription : public InputDescription + class NGRAPH_API MergedInputDescription : public MultiSubGraphOp::InputDescription { public: static constexpr type_info_t type_info{"MergedInputDescription", 0}; @@ -103,55 +80,12 @@ namespace ngraph uint64_t body_parameter_index, uint64_t body_value_index); MergedInputDescription() = default; - std::shared_ptr copy() const override; + std::shared_ptr copy() const override; uint64_t m_body_value_index{0}; }; - /// - /// \brief Describes a body input initialized from a SubGraphOp input on - /// the first iteration, and invariant thereafter. - /// - class NGRAPH_API InvariantInputDescription : public InputDescription - { - public: - static constexpr type_info_t type_info{"InvariantInputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } - /// - /// \brief Constructs a new instance. - /// - /// \param input_index Position of the SubGraphOp input - /// \param body_parameter_index Body parameter to receive input - /// - InvariantInputDescription(uint64_t input_index, uint64_t body_parameter_index); - InvariantInputDescription() = default; - std::shared_ptr copy() const override; - }; - - /// \brief Describes how a SubGraphOp output is produced from the body. - class OutputDescription - { - protected: - /// - /// \brief Constructs a new instance. - /// - /// \param body_value_index A body value that produces the output - /// \param output_index The SubGraphOp output index - /// - OutputDescription(uint64_t body_value_index, uint64_t output_index); - OutputDescription() = default; - - public: - using type_info_t = DiscreteTypeInfo; - virtual ~OutputDescription() = default; - virtual std::shared_ptr copy() const = 0; - virtual const type_info_t& get_type_info() const = 0; - - uint64_t m_body_value_index{0}; - uint64_t m_output_index{0}; - }; - /// \brief Produces an output by concatenating an output from each iteration - class NGRAPH_API ConcatOutputDescription : public OutputDescription + class NGRAPH_API ConcatOutputDescription : public MultiSubGraphOp::OutputDescription { public: static constexpr type_info_t type_info{"ConcatOutputDescription", 0}; @@ -176,7 +110,7 @@ namespace ngraph int64_t axis); ConcatOutputDescription() = default; - std::shared_ptr copy() const override; + std::shared_ptr copy() const override; int64_t m_start{0}; int64_t m_stride{0}; int64_t m_part_size{0}; @@ -185,7 +119,7 @@ namespace ngraph }; /// \brief Produces an output from a specific iteration - class NGRAPH_API BodyOutputDescription : public OutputDescription + class NGRAPH_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription { public: static constexpr type_info_t type_info{"BodyOutputDescription", 0}; @@ -202,37 +136,40 @@ namespace ngraph uint64_t output_index, int64_t iteration); BodyOutputDescription() = default; - std::shared_ptr copy() const override; + std::shared_ptr copy() const override; int64_t m_iteration{0}; }; - virtual std::shared_ptr get_function() { return m_body; }; - virtual std::shared_ptr get_function() const { return m_body; }; - virtual void set_function(const std::shared_ptr& func) { m_body = func; }; + virtual std::shared_ptr get_function() { return m_bodies[0]; }; + virtual std::shared_ptr get_function() const { return m_bodies[0]; }; + virtual void set_function(const std::shared_ptr& func) + { + m_bodies[0] = func; + }; /// \return a reference to the input descriptions. const std::vector>& get_input_descriptions() const { - return m_input_descriptions; + return m_input_descriptions[0]; } /// \return a reference to the input descriptions. Can add input descriptions /// before /// validation. std::vector>& get_input_descriptions() { - return m_input_descriptions; + return m_input_descriptions[0]; } /// \return a reference to the output descriptions. const std::vector>& get_output_descriptions() const { - return m_output_descriptions; + return m_output_descriptions[0]; } /// \return a reference to the output descriptions. Can add output descriptions /// before /// validation. std::vector>& get_output_descriptions() { - return m_output_descriptions; + return m_output_descriptions[0]; } /// @@ -312,11 +249,14 @@ namespace ngraph SubGraphOp(const SubGraphOp&) = delete; SubGraphOp(SubGraphOp&&) = default; + + SubGraphOp& operator=(const SubGraphOp&) = delete; SubGraphOp& operator=(SubGraphOp&&) = default; int64_t get_num_iterations() const { return m_num_iterations; } + protected: int64_t m_num_iterations = -1; // -1 means infinity for Loop op, inconsistent for TensorIterator @@ -324,15 +264,9 @@ namespace ngraph // Find an input corresponding to value, adding one if necessary. Input input_for_value(const Output& value); - SubGraphOp() = default; - + SubGraphOp(); explicit SubGraphOp(const OutputVector& args); - std::shared_ptr m_body; - std::vector> - m_input_descriptions; - std::vector> - m_output_descriptions; }; using InputDescriptionPtr = std::shared_ptr; using OutputDescriptionPtr = std::shared_ptr; @@ -341,47 +275,4 @@ namespace ngraph } // namespace util } // namespace op - template <> - class NGRAPH_API AttributeAdapter< - std::vector>> - : public DirectValueAccessor< - std::vector>> - { - public: - AttributeAdapter( - std::vector>& value) - : DirectValueAccessor< - std::vector>>( - value) - { - } - - static constexpr DiscreteTypeInfo type_info{ - "AttributeAdapter>>", - 0}; - const DiscreteTypeInfo& get_type_info() const override { return type_info; } - }; - - template <> - class NGRAPH_API AttributeAdapter< - std::vector>> - : public DirectValueAccessor< - std::vector>> - { - public: - AttributeAdapter( - std::vector>& value) - : DirectValueAccessor< - std::vector>>( - value) - { - } - - static constexpr DiscreteTypeInfo type_info{ - "AttributeAdapter>>", - 0}; - const DiscreteTypeInfo& get_type_info() const override { return type_info; } - }; } // namespace ngraph diff --git a/ngraph/core/src/op/loop.cpp b/ngraph/core/src/op/loop.cpp index 2941d46d2e2345..f56393dcbe37b1 100644 --- a/ngraph/core/src/op/loop.cpp +++ b/ngraph/core/src/op/loop.cpp @@ -18,6 +18,7 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::v5::Loop, "Loop", 5); op::v5::Loop::Loop(const Output& trip_count, const Output& execution_condition) + : SubGraphOp() { set_argument(0, trip_count); set_argument(1, execution_condition); @@ -26,9 +27,9 @@ op::v5::Loop::Loop(const Output& trip_count, const Output& execution bool op::v5::Loop::visit_attributes(AttributeVisitor& visitor) { NGRAPH_OP_SCOPE(v5_Loop_visit_attributes); - visitor.on_attribute("body", m_body); - visitor.on_attribute("input_descriptions", m_input_descriptions); - visitor.on_attribute("output_descriptions", m_output_descriptions); + visitor.on_attribute("body", m_bodies[0]); + visitor.on_attribute("input_descriptions", m_input_descriptions[0]); + visitor.on_attribute("output_descriptions", m_output_descriptions[0]); visitor.on_attribute("special_body_ports", m_special_body_ports); return true; @@ -39,7 +40,7 @@ void op::v5::Loop::validate_and_infer_types() NGRAPH_OP_SCOPE(v5_Loop_validate_and_infer_types); if (m_special_body_ports.current_iteration_input_idx >= 0) { - const auto& cur_iter_rank = m_body->get_parameters() + const auto& cur_iter_rank = m_bodies[0]->get_parameters() .at(m_special_body_ports.current_iteration_input_idx) ->get_partial_shape() .rank(); @@ -79,7 +80,7 @@ void op::v5::Loop::validate_and_infer_types() return; const auto& body_execution_condition = - m_body->get_results().at(m_special_body_ports.body_condition_output_idx)->input_value(0); + m_bodies[0]->get_results().at(m_special_body_ports.body_condition_output_idx)->input_value(0); const auto& body_condition_rank = body_execution_condition.get_partial_shape().rank(); if (body_condition_rank.is_static()) { @@ -110,7 +111,7 @@ void op::v5::Loop::validate_and_infer_types() // Const(true or false) -> Loop (body: Parameter -> execution_condition output) for (const auto& desc : get_input_descriptions()) { - if (m_body->get_parameters().at(desc->m_body_parameter_index) == cond_param) + if (m_bodies[0]->get_parameters().at(desc->m_body_parameter_index) == cond_param) { if (const auto& cond_value = get_constant_from_source(input_value(desc->m_input_index))) @@ -156,7 +157,7 @@ void op::v5::Loop::validate_and_infer_types() // the inputs. // When using visit_attributes() no duplication occurs, input_offset shall be decremented. size_t input_offset = 2; - for (const auto& in_desc : m_input_descriptions) + for (const auto& in_desc : m_input_descriptions[0]) { if (in_desc->m_input_index == 0 || in_desc->m_input_index == 1) { @@ -169,18 +170,18 @@ void op::v5::Loop::validate_and_infer_types() NODE_VALIDATION_CHECK(this, input_offset >= 0, "External port id 0 or 1 is duplicated."); NODE_VALIDATION_CHECK(this, - get_input_size() == m_input_descriptions.size() + input_offset, + get_input_size() == m_input_descriptions[0].size() + input_offset, "Number of inputs must be the same as number of input descriptions"); // Input - for (const auto& input_description : m_input_descriptions) + for (const auto& input_description : m_input_descriptions[0]) { auto index = input_description->m_input_index; if (auto slice_input_description = as_type_ptr(input_description)) { auto body_parameter = - m_body->get_parameters().at(slice_input_description->m_body_parameter_index); + m_bodies[0]->get_parameters().at(slice_input_description->m_body_parameter_index); const auto& input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); if (input_partial_shape.rank().is_dynamic()) @@ -200,10 +201,10 @@ void op::v5::Loop::validate_and_infer_types() as_type_ptr(input_description)) { auto body_value = - m_body->get_results().at(merged_input_description->m_body_value_index); + m_bodies[0]->get_results().at(merged_input_description->m_body_value_index); auto body_parameter = - m_body->get_parameters().at(merged_input_description->m_body_parameter_index); + m_bodies[0]->get_parameters().at(merged_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = input(index).get_partial_shape(); @@ -214,7 +215,7 @@ void op::v5::Loop::validate_and_infer_types() as_type_ptr(input_description)) { auto body_parameter = - m_body->get_parameters().at(invariant_input_description->m_body_parameter_index); + m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = input(index).get_partial_shape(); @@ -224,15 +225,15 @@ void op::v5::Loop::validate_and_infer_types() } // Body - m_body->validate_nodes_and_infer_types(); + m_bodies[0]->validate_nodes_and_infer_types(); // Output - for (const auto& output_description : m_output_descriptions) + for (const auto& output_description : m_output_descriptions[0]) { auto index = output_description->m_output_index; auto body_value = - m_body->get_results().at(output_description->m_body_value_index)->input_value(0); + m_bodies[0]->get_results().at(output_description->m_body_value_index)->input_value(0); if (auto concat_output_description = as_type_ptr(output_description)) @@ -286,7 +287,7 @@ void op::v5::Loop::validate_and_infer_types() } NODE_VALIDATION_CHECK(this, - get_output_size() == m_output_descriptions.size(), + get_output_size() == m_output_descriptions[0].size(), "Number of outputs must be the same as number of output descriptions"); } @@ -322,8 +323,12 @@ Output op::v5::Loop::get_concatenated_slices(const Output& value, bool op::v5::Loop::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v5_Loop_evaluate); - runtime::reference::loop( - m_body, m_output_descriptions, m_input_descriptions, m_special_body_ports, outputs, inputs); + runtime::reference::loop(m_bodies[0], + m_output_descriptions[0], + m_input_descriptions[0], + m_special_body_ports, + outputs, + inputs); return true; } @@ -347,20 +352,21 @@ void op::v5::Loop::clone_to(op::v5::Loop& dst, const OutputVector& new_args) con dst.m_num_iterations = m_num_iterations; dst.m_special_body_ports = m_special_body_ports; - dst.m_body = clone_function(*get_function()); + dst.m_bodies[0] = clone_function(*get_function()); - for (auto& input_description : m_input_descriptions) + for (auto& input_description : m_input_descriptions[0]) { - dst.m_input_descriptions.push_back(input_description->copy()); + dst.m_input_descriptions[0].push_back(input_description->copy()); } - for (auto& output_description : m_output_descriptions) + for (auto& output_description : m_output_descriptions[0]) { - dst.m_output_descriptions.push_back(output_description->copy()); + dst.m_output_descriptions[0].push_back(output_description->copy()); } dst.validate_and_infer_types(); } op::v5::Loop::Loop(const op::v5::Loop& other) + : SubGraphOp() { other.clone_to(*this, other.input_values()); } diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index 6dffdaa77fe96b..fa34c1e9151110 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -11,7 +11,7 @@ using namespace std; using namespace ngraph; -NGRAPH_RTTI_DEFINITION(op::v0::TensorIterator, "TensorIterator", 0, op::util::SubGraphOp); +constexpr NodeTypeInfo op::v0::TensorIterator::type_info; op::v0::TensorIterator::TensorIterator(const OutputVector& values) : op::util::SubGraphOp(values) @@ -21,9 +21,9 @@ op::v0::TensorIterator::TensorIterator(const OutputVector& values) bool op::v0::TensorIterator::visit_attributes(AttributeVisitor& visitor) { NGRAPH_OP_SCOPE(v0_TensorIterator_visit_attributes); - visitor.on_attribute("body", m_body); - visitor.on_attribute("input_descriptions", m_input_descriptions); - visitor.on_attribute("output_descriptions", m_output_descriptions); + visitor.on_attribute("body", m_bodies[0]); + visitor.on_attribute("input_descriptions", m_input_descriptions[0]); + visitor.on_attribute("output_descriptions", m_output_descriptions[0]); return true; } @@ -33,7 +33,7 @@ void op::v0::TensorIterator::revalidate_and_infer_types_for_body_ops() std::stack, std::vector>> nodes_to_do; std::unordered_set> nodes_done; - for (const auto& r : m_body->get_results()) + for (const auto& r : m_bodies[0]->get_results()) { nodes_to_do.push(r); } @@ -76,7 +76,7 @@ void op::v0::TensorIterator::validate_and_infer_types() { NGRAPH_OP_SCOPE(v0_TensorIterator_validate_and_infer_types); NODE_VALIDATION_CHECK(this, - get_input_size() == m_input_descriptions.size(), + get_input_size() == m_input_descriptions[0].size(), "Number of inputs must be the same as number of input descriptions"); std::vector> ends; @@ -89,15 +89,16 @@ void op::v0::TensorIterator::validate_and_infer_types() return value; }; + auto body = get_function(); // Input - for (const auto& input_description : m_input_descriptions) + for (const auto& input_description : m_input_descriptions[0]) { auto index = input_description->m_input_index; if (auto slice_input_description = as_type_ptr(input_description)) { auto body_parameter = - m_body->get_parameters().at(slice_input_description->m_body_parameter_index); + body->get_parameters().at(slice_input_description->m_body_parameter_index); auto input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); if (input_partial_shape.is_static()) { @@ -126,11 +127,11 @@ void op::v0::TensorIterator::validate_and_infer_types() as_type_ptr(input_description)) { auto body_value = - m_body->get_results().at(merged_input_description->m_body_value_index)->input(0); + m_bodies[0]->get_results().at(merged_input_description->m_body_value_index)->input(0); ends.push_back(body_value.get_node()->shared_from_this()); auto body_parameter = - m_body->get_parameters().at(merged_input_description->m_body_parameter_index); + m_bodies[0]->get_parameters().at(merged_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); @@ -140,7 +141,7 @@ void op::v0::TensorIterator::validate_and_infer_types() as_type_ptr(input_description)) { auto body_parameter = - m_body->get_parameters().at(invariant_input_description->m_body_parameter_index); + m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); @@ -154,12 +155,12 @@ void op::v0::TensorIterator::validate_and_infer_types() // Output try_to_set_num_iterations_if_no_slice_inputs(); - for (const auto& output_description : m_output_descriptions) + for (const auto& output_description : m_output_descriptions[0]) { auto index = output_description->m_output_index; auto body_value = - m_body->get_results().at(output_description->m_body_value_index)->input_value(0); + m_bodies[0]->get_results().at(output_description->m_body_value_index)->input_value(0); if (auto concat_output_description = as_type_ptr(output_description)) @@ -207,7 +208,7 @@ void op::v0::TensorIterator::validate_and_infer_types() } NODE_VALIDATION_CHECK(this, - get_output_size() == m_output_descriptions.size(), + get_output_size() == m_output_descriptions[0].size(), "Number of outputs must be the same as number of output descriptions"); } @@ -235,7 +236,7 @@ void op::v0::TensorIterator::try_to_set_num_iterations_if_no_slice_inputs() return; } - for (const auto& output_description : m_output_descriptions) + for (const auto& output_description : m_output_descriptions[0]) { if (auto concat = as_type_ptr(output_description)) { @@ -256,14 +257,14 @@ std::shared_ptr description(), " operation with name ", get_friendly_name()); - op->set_output_size(m_output_descriptions.size()); + op->set_output_size(m_output_descriptions[0].size()); - std::vector<::ngraph::element::Type> types(m_body->get_parameters().size()); - std::vector<::ngraph::PartialShape> new_shapes(m_body->get_parameters().size()); + std::vector<::ngraph::element::Type> types(m_bodies[0]->get_parameters().size()); + std::vector<::ngraph::PartialShape> new_shapes(m_bodies[0]->get_parameters().size()); for (size_t input_index = 0; input_index < new_args.size(); ++input_index) { - for (auto& input_description : m_input_descriptions) + for (auto& input_description : m_input_descriptions[0]) { if (input_description->m_input_index == input_index) { @@ -288,19 +289,19 @@ std::shared_ptr op->m_num_iterations = m_num_iterations; auto func = std::make_shared( - m_body->get_results(), m_body->get_sinks(), m_body->get_parameters()); + m_bodies[0]->get_results(), m_bodies[0]->get_sinks(), m_bodies[0]->get_parameters()); auto spec_func = specialize_function(func, types, new_shapes, std::vector(new_args.size(), nullptr)); - op->m_body = std::make_shared( + op->m_bodies[0] = std::make_shared( spec_func->get_results(), spec_func->get_sinks(), spec_func->get_parameters()); - for (auto& input_description : m_input_descriptions) + for (auto& input_description : m_input_descriptions[0]) { - op->m_input_descriptions.push_back(input_description->copy()); + op->m_input_descriptions[0].push_back(input_description->copy()); } - for (auto& output_description : m_output_descriptions) + for (auto& output_description : m_output_descriptions[0]) { - op->m_output_descriptions.push_back(output_description->copy()); + op->m_output_descriptions[0].push_back(output_description->copy()); } op->validate_and_infer_types(); return op; diff --git a/ngraph/core/src/op/util/multi_subgraph_base.cpp b/ngraph/core/src/op/util/multi_subgraph_base.cpp new file mode 100644 index 00000000000000..a14ff78ad69efc --- /dev/null +++ b/ngraph/core/src/op/util/multi_subgraph_base.cpp @@ -0,0 +1,124 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "ngraph/op/util/multi_subgraph_base.hpp" +#include "ngraph/opsets/opset5.hpp" + +#include "ngraph/graph_util.hpp" + +using namespace ngraph; + +NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp, "MultiSubGraphOp", 0); + +constexpr DiscreteTypeInfo op::util::MultiSubGraphOp::InvariantInputDescription::type_info; +constexpr DiscreteTypeInfo op::util::MultiSubGraphOp::BodyOutputDescription::type_info; + +op::util::MultiSubGraphOp::InputDescription::InputDescription(uint64_t input_index, + uint64_t body_parameter_index) + : m_input_index(input_index) + , m_body_parameter_index(body_parameter_index) +{ +} + +op::util::MultiSubGraphOp::OutputDescription::OutputDescription(uint64_t body_value_index, + uint64_t output_index) + : m_body_value_index(body_value_index) + , m_output_index(output_index) +{ +} + +op::util::MultiSubGraphOp::InvariantInputDescription::InvariantInputDescription( + uint64_t input_index, uint64_t body_parameter_index) + : InputDescription(input_index, body_parameter_index) +{ +} + +std::shared_ptr + op::util::MultiSubGraphOp::InvariantInputDescription::copy() const +{ + return std::make_shared(m_input_index, + m_body_parameter_index); +} + +op::util::MultiSubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, + uint64_t output_index) + : OutputDescription(body_value_index, output_index) +{ +} + +std::shared_ptr + op::util::MultiSubGraphOp::BodyOutputDescription::copy() const +{ + return std::make_shared(m_body_value_index, m_output_index); +} + +op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args) + : Op(args) +{ +} + +op::util::MultiSubGraphOp::MultiSubGraphOp(size_t bodies_index) +{ + m_bodies.resize(bodies_index); + m_input_descriptions.resize(bodies_index); + m_output_descriptions.resize(bodies_index); +} + + +op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args, size_t bodies_index) + : MultiSubGraphOp(args) +{ + m_bodies.resize(bodies_index); + m_input_descriptions.resize(bodies_index); + m_output_descriptions.resize(bodies_index); +} + +Input op::util::MultiSubGraphOp::input_for_value(const Output& value) +{ + auto input_index = get_input_size(); + set_argument(input_index, value); + return Input(this, input_index); +} + +void op::util::MultiSubGraphOp::set_invariant_inputs(const Output& value, + const ParameterVector bodies_parameters) +{ + auto input_index = input_for_value(value).get_index(); + size_t body_index = 0; + for (auto& param : bodies_parameters) + { + if (param == nullptr) + { + body_index++; + continue; + } + m_input_descriptions[body_index].push_back( + std::make_shared( + input_index, m_bodies[body_index]->get_parameter_index(param))); + body_index++; + } +} + +Output op::util::MultiSubGraphOp::set_body_outputs(ResultVector bodies_results) +{ + auto output_index = m_output_descriptions[0].size(); + size_t body_index = 0; + for (auto& body_result : bodies_results) + { + m_output_descriptions[body_index].push_back(std::make_shared( + m_bodies[body_index]->get_result_index(body_result), output_index)); + body_index++; + } + set_output_size(output_index + 1); + return Output(shared_from_this(), output_index); +} + +namespace ngraph +{ + constexpr DiscreteTypeInfo AttributeAdapter< + std::vector>>::type_info; + + constexpr DiscreteTypeInfo AttributeAdapter< + std::vector>>::type_info; +} // namespace ngraph diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index 916b7cc7c5bafc..41c59ff7ba1c61 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -13,18 +13,10 @@ NGRAPH_RTTI_DEFINITION(op::util::SubGraphOp, "SubGraphOp", 0); constexpr DiscreteTypeInfo op::util::SubGraphOp::SliceInputDescription::type_info; constexpr DiscreteTypeInfo op::util::SubGraphOp::MergedInputDescription::type_info; -constexpr DiscreteTypeInfo op::util::SubGraphOp::InvariantInputDescription::type_info; constexpr DiscreteTypeInfo op::util::SubGraphOp::BodyOutputDescription::type_info; constexpr DiscreteTypeInfo op::util::SubGraphOp::ConcatOutputDescription::type_info; -op::util::SubGraphOp::InputDescription::InputDescription(uint64_t input_index, - uint64_t body_parameter_index) - : m_input_index(input_index) - , m_body_parameter_index(body_parameter_index) -{ -} - op::util::SubGraphOp::SliceInputDescription::SliceInputDescription(uint64_t input_index, uint64_t body_parameter_index, int64_t start, @@ -41,7 +33,7 @@ op::util::SubGraphOp::SliceInputDescription::SliceInputDescription(uint64_t inpu { } -std::shared_ptr +std::shared_ptr op::util::SubGraphOp::SliceInputDescription::copy() const { return std::make_shared( @@ -56,31 +48,13 @@ op::util::SubGraphOp::MergedInputDescription::MergedInputDescription(uint64_t in { } -std::shared_ptr +std::shared_ptr op::util::SubGraphOp::MergedInputDescription::copy() const { return std::make_shared( m_input_index, m_body_parameter_index, m_body_value_index); } -op::util::SubGraphOp::InvariantInputDescription::InvariantInputDescription( - uint64_t input_index, uint64_t body_parameter_index) - : InputDescription(input_index, body_parameter_index) -{ -} - -std::shared_ptr - op::util::SubGraphOp::InvariantInputDescription::copy() const -{ - return std::make_shared(m_input_index, m_body_parameter_index); -} - -op::util::SubGraphOp::OutputDescription::OutputDescription(uint64_t body_value_index, - uint64_t output_index) - : m_body_value_index(body_value_index) - , m_output_index(output_index) -{ -} op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t body_value_index, uint64_t output_index, @@ -98,7 +72,7 @@ op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t { } -std::shared_ptr +std::shared_ptr op::util::SubGraphOp::ConcatOutputDescription::copy() const { return std::make_shared( @@ -113,14 +87,19 @@ op::util::SubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body { } -std::shared_ptr +std::shared_ptr op::util::SubGraphOp::BodyOutputDescription::copy() const { return std::make_shared(m_body_value_index, m_output_index, m_iteration); } +op::util::SubGraphOp::SubGraphOp() + : MultiSubGraphOp(1) +{ +} + op::util::SubGraphOp::SubGraphOp(const OutputVector& args) - : Op(args) + : MultiSubGraphOp(args, 1) { } @@ -128,26 +107,30 @@ void op::util::SubGraphOp::set_merged_input(const std::shared_ptr& bo const Output& initial_value, const Output& successive_value) { - m_input_descriptions.push_back(std::make_shared( + auto body = get_function(); + + m_input_descriptions[0].push_back(std::make_shared( input_for_value(initial_value).get_index(), - m_body->get_parameter_index(body_parameter), - m_body->get_result_index(successive_value))); + body->get_parameter_index(body_parameter), + body->get_result_index(successive_value))); validate_and_infer_types(); } void op::util::SubGraphOp::set_invariant_input(const std::shared_ptr& body_parameter, const Output& value) { - m_input_descriptions.push_back(std::make_shared( - input_for_value(value).get_index(), m_body->get_parameter_index(body_parameter))); + auto body = get_function(); + m_input_descriptions[0].push_back(std::make_shared( + input_for_value(value).get_index(), body->get_parameter_index(body_parameter))); validate_and_infer_types(); } Output op::util::SubGraphOp::get_iter_value(const Output& body_value, int64_t iteration) { auto output_index = get_output_size(); - m_output_descriptions.push_back(std::make_shared( - m_body->get_result_index(body_value), output_index, iteration)); + auto body = get_function(); + m_output_descriptions[0].push_back(std::make_shared( + body->get_result_index(body_value), output_index, iteration)); set_output_size(output_index + 1); validate_and_infer_types(); return Output(shared_from_this(), output_index); @@ -161,8 +144,9 @@ Output op::util::SubGraphOp::get_concatenated_slices(const Output& b int64_t axis) { auto output_index = get_output_size(); - m_output_descriptions.push_back(std::make_shared( - m_body->get_result_index(body_value), output_index, start, stride, part_size, end, axis)); + auto body = get_function(); + m_output_descriptions[0].push_back(std::make_shared( + body->get_result_index(body_value), output_index, start, stride, part_size, end, axis)); set_output_size(output_index + 1); validate_and_infer_types(); return Output(shared_from_this(), output_index); @@ -176,9 +160,10 @@ void op::util::SubGraphOp::set_sliced_input(const std::shared_ptr& pa int64_t end, int64_t axis) { - m_input_descriptions.push_back( + auto body = get_function(); + m_input_descriptions[0].push_back( std::make_shared(input_for_value(value).get_index(), - m_body->get_parameter_index(parameter), + body->get_parameter_index(parameter), start, stride, part_size, From 050f2320940900020700b1a22f5c05fdf86240a4 Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 13 Jul 2021 12:34:50 +0300 Subject: [PATCH 02/21] Fix format --- ngraph/core/include/ngraph/op/tensor_iterator.hpp | 4 ++-- ngraph/core/src/op/loop.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ngraph/core/include/ngraph/op/tensor_iterator.hpp b/ngraph/core/include/ngraph/op/tensor_iterator.hpp index 6c751fb45f95c8..6a8eaaef349caf 100644 --- a/ngraph/core/include/ngraph/op/tensor_iterator.hpp +++ b/ngraph/core/include/ngraph/op/tensor_iterator.hpp @@ -20,8 +20,8 @@ namespace ngraph class NGRAPH_API TensorIterator : public op::util::SubGraphOp { public: - static constexpr NodeTypeInfo type_info{"TensorIterator", 0}; - const NodeTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; + bool visit_attributes(AttributeVisitor& visitor) override; TensorIterator() = default; diff --git a/ngraph/core/src/op/loop.cpp b/ngraph/core/src/op/loop.cpp index f56393dcbe37b1..94658148755037 100644 --- a/ngraph/core/src/op/loop.cpp +++ b/ngraph/core/src/op/loop.cpp @@ -40,7 +40,8 @@ void op::v5::Loop::validate_and_infer_types() NGRAPH_OP_SCOPE(v5_Loop_validate_and_infer_types); if (m_special_body_ports.current_iteration_input_idx >= 0) { - const auto& cur_iter_rank = m_bodies[0]->get_parameters() + const auto& cur_iter_rank = m_bodies[0] + ->get_parameters() .at(m_special_body_ports.current_iteration_input_idx) ->get_partial_shape() .rank(); @@ -79,8 +80,10 @@ void op::v5::Loop::validate_and_infer_types() // special body ports were not set yet, so we can't calculate output shape return; - const auto& body_execution_condition = - m_bodies[0]->get_results().at(m_special_body_ports.body_condition_output_idx)->input_value(0); + const auto& body_execution_condition = m_bodies[0] + ->get_results() + .at(m_special_body_ports.body_condition_output_idx) + ->input_value(0); const auto& body_condition_rank = body_execution_condition.get_partial_shape().rank(); if (body_condition_rank.is_static()) { @@ -214,8 +217,8 @@ void op::v5::Loop::validate_and_infer_types() else if (auto invariant_input_description = as_type_ptr(input_description)) { - auto body_parameter = - m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index); + auto body_parameter = m_bodies[0]->get_parameters().at( + invariant_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = input(index).get_partial_shape(); From 2606b0a5db491c8396ddc072e74024a79dca0a5e Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 13 Jul 2021 12:51:45 +0300 Subject: [PATCH 03/21] Fix clang format --- .../include/ngraph/op/util/multi_subgraph_base.hpp | 4 +++- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 9 ++++----- ngraph/core/src/op/tensor_iterator.cpp | 10 ++++++---- ngraph/core/src/op/util/multi_subgraph_base.cpp | 1 - ngraph/core/src/op/util/sub_graph_base.cpp | 1 - 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 4273f66ddc99f3..6c9c41663e8cfe 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -216,9 +216,11 @@ namespace ngraph MultiSubGraphOp(const MultiSubGraphOp&) = delete; MultiSubGraphOp(MultiSubGraphOp&&) = default; + MultiSubGraphOp(size_t bodies_index); + MultiSubGraphOp& operator=(const MultiSubGraphOp&) = delete; MultiSubGraphOp& operator=(MultiSubGraphOp&&) = default; - MultiSubGraphOp::MultiSubGraphOp(size_t bodies_index); + protected: // Find an input corresponding to value, adding one if necessary. Input input_for_value(const Output& value); diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 5ab16b2e1a829b..06e393da2451b6 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -141,7 +141,10 @@ namespace ngraph }; virtual std::shared_ptr get_function() { return m_bodies[0]; }; - virtual std::shared_ptr get_function() const { return m_bodies[0]; }; + virtual std::shared_ptr get_function() const + { + return m_bodies[0]; + }; virtual void set_function(const std::shared_ptr& func) { m_bodies[0] = func; @@ -249,14 +252,11 @@ namespace ngraph SubGraphOp(const SubGraphOp&) = delete; SubGraphOp(SubGraphOp&&) = default; - - SubGraphOp& operator=(const SubGraphOp&) = delete; SubGraphOp& operator=(SubGraphOp&&) = default; int64_t get_num_iterations() const { return m_num_iterations; } - protected: int64_t m_num_iterations = -1; // -1 means infinity for Loop op, inconsistent for TensorIterator @@ -266,7 +266,6 @@ namespace ngraph SubGraphOp(); explicit SubGraphOp(const OutputVector& args); - }; using InputDescriptionPtr = std::shared_ptr; using OutputDescriptionPtr = std::shared_ptr; diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index fa34c1e9151110..826dc59920db01 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -126,8 +126,10 @@ void op::v0::TensorIterator::validate_and_infer_types() else if (auto merged_input_description = as_type_ptr(input_description)) { - auto body_value = - m_bodies[0]->get_results().at(merged_input_description->m_body_value_index)->input(0); + auto body_value = m_bodies[0] + ->get_results() + .at(merged_input_description->m_body_value_index) + ->input(0); ends.push_back(body_value.get_node()->shared_from_this()); auto body_parameter = @@ -140,8 +142,8 @@ void op::v0::TensorIterator::validate_and_infer_types() else if (auto invariant_input_description = as_type_ptr(input_description)) { - auto body_parameter = - m_bodies[0]->get_parameters().at(invariant_input_description->m_body_parameter_index); + auto body_parameter = m_bodies[0]->get_parameters().at( + invariant_input_description->m_body_parameter_index); auto body_param_partial_shape = body_parameter->get_partial_shape(); auto input_partial_shape = inputs().at(index).get_source_output().get_partial_shape(); diff --git a/ngraph/core/src/op/util/multi_subgraph_base.cpp b/ngraph/core/src/op/util/multi_subgraph_base.cpp index a14ff78ad69efc..825ff68a62f0e2 100644 --- a/ngraph/core/src/op/util/multi_subgraph_base.cpp +++ b/ngraph/core/src/op/util/multi_subgraph_base.cpp @@ -65,7 +65,6 @@ op::util::MultiSubGraphOp::MultiSubGraphOp(size_t bodies_index) m_output_descriptions.resize(bodies_index); } - op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args, size_t bodies_index) : MultiSubGraphOp(args) { diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index 41c59ff7ba1c61..87e2abbc509ba2 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -55,7 +55,6 @@ std::shared_ptr m_input_index, m_body_parameter_index, m_body_value_index); } - op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t body_value_index, uint64_t output_index, int64_t start, From 81a0c98139f78a5f2aad03707fa83c31e3295514 Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 13 Jul 2021 13:01:37 +0300 Subject: [PATCH 04/21] Fix TensorIterator RTT --- ngraph/core/src/op/tensor_iterator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index 826dc59920db01..fb4e123985078c 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -11,7 +11,7 @@ using namespace std; using namespace ngraph; -constexpr NodeTypeInfo op::v0::TensorIterator::type_info; +NGRAPH_RTTI_DEFINITION(op::v0::TensorIterator, "TensorIterator", 0, op::util::SubGraphOp); op::v0::TensorIterator::TensorIterator(const OutputVector& values) : op::util::SubGraphOp(values) From fe358edd82a1a9025e380c1046a5503e7ef8a7ae Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 13 Jul 2021 13:17:59 +0300 Subject: [PATCH 05/21] Fix subgraph --- ngraph/core/src/op/util/sub_graph_base.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index 87e2abbc509ba2..aba1821f93db86 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -178,11 +178,3 @@ Input op::util::SubGraphOp::input_for_value(const Output& value) return Input(this, input_index); } -namespace ngraph -{ - constexpr DiscreteTypeInfo AttributeAdapter< - std::vector>>::type_info; - - constexpr DiscreteTypeInfo AttributeAdapter< - std::vector>>::type_info; -} // namespace ngraph From fcec7c4f16e788d1b3ab0e0539acc1845ccd5491 Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 13 Jul 2021 13:47:37 +0300 Subject: [PATCH 06/21] Fix codestyle --- ngraph/core/src/op/util/sub_graph_base.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index aba1821f93db86..5f734bdbe4529f 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -177,4 +177,3 @@ Input op::util::SubGraphOp::input_for_value(const Output& value) set_argument(input_index, value); return Input(this, input_index); } - From 8af90a93adcb16d11c9eeb2e30000cd9641235b3 Mon Sep 17 00:00:00 2001 From: evolosen Date: Fri, 16 Jul 2021 12:44:13 +0300 Subject: [PATCH 07/21] Fix comments --- .../ngraph/op/util/multi_subgraph_base.hpp | 104 ++++++++++++++++- .../include/ngraph/op/util/sub_graph_base.hpp | 101 +--------------- ngraph/core/src/op/loop.cpp | 11 ++ ngraph/core/src/op/tensor_iterator.cpp | 11 ++ .../core/src/op/util/multi_subgraph_base.cpp | 110 ++++++++++++++---- ngraph/core/src/op/util/sub_graph_base.cpp | 65 ----------- 6 files changed, 214 insertions(+), 188 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 6c9c41663e8cfe..3ba821497c4126 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -68,6 +68,105 @@ namespace ngraph uint64_t m_body_value_index{0}; uint64_t m_output_index{0}; }; + + /// + /// \brief Describes a body input formed from slices of an input to + /// MultiSubGraphOp. + /// + class NGRAPH_API SliceInputDescription : public InputDescription + { + public: + static constexpr type_info_t type_info{"SliceInputDescription", 0}; + const type_info_t& get_type_info() const override { return type_info; } + /// + /// \brief Constructs a new instance. + /// + /// \param input_index Position of the MultiSubGraphOp input + /// \param body_parameter_index Body parameter position to receive input + /// \param start First index for slices + /// \param stride Step amount for slices + /// \param part_size Width of slices + /// \param end Last index for slices + /// \param axis Axis being sliced + /// + SliceInputDescription(uint64_t input_index, + uint64_t body_parameter_index, + int64_t start, + int64_t stride, + int64_t part_size, + int64_t end, + int64_t axis); + SliceInputDescription() = default; + std::shared_ptr copy() const override; + int64_t m_start{0}; + int64_t m_stride{0}; + int64_t m_part_size{0}; + int64_t m_end{0}; + int64_t m_axis{0}; + }; + + /// + /// \brief Describes a body input initialized from a MultiSubGraphOp input + /// on the first iteration, and then a body output thereafter. + /// + class NGRAPH_API MergedInputDescription : public InputDescription + { + public: + static constexpr type_info_t type_info{"MergedInputDescription", 0}; + const type_info_t& get_type_info() const override { return type_info; } + /// + /// \brief Constructs a new instance. + /// + /// \param input_index Position of the MultiSubGraphOp input + /// supplying a value to body_parameter for + /// the initial iteration. + /// \param body_parameter_index Body parameter position to receive input. + /// \param body_value_index Body value to supply body_parameter for + /// successive + /// iterations. + /// + MergedInputDescription(uint64_t input_index, + uint64_t body_parameter_index, + uint64_t body_value_index); + MergedInputDescription() = default; + std::shared_ptr copy() const override; + uint64_t m_body_value_index{0}; + }; + + /// \brief Produces an output by concatenating an output from each iteration + class NGRAPH_API ConcatOutputDescription : public OutputDescription + { + public: + static constexpr type_info_t type_info{"ConcatOutputDescription", 0}; + const type_info_t& get_type_info() const override { return type_info; } + /// + /// \brief Constructs a new instance. + /// + /// \param body_value_index A body value that produces the output + /// \param output_index The MultiSubGraphOp output index + /// \param start First index for slices + /// \param stride Step amount for slices + /// \param part_size Width of slices + /// \param end Last index for slices + /// \param axis Axis being sliced + /// + ConcatOutputDescription(uint64_t body_value_index, + uint64_t output_index, + int64_t start, + int64_t stride, + int64_t part_size, + int64_t end, + int64_t axis); + ConcatOutputDescription() = default; + + std::shared_ptr copy() const override; + int64_t m_start{0}; + int64_t m_stride{0}; + int64_t m_part_size{0}; + int64_t m_end{0}; + int64_t m_axis{0}; + }; + /// \brief Produces an input class NGRAPH_API InvariantInputDescription : public InputDescription { @@ -216,8 +315,6 @@ namespace ngraph MultiSubGraphOp(const MultiSubGraphOp&) = delete; MultiSubGraphOp(MultiSubGraphOp&&) = default; - MultiSubGraphOp(size_t bodies_index); - MultiSubGraphOp& operator=(const MultiSubGraphOp&) = delete; MultiSubGraphOp& operator=(MultiSubGraphOp&&) = default; @@ -225,8 +322,9 @@ namespace ngraph // Find an input corresponding to value, adding one if necessary. Input input_for_value(const Output& value); + MultiSubGraphOp(size_t number_of_bodies); MultiSubGraphOp() = default; - MultiSubGraphOp(const OutputVector& args, size_t bodies_index); + MultiSubGraphOp(const OutputVector& args, size_t number_of_bodies); explicit MultiSubGraphOp(const OutputVector& args); std::vector> m_bodies; diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 06e393da2451b6..436e302a02ed45 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -13,111 +13,14 @@ namespace ngraph { namespace util { - /// \brief Abstract base class for sub-graph based ops, i.e ops that have sub-graph + /// \brief Abstract base class for sub-graph based ops, i.e ops that have only one + /// sub-graph /// class NGRAPH_API SubGraphOp : public MultiSubGraphOp { public: NGRAPH_RTTI_DECLARATION; - /// - /// \brief Describes a body input formed from slices of an input to - /// SubGraphOp. - /// - class NGRAPH_API SliceInputDescription : public MultiSubGraphOp::InputDescription - { - public: - static constexpr type_info_t type_info{"SliceInputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } - /// - /// \brief Constructs a new instance. - /// - /// \param input_index Position of the SubGraphOp input - /// \param body_parameter_index Body parameter position to receive input - /// \param start First index for slices - /// \param stride Step amount for slices - /// \param part_size Width of slices - /// \param end Last index for slices - /// \param axis Axis being sliced - /// - SliceInputDescription(uint64_t input_index, - uint64_t body_parameter_index, - int64_t start, - int64_t stride, - int64_t part_size, - int64_t end, - int64_t axis); - SliceInputDescription() = default; - std::shared_ptr copy() const override; - int64_t m_start{0}; - int64_t m_stride{0}; - int64_t m_part_size{0}; - int64_t m_end{0}; - int64_t m_axis{0}; - }; - - /// - /// \brief Describes a body input initialized from a SubGraphOp input on - /// the first iteration, and then a body output thereafter. - /// - class NGRAPH_API MergedInputDescription : public MultiSubGraphOp::InputDescription - { - public: - static constexpr type_info_t type_info{"MergedInputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } - /// - /// \brief Constructs a new instance. - /// - /// \param input_index Position of the SubGraphOp input - /// supplying a value to body_parameter for - /// the initial iteration. - /// \param body_parameter_index Body parameter position to receive input. - /// \param body_value_index Body value to supply body_parameter for - /// successive - /// iterations. - /// - MergedInputDescription(uint64_t input_index, - uint64_t body_parameter_index, - uint64_t body_value_index); - MergedInputDescription() = default; - std::shared_ptr copy() const override; - uint64_t m_body_value_index{0}; - }; - - /// \brief Produces an output by concatenating an output from each iteration - class NGRAPH_API ConcatOutputDescription : public MultiSubGraphOp::OutputDescription - { - public: - static constexpr type_info_t type_info{"ConcatOutputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } - /// - /// \brief Constructs a new instance. - /// - /// \param body_value_index A body value that produces the output - /// \param output_index The SubGraphOp output index - /// \param start First index for slices - /// \param stride Step amount for slices - /// \param part_size Width of slices - /// \param end Last index for slices - /// \param axis Axis being sliced - /// - ConcatOutputDescription(uint64_t body_value_index, - uint64_t output_index, - int64_t start, - int64_t stride, - int64_t part_size, - int64_t end, - int64_t axis); - ConcatOutputDescription() = default; - - std::shared_ptr copy() const override; - int64_t m_start{0}; - int64_t m_stride{0}; - int64_t m_part_size{0}; - int64_t m_end{0}; - int64_t m_axis{0}; - }; - /// \brief Produces an output from a specific iteration class NGRAPH_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription { diff --git a/ngraph/core/src/op/loop.cpp b/ngraph/core/src/op/loop.cpp index 94658148755037..b7cc41288100d9 100644 --- a/ngraph/core/src/op/loop.cpp +++ b/ngraph/core/src/op/loop.cpp @@ -38,6 +38,17 @@ bool op::v5::Loop::visit_attributes(AttributeVisitor& visitor) void op::v5::Loop::validate_and_infer_types() { NGRAPH_OP_SCOPE(v5_Loop_validate_and_infer_types); + + NODE_VALIDATION_CHECK( + this, m_bodies.size() == 1, "Number of bodies for loop is greater than 1"); + + NODE_VALIDATION_CHECK(this, + m_input_descriptions.size() == 1, + "Loop contains input descriptions for other bodies"); + NODE_VALIDATION_CHECK(this, + m_output_descriptions.size() == 1, + "Loop contains output descriptions for other bodies"); + if (m_special_body_ports.current_iteration_input_idx >= 0) { const auto& cur_iter_rank = m_bodies[0] diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index fb4e123985078c..26d1901c34a717 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -75,6 +75,17 @@ void op::v0::TensorIterator::revalidate_and_infer_types_for_body_ops() void op::v0::TensorIterator::validate_and_infer_types() { NGRAPH_OP_SCOPE(v0_TensorIterator_validate_and_infer_types); + + NODE_VALIDATION_CHECK( + this, m_bodies.size() == 1, "Number of bodies for loop is greater than 1"); + + NODE_VALIDATION_CHECK(this, + m_input_descriptions.size() == 1, + "Loop contains input descriptions for other bodies"); + NODE_VALIDATION_CHECK(this, + m_output_descriptions.size() == 1, + "Loop contains output descriptions for other bodies"); + NODE_VALIDATION_CHECK(this, get_input_size() == m_input_descriptions[0].size(), "Number of inputs must be the same as number of input descriptions"); diff --git a/ngraph/core/src/op/util/multi_subgraph_base.cpp b/ngraph/core/src/op/util/multi_subgraph_base.cpp index 825ff68a62f0e2..39ea935699e82a 100644 --- a/ngraph/core/src/op/util/multi_subgraph_base.cpp +++ b/ngraph/core/src/op/util/multi_subgraph_base.cpp @@ -11,8 +11,11 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp, "MultiSubGraphOp", 0); +constexpr DiscreteTypeInfo op::util::SubGraphOp::SliceInputDescription::type_info; +constexpr DiscreteTypeInfo op::util::SubGraphOp::MergedInputDescription::type_info; constexpr DiscreteTypeInfo op::util::MultiSubGraphOp::InvariantInputDescription::type_info; constexpr DiscreteTypeInfo op::util::MultiSubGraphOp::BodyOutputDescription::type_info; +constexpr DiscreteTypeInfo op::util::SubGraphOp::ConcatOutputDescription::type_info; op::util::MultiSubGraphOp::InputDescription::InputDescription(uint64_t input_index, uint64_t body_parameter_index) @@ -28,6 +31,66 @@ op::util::MultiSubGraphOp::OutputDescription::OutputDescription(uint64_t body_va { } +op::util::SubGraphOp::SliceInputDescription::SliceInputDescription(uint64_t input_index, + uint64_t body_parameter_index, + int64_t start, + int64_t stride, + int64_t part_size, + int64_t end, + int64_t axis) + : InputDescription(input_index, body_parameter_index) + , m_start(start) + , m_stride(stride) + , m_part_size(part_size) + , m_end(end) + , m_axis(axis) +{ +} + +std::shared_ptr + op::util::SubGraphOp::SliceInputDescription::copy() const +{ + return std::make_shared( + m_input_index, m_body_parameter_index, m_start, m_stride, m_part_size, m_end, m_axis); +} + +op::util::SubGraphOp::MergedInputDescription::MergedInputDescription(uint64_t input_index, + uint64_t body_parameter_index, + uint64_t body_value_index) + : InputDescription(input_index, body_parameter_index) + , m_body_value_index(body_value_index) +{ +} + +std::shared_ptr + op::util::SubGraphOp::MergedInputDescription::copy() const +{ + return std::make_shared( + m_input_index, m_body_parameter_index, m_body_value_index); +} + +op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t body_value_index, + uint64_t output_index, + int64_t start, + int64_t stride, + int64_t part_size, + int64_t end, + int64_t axis) + : OutputDescription(body_value_index, output_index) + , m_start(start) + , m_stride(stride) + , m_part_size(part_size) + , m_end(end) + , m_axis(axis) +{ +} + +std::shared_ptr + op::util::SubGraphOp::ConcatOutputDescription::copy() const +{ + return std::make_shared( + m_body_value_index, m_output_index, m_start, m_stride, m_part_size, m_end, m_axis); +} op::util::MultiSubGraphOp::InvariantInputDescription::InvariantInputDescription( uint64_t input_index, uint64_t body_parameter_index) : InputDescription(input_index, body_parameter_index) @@ -58,19 +121,19 @@ op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args) { } -op::util::MultiSubGraphOp::MultiSubGraphOp(size_t bodies_index) +op::util::MultiSubGraphOp::MultiSubGraphOp(size_t number_of_bodies) { - m_bodies.resize(bodies_index); - m_input_descriptions.resize(bodies_index); - m_output_descriptions.resize(bodies_index); + m_bodies.resize(number_of_bodies); + m_input_descriptions.resize(number_of_bodies); + m_output_descriptions.resize(number_of_bodies); } -op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args, size_t bodies_index) +op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args, size_t number_of_bodies) : MultiSubGraphOp(args) { - m_bodies.resize(bodies_index); - m_input_descriptions.resize(bodies_index); - m_output_descriptions.resize(bodies_index); + m_bodies.resize(number_of_bodies); + m_input_descriptions.resize(number_of_bodies); + m_output_descriptions.resize(number_of_bodies); } Input op::util::MultiSubGraphOp::input_for_value(const Output& value) @@ -84,30 +147,35 @@ void op::util::MultiSubGraphOp::set_invariant_inputs(const Output& value, const ParameterVector bodies_parameters) { auto input_index = input_for_value(value).get_index(); - size_t body_index = 0; for (auto& param : bodies_parameters) { - if (param == nullptr) + for (size_t body_index = 0; body_index < m_bodies.size(); ++body_index) { - body_index++; - continue; + auto param_index = m_bodies[body_index]->get_parameter_index(param); + if (param_index != -1) + { + m_input_descriptions[body_index].push_back( + std::make_shared(input_index, + param_index)); + } } - m_input_descriptions[body_index].push_back( - std::make_shared( - input_index, m_bodies[body_index]->get_parameter_index(param))); - body_index++; } } Output op::util::MultiSubGraphOp::set_body_outputs(ResultVector bodies_results) { - auto output_index = m_output_descriptions[0].size(); - size_t body_index = 0; + auto output_index = get_output_size(); for (auto& body_result : bodies_results) { - m_output_descriptions[body_index].push_back(std::make_shared( - m_bodies[body_index]->get_result_index(body_result), output_index)); - body_index++; + for (size_t body_index = 0; body_index < m_bodies.size(); body_index++) + { + auto body_result_index = m_bodies[body_index]->get_result_index(body_result); + if (body_result_index != -1) + { + m_output_descriptions[body_index].push_back( + std::make_shared(body_result_index, output_index)); + } + } } set_output_size(output_index + 1); return Output(shared_from_this(), output_index); diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index 5f734bdbe4529f..5c74519bab690e 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -11,72 +11,7 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::util::SubGraphOp, "SubGraphOp", 0); -constexpr DiscreteTypeInfo op::util::SubGraphOp::SliceInputDescription::type_info; -constexpr DiscreteTypeInfo op::util::SubGraphOp::MergedInputDescription::type_info; - constexpr DiscreteTypeInfo op::util::SubGraphOp::BodyOutputDescription::type_info; -constexpr DiscreteTypeInfo op::util::SubGraphOp::ConcatOutputDescription::type_info; - -op::util::SubGraphOp::SliceInputDescription::SliceInputDescription(uint64_t input_index, - uint64_t body_parameter_index, - int64_t start, - int64_t stride, - int64_t part_size, - int64_t end, - int64_t axis) - : InputDescription(input_index, body_parameter_index) - , m_start(start) - , m_stride(stride) - , m_part_size(part_size) - , m_end(end) - , m_axis(axis) -{ -} - -std::shared_ptr - op::util::SubGraphOp::SliceInputDescription::copy() const -{ - return std::make_shared( - m_input_index, m_body_parameter_index, m_start, m_stride, m_part_size, m_end, m_axis); -} - -op::util::SubGraphOp::MergedInputDescription::MergedInputDescription(uint64_t input_index, - uint64_t body_parameter_index, - uint64_t body_value_index) - : InputDescription(input_index, body_parameter_index) - , m_body_value_index(body_value_index) -{ -} - -std::shared_ptr - op::util::SubGraphOp::MergedInputDescription::copy() const -{ - return std::make_shared( - m_input_index, m_body_parameter_index, m_body_value_index); -} - -op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t body_value_index, - uint64_t output_index, - int64_t start, - int64_t stride, - int64_t part_size, - int64_t end, - int64_t axis) - : OutputDescription(body_value_index, output_index) - , m_start(start) - , m_stride(stride) - , m_part_size(part_size) - , m_end(end) - , m_axis(axis) -{ -} - -std::shared_ptr - op::util::SubGraphOp::ConcatOutputDescription::copy() const -{ - return std::make_shared( - m_body_value_index, m_output_index, m_start, m_stride, m_part_size, m_end, m_axis); -} op::util::SubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, uint64_t output_index, From aedbcffa79f3c8bf25caefd9ffde7b288071dc43 Mon Sep 17 00:00:00 2001 From: evolosen Date: Fri, 16 Jul 2021 17:13:34 +0300 Subject: [PATCH 08/21] Fix comments --- .../ngraph/op/util/multi_subgraph_base.hpp | 14 ++++++++---- .../include/ngraph/op/util/sub_graph_base.hpp | 22 ------------------- .../core/src/op/util/multi_subgraph_base.cpp | 8 ++++--- ngraph/core/src/op/util/sub_graph_base.cpp | 16 -------------- 4 files changed, 15 insertions(+), 45 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 3ba821497c4126..ed4a35bc4c6540 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -185,7 +185,8 @@ namespace ngraph }; /// \brief Produces an output - class NGRAPH_API BodyOutputDescription : public OutputDescription + /// \brief Produces an output from a specific iteration + class NGRAPH_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription { public: static constexpr type_info_t type_info{"BodyOutputDescription", 0}; @@ -194,11 +195,16 @@ namespace ngraph /// \brief Constructs a new instance. /// /// \param body_value_index A body value that produces the output - /// \param output_index The MultiSubGraphOp output index + /// \param output_index The SubGraphOp output index + /// \param iteration which iteration (typically -1, final) will + /// supply the value /// - BodyOutputDescription(uint64_t body_value_index, uint64_t output_index); + BodyOutputDescription(uint64_t body_value_index, + uint64_t output_index, + int64_t iteration = -1); BodyOutputDescription() = default; - std::shared_ptr copy() const override; + std::shared_ptr copy() const override; + int64_t m_iteration{0}; }; using MultiSubgraphInputDescriptionPtr = std::shared_ptr; diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 436e302a02ed45..6e4ec954c0b383 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -21,28 +21,6 @@ namespace ngraph public: NGRAPH_RTTI_DECLARATION; - /// \brief Produces an output from a specific iteration - class NGRAPH_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription - { - public: - static constexpr type_info_t type_info{"BodyOutputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } - /// - /// \brief Constructs a new instance. - /// - /// \param body_value_index A body value that produces the output - /// \param output_index The SubGraphOp output index - /// \param iteration which iteration (typically -1, final) will - /// supply the value - /// - BodyOutputDescription(uint64_t body_value_index, - uint64_t output_index, - int64_t iteration); - BodyOutputDescription() = default; - std::shared_ptr copy() const override; - int64_t m_iteration{0}; - }; - virtual std::shared_ptr get_function() { return m_bodies[0]; }; virtual std::shared_ptr get_function() const { diff --git a/ngraph/core/src/op/util/multi_subgraph_base.cpp b/ngraph/core/src/op/util/multi_subgraph_base.cpp index 39ea935699e82a..7f7f881fe28984 100644 --- a/ngraph/core/src/op/util/multi_subgraph_base.cpp +++ b/ngraph/core/src/op/util/multi_subgraph_base.cpp @@ -104,16 +104,18 @@ std::shared_ptr m_body_parameter_index); } -op::util::MultiSubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, - uint64_t output_index) +op::util::SubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, + uint64_t output_index, + int64_t iteration) : OutputDescription(body_value_index, output_index) + , m_iteration(iteration) { } std::shared_ptr op::util::MultiSubGraphOp::BodyOutputDescription::copy() const { - return std::make_shared(m_body_value_index, m_output_index); + return std::make_shared(m_body_value_index, m_output_index, m_iteration); } op::util::MultiSubGraphOp::MultiSubGraphOp(const OutputVector& args) diff --git a/ngraph/core/src/op/util/sub_graph_base.cpp b/ngraph/core/src/op/util/sub_graph_base.cpp index 5c74519bab690e..7a42ed27daca3b 100644 --- a/ngraph/core/src/op/util/sub_graph_base.cpp +++ b/ngraph/core/src/op/util/sub_graph_base.cpp @@ -11,22 +11,6 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::util::SubGraphOp, "SubGraphOp", 0); -constexpr DiscreteTypeInfo op::util::SubGraphOp::BodyOutputDescription::type_info; - -op::util::SubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, - uint64_t output_index, - int64_t iteration) - : OutputDescription(body_value_index, output_index) - , m_iteration(iteration) -{ -} - -std::shared_ptr - op::util::SubGraphOp::BodyOutputDescription::copy() const -{ - return std::make_shared(m_body_value_index, m_output_index, m_iteration); -} - op::util::SubGraphOp::SubGraphOp() : MultiSubGraphOp(1) { From 7fa0e14404208592b24d20e601e219d176f8cbed Mon Sep 17 00:00:00 2001 From: evolosen Date: Mon, 19 Jul 2021 10:47:18 +0300 Subject: [PATCH 09/21] Fix coments --- .../ngraph/op/util/multi_subgraph_base.hpp | 47 +++------- .../core/src/op/util/multi_subgraph_base.cpp | 89 +++++++++++-------- 2 files changed, 67 insertions(+), 69 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index ed4a35bc4c6540..8606caed16eaae 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -76,8 +76,7 @@ namespace ngraph class NGRAPH_API SliceInputDescription : public InputDescription { public: - static constexpr type_info_t type_info{"SliceInputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; /// /// \brief Constructs a new instance. /// @@ -112,8 +111,7 @@ namespace ngraph class NGRAPH_API MergedInputDescription : public InputDescription { public: - static constexpr type_info_t type_info{"MergedInputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; /// /// \brief Constructs a new instance. /// @@ -137,8 +135,7 @@ namespace ngraph class NGRAPH_API ConcatOutputDescription : public OutputDescription { public: - static constexpr type_info_t type_info{"ConcatOutputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; /// /// \brief Constructs a new instance. /// @@ -171,8 +168,7 @@ namespace ngraph class NGRAPH_API InvariantInputDescription : public InputDescription { public: - static constexpr type_info_t type_info{"InvariantInputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; /// /// \brief Constructs a new instance. /// @@ -184,13 +180,11 @@ namespace ngraph std::shared_ptr copy() const override; }; - /// \brief Produces an output /// \brief Produces an output from a specific iteration class NGRAPH_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription { public: - static constexpr type_info_t type_info{"BodyOutputDescription", 0}; - const type_info_t& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; /// /// \brief Constructs a new instance. /// @@ -227,17 +221,11 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual std::shared_ptr get_function(int index) const + virtual const std::shared_ptr& get_function(int index) const { return m_bodies[index]; }; - /// \brief Adds sub-graph to MultiSubGraphOp - /// - /// \param func new sub_graph as ngraph::Function - virtual void add_function(const std::shared_ptr& func) - { - m_bodies.push_back(func); - } + /// \brief Adds sub-graph to MultiSubGraphOp /// /// \param index index of new sub-graph @@ -288,7 +276,8 @@ namespace ngraph /// /// \param index index of internal sub-graph /// \param inputs vector of input descriptions - void set_input_descriptions(int index, MultiSubgraphInputDescriptionVector inputs) + void set_input_descriptions(int index, + const MultiSubgraphInputDescriptionVector& inputs) { m_input_descriptions[index] = inputs; } @@ -299,7 +288,7 @@ namespace ngraph /// \param index index of internal sub-graph /// \param outputs vector of input descriptions void set_output_descriptions(int index, - MultiSubgraphOutputDescriptionVector outputs) + const MultiSubgraphOutputDescriptionVector& outputs) { m_output_descriptions[index] = outputs; } @@ -310,13 +299,13 @@ namespace ngraph /// \param value The value supplied as an input to the block. /// \param bodies_parameters vector of bodies parameters. virtual void set_invariant_inputs(const Output& value, - const ParameterVector bodies_parameters); + const ParameterVector& bodies_parameters); /// /// \brief Set output decriptions for MultiSubGraphOp output. /// /// \param bodies_results vector of bodies results for one output. /// \return value Output node for bodies_results. - virtual Output set_body_outputs(ResultVector bodies_results); + virtual Output set_body_outputs(const ResultVector& bodies_results); MultiSubGraphOp(const MultiSubGraphOp&) = delete; MultiSubGraphOp(MultiSubGraphOp&&) = default; @@ -364,11 +353,7 @@ namespace ngraph { } - static constexpr DiscreteTypeInfo type_info{ - "AttributeAdapter>>", - 0}; - const DiscreteTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; }; template <> @@ -386,10 +371,6 @@ namespace ngraph { } - static constexpr DiscreteTypeInfo type_info{ - "AttributeAdapter>>", - 0}; - const DiscreteTypeInfo& get_type_info() const override { return type_info; } + NGRAPH_RTTI_DECLARATION; }; } // namespace ngraph diff --git a/ngraph/core/src/op/util/multi_subgraph_base.cpp b/ngraph/core/src/op/util/multi_subgraph_base.cpp index 7f7f881fe28984..0b14f2e20fb8e0 100644 --- a/ngraph/core/src/op/util/multi_subgraph_base.cpp +++ b/ngraph/core/src/op/util/multi_subgraph_base.cpp @@ -10,12 +10,21 @@ using namespace ngraph; NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp, "MultiSubGraphOp", 0); - -constexpr DiscreteTypeInfo op::util::SubGraphOp::SliceInputDescription::type_info; -constexpr DiscreteTypeInfo op::util::SubGraphOp::MergedInputDescription::type_info; -constexpr DiscreteTypeInfo op::util::MultiSubGraphOp::InvariantInputDescription::type_info; -constexpr DiscreteTypeInfo op::util::MultiSubGraphOp::BodyOutputDescription::type_info; -constexpr DiscreteTypeInfo op::util::SubGraphOp::ConcatOutputDescription::type_info; +NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp::SliceInputDescription, + "SliceInputDescription", + 0); +NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp::MergedInputDescription, + "MergedInputDescription", + 0); +NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp::InvariantInputDescription, + "InvariantInputDescription", + 0); +NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp::BodyOutputDescription, + "BodyOutputDescription", + 0); +NGRAPH_RTTI_DEFINITION(op::util::MultiSubGraphOp::ConcatOutputDescription, + "ConcatOutputDescription", + 0); op::util::MultiSubGraphOp::InputDescription::InputDescription(uint64_t input_index, uint64_t body_parameter_index) @@ -31,13 +40,14 @@ op::util::MultiSubGraphOp::OutputDescription::OutputDescription(uint64_t body_va { } -op::util::SubGraphOp::SliceInputDescription::SliceInputDescription(uint64_t input_index, - uint64_t body_parameter_index, - int64_t start, - int64_t stride, - int64_t part_size, - int64_t end, - int64_t axis) +op::util::MultiSubGraphOp::SliceInputDescription::SliceInputDescription( + uint64_t input_index, + uint64_t body_parameter_index, + int64_t start, + int64_t stride, + int64_t part_size, + int64_t end, + int64_t axis) : InputDescription(input_index, body_parameter_index) , m_start(start) , m_stride(stride) @@ -48,34 +58,34 @@ op::util::SubGraphOp::SliceInputDescription::SliceInputDescription(uint64_t inpu } std::shared_ptr - op::util::SubGraphOp::SliceInputDescription::copy() const + op::util::MultiSubGraphOp::SliceInputDescription::copy() const { return std::make_shared( m_input_index, m_body_parameter_index, m_start, m_stride, m_part_size, m_end, m_axis); } -op::util::SubGraphOp::MergedInputDescription::MergedInputDescription(uint64_t input_index, - uint64_t body_parameter_index, - uint64_t body_value_index) +op::util::MultiSubGraphOp::MergedInputDescription::MergedInputDescription( + uint64_t input_index, uint64_t body_parameter_index, uint64_t body_value_index) : InputDescription(input_index, body_parameter_index) , m_body_value_index(body_value_index) { } std::shared_ptr - op::util::SubGraphOp::MergedInputDescription::copy() const + op::util::MultiSubGraphOp::MergedInputDescription::copy() const { return std::make_shared( m_input_index, m_body_parameter_index, m_body_value_index); } -op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t body_value_index, - uint64_t output_index, - int64_t start, - int64_t stride, - int64_t part_size, - int64_t end, - int64_t axis) +op::util::MultiSubGraphOp::ConcatOutputDescription::ConcatOutputDescription( + uint64_t body_value_index, + uint64_t output_index, + int64_t start, + int64_t stride, + int64_t part_size, + int64_t end, + int64_t axis) : OutputDescription(body_value_index, output_index) , m_start(start) , m_stride(stride) @@ -86,7 +96,7 @@ op::util::SubGraphOp::ConcatOutputDescription::ConcatOutputDescription(uint64_t } std::shared_ptr - op::util::SubGraphOp::ConcatOutputDescription::copy() const + op::util::MultiSubGraphOp::ConcatOutputDescription::copy() const { return std::make_shared( m_body_value_index, m_output_index, m_start, m_stride, m_part_size, m_end, m_axis); @@ -104,9 +114,9 @@ std::shared_ptr m_body_parameter_index); } -op::util::SubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, - uint64_t output_index, - int64_t iteration) +op::util::MultiSubGraphOp::BodyOutputDescription::BodyOutputDescription(uint64_t body_value_index, + uint64_t output_index, + int64_t iteration) : OutputDescription(body_value_index, output_index) , m_iteration(iteration) { @@ -146,7 +156,7 @@ Input op::util::MultiSubGraphOp::input_for_value(const Output& value } void op::util::MultiSubGraphOp::set_invariant_inputs(const Output& value, - const ParameterVector bodies_parameters) + const ParameterVector& bodies_parameters) { auto input_index = input_for_value(value).get_index(); for (auto& param : bodies_parameters) @@ -164,7 +174,7 @@ void op::util::MultiSubGraphOp::set_invariant_inputs(const Output& value, } } -Output op::util::MultiSubGraphOp::set_body_outputs(ResultVector bodies_results) +Output op::util::MultiSubGraphOp::set_body_outputs(const ResultVector& bodies_results) { auto output_index = get_output_size(); for (auto& body_result : bodies_results) @@ -185,9 +195,16 @@ Output op::util::MultiSubGraphOp::set_body_outputs(ResultVector bodies_res namespace ngraph { - constexpr DiscreteTypeInfo AttributeAdapter< - std::vector>>::type_info; - - constexpr DiscreteTypeInfo AttributeAdapter< - std::vector>>::type_info; + NGRAPH_RTTI_DEFINITION( + AttributeAdapter>>, + "AttributeAdapter>>", + 0); + + NGRAPH_RTTI_DEFINITION( + AttributeAdapter< + std::vector>>, + "AttributeAdapter>>", + 0); } // namespace ngraph From b6989b6d204d578bd9e100f080816674e5c97975 Mon Sep 17 00:00:00 2001 From: evolosen Date: Mon, 19 Jul 2021 10:53:58 +0300 Subject: [PATCH 10/21] Fix comments --- ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 8606caed16eaae..69118be8289952 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -213,7 +213,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual std::shared_ptr get_function(int index) + virtual const std::shared_ptr& get_function(int index) const { return m_bodies[index]; }; @@ -221,7 +221,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual const std::shared_ptr& get_function(int index) const + virtual std::shared_ptr get_function(int index) { return m_bodies[index]; }; From de03f2681f51b940f53eab5459988407fe50990f Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 20 Jul 2021 13:33:03 +0300 Subject: [PATCH 11/21] delete get function --- ngraph/core/include/ngraph/op/tensor_iterator.hpp | 4 +--- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 2 +- ngraph/core/src/op/tensor_iterator.cpp | 5 ----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/ngraph/core/include/ngraph/op/tensor_iterator.hpp b/ngraph/core/include/ngraph/op/tensor_iterator.hpp index 6a8eaaef349caf..41e02d43ca94c9 100644 --- a/ngraph/core/include/ngraph/op/tensor_iterator.hpp +++ b/ngraph/core/include/ngraph/op/tensor_iterator.hpp @@ -32,11 +32,9 @@ namespace ngraph /// \return the body of the iteration std::shared_ptr get_body() const { return m_bodies[0]; } /// \param body set the body of the iteration - void set_body(const std::shared_ptr& body) { m_bodies[0] = body; } + void set_body(const std::shared_ptr& body) { set_function(body); } void validate_and_infer_types() override; void revalidate_and_infer_types_for_body_ops(); - /// \return the body of the iteration - std::shared_ptr get_function() override; private: void try_to_set_num_iterations_if_no_slice_inputs(); diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 6e4ec954c0b383..b93ed72dd6bb24 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -21,7 +21,7 @@ namespace ngraph public: NGRAPH_RTTI_DECLARATION; - virtual std::shared_ptr get_function() { return m_bodies[0]; }; + virtual const std::shared_ptr& get_function() { return m_bodies[0]; }; virtual std::shared_ptr get_function() const { return m_bodies[0]; diff --git a/ngraph/core/src/op/tensor_iterator.cpp b/ngraph/core/src/op/tensor_iterator.cpp index 26d1901c34a717..0ae86f6052a9c2 100644 --- a/ngraph/core/src/op/tensor_iterator.cpp +++ b/ngraph/core/src/op/tensor_iterator.cpp @@ -225,11 +225,6 @@ void op::v0::TensorIterator::validate_and_infer_types() "Number of outputs must be the same as number of output descriptions"); } -std::shared_ptr op::v0::TensorIterator::get_function() -{ - return get_body(); -} - namespace { template From dbac5ed200a50a10bf8291d6f5434e46bb210c86 Mon Sep 17 00:00:00 2001 From: evolosen Date: Tue, 20 Jul 2021 13:53:00 +0300 Subject: [PATCH 12/21] fix methods --- ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp | 2 +- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 69118be8289952..6ab64740bcafd0 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -221,7 +221,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual std::shared_ptr get_function(int index) + virtual const std::shared_ptr& get_function(int index) { return m_bodies[index]; }; diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index b93ed72dd6bb24..111854dce5d6be 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -22,7 +22,7 @@ namespace ngraph NGRAPH_RTTI_DECLARATION; virtual const std::shared_ptr& get_function() { return m_bodies[0]; }; - virtual std::shared_ptr get_function() const + virtual const std::shared_ptr& get_function() const { return m_bodies[0]; }; From 12cca12dd0de0f27b19030a361640fbf9349684f Mon Sep 17 00:00:00 2001 From: evolosen Date: Wed, 21 Jul 2021 10:05:59 +0300 Subject: [PATCH 13/21] fix ci --- ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 6ab64740bcafd0..3f3c40aa043a0c 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -225,7 +225,6 @@ namespace ngraph { return m_bodies[index]; }; - /// \brief Adds sub-graph to MultiSubGraphOp /// /// \param index index of new sub-graph From d22ed7666f98d594a9fe92f928aa936cc172c442 Mon Sep 17 00:00:00 2001 From: evolosen Date: Wed, 21 Jul 2021 10:41:31 +0300 Subject: [PATCH 14/21] Fix ci --- ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 3f3c40aa043a0c..fde14ed7507b8a 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -269,7 +269,6 @@ namespace ngraph { return m_output_descriptions[index]; } - /// \brief Sets vector with connections beewtwen operation inputs /// and internal sub-graph parameters /// From 45387373a9d8eaf9277333bf9592272cfd59c09e Mon Sep 17 00:00:00 2001 From: evolosen Date: Wed, 21 Jul 2021 11:13:26 +0300 Subject: [PATCH 15/21] fix bugs --- ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp | 2 +- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index fde14ed7507b8a..a0ba1e4865d6fa 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -221,7 +221,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual const std::shared_ptr& get_function(int index) + virtual std::shared_ptr get_function(int index) { return m_bodies[index]; }; diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 111854dce5d6be..b93ed72dd6bb24 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -22,7 +22,7 @@ namespace ngraph NGRAPH_RTTI_DECLARATION; virtual const std::shared_ptr& get_function() { return m_bodies[0]; }; - virtual const std::shared_ptr& get_function() const + virtual std::shared_ptr get_function() const { return m_bodies[0]; }; From 572d3ebf9c5b292991656431491a667a72c4e6e0 Mon Sep 17 00:00:00 2001 From: evolosen Date: Wed, 21 Jul 2021 12:58:27 +0300 Subject: [PATCH 16/21] Fix cmake --- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index b93ed72dd6bb24..cbf0bdc09ee4ab 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -26,6 +26,7 @@ namespace ngraph { return m_bodies[0]; }; + virtual void set_function(const std::shared_ptr& func) { m_bodies[0] = func; From 728f8d996ce0e95baf661ecb8a3c2ec1e1ec5eae Mon Sep 17 00:00:00 2001 From: evolosen Date: Wed, 21 Jul 2021 14:03:18 +0300 Subject: [PATCH 17/21] Fix ci --- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index cbf0bdc09ee4ab..b93ed72dd6bb24 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -26,7 +26,6 @@ namespace ngraph { return m_bodies[0]; }; - virtual void set_function(const std::shared_ptr& func) { m_bodies[0] = func; From 847ed453fb296811067b04146a286318fac568bd Mon Sep 17 00:00:00 2001 From: evolosen Date: Thu, 22 Jul 2021 09:19:53 +0300 Subject: [PATCH 18/21] delete virtual function --- ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp | 6 +++--- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index a0ba1e4865d6fa..ed94b9b563f93e 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -213,7 +213,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual const std::shared_ptr& get_function(int index) const + const std::shared_ptr& get_function(int index) const { return m_bodies[index]; }; @@ -221,7 +221,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - virtual std::shared_ptr get_function(int index) + std::shared_ptr get_function(int index) { return m_bodies[index]; }; @@ -229,7 +229,7 @@ namespace ngraph /// /// \param index index of new sub-graph /// \param func func new sub_graph as ngraph::Function - virtual void set_function(int index, const std::shared_ptr& func) + void set_function(int index, const std::shared_ptr& func) { m_bodies[index] = func; } diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index b93ed72dd6bb24..f00e81ee58caf4 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -21,12 +21,12 @@ namespace ngraph public: NGRAPH_RTTI_DECLARATION; - virtual const std::shared_ptr& get_function() { return m_bodies[0]; }; - virtual std::shared_ptr get_function() const + const std::shared_ptr& get_function() { return m_bodies[0]; }; + std::shared_ptr get_function() const { return m_bodies[0]; }; - virtual void set_function(const std::shared_ptr& func) + void set_function(const std::shared_ptr& func) { m_bodies[0] = func; }; From f5d5ad483f346d5a8f6127c92a8c7363764510e7 Mon Sep 17 00:00:00 2001 From: evolosen Date: Thu, 22 Jul 2021 09:31:05 +0300 Subject: [PATCH 19/21] delete virtual function --- .../include/ngraph/op/util/multi_subgraph_base.hpp | 5 +---- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 10 ++-------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index ed94b9b563f93e..9843cab4d866bb 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -221,10 +221,7 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - std::shared_ptr get_function(int index) - { - return m_bodies[index]; - }; + std::shared_ptr get_function(int index) { return m_bodies[index]; }; /// \brief Adds sub-graph to MultiSubGraphOp /// /// \param index index of new sub-graph diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index f00e81ee58caf4..f7c463831ef162 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -22,14 +22,8 @@ namespace ngraph NGRAPH_RTTI_DECLARATION; const std::shared_ptr& get_function() { return m_bodies[0]; }; - std::shared_ptr get_function() const - { - return m_bodies[0]; - }; - void set_function(const std::shared_ptr& func) - { - m_bodies[0] = func; - }; + std::shared_ptr get_function() const { return m_bodies[0]; }; + void set_function(const std::shared_ptr& func) { m_bodies[0] = func; }; /// \return a reference to the input descriptions. const std::vector>& get_input_descriptions() const { From 23a59e1d41e95bb13aced17e0e5246a3b5fcb210 Mon Sep 17 00:00:00 2001 From: evolosen Date: Thu, 22 Jul 2021 10:33:33 +0300 Subject: [PATCH 20/21] fix ci --- .../include/ngraph/op/util/multi_subgraph_base.hpp | 9 ++------- .../core/include/ngraph/op/util/sub_graph_base.hpp | 14 ++++++++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp index 9843cab4d866bb..c50b98aa4c757a 100644 --- a/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/multi_subgraph_base.hpp @@ -213,20 +213,15 @@ namespace ngraph /// /// \param index sub-graph's index in op /// \return pointer to ngraph::Function with sub-graph - const std::shared_ptr& get_function(int index) const + virtual const std::shared_ptr& get_function(int index) const { return m_bodies[index]; }; - /// \brief Gets internal sub-graph by index in MultiSubGraphOp - /// - /// \param index sub-graph's index in op - /// \return pointer to ngraph::Function with sub-graph - std::shared_ptr get_function(int index) { return m_bodies[index]; }; /// \brief Adds sub-graph to MultiSubGraphOp /// /// \param index index of new sub-graph /// \param func func new sub_graph as ngraph::Function - void set_function(int index, const std::shared_ptr& func) + virtual void set_function(int index, const std::shared_ptr& func) { m_bodies[index] = func; } diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index f7c463831ef162..2a9d4ca179a90a 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -21,9 +21,11 @@ namespace ngraph public: NGRAPH_RTTI_DECLARATION; - const std::shared_ptr& get_function() { return m_bodies[0]; }; - std::shared_ptr get_function() const { return m_bodies[0]; }; - void set_function(const std::shared_ptr& func) { m_bodies[0] = func; }; + virtual const std::shared_ptr& get_function() const { return m_bodies[0]; }; + virtual void set_function(const std::shared_ptr& func) + { + m_bodies[0] = func; + }; /// \return a reference to the input descriptions. const std::vector>& get_input_descriptions() const { @@ -131,7 +133,6 @@ namespace ngraph SubGraphOp& operator=(SubGraphOp&&) = default; int64_t get_num_iterations() const { return m_num_iterations; } - protected: int64_t m_num_iterations = -1; // -1 means infinity for Loop op, inconsistent for TensorIterator @@ -141,6 +142,11 @@ namespace ngraph SubGraphOp(); explicit SubGraphOp(const OutputVector& args); + + private: + using MultiSubGraphOp::get_function; + + using MultiSubGraphOp::set_function; }; using InputDescriptionPtr = std::shared_ptr; using OutputDescriptionPtr = std::shared_ptr; From 3d26e899b53d4a5dea4565bf4ab890f51676960a Mon Sep 17 00:00:00 2001 From: evolosen Date: Thu, 22 Jul 2021 15:35:39 +0300 Subject: [PATCH 21/21] Fix ci --- ngraph/core/include/ngraph/op/util/sub_graph_base.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp index 2a9d4ca179a90a..44701e382e5ba3 100644 --- a/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp +++ b/ngraph/core/include/ngraph/op/util/sub_graph_base.hpp @@ -21,7 +21,10 @@ namespace ngraph public: NGRAPH_RTTI_DECLARATION; - virtual const std::shared_ptr& get_function() const { return m_bodies[0]; }; + virtual const std::shared_ptr& get_function() const + { + return m_bodies[0]; + }; virtual void set_function(const std::shared_ptr& func) { m_bodies[0] = func; @@ -133,6 +136,7 @@ namespace ngraph SubGraphOp& operator=(SubGraphOp&&) = default; int64_t get_num_iterations() const { return m_num_iterations; } + protected: int64_t m_num_iterations = -1; // -1 means infinity for Loop op, inconsistent for TensorIterator