From eb838d56999348aaf4815445632172644f672bc7 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 14 Oct 2021 12:58:43 +0300 Subject: [PATCH] Cleanup Core API added common header (#7994) --- ngraph/core/include/ngraph/node.hpp | 6 +- ngraph/core/include/openvino/core/core.hpp | 59 +++++++++++++++++++ .../core/include/openvino/core/graph_util.hpp | 3 +- ngraph/core/include/openvino/core/node.hpp | 18 ------ .../include/openvino/core/node_output.hpp | 5 -- .../include/openvino/core/node_vector.hpp | 19 ++++++ ngraph/core/src/node.cpp | 30 +--------- ngraph/core/src/node_vector.cpp | 35 +++++++++++ 8 files changed, 121 insertions(+), 54 deletions(-) create mode 100644 ngraph/core/include/openvino/core/core.hpp create mode 100644 ngraph/core/src/node_vector.cpp diff --git a/ngraph/core/include/ngraph/node.hpp b/ngraph/core/include/ngraph/node.hpp index 81ce72a2288..d32d44949a6 100644 --- a/ngraph/core/include/ngraph/node.hpp +++ b/ngraph/core/include/ngraph/node.hpp @@ -67,9 +67,11 @@ using EvaluationContext = std::map>; using ResultVector = std::vector>; const auto node_validation_failure_loc_string = ov::node_validation_failure_loc_string; -const auto check_single_output_arg = ov::check_single_output_arg; -const auto check_single_output_args = ov::check_single_output_args; +NGRAPH_API +const std::shared_ptr& check_single_output_arg(const std::shared_ptr& node, size_t i); +NGRAPH_API +const NodeVector& check_single_output_args(const NodeVector& args); const auto as_output_vector = ov::as_output_vector; const auto as_node_vector = ov::as_node_vector; diff --git a/ngraph/core/include/openvino/core/core.hpp b/ngraph/core/include/openvino/core/core.hpp new file mode 100644 index 00000000000..611af2ee1aa --- /dev/null +++ b/ngraph/core/include/openvino/core/core.hpp @@ -0,0 +1,59 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +// +// The public OpenVINO core API +// + +#include "openvino/core/attribute_adapter.hpp" +#include "openvino/core/attribute_visitor.hpp" +#include "openvino/core/axis_set.hpp" +#include "openvino/core/axis_vector.hpp" +#include "openvino/core/coordinate.hpp" +#include "openvino/core/coordinate_diff.hpp" +#include "openvino/core/core_visibility.hpp" +#include "openvino/core/deprecated.hpp" +#include "openvino/core/dimension.hpp" +#include "openvino/core/enum_mask.hpp" +#include "openvino/core/enum_names.hpp" +#include "openvino/core/except.hpp" +#include "openvino/core/function.hpp" +#include "openvino/core/graph_util.hpp" +#include "openvino/core/interval.hpp" +#include "openvino/core/layout.hpp" +#include "openvino/core/node.hpp" +#include "openvino/core/node_input.hpp" +#include "openvino/core/node_output.hpp" +#include "openvino/core/node_vector.hpp" +#include "openvino/core/partial_shape.hpp" +#include "openvino/core/rank.hpp" +#include "openvino/core/rtti.hpp" +#include "openvino/core/shape.hpp" +#include "openvino/core/strides.hpp" +#include "openvino/core/type.hpp" +#include "openvino/core/validation_util.hpp" +#include "openvino/core/variant.hpp" +#include "openvino/core/version.hpp" +#include "openvino/core/visibility.hpp" + +// Descriptor +#include "openvino/core/descriptor/input.hpp" +#include "openvino/core/descriptor/output.hpp" +#include "openvino/core/descriptor/tensor.hpp" + +// Preprocessing +#include "openvino/core/preprocess/color_format.hpp" +#include "openvino/core/preprocess/input_info.hpp" +#include "openvino/core/preprocess/input_network_info.hpp" +#include "openvino/core/preprocess/input_tensor_info.hpp" +#include "openvino/core/preprocess/output_info.hpp" +#include "openvino/core/preprocess/output_network_info.hpp" +#include "openvino/core/preprocess/output_tensor_info.hpp" +#include "openvino/core/preprocess/postprocess_steps.hpp" +#include "openvino/core/preprocess/pre_post_process.hpp" +#include "openvino/core/preprocess/preprocess_steps.hpp" +#include "openvino/core/preprocess/resize_algorithm.hpp" + +// type +#include "openvino/core/type/element_type.hpp" diff --git a/ngraph/core/include/openvino/core/graph_util.hpp b/ngraph/core/include/openvino/core/graph_util.hpp index 1ef92dab2ac..d3ce75c3cf0 100644 --- a/ngraph/core/include/openvino/core/graph_util.hpp +++ b/ngraph/core/include/openvino/core/graph_util.hpp @@ -265,7 +265,8 @@ std::vector> topological_sort(T root_nodes) { // NodeMap input may contain default node mapping i.e. pre-cloned nodes // NodeMap output (by reference) fully maps input and cloned function ops OPENVINO_API -std::shared_ptr clone_function(const ov::Function& func, NodeMap& node_map); +std::shared_ptr clone_function(const ov::Function& func, + std::unordered_map>& node_map); // input function is cloned and returned OPENVINO_API diff --git a/ngraph/core/include/openvino/core/node.hpp b/ngraph/core/include/openvino/core/node.hpp index 3e0134f9b35..2f5af675f58 100644 --- a/ngraph/core/include/openvino/core/node.hpp +++ b/ngraph/core/include/openvino/core/node.hpp @@ -75,27 +75,9 @@ class Node; /// environment) for evaluating ov::Function. using EvaluationContext = std::map>; -using ResultVector = std::vector>; - OPENVINO_API std::string node_validation_failure_loc_string(const Node* node); -OPENVINO_API -const std::shared_ptr& check_single_output_arg(const std::shared_ptr& node, size_t i); -OPENVINO_API -const NodeVector& check_single_output_args(const NodeVector& args); - -OPENVINO_API -OutputVector as_output_vector(const NodeVector& args); -OPENVINO_API -NodeVector as_node_vector(const OutputVector& values); -/// Returns a ResultVector referencing values. -OPENVINO_API -ResultVector as_result_vector(const OutputVector& values); - -/// Alias useful for cloning -using NodeMap = std::unordered_map>; - /// \brief Used in evaluator switch statement so that the case type and evaluate call /// are guaranteed to have the types match. /// diff --git a/ngraph/core/include/openvino/core/node_output.hpp b/ngraph/core/include/openvino/core/node_output.hpp index db2396e05e1..71b593f28cf 100644 --- a/ngraph/core/include/openvino/core/node_output.hpp +++ b/ngraph/core/include/openvino/core/node_output.hpp @@ -37,7 +37,6 @@ public: /// \param node A `shared_ptr` to the node for the output handle. /// \param index The index of the output. /// - /// TODO: Make a plan to deprecate this. Output(const std::shared_ptr& node, size_t index); /// \brief Constructs a Output, referencing the zeroth output of the node. @@ -56,7 +55,6 @@ public: Node* get_node() const; /// \return A `shared_ptr` to the node referred to by this output handle. /// - /// TODO: Make a plan to deprecate this. std::shared_ptr get_node_shared_ptr() const; /// \return The index of the output referred to by this output handle. @@ -84,7 +82,6 @@ public: /// \brief Removes a target input from the output referenced by this output handle. /// \param target_input The target input to remove. /// - // TODO(amprocte): Investigate whether this really ought to be public. void remove_target_input(const Input& target_input) const; /// \brief Replace all users of this value with replacement @@ -114,7 +111,6 @@ public: /// \param node A `shared_ptr` to the node for the output handle. /// \param index The index of the output. /// - /// TODO: Make a plan to deprecate this. Output(const std::shared_ptr& node, size_t index); /// \brief Constructs a Output, referencing the zeroth output of the node. @@ -134,7 +130,6 @@ public: const Node* get_node() const; /// \return A `shared_ptr` to the node referred to by this output handle. /// - /// TODO: Make a plan to deprecate this. std::shared_ptr get_node_shared_ptr() const; /// \return The index of the output referred to by this output handle. size_t get_index() const; diff --git a/ngraph/core/include/openvino/core/node_vector.hpp b/ngraph/core/include/openvino/core/node_vector.hpp index f76d888e69e..3ec1b1eb523 100644 --- a/ngraph/core/include/openvino/core/node_vector.hpp +++ b/ngraph/core/include/openvino/core/node_vector.hpp @@ -7,6 +7,8 @@ #include #include +#include "openvino/core/core_visibility.hpp" + namespace ov { template @@ -14,6 +16,23 @@ class Output; class Node; +namespace op { +namespace v0 { + +class Result; + +} // namespace v0 +} // namespace op + using NodeVector = std::vector>; using OutputVector = std::vector>; +using ResultVector = std::vector>; + +OPENVINO_API +OutputVector as_output_vector(const NodeVector& args); +OPENVINO_API +NodeVector as_node_vector(const OutputVector& values); +/// Returns a ResultVector referencing values. +OPENVINO_API +ResultVector as_result_vector(const OutputVector& values); } // namespace ov diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index b1c77b6167b..04031f659a7 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -600,44 +600,18 @@ std::string ov::node_validation_failure_loc_string(const Node* node) { return ss.str(); } -const std::shared_ptr& ov::check_single_output_arg(const std::shared_ptr& node, size_t i) { +const std::shared_ptr& ngraph::check_single_output_arg(const std::shared_ptr& node, size_t i) { NGRAPH_CHECK(node->get_output_size() == 1, "Argument ", i, node, " must produce exactly one value."); return node; } -const ov::NodeVector& ov::check_single_output_args(const NodeVector& args) { +const ov::NodeVector& ngraph::check_single_output_args(const NodeVector& args) { for (size_t i = 0; i < args.size(); ++i) { ngraph::check_single_output_arg(args.at(i), i); } return args; } -ov::OutputVector ov::as_output_vector(const NodeVector& args) { - OutputVector output_vector; - for (const auto& arg : args) { - output_vector.push_back(arg); - } - return output_vector; -} - -ov::NodeVector ov::as_node_vector(const OutputVector& values) { - NodeVector node_vector; - for (auto& value : values) { - node_vector.emplace_back(value.get_node_shared_ptr()); - } - return node_vector; -} - -ov::ResultVector ov::as_result_vector(const OutputVector& values) { - ResultVector result; - for (auto value : values) { - shared_ptr node = value.get_node_shared_ptr(); - result.push_back(ov::is_type(node) ? ov::as_type_ptr(node) - : make_shared(value)); - } - return result; -} - bool ov::Node::match_value(ngraph::pattern::Matcher* matcher, const Output& pattern_value, const Output& graph_value) { diff --git a/ngraph/core/src/node_vector.cpp b/ngraph/core/src/node_vector.cpp new file mode 100644 index 00000000000..6eea8892ca9 --- /dev/null +++ b/ngraph/core/src/node_vector.cpp @@ -0,0 +1,35 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/core/node_vector.hpp" + +#include "openvino/core/node_output.hpp" +#include "openvino/core/type.hpp" +#include "openvino/op/result.hpp" + +ov::OutputVector ov::as_output_vector(const ov::NodeVector& args) { + ov::OutputVector output_vector; + for (const auto& arg : args) { + output_vector.push_back(arg); + } + return output_vector; +} + +ov::NodeVector ov::as_node_vector(const ov::OutputVector& values) { + NodeVector node_vector; + for (auto& value : values) { + node_vector.emplace_back(value.get_node_shared_ptr()); + } + return node_vector; +} + +ov::ResultVector ov::as_result_vector(const OutputVector& values) { + ResultVector result; + for (const auto& value : values) { + std::shared_ptr node = value.get_node_shared_ptr(); + result.push_back(ov::is_type(node) ? ov::as_type_ptr(node) + : std::make_shared(value)); + } + return result; +}