From 8073c7be9f156e2c573e36b033ef96c0b27cf15c Mon Sep 17 00:00:00 2001 From: Oleg Pipikin Date: Mon, 29 Jan 2024 18:40:24 +0100 Subject: [PATCH 01/27] Remove ngraph node (#22460) --- docs/snippets/lpt_intel_cpu_plugin.cpp | 12 +- src/core/include/ngraph/evaluator.hpp | 30 ++-- src/core/include/ngraph/graph_util.hpp | 70 ++++---- src/core/include/ngraph/node.hpp | 169 ------------------ src/core/include/ngraph/op/split.hpp | 1 - src/core/include/ngraph/op/util/op_types.hpp | 1 - src/core/include/ngraph/util.hpp | 1 - src/core/src/graph_util.cpp | 2 +- src/core/src/node.cpp | 14 -- src/core/src/specialize_function.cpp | 2 +- src/core/tests/specialize_function.cpp | 4 +- src/frontends/onnx/docs/how_to_add_op.md | 1 - .../onnx/frontend/src/op/bitwise_not.hpp | 1 - .../onnx/frontend/src/op/conv_transpose.cpp | 22 +-- .../onnx/frontend/src/op/quant_conv.cpp | 22 +-- src/frontends/onnx/frontend/src/op/scan.hpp | 1 - .../onnx/frontend/src/op/scatter_elements.hpp | 1 - .../onnx/frontend/src/op/scatter_nd.hpp | 1 - src/frontends/onnx/frontend/src/op/selu.hpp | 1 - src/frontends/onnx/frontend/src/op/shape.cpp | 1 - src/frontends/onnx/frontend/src/op/shape.hpp | 1 - src/frontends/onnx/frontend/src/op/shrink.cpp | 9 +- src/frontends/onnx/frontend/src/op/shrink.hpp | 1 - .../onnx/frontend/src/op/sigmoid.hpp | 1 - src/frontends/onnx/frontend/src/op/sign.hpp | 1 - src/frontends/onnx/frontend/src/op/sin.hpp | 1 - src/frontends/onnx/frontend/src/op/sinh.hpp | 1 - src/frontends/onnx/frontend/src/op/size.hpp | 1 - src/frontends/onnx/frontend/src/op/slice.cpp | 4 +- src/frontends/onnx/frontend/src/op/slice.hpp | 1 - .../onnx/frontend/src/op/softmax.cpp | 6 +- .../onnx/frontend/src/op/softmax.hpp | 1 - .../onnx/frontend/src/op/softplus.cpp | 1 - .../onnx/frontend/src/op/softplus.hpp | 1 - .../onnx/frontend/src/op/softsign.hpp | 1 - .../onnx/frontend/src/op/space_to_depth.hpp | 1 - src/frontends/onnx/frontend/src/op/split.hpp | 1 - src/frontends/onnx/frontend/src/op/sqrt.hpp | 1 - .../onnx/frontend/src/op/squeeze.hpp | 1 - src/frontends/onnx/frontend/src/op/stft.hpp | 1 - src/frontends/onnx/frontend/src/op/sub.hpp | 1 - src/frontends/onnx/frontend/src/op/sum.hpp | 3 +- src/frontends/onnx/frontend/src/op/tan.hpp | 1 - src/frontends/onnx/frontend/src/op/tanh.hpp | 1 - .../onnx/frontend/src/op/thresholded_relu.hpp | 1 - src/frontends/onnx/frontend/src/op/tile.hpp | 1 - src/frontends/onnx/frontend/src/op/topk.cpp | 31 ++-- src/frontends/onnx/frontend/src/op/topk.hpp | 1 - .../onnx/frontend/src/op/transpose.cpp | 3 +- .../onnx/frontend/src/op/transpose.hpp | 1 - src/frontends/onnx/frontend/src/op/trilu.cpp | 4 +- src/frontends/onnx/frontend/src/op/unique.hpp | 1 - .../onnx/frontend/src/op/unsqueeze.hpp | 1 - .../onnx/frontend/src/op/upsample.hpp | 1 - src/frontends/onnx/frontend/src/op/where.hpp | 1 - src/frontends/onnx/frontend/src/op/xor.hpp | 8 +- .../onnx/frontend/src/utils/convpool.hpp | 8 +- .../frontend/src/utils/pooling_factory.cpp | 4 +- src/inference/src/cnn_network_ngraph_impl.cpp | 10 +- .../interface/ie_iplugin_internal.cpp | 2 +- src/inference/src/dev/converter_utils.cpp | 2 +- src/plugins/intel_cpu/src/nodes/rope.cpp | 4 +- src/plugins/intel_cpu/src/nodes/rope.h | 4 +- .../intel_cpu/src/nodes/scaled_attn.cpp | 4 +- src/plugins/intel_cpu/src/nodes/scaled_attn.h | 4 +- .../cpu_opset/common/op/rope.cpp | 2 +- .../cpu_opset/common/op/rope.hpp | 2 - .../common/pass/swap_convert_transpose.cpp | 2 - .../common/pass/swap_convert_transpose.hpp | 1 - .../single_layer_tests/topk.cpp | 2 +- .../single_layer/memory.hpp | 2 +- .../src/base/layer_test_utils.cpp | 4 +- .../src/single_layer/memory.cpp | 2 +- .../src/single_layer/random_uniform.cpp | 2 +- .../ov_models/include/ov_models/builders.hpp | 26 +-- .../ov_models/src/binary_convolution.cpp | 2 +- .../ov_helpers/ov_models/src/convolution.cpp | 4 +- .../src/convolution_backprop_data.cpp | 6 +- .../ov_models/src/group_convolution.cpp | 4 +- .../src/group_convolution_backprop_data.cpp | 6 +- .../ov_helpers/ov_models/src/pooling.cpp | 4 +- 81 files changed, 167 insertions(+), 399 deletions(-) delete mode 100644 src/core/include/ngraph/node.hpp diff --git a/docs/snippets/lpt_intel_cpu_plugin.cpp b/docs/snippets/lpt_intel_cpu_plugin.cpp index dbc2d3d8f26e0e..9c479b89d395f9 100644 --- a/docs/snippets/lpt_intel_cpu_plugin.cpp +++ b/docs/snippets/lpt_intel_cpu_plugin.cpp @@ -52,12 +52,12 @@ if (useLpt) { if (useLpt) { // convert not supported cases FakeQuantize -> Convert -> Convert -> Subtract -> Multiply to a single FakeQuantize - pass_config->set_callback([&defaultPrecisions](const std::shared_ptr &node) -> bool { + pass_config->set_callback([&defaultPrecisions](const std::shared_ptr &node) -> bool { return ov::pass::low_precision::NetworkHelper::areQuantizeAndDequantizeSupportedForMultiply(node, defaultPrecisions); }); // convert not supported cases FakeQuantize -> Convert -> Convert -> Subtract -> Multiply to a single FakeQuantize - pass_config->set_callback([&defaultPrecisions](const std::shared_ptr &node) -> bool { + pass_config->set_callback([&defaultPrecisions](const std::shared_ptr &node) -> bool { return ov::pass::low_precision::NetworkHelper::areQuantizeAndDequantizeSupportedForSubtract(node, defaultPrecisions); }); } @@ -95,16 +95,16 @@ if (useLpt) { lptManager.register_pass(supportedPrecisions, perTensorQuantization); // Low precision transformations plugin specific configuration: transformation callbacks definition - lptManager.get_pass_config()->set_callback([](const std::shared_ptr& node) -> bool { + lptManager.get_pass_config()->set_callback([](const std::shared_ptr& node) -> bool { if (const auto multiply = std::dynamic_pointer_cast(node)) { return !MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolution(multiply); } return false; }); - lptManager.get_pass_config()->set_callback([&defaultPrecisions](const std::shared_ptr& node) -> bool { + lptManager.get_pass_config()->set_callback([&defaultPrecisions](const std::shared_ptr& node) -> bool { return LayerTransformation::isAsymmetricQuantization(node, defaultPrecisions) || WeightableLayerTransformation::isAsymmetricOnWeights(node); }); - lptManager.get_pass_config()->set_callback([](const std::shared_ptr& node) -> bool { + lptManager.get_pass_config()->set_callback([](const std::shared_ptr& node) -> bool { return MultiplyToGroupConvolutionTransformation::isDynamicOrScalar(node); }); @@ -177,7 +177,7 @@ using namespace ov::pass::low_precision; ov::pass::Manager lptManager; lptManager.register_pass(); -lptManager.get_pass_config()->set_callback([&defaultPrecisions](const std::shared_ptr& node) -> bool { +lptManager.get_pass_config()->set_callback([&defaultPrecisions](const std::shared_ptr& node) -> bool { return LayerTransformation::isAsymmetricQuantization(node, defaultPrecisions) || WeightableLayerTransformation::isAsymmetricOnWeights(node); }); lptManager.run_passes(nGraphFunc); diff --git a/src/core/include/ngraph/evaluator.hpp b/src/core/include/ngraph/evaluator.hpp index 6e1aecb325e480..8a77cb3e8ae140 100644 --- a/src/core/include/ngraph/evaluator.hpp +++ b/src/core/include/ngraph/evaluator.hpp @@ -19,8 +19,8 @@ #include #include "ngraph/deprecated.hpp" -#include "ngraph/node.hpp" #include "ngraph/shape.hpp" +#include "openvino/core/node.hpp" #include "openvino/core/type/element_type_traits.hpp" namespace ngraph { @@ -32,16 +32,16 @@ class NGRAPH_API_DEPRECATED Evaluator { NGRAPH_SUPPRESS_DEPRECATED_START public: /// \brief values we compute for outputs - using value_map = std::map; + using value_map = std::map; /// \brief Handler for a computation of a value about an op /// /// A handler is passed a Node* and a vector of computed input values. The handler should /// return a vector of computed output values. - using op_handler = std::function(Node* op, std::vector& inputs)>; + using op_handler = std::function(ov::Node* op, std::vector& inputs)>; /// \brief Table of ops with handlers - using op_handler_map = std::map; + using op_handler_map = std::map; /// \brief construct handler using the provided op handlers. /// @@ -78,7 +78,7 @@ class NGRAPH_API_DEPRECATED Evaluator { } protected: - op_handler get_handler(Node* node) { + op_handler get_handler(ov::Node* node) { op_handler handler = m_universal_handler; if (!handler) { auto it = m_handlers.find(node->get_type_info()); @@ -98,27 +98,27 @@ class NGRAPH_API_DEPRECATED Evaluator { /// \brief Intstructions for evaluations state machine class Inst { protected: - Inst(Node* node) : m_node(node) {} + Inst(ov::Node* node) : m_node(node) {} public: virtual ~Inst() {} - virtual void handle(Evaluator& evaluator, InstStack& inst_stack, Node* node) = 0; - Node* get_node() { + virtual void handle(Evaluator& evaluator, InstStack& inst_stack, ov::Node* node) = 0; + ov::Node* get_node() { return m_node; } protected: - Node* m_node; + ov::Node* m_node; }; /// \brief Ensure value has been analyzed class ValueInst : public Inst { public: - ValueInst(const ov::Output& value) : Inst(value.get_node()), m_index(value.get_index()) {} + ValueInst(const ov::Output& value) : Inst(value.get_node()), m_index(value.get_index()) {} - ValueInst(const RawNodeOutput& value) : Inst(value.node), m_index(value.index) {} + ValueInst(const ov::RawNodeOutput& value) : Inst(value.node), m_index(value.index) {} - void handle(Evaluator& evaluator, InstStack& inst_stack, Node* node) override { + void handle(Evaluator& evaluator, InstStack& inst_stack, ov::Node* node) override { // Request to analyze this value if we can if (auto handler = evaluator.get_handler(node)) { // Ensure the inputs are processed and then execute the op handler @@ -141,9 +141,9 @@ class NGRAPH_API_DEPRECATED Evaluator { /// \brief All arguments have been handled; execute the node handler class ExecuteInst : public Inst { public: - ExecuteInst(Node* node, op_handler& handler) : Inst(node), m_handler(handler) {} + ExecuteInst(ov::Node* node, op_handler& handler) : Inst(node), m_handler(handler) {} - void handle(Evaluator& evaluator, InstStack& inst_stack, Node* node) override { + void handle(Evaluator& evaluator, InstStack& inst_stack, ov::Node* node) override { // Request to execute the handleer. Pass what we know about the inputs to the // handler and associate the results with the outputs std::vector inputs; @@ -162,7 +162,7 @@ class NGRAPH_API_DEPRECATED Evaluator { public: /// \brief Determine information about value - V evaluate(const ov::Output& value) { + V evaluate(const ov::Output& value) { InstStack inst_stack; inst_stack.push(InstPtr(new ValueInst(value))); while (!inst_stack.empty()) { diff --git a/src/core/include/ngraph/graph_util.hpp b/src/core/include/ngraph/graph_util.hpp index 5dfe6d28bdc51f..488a8077591ebe 100644 --- a/src/core/include/ngraph/graph_util.hpp +++ b/src/core/include/ngraph/graph_util.hpp @@ -25,7 +25,7 @@ #include #include "ngraph/check.hpp" -#include "ngraph/node.hpp" +#include "ngraph/deprecated.hpp" #include "openvino/core/graph_util.hpp" namespace ov { @@ -53,17 +53,19 @@ using ov::replace_output_update_name; using ov::topological_sort; using ov::traverse_nodes; +using NodeMap = std::unordered_map>; + NGRAPH_API_DEPRECATED NGRAPH_API -ov::NodeVector find_common_args(std::shared_ptr target, std::shared_ptr replacement); +ov::NodeVector find_common_args(std::shared_ptr target, std::shared_ptr replacement); /// Topological sort of just nodes template -NGRAPH_API_DEPRECATED std::vector> subgraph_topological_sort(T nodes) { - std::stack> nodes_to_do; - std::unordered_set nodes_done; - std::unordered_set nodes_to_emit; - std::vector> result; +NGRAPH_API_DEPRECATED std::vector> subgraph_topological_sort(T nodes) { + std::stack> nodes_to_do; + std::unordered_set nodes_done; + std::unordered_set nodes_to_emit; + std::vector> result; for (auto& node : nodes) { nodes_to_emit.insert(node.get()); @@ -72,19 +74,19 @@ NGRAPH_API_DEPRECATED std::vector> subgraph_topological_so // NB: Some centos versions implement std::list::size() by counting elements size_t nodes_remaining = nodes_to_emit.size(); while (nodes_to_do.size() > 0 && nodes_remaining > 0) { - Node* node = nodes_to_do.top(); + ov::Node* node = nodes_to_do.top(); if (nodes_done.count(node) == 0) { bool can_add = true; size_t arg_count = node->get_input_size(); for (size_t i = 0; i < arg_count; ++i) { - Node* dep = node->get_input_node_ptr(arg_count - i - 1); + ov::Node* dep = node->get_input_node_ptr(arg_count - i - 1); if (nodes_done.count(dep) == 0 && nodes_to_emit.count(node) != 0) { can_add = false; nodes_to_do.push(dep); } } for (auto& depptr : node->get_control_dependencies()) { - Node* dep = depptr.get(); + ov::Node* dep = depptr.get(); if (nodes_done.count(dep) == 0) { can_add = false; nodes_to_do.push(dep); @@ -119,53 +121,53 @@ NGRAPH_API_DEPRECATED void validate_nodes_and_infer_types(const T& nodes) { // Check if all paths from X to a result go through Y NGRAPH_API_DEPRECATED NGRAPH_API -bool is_post_dominated(Node* X, Node* Y); +bool is_post_dominated(ov::Node* X, ov::Node* Y); NGRAPH_API_DEPRECATED NGRAPH_API -bool is_equal_to_const_value(const std::string& const_value, const ov::Output& reduce_constant); +bool is_equal_to_const_value(const std::string& const_value, const ov::Output& reduce_constant); // input nodes are cloned and returned // NodeMap input may contain default node mapping i.e. pre-cloned nodes // NodeMap output (by reference) fully maps input and cloned nodes NGRAPH_API_DEPRECATED NGRAPH_API -std::vector> clone_nodes(const std::vector>& nodes, - NodeMap& node_map); +std::vector> clone_nodes(const std::vector>& nodes, + NodeMap& node_map); // input nodes are cloned and returned // NodeMap input may contain default node mapping i.e. pre-cloned nodes // NodeMap output (by reference) fully maps input and cloned nodes NGRAPH_API_DEPRECATED NGRAPH_API -std::list> clone_nodes(const std::vector>& nodes, - RawNodeOutputMap& node_map); +std::list> clone_nodes(const std::vector>& nodes, + ov::RawNodeOutputMap& node_map); NGRAPH_API_DEPRECATED NGRAPH_API std::pair, std::shared_ptr> insert_result_parameter_split( - const std::shared_ptr& src_node, - const std::shared_ptr& dst_node); + const std::shared_ptr& src_node, + const std::shared_ptr& dst_node); NGRAPH_API_DEPRECATED NGRAPH_API -void insert_new_node_between(const std::shared_ptr& src_node, - const std::shared_ptr& dst_node, - const std::shared_ptr& new_node); +void insert_new_node_between(const std::shared_ptr& src_node, + const std::shared_ptr& dst_node, + const std::shared_ptr& new_node); NGRAPH_API_DEPRECATED NGRAPH_API -std::shared_ptr make_zero(const ov::element::Type& element_type, const ov::Shape& shape); +std::shared_ptr make_zero(const ov::element::Type& element_type, const ov::Shape& shape); NGRAPH_API_DEPRECATED NGRAPH_API -std::shared_ptr make_constant_from_string(std::string val, - const ov::element::Type& element_type, - const ov::Shape& shape); +std::shared_ptr make_constant_from_string(std::string val, + const ov::element::Type& element_type, + const ov::Shape& shape); NGRAPH_API_DEPRECATED NGRAPH_API -bool is_zero(const ov::Output& reduce_constant); +bool is_zero(const ov::Output& reduce_constant); NGRAPH_API_DEPRECATED NGRAPH_API @@ -183,43 +185,43 @@ ov::NodeVector extract_subgraph(const ov::NodeVector& results, const ov::NodeVec NGRAPH_API_DEPRECATED NGRAPH_API -bool is_one(const ov::Output& reduce_constant); +bool is_one(const ov::Output& reduce_constant); // Returns true if `node` is live in the graph i.e. a result op // transitively uses this `node` NGRAPH_API_DEPRECATED NGRAPH_API -bool is_used(Node* node); +bool is_used(ov::Node* node); // Returns count of `node` users that are still live in the graph NGRAPH_API_DEPRECATED NGRAPH_API -size_t get_user_count(Node* node); +size_t get_user_count(ov::Node* node); NGRAPH_API_DEPRECATED NGRAPH_API -bool is_strided(const Strides& strides); +bool is_strided(const ov::Strides& strides); NGRAPH_API_DEPRECATED NGRAPH_API -bool is_valid_rank(const std::shared_ptr& node, std::vector valid_ranks); +bool is_valid_rank(const std::shared_ptr& node, std::vector valid_ranks); NGRAPH_API_DEPRECATED NGRAPH_API void plot_graph(std::shared_ptr f, const std::string& filename, - std::function& attributes)> = nullptr); + std::function& attributes)> = nullptr); /// \return A vector containing handles for each input of dst that is connected to an output /// of `src`. NGRAPH_API_DEPRECATED NGRAPH_API -std::vector> get_inputs_from(Node& src, Node& dst); +std::vector> get_inputs_from(ov::Node& src, ov::Node& dst); /// \return A vector containing a handle for each output of src that is connected to an input /// of `dst`. NGRAPH_API_DEPRECATED NGRAPH_API -std::vector> get_outputs_to(Node& src, Node& dst); +std::vector> get_outputs_to(ov::Node& src, ov::Node& dst); /// Checks the func for graph cycles starting from results going backwards, then from parameters /// going forward. diff --git a/src/core/include/ngraph/node.hpp b/src/core/include/ngraph/node.hpp deleted file mode 100644 index 8b66bf793c6c55..00000000000000 --- a/src/core/include/ngraph/node.hpp +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#if !defined(IN_OV_COMPONENT) && !defined(NGRAPH_LEGACY_HEADER_INCLUDED) -# define NGRAPH_LEGACY_HEADER_INCLUDED -# ifdef _MSC_VER -# pragma message( \ - "The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html") -# else -# warning("The nGraph API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html") -# endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ngraph/check.hpp" -#include "ngraph/coordinate_diff.hpp" -#include "ngraph/deprecated.hpp" -#include "ngraph/op/util/attr_types.hpp" -#include "ngraph/strides.hpp" -#include "openvino/core/any.hpp" -#include "openvino/core/descriptor/input.hpp" -#include "openvino/core/descriptor/output.hpp" -#include "openvino/core/descriptor/tensor.hpp" -#include "openvino/core/node.hpp" -#include "openvino/core/node_vector.hpp" -#include "openvino/op/util/variable.hpp" -#include "openvino/op/util/variable_value.hpp" - -namespace ov { -namespace op { -namespace v0 { -class Result; -} -} // namespace op -} // namespace ov -namespace ngraph { - -using ov::Node; - -namespace op { -namespace v0 { -using ov::op::v0::Result; -} -} // namespace op - -using EvaluationContext = ov::EvaluationContext; -using ResultVector = std::vector>; - -const auto node_validation_failure_loc_string = ov::node_validation_failure_loc_string; - -NGRAPH_API -NGRAPH_API_DEPRECATED -const std::shared_ptr& check_single_output_arg(const std::shared_ptr& node, size_t i); -NGRAPH_API -NGRAPH_API_DEPRECATED -const ov::NodeVector& check_single_output_args(const ov::NodeVector& args); - -const auto as_output_vector = ov::as_output_vector; -const auto as_node_vector = ov::as_node_vector; -const auto as_result_vector = ov::as_result_vector; - -/// Alias useful for cloning -using NodeMap = std::unordered_map>; - -/// Nodes are the backbone of the graph of Value dataflow. Every node has -/// zero or more nodes as arguments and one value, which is either a tensor -/// or a (possibly empty) tuple of values. -using ov::NodeValidationFailure; - -using NodeTypeInfo = Node::type_info_t; - -// Like an Output but with a Node* instead of a shared_ptr -using ov::RawNodeOutput; - -using RawNodeOutputMap = std::map>; - -using ov::check_new_args_count; - -/// Helper macro that puts necessary declarations of RTTI block inside a class definition. -/// Should be used in the scope of class that requires type identification besides one provided by -/// C++ RTTI. -/// Recommended to be used for all classes that are inherited from class ov::Node to enable -/// pattern -/// matching for them. Accepts necessary type identification details like type of the operation, -/// version and optional parent class. -/// -/// Applying this macro within a class definition provides declaration of type_info static -/// constant for backward compatibility with old RTTI definition for Node, -/// static function get_type_info_static which returns a reference to an object that is equal to -/// type_info but not necessary to the same object, and get_type_info virtual function that -/// overrides Node::get_type_info and returns a reference to the same object that -/// get_type_info_static gives. -/// -/// Use this macro as a public part of the class definition: -/// -/// class MyOp : public Node -/// { -/// public: -/// // Don't use Node as a parent for type_info, it doesn't have any value and -/// prohibited -/// NGRAPH_RTTI_DECLARATION; -/// -/// ... -/// }; -/// -/// class MyInheritedOp : public MyOp -/// { -/// public: -/// NGRAPH_RTTI_DECLARATION; -/// -/// ... -/// }; -/// -/// To complete type identification for a class, use NGRAPH_RTTI_DEFINITION. -/// -#ifdef OPENVINO_STATIC_LIBRARY -# define NGRAPH_RTTI_DECLARATION \ - const ::ngraph::Node::type_info_t& get_type_info() const override; \ - static const ::ngraph::Node::type_info_t& get_type_info_static() -# define _NGRAPH_RTTI_DEFINITION_COMMON(CLASS) \ - const ::ngraph::Node::type_info_t& CLASS::get_type_info() const { \ - return get_type_info_static(); \ - } -#else -# define NGRAPH_RTTI_DECLARATION \ - static const ::ngraph::Node::type_info_t type_info; \ - const ::ngraph::Node::type_info_t& get_type_info() const override; \ - static const ::ngraph::Node::type_info_t& get_type_info_static() -# define _NGRAPH_RTTI_DEFINITION_COMMON(CLASS) \ - const ::ngraph::Node::type_info_t& CLASS::get_type_info() const { \ - return get_type_info_static(); \ - } -#endif - -#define _NGRAPH_RTTI_DEFINITION_WITH_PARENT(CLASS, TYPE_NAME, PARENT_CLASS) \ - const ::ngraph::Node::type_info_t& CLASS::get_type_info_static() { \ - static const ::ngraph::Node::type_info_t type_info_static{TYPE_NAME, &PARENT_CLASS::get_type_info_static()}; \ - return type_info_static; \ - } \ - _NGRAPH_RTTI_DEFINITION_COMMON(CLASS) - -#define _NGRAPH_RTTI_DEFINITION_NO_PARENT(CLASS, TYPE_NAME) \ - const ::ngraph::Node::type_info_t& CLASS::get_type_info_static() { \ - static const ::ngraph::Node::type_info_t type_info_static{TYPE_NAME}; \ - return type_info_static; \ - } \ - _NGRAPH_RTTI_DEFINITION_COMMON(CLASS) -#define NGRAPH_RTTI_DEFINITION(...) \ - _OPENVINO_RTTI_EXPAND(_OPENVINO_RTTI_DEFINITION_SELECTOR(__VA_ARGS__, \ - _NGRAPH_RTTI_DEFINITION_WITH_PARENT, \ - _NGRAPH_RTTI_DEFINITION_NO_PARENT)(__VA_ARGS__)) - -} // namespace ngraph diff --git a/src/core/include/ngraph/op/split.hpp b/src/core/include/ngraph/op/split.hpp index 1ab39e2ace354d..0afd5979ef18f8 100644 --- a/src/core/include/ngraph/op/split.hpp +++ b/src/core/include/ngraph/op/split.hpp @@ -17,7 +17,6 @@ #include #include -#include "ngraph/node.hpp" #include "openvino/op/split.hpp" namespace ngraph { diff --git a/src/core/include/ngraph/op/util/op_types.hpp b/src/core/include/ngraph/op/util/op_types.hpp index 61a9e2bfe373ea..bd882f0e4827bf 100644 --- a/src/core/include/ngraph/op/util/op_types.hpp +++ b/src/core/include/ngraph/op/util/op_types.hpp @@ -17,7 +17,6 @@ #include #include "ngraph/ngraph_visibility.hpp" -#include "ngraph/node.hpp" #include "openvino/op/util/op_types.hpp" namespace ngraph { diff --git a/src/core/include/ngraph/util.hpp b/src/core/include/ngraph/util.hpp index d81d852a874f8b..01e5dab9dbc6dd 100644 --- a/src/core/include/ngraph/util.hpp +++ b/src/core/include/ngraph/util.hpp @@ -31,7 +31,6 @@ #include "ngraph/axis_vector.hpp" #include "ngraph/graph_util.hpp" -#include "ngraph/node.hpp" #include "ngraph/shape.hpp" #include "openvino/core/enum_mask.hpp" #include "openvino/core/type/element_type.hpp" diff --git a/src/core/src/graph_util.cpp b/src/core/src/graph_util.cpp index 1c43c32a95e1df..d66977c0d1c4e2 100644 --- a/src/core/src/graph_util.cpp +++ b/src/core/src/graph_util.cpp @@ -448,7 +448,7 @@ std::vector> clone_nodes(const std::vector> clone_nodes(const std::vector>& nodes, - RawNodeOutputMap& output_map) { + ov::RawNodeOutputMap& output_map) { // for each node in topological order auto sorted_nodes = topological_sort(nodes); std::list> cloned_nodes; diff --git a/src/core/src/node.cpp b/src/core/src/node.cpp index 054955e241748e..80ac8cdeba84fd 100644 --- a/src/core/src/node.cpp +++ b/src/core/src/node.cpp @@ -534,20 +534,6 @@ std::string ov::node_validation_failure_loc_string(const Node* node) { return ss.str(); } -OPENVINO_SUPPRESS_DEPRECATED_START -const std::shared_ptr& ngraph::check_single_output_arg(const std::shared_ptr& node, size_t i) { - OPENVINO_ASSERT(node->get_output_size() == 1, "Argument ", i, node, " must produce exactly one value."); - return node; -} - -const ov::NodeVector& ngraph::check_single_output_args(const ov::NodeVector& args) { - for (size_t i = 0; i < args.size(); ++i) { - ngraph::check_single_output_arg(args.at(i), i); - } - return args; -} -OPENVINO_SUPPRESS_DEPRECATED_END - bool ov::Node::match_value(ov::pass::pattern::Matcher* matcher, const Output& pattern_value, const Output& graph_value) { diff --git a/src/core/src/specialize_function.cpp b/src/core/src/specialize_function.cpp index f9c5085370ae05..5ecc9742772830 100644 --- a/src/core/src/specialize_function.cpp +++ b/src/core/src/specialize_function.cpp @@ -86,7 +86,7 @@ std::shared_ptr ngraph::specialize_function(std::shared_ptrset_friendly_name(name); } - ResultVector new_results = f->get_results(); + ov::ResultVector new_results = f->get_results(); for (size_t i = 0; i < new_results.size(); i++) { auto name = new_results[i]->get_friendly_name(); new_results[i] = std::static_pointer_cast(m[new_results[i].get()]); diff --git a/src/core/tests/specialize_function.cpp b/src/core/tests/specialize_function.cpp index efb354e7e48f3d..9da33c1bd18c75 100644 --- a/src/core/tests/specialize_function.cpp +++ b/src/core/tests/specialize_function.cpp @@ -158,7 +158,7 @@ TEST(specialize_function, et_static_shape_rank_dynamic_validation_fails) { {ov::PartialShape{1, 2, 3}, ov::PartialShape{1, 2, 3, 4}}, param_vals); }, - NodeValidationFailure); + ov::NodeValidationFailure); } // Test specialization of dynamic element types to a case where validation will fail. @@ -182,7 +182,7 @@ TEST(specialize_function, et_dynamic_shape_static_validation_fails) { {ov::PartialShape{1, 2, 3}, ov::PartialShape{1, 2, 3}}, param_vals); }, - NodeValidationFailure); + ov::NodeValidationFailure); } // Test specialization of rank-static dynamic shapes, where the replacement shapes have the wrong diff --git a/src/frontends/onnx/docs/how_to_add_op.md b/src/frontends/onnx/docs/how_to_add_op.md index d05b4d7ecdda7c..283292ba223cee 100644 --- a/src/frontends/onnx/docs/how_to_add_op.md +++ b/src/frontends/onnx/docs/how_to_add_op.md @@ -9,7 +9,6 @@ The declaration in `.hpp` can look like: ```cpp #pragma once -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/bitwise_not.hpp b/src/frontends/onnx/frontend/src/op/bitwise_not.hpp index bfffeff7b39443..38d69385f96033 100644 --- a/src/frontends/onnx/frontend/src/op/bitwise_not.hpp +++ b/src/frontends/onnx/frontend/src/op/bitwise_not.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/conv_transpose.cpp b/src/frontends/onnx/frontend/src/op/conv_transpose.cpp index e46533317d1f7c..2e0276ada0172f 100644 --- a/src/frontends/onnx/frontend/src/op/conv_transpose.cpp +++ b/src/frontends/onnx/frontend/src/op/conv_transpose.cpp @@ -30,8 +30,8 @@ ov::Output make_group_conv_backprop(const ov::Output& data, const ov::Output& filters, const Strides& strides, const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, + const ov::CoordinateDiff& pads_begin, + const ov::CoordinateDiff& pads_end, const ov::op::PadType& auto_pad_type, const std::vector& output_shape, const std::vector& output_padding) { @@ -44,7 +44,7 @@ ov::Output make_group_conv_backprop(const ov::Output& data, pads_end, dilations, auto_pad_type, - CoordinateDiff(std::begin(output_padding), std::end(output_padding))); + ov::CoordinateDiff(std::begin(output_padding), std::end(output_padding))); } else { return std::make_shared( data, @@ -53,7 +53,7 @@ ov::Output make_group_conv_backprop(const ov::Output& data, strides, dilations, auto_pad_type, - CoordinateDiff(std::begin(output_padding), std::end(output_padding))); + ov::CoordinateDiff(std::begin(output_padding), std::end(output_padding))); } } @@ -61,8 +61,8 @@ ov::Output make_conv_backprop(const ov::Output& data, const ov::Output& filters, const Strides& strides, const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, + const ov::CoordinateDiff& pads_begin, + const ov::CoordinateDiff& pads_end, const ov::op::PadType& auto_pad_type, const std::vector& output_shape, const std::vector& output_padding) { @@ -75,7 +75,7 @@ ov::Output make_conv_backprop(const ov::Output& data, pads_end, dilations, auto_pad_type, - CoordinateDiff(std::begin(output_padding), std::end(output_padding))); + ov::CoordinateDiff(std::begin(output_padding), std::end(output_padding))); } else { return std::make_shared( data, @@ -86,7 +86,7 @@ ov::Output make_conv_backprop(const ov::Output& data, pads_end, dilations, auto_pad_type, - CoordinateDiff(std::begin(output_padding), std::end(output_padding))); + ov::CoordinateDiff(std::begin(output_padding), std::end(output_padding))); } } @@ -140,7 +140,7 @@ ov::OutputVector conv_transpose(const Node& node) { std::size_t num_spatial_dims = 0; Strides strides, dilations; - std::pair paddings; + std::pair paddings; ov::op::PadType auto_pad_type = convpool::get_auto_pad(node); // Get attirbutes or infer them from input data rank it it's static. @@ -163,8 +163,8 @@ ov::OutputVector conv_transpose(const Node& node) { strides = convpool::get_strides(node, num_spatial_dims); dilations = convpool::get_dilations(node, num_spatial_dims); paddings = convpool::get_pads(node, num_spatial_dims); - CoordinateDiff pads_begin = paddings.first; - CoordinateDiff pads_end = paddings.second; + ov::CoordinateDiff pads_begin = paddings.first; + ov::CoordinateDiff pads_end = paddings.second; std::vector output_shape{node.get_attribute_value>("output_shape", {})}; diff --git a/src/frontends/onnx/frontend/src/op/quant_conv.cpp b/src/frontends/onnx/frontend/src/op/quant_conv.cpp index 9feefe738500ee..942d877e9f5a7e 100644 --- a/src/frontends/onnx/frontend/src/op/quant_conv.cpp +++ b/src/frontends/onnx/frontend/src/op/quant_conv.cpp @@ -34,21 +34,21 @@ namespace ngraph { struct OpScale { - Output data_scale; - Output filter_scale; - Output output_scale; + Output data_scale; + Output filter_scale; + Output output_scale; }; struct OpZeroPoint { - Output data_zero_point; - Output filter_zero_point; - Output output_zero_point; + Output data_zero_point; + Output filter_zero_point; + Output output_zero_point; }; - std::shared_ptr - make_ng_quant_conv(const Output& data, - const Output& filters, + std::shared_ptr + make_ng_quant_conv(const Output& data, + const Output& filters, const Strides& strides, const Strides& filter_dilations, const CoordinateDiff& padding_below, @@ -57,7 +57,7 @@ namespace ngraph int groups, const OpScale& op_scale, const OpZeroPoint& op_zero_point, - const Output& bias = nullptr) + const Output& bias = nullptr) { ngraph:: ov::element::Type output_type; if (data.get_element_type() == ngraph:: ov::element::u8 && @@ -228,7 +228,7 @@ namespace ngraph padding_below, padding_above); - std::shared_ptr conv_node = nullptr; + std::shared_ptr conv_node = nullptr; // no bias param if (inputs.size() == 9 && !ngraph::op::is_null(inputs.at(8))) diff --git a/src/frontends/onnx/frontend/src/op/scan.hpp b/src/frontends/onnx/frontend/src/op/scan.hpp index d9c3b8addb294a..1ccbd35b22464b 100644 --- a/src/frontends/onnx/frontend/src/op/scan.hpp +++ b/src/frontends/onnx/frontend/src/op/scan.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/scatter_elements.hpp b/src/frontends/onnx/frontend/src/op/scatter_elements.hpp index 6b3b9f420fe5b0..f0f97e2ac7bc89 100644 --- a/src/frontends/onnx/frontend/src/op/scatter_elements.hpp +++ b/src/frontends/onnx/frontend/src/op/scatter_elements.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/scatter_nd.hpp b/src/frontends/onnx/frontend/src/op/scatter_nd.hpp index 37fa256d05febf..771153b46db9f3 100644 --- a/src/frontends/onnx/frontend/src/op/scatter_nd.hpp +++ b/src/frontends/onnx/frontend/src/op/scatter_nd.hpp @@ -10,7 +10,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/selu.hpp b/src/frontends/onnx/frontend/src/op/selu.hpp index 8d57a9e0c055bf..fa360f1d0f6c01 100644 --- a/src/frontends/onnx/frontend/src/op/selu.hpp +++ b/src/frontends/onnx/frontend/src/op/selu.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/shape.cpp b/src/frontends/onnx/frontend/src/op/shape.cpp index 99f850aea4907b..58f3e0caa49ac0 100644 --- a/src/frontends/onnx/frontend/src/op/shape.cpp +++ b/src/frontends/onnx/frontend/src/op/shape.cpp @@ -7,7 +7,6 @@ #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "op/shape.hpp" #include "openvino/core/type/element_type.hpp" diff --git a/src/frontends/onnx/frontend/src/op/shape.hpp b/src/frontends/onnx/frontend/src/op/shape.hpp index 8830fd0648095c..a2dc019dd05f02 100644 --- a/src/frontends/onnx/frontend/src/op/shape.hpp +++ b/src/frontends/onnx/frontend/src/op/shape.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/shrink.cpp b/src/frontends/onnx/frontend/src/op/shrink.cpp index 3bcb817cf6cb95..0a3ff14412a069 100644 --- a/src/frontends/onnx/frontend/src/op/shrink.cpp +++ b/src/frontends/onnx/frontend/src/op/shrink.cpp @@ -38,17 +38,16 @@ ov::OutputVector shrink(const Node& node) { // Create a mask indicating locations of values that need to be adjusted // by adding and subtracting bias // All other values indicated by 'false' in the masks need to be zeroed out - std::shared_ptr values_below_neg_lambd = std::make_shared(input, negative_lambd); - std::shared_ptr values_above_pos_lambd = - std::make_shared(input, positive_lambd); + std::shared_ptr values_below_neg_lambd = std::make_shared(input, negative_lambd); + std::shared_ptr values_above_pos_lambd = std::make_shared(input, positive_lambd); // Convert from bool to the input type to be able to multiply adjusted inputs // by the created masks values_below_neg_lambd = std::make_shared(values_below_neg_lambd, input_element_type); values_above_pos_lambd = std::make_shared(values_above_pos_lambd, input_element_type); - std::shared_ptr input_minus_bias = std::make_shared(input, bias_tensor); - std::shared_ptr input_plus_bias = std::make_shared(input, bias_tensor); + std::shared_ptr input_minus_bias = std::make_shared(input, bias_tensor); + std::shared_ptr input_plus_bias = std::make_shared(input, bias_tensor); // multiply by the corresponding mask to zero-out the values within // the <-lambd;lambd> range and keep the bias-adjusted values from outside of it diff --git a/src/frontends/onnx/frontend/src/op/shrink.hpp b/src/frontends/onnx/frontend/src/op/shrink.hpp index 5e7c065f7c38aa..1705505d6b1e4b 100644 --- a/src/frontends/onnx/frontend/src/op/shrink.hpp +++ b/src/frontends/onnx/frontend/src/op/shrink.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sigmoid.hpp b/src/frontends/onnx/frontend/src/op/sigmoid.hpp index 69c19c668ae58a..63a0ee202939b0 100644 --- a/src/frontends/onnx/frontend/src/op/sigmoid.hpp +++ b/src/frontends/onnx/frontend/src/op/sigmoid.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sign.hpp b/src/frontends/onnx/frontend/src/op/sign.hpp index d0c0c9c461a934..4c25db7fe8834f 100644 --- a/src/frontends/onnx/frontend/src/op/sign.hpp +++ b/src/frontends/onnx/frontend/src/op/sign.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sin.hpp b/src/frontends/onnx/frontend/src/op/sin.hpp index 9b538e0f005b4b..9b92ec68f2a2c7 100644 --- a/src/frontends/onnx/frontend/src/op/sin.hpp +++ b/src/frontends/onnx/frontend/src/op/sin.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sinh.hpp b/src/frontends/onnx/frontend/src/op/sinh.hpp index 02e4b414582c27..90895abd09abf1 100644 --- a/src/frontends/onnx/frontend/src/op/sinh.hpp +++ b/src/frontends/onnx/frontend/src/op/sinh.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/size.hpp b/src/frontends/onnx/frontend/src/op/size.hpp index cd0d977af018b1..6bce2d6f816e27 100644 --- a/src/frontends/onnx/frontend/src/op/size.hpp +++ b/src/frontends/onnx/frontend/src/op/size.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/slice.cpp b/src/frontends/onnx/frontend/src/op/slice.cpp index 23f8c4f4a5b66c..ecfce8472220a4 100644 --- a/src/frontends/onnx/frontend/src/op/slice.cpp +++ b/src/frontends/onnx/frontend/src/op/slice.cpp @@ -27,7 +27,7 @@ ov::OutputVector slice(const Node& node) { const bool axes_input_provided = inputs.size() >= 4 && !is_null(inputs.at(3)); const bool steps_input_provided = inputs.size() == 5 && !is_null(inputs.at(4)); - ov::Output steps; + ov::Output steps; if (steps_input_provided) { steps = inputs.at(4); } else { @@ -48,7 +48,7 @@ ov::OutputVector slice(const Node& node) { namespace set_1 { ov::OutputVector slice(const Node& node) { - ov::Output data = node.get_ng_inputs().at(0); + ov::Output data = node.get_ng_inputs().at(0); const auto starts_atr = node.get_attribute_value>("starts"); const auto ends = node.get_attribute_as_constant>("ends"); diff --git a/src/frontends/onnx/frontend/src/op/slice.hpp b/src/frontends/onnx/frontend/src/op/slice.hpp index f75343c0d0100a..6dc4d7d388debb 100644 --- a/src/frontends/onnx/frontend/src/op/slice.hpp +++ b/src/frontends/onnx/frontend/src/op/slice.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/softmax.cpp b/src/frontends/onnx/frontend/src/op/softmax.cpp index 566f46e28c78a6..0bd1ef0c0c962f 100644 --- a/src/frontends/onnx/frontend/src/op/softmax.cpp +++ b/src/frontends/onnx/frontend/src/op/softmax.cpp @@ -14,7 +14,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { namespace onnx_import { namespace { -std::shared_ptr onnx_softmax(const ov::Output data, const int64_t axis) { +std::shared_ptr onnx_softmax(const ov::Output data, const int64_t axis) { const auto coerced_data = ov::op::util::flatten(data, static_cast(axis)); const auto result = std::make_shared(coerced_data, 1); const auto data_shape = std::make_shared(data); @@ -32,7 +32,7 @@ ov::OutputVector softmax(const Node& node) { const auto axis = node.get_attribute_value("axis", 1); - std::shared_ptr result; + std::shared_ptr result; switch (data_rank.get_length()) { case 0: { result = default_opset::Constant::create(data.get_element_type(), Shape{}, {1}); @@ -55,7 +55,7 @@ ov::OutputVector softmax(const Node& node) { const auto axis = node.get_attribute_value("axis", 1); - std::shared_ptr result; + std::shared_ptr result; switch (data_rank.get_length()) { case 0: { result = default_opset::Constant::create(data.get_element_type(), Shape{}, {1}); diff --git a/src/frontends/onnx/frontend/src/op/softmax.hpp b/src/frontends/onnx/frontend/src/op/softmax.hpp index 7e352cb8a0d1cf..b87bda13aac05e 100644 --- a/src/frontends/onnx/frontend/src/op/softmax.hpp +++ b/src/frontends/onnx/frontend/src/op/softmax.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/softplus.cpp b/src/frontends/onnx/frontend/src/op/softplus.cpp index c1685ad855513d..1e05b69285e8dd 100644 --- a/src/frontends/onnx/frontend/src/op/softplus.cpp +++ b/src/frontends/onnx/frontend/src/op/softplus.cpp @@ -7,7 +7,6 @@ #include #include "default_opset.hpp" -#include "ngraph/node.hpp" OPENVINO_SUPPRESS_DEPRECATED_START namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/softplus.hpp b/src/frontends/onnx/frontend/src/op/softplus.hpp index 323b92e0cbcca7..25ac0bef0cb692 100644 --- a/src/frontends/onnx/frontend/src/op/softplus.hpp +++ b/src/frontends/onnx/frontend/src/op/softplus.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/softsign.hpp b/src/frontends/onnx/frontend/src/op/softsign.hpp index 3f8b6015442eb5..a6f997950b6f97 100644 --- a/src/frontends/onnx/frontend/src/op/softsign.hpp +++ b/src/frontends/onnx/frontend/src/op/softsign.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/space_to_depth.hpp b/src/frontends/onnx/frontend/src/op/space_to_depth.hpp index dc175be96e257b..491d698d5f9a5b 100644 --- a/src/frontends/onnx/frontend/src/op/space_to_depth.hpp +++ b/src/frontends/onnx/frontend/src/op/space_to_depth.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/split.hpp b/src/frontends/onnx/frontend/src/op/split.hpp index 05a21ceeaf1fbe..c85fcbae5aef97 100644 --- a/src/frontends/onnx/frontend/src/op/split.hpp +++ b/src/frontends/onnx/frontend/src/op/split.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sqrt.hpp b/src/frontends/onnx/frontend/src/op/sqrt.hpp index b4c4f48ad8a94f..d958095baee793 100644 --- a/src/frontends/onnx/frontend/src/op/sqrt.hpp +++ b/src/frontends/onnx/frontend/src/op/sqrt.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/squeeze.hpp b/src/frontends/onnx/frontend/src/op/squeeze.hpp index ffcff5846b3e9c..ef1005081d90a2 100644 --- a/src/frontends/onnx/frontend/src/op/squeeze.hpp +++ b/src/frontends/onnx/frontend/src/op/squeeze.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/stft.hpp b/src/frontends/onnx/frontend/src/op/stft.hpp index bd16cd88b370d4..509751329658df 100644 --- a/src/frontends/onnx/frontend/src/op/stft.hpp +++ b/src/frontends/onnx/frontend/src/op/stft.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sub.hpp b/src/frontends/onnx/frontend/src/op/sub.hpp index 46b6be6e3ae5e6..32467f94c7f72a 100644 --- a/src/frontends/onnx/frontend/src/op/sub.hpp +++ b/src/frontends/onnx/frontend/src/op/sub.hpp @@ -8,7 +8,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/sum.hpp b/src/frontends/onnx/frontend/src/op/sum.hpp index 7365b1073390ee..7762469a9f2d46 100644 --- a/src/frontends/onnx/frontend/src/op/sum.hpp +++ b/src/frontends/onnx/frontend/src/op/sum.hpp @@ -8,7 +8,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" #include "utils/variadic.hpp" @@ -17,7 +16,7 @@ namespace onnx_import { namespace op { namespace set_1 { inline ov::OutputVector sum(const Node& node) { - return variadic::make_ng_variadic_op(node, ngraph::op::AutoBroadcastType::NONE); + return variadic::make_ng_variadic_op(node, ov::op::AutoBroadcastType::NONE); } } // namespace set_1 diff --git a/src/frontends/onnx/frontend/src/op/tan.hpp b/src/frontends/onnx/frontend/src/op/tan.hpp index 4b8b08c265609d..ba126bcaa056d2 100644 --- a/src/frontends/onnx/frontend/src/op/tan.hpp +++ b/src/frontends/onnx/frontend/src/op/tan.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/tanh.hpp b/src/frontends/onnx/frontend/src/op/tanh.hpp index c8b639970d81c3..bda87687748073 100644 --- a/src/frontends/onnx/frontend/src/op/tanh.hpp +++ b/src/frontends/onnx/frontend/src/op/tanh.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/thresholded_relu.hpp b/src/frontends/onnx/frontend/src/op/thresholded_relu.hpp index 8145e1c2811d6e..07e7d5181d0d3b 100644 --- a/src/frontends/onnx/frontend/src/op/thresholded_relu.hpp +++ b/src/frontends/onnx/frontend/src/op/thresholded_relu.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/tile.hpp b/src/frontends/onnx/frontend/src/op/tile.hpp index 20d4c7c56a37e5..87bddcca502a40 100644 --- a/src/frontends/onnx/frontend/src/op/tile.hpp +++ b/src/frontends/onnx/frontend/src/op/tile.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/topk.cpp b/src/frontends/onnx/frontend/src/op/topk.cpp index 85eacfe320775a..631b3e3aefa1fa 100644 --- a/src/frontends/onnx/frontend/src/op/topk.cpp +++ b/src/frontends/onnx/frontend/src/op/topk.cpp @@ -8,7 +8,6 @@ #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "ngraph/shape.hpp" #include "openvino/core/type/element_type.hpp" #include "openvino/frontend/exception.hpp" @@ -17,7 +16,7 @@ OPENVINO_SUPPRESS_DEPRECATED_START namespace { /// \return Return the second input to the TopK node reshaped to a scalar. -ov::Output get_k(const ngraph::onnx_import::Node& node) { +ov::Output get_k(const ngraph::onnx_import::Node& node) { auto k_node = node.get_ng_inputs().at(1); FRONT_END_GENERAL_CHECK(shape_size(k_node.get_shape()) == 1, "ONNX TopK operator: 'K' parameter must contain a single positive value.", @@ -36,13 +35,12 @@ ov::OutputVector topk(const Node& node) { const auto k_node = node.get_attribute_as_constant("k"); const std::int64_t axis{node.get_attribute_value("axis", -1)}; - std::shared_ptr top_k = - std::make_shared(data, - k_node, - axis, - default_opset::TopK::Mode::MAX, - default_opset::TopK::SortType::SORT_VALUES, - ov::element::i64); + std::shared_ptr top_k = std::make_shared(data, + k_node, + axis, + default_opset::TopK::Mode::MAX, + default_opset::TopK::SortType::SORT_VALUES, + ov::element::i64); return {top_k->output(0), top_k->output(1)}; } @@ -54,13 +52,12 @@ ov::OutputVector topk(const Node& node) { auto k = get_k(node); const std::int64_t axis{node.get_attribute_value("axis", -1)}; - std::shared_ptr top_k = - std::make_shared(data, - k, - axis, - default_opset::TopK::Mode::MAX, - default_opset::TopK::SortType::SORT_VALUES, - ov::element::i64); + std::shared_ptr top_k = std::make_shared(data, + k, + axis, + default_opset::TopK::Mode::MAX, + default_opset::TopK::SortType::SORT_VALUES, + ov::element::i64); return {top_k->output(0), top_k->output(1)}; } @@ -83,7 +80,7 @@ ov::OutputVector topk(const Node& node) { const auto compute_max = static_cast(largest); const auto mode = compute_max ? default_opset::TopK::Mode::MAX : default_opset::TopK::Mode::MIN; - std::shared_ptr top_k = + std::shared_ptr top_k = std::make_shared(data, k, axis, mode, sort_type, ov::element::i64); return {top_k->output(0), top_k->output(1)}; diff --git a/src/frontends/onnx/frontend/src/op/topk.hpp b/src/frontends/onnx/frontend/src/op/topk.hpp index f6b4241f17a74c..e05e3efacf8f15 100644 --- a/src/frontends/onnx/frontend/src/op/topk.hpp +++ b/src/frontends/onnx/frontend/src/op/topk.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/transpose.cpp b/src/frontends/onnx/frontend/src/op/transpose.cpp index fbaaf0b86dcb55..56f73d0a263364 100644 --- a/src/frontends/onnx/frontend/src/op/transpose.cpp +++ b/src/frontends/onnx/frontend/src/op/transpose.cpp @@ -7,7 +7,6 @@ #include #include -#include "ngraph/node.hpp" #include "ov_models/ov_builders/reshape.hpp" OPENVINO_SUPPRESS_DEPRECATED_START @@ -16,7 +15,7 @@ namespace onnx_import { namespace op { namespace set_1 { ov::OutputVector transpose(const Node& node) { - ov::Output data = node.get_ng_inputs().at(0); + ov::Output data = node.get_ng_inputs().at(0); auto permute_axes = node.get_attribute_value>("perm", {}); diff --git a/src/frontends/onnx/frontend/src/op/transpose.hpp b/src/frontends/onnx/frontend/src/op/transpose.hpp index 1cdd371b2ad47f..ff28adf92ecb96 100644 --- a/src/frontends/onnx/frontend/src/op/transpose.hpp +++ b/src/frontends/onnx/frontend/src/op/transpose.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/trilu.cpp b/src/frontends/onnx/frontend/src/op/trilu.cpp index e0dc3de8d474b4..8033edfcf22af9 100644 --- a/src/frontends/onnx/frontend/src/op/trilu.cpp +++ b/src/frontends/onnx/frontend/src/op/trilu.cpp @@ -76,7 +76,7 @@ ov::OutputVector trilu(const Node& node) { std::make_shared(zero, M, one, ov::element::i64), zero); // create 2D tensor with shape [N, 1] and values [[k], [k + 1], ..., [N + k - 1]] - std::shared_ptr vertical_range; + std::shared_ptr vertical_range; if (is_k_available) { vertical_range = std::make_shared(inputs[1], std::make_shared(N, inputs[1]), @@ -88,7 +88,7 @@ ov::OutputVector trilu(const Node& node) { vertical_range = std::make_shared(vertical_range, one); const bool upper = node.get_attribute_value("upper", 1) == 1; - std::shared_ptr mask; + std::shared_ptr mask; if (upper) { mask = std::make_shared(horizontal_range, vertical_range); } else { diff --git a/src/frontends/onnx/frontend/src/op/unique.hpp b/src/frontends/onnx/frontend/src/op/unique.hpp index d868983c0054e9..358608a055ab8c 100644 --- a/src/frontends/onnx/frontend/src/op/unique.hpp +++ b/src/frontends/onnx/frontend/src/op/unique.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/unsqueeze.hpp b/src/frontends/onnx/frontend/src/op/unsqueeze.hpp index 9bc9813d47e0bb..c536691dcd701f 100644 --- a/src/frontends/onnx/frontend/src/op/unsqueeze.hpp +++ b/src/frontends/onnx/frontend/src/op/unsqueeze.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/upsample.hpp b/src/frontends/onnx/frontend/src/op/upsample.hpp index 02867a5be2d9d4..49010f45d84f39 100644 --- a/src/frontends/onnx/frontend/src/op/upsample.hpp +++ b/src/frontends/onnx/frontend/src/op/upsample.hpp @@ -7,7 +7,6 @@ #include "openvino/core/deprecated.hpp" OPENVINO_SUPPRESS_DEPRECATED_START -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/where.hpp b/src/frontends/onnx/frontend/src/op/where.hpp index 82894cd33e3e77..a80febd24dc61e 100644 --- a/src/frontends/onnx/frontend/src/op/where.hpp +++ b/src/frontends/onnx/frontend/src/op/where.hpp @@ -10,7 +10,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { diff --git a/src/frontends/onnx/frontend/src/op/xor.hpp b/src/frontends/onnx/frontend/src/op/xor.hpp index 005633f3f363b3..502d90efd0eb7d 100644 --- a/src/frontends/onnx/frontend/src/op/xor.hpp +++ b/src/frontends/onnx/frontend/src/op/xor.hpp @@ -8,7 +8,6 @@ OPENVINO_SUPPRESS_DEPRECATED_START #include "default_opset.hpp" -#include "ngraph/node.hpp" #include "onnx_import/core/node.hpp" namespace ngraph { @@ -16,10 +15,9 @@ namespace onnx_import { namespace op { namespace set_1 { inline ov::OutputVector logical_xor(const Node& node) { - return {std::make_shared( - node.get_ng_inputs().at(0), - node.get_ng_inputs().at(1), - ngraph::op::AutoBroadcastSpec(ngraph::op::AutoBroadcastType::NUMPY))}; + return {std::make_shared(node.get_ng_inputs().at(0), + node.get_ng_inputs().at(1), + ov::op::AutoBroadcastSpec(ov::op::AutoBroadcastType::NUMPY))}; } } // namespace set_1 diff --git a/src/frontends/onnx/frontend/src/utils/convpool.hpp b/src/frontends/onnx/frontend/src/utils/convpool.hpp index 078a3975de4d7b..91ddad14c00fc6 100644 --- a/src/frontends/onnx/frontend/src/utils/convpool.hpp +++ b/src/frontends/onnx/frontend/src/utils/convpool.hpp @@ -56,7 +56,7 @@ ov::op::RoundingType get_rounding_type(const Node& node); /// /// \return A pair of (padding_above, padding_below), which elements contains number of /// pixels to pad in respective dimensions (height, width, depth). -std::pair get_pads(const Node& node, const size_t kernel_rank); +std::pair get_pads(const Node& node, const size_t kernel_rank); /// \brief Get padding values for the operation described by an ONNX node. /// \details Values are taken from the `pads` attribute. @@ -67,7 +67,7 @@ std::pair get_pads(const Node& node, const size_ /// /// \return A pair of (padding_above, padding_below), which elements contains number of /// pixels to pad in respective dimensions (height, width, depth). -std::pair get_pads(const Node& node); +std::pair get_pads(const Node& node); /// /// \brief Calculate paddings with respect to auto_pad value. @@ -86,8 +86,8 @@ void calculate_auto_pads(const Shape& data_shape, const Strides& strides, const Strides& dilations, const ov::op::PadType& pad_type, - CoordinateDiff& padding_below, - CoordinateDiff& padding_above); + ov::CoordinateDiff& padding_below, + ov::CoordinateDiff& padding_above); /// \brief Gets the 'auto_pad' attribute value. /// diff --git a/src/frontends/onnx/frontend/src/utils/pooling_factory.cpp b/src/frontends/onnx/frontend/src/utils/pooling_factory.cpp index e3d564a5b617ff..32a4ba1f1cbdb3 100644 --- a/src/frontends/onnx/frontend/src/utils/pooling_factory.cpp +++ b/src/frontends/onnx/frontend/src/utils/pooling_factory.cpp @@ -44,8 +44,8 @@ PoolingFactory::PoolingFactory(const Node& node) m_auto_pad{convpool::get_auto_pad(node)}, m_rounding_type{convpool::get_rounding_type(node)} { const auto paddings = convpool::get_pads(node, m_kernel_shape.size()); - const CoordinateDiff& padding_above{paddings.second}; - const CoordinateDiff& padding_below{paddings.first}; + const ov::CoordinateDiff& padding_above{paddings.second}; + const ov::CoordinateDiff& padding_below{paddings.first}; m_padding_below = Shape{std::begin(padding_below), std::end(padding_below)}; m_padding_above = Shape{std::begin(padding_above), std::end(padding_above)}; m_storage_order = static_cast(node.get_attribute_value("storage_order", 0)); diff --git a/src/inference/src/cnn_network_ngraph_impl.cpp b/src/inference/src/cnn_network_ngraph_impl.cpp index e7145e1e2c7835..72607a8bf4eb95 100644 --- a/src/inference/src/cnn_network_ngraph_impl.cpp +++ b/src/inference/src/cnn_network_ngraph_impl.cpp @@ -36,7 +36,7 @@ using namespace InferenceEngine; using details::CNNNetworkNGraphImpl; using InferenceEngine::details::CNNNetworkNGraphImpl; -void CNNNetworkNGraphImpl::createDataForResult(const ::ov::Output<::ngraph::Node>& output, +void CNNNetworkNGraphImpl::createDataForResult(const ::ov::Output<::ov::Node>& output, const std::string& outName, DataPtr& ptr) { const auto isCompatible = [](int64_t size, const Layout& l) -> bool { @@ -88,7 +88,7 @@ void CNNNetworkNGraphImpl::createDataForResult(const ::ov::Output<::ngraph::Node void CNNNetworkNGraphImpl::validateFunctionNames() const { // nGraph function parameters and pre-Results operations should have unique names - std::unordered_map> unique_names; + std::unordered_map> unique_names; for (const auto& param : _ngraph_function->get_parameters()) { if (unique_names.count(param->get_friendly_name())) { IE_THROW() << "Function contains several inputs with one friendly name!"; @@ -296,7 +296,7 @@ StatusCode CNNNetworkNGraphImpl::addOutput(const std::string& layerName, return DescriptionBuffer(NOT_FOUND, resp) << "Cannot add output! Layer " << layerName << " wasn't found!"; } -void CNNNetworkNGraphImpl::addOutput(const ::ov::Output<::ngraph::Node>& output) { +void CNNNetworkNGraphImpl::addOutput(const ::ov::Output<::ov::Node>& output) { auto dataName = ov::op::util::create_ie_output_name(output); DataPtr data; if (_data.count(dataName)) @@ -317,7 +317,7 @@ size_t CNNNetworkNGraphImpl::getBatchSize() const { // This is not correct in general. We can follow the same semantics, but order of inputs should be // guaranteed to be the same. auto params = _ngraph_function->get_parameters(); - sort(params.begin(), params.end(), [](std::shared_ptr lhs, std::shared_ptr rhs) { + sort(params.begin(), params.end(), [](std::shared_ptr lhs, std::shared_ptr rhs) { return lhs->get_friendly_name() < rhs->get_friendly_name(); }); @@ -592,7 +592,7 @@ StatusCode CNNNetworkNGraphImpl::setBatchSize(size_t size, ResponseDesc* respons const auto first_parameter = *std::min_element(original_parameters.begin(), original_parameters.end(), - [](std::shared_ptr lhs, std::shared_ptr rhs) { + [](std::shared_ptr lhs, std::shared_ptr rhs) { return lhs->get_friendly_name() < rhs->get_friendly_name(); }); const auto first_parameter_pshape = first_parameter->get_output_partial_shape(0); diff --git a/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp b/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp index 97a08ed4fca468..08d22fd16ab2f8 100644 --- a/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp +++ b/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp @@ -281,7 +281,7 @@ std::unordered_set GetRemovedNodes(const std::shared_ptr GetSupportedNodes( const std::shared_ptr& model, std::function&)> transform, - std::function)> is_node_supported) { + std::function)> is_node_supported) { return ov::get_supported_nodes(model, transform, is_node_supported); } diff --git a/src/inference/src/dev/converter_utils.cpp b/src/inference/src/dev/converter_utils.cpp index 04c68ec0481e78..6aca89c09c6e8e 100644 --- a/src/inference/src/dev/converter_utils.cpp +++ b/src/inference/src/dev/converter_utils.cpp @@ -47,7 +47,7 @@ namespace { std::string get_legacy_name_from_port(const ov::Output& port) { - ov::Output p(std::const_pointer_cast(port.get_node_shared_ptr()), port.get_index()); + ov::Output p(std::const_pointer_cast(port.get_node_shared_ptr()), port.get_index()); if (auto node = std::dynamic_pointer_cast(p.get_node_shared_ptr())) { p = node->input_value(0); } diff --git a/src/plugins/intel_cpu/src/nodes/rope.cpp b/src/plugins/intel_cpu/src/nodes/rope.cpp index b37160c3695edb..9bee380d4ee276 100644 --- a/src/plugins/intel_cpu/src/nodes/rope.cpp +++ b/src/plugins/intel_cpu/src/nodes/rope.cpp @@ -18,7 +18,7 @@ namespace ov { namespace intel_cpu { namespace node { -RoPE::RoPE(const std::shared_ptr& op, const GraphContext::CPtr context) +RoPE::RoPE(const std::shared_ptr& op, const GraphContext::CPtr context) : Node(op, context, NgraphShapeInferFactory(op, EMPTY_PORT_MASK)) { std::string errorMessage; if (!isSupportedOperation(op, errorMessage)) { @@ -287,7 +287,7 @@ void RoPE::execute(dnnl::stream strm) { m_executor->execute(strm, m_config, inputs, outputs); } -bool RoPE::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { +bool RoPE::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { const auto node = std::dynamic_pointer_cast(op); if (!node) { diff --git a/src/plugins/intel_cpu/src/nodes/rope.h b/src/plugins/intel_cpu/src/nodes/rope.h index 47d92b7a00aa43..c0264d2065a459 100644 --- a/src/plugins/intel_cpu/src/nodes/rope.h +++ b/src/plugins/intel_cpu/src/nodes/rope.h @@ -13,7 +13,7 @@ namespace node { class RoPE : public Node { public: - RoPE(const std::shared_ptr& op, const GraphContext::CPtr context); + RoPE(const std::shared_ptr& op, const GraphContext::CPtr context); void getSupportedDescriptors() override {} bool created() const override { @@ -27,7 +27,7 @@ class RoPE : public Node { } void initSupportedPrimitiveDescriptors() override; void execute(dnnl::stream strm) override; - static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; + static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; private: struct Executor { diff --git a/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp b/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp index e56d289a20cece..aa659a636238ac 100644 --- a/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp +++ b/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp @@ -638,7 +638,7 @@ struct ScaledDotProductAttention::AttentionExecutor : public ScaledDotProductAtt } }; -ScaledDotProductAttention::ScaledDotProductAttention(const std::shared_ptr& op, const GraphContext::CPtr context) +ScaledDotProductAttention::ScaledDotProductAttention(const std::shared_ptr& op, const GraphContext::CPtr context) : Node(op, context, SDPAShapeInferFactory(op)), m_tmp_reorder(true) { std::string errorMessage; if (!isSupportedOperation(op, errorMessage)) { @@ -773,7 +773,7 @@ void ScaledDotProductAttention::execute(dnnl::stream strm) { m_executor->execute(strm, m_config, inputs, output, presentk_input, presentv_input, beam_input); } -bool ScaledDotProductAttention::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { +bool ScaledDotProductAttention::isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept { try { if (!std::dynamic_pointer_cast(op) && !std::dynamic_pointer_cast(op)) { diff --git a/src/plugins/intel_cpu/src/nodes/scaled_attn.h b/src/plugins/intel_cpu/src/nodes/scaled_attn.h index 9a614d0c7af2e3..cd1fd0da46bfff 100644 --- a/src/plugins/intel_cpu/src/nodes/scaled_attn.h +++ b/src/plugins/intel_cpu/src/nodes/scaled_attn.h @@ -15,7 +15,7 @@ namespace node { class ScaledDotProductAttention : public Node { public: - ScaledDotProductAttention(const std::shared_ptr& op, const GraphContext::CPtr context); + ScaledDotProductAttention(const std::shared_ptr& op, const GraphContext::CPtr context); void getSupportedDescriptors() override {} bool created() const override { @@ -34,7 +34,7 @@ class ScaledDotProductAttention : public Node { void initSupportedPrimitiveDescriptors() override; void execute(dnnl::stream strm) override; void createPrimitive() override; - static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; + static bool isSupportedOperation(const std::shared_ptr& op, std::string& errorMessage) noexcept; enum KernelTypes { KT_REF, KT_ONEDNN, KT_MLAS}; diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp index fb38c4e3f5bc7e..fb06a4dfb199d7 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.cpp @@ -11,7 +11,7 @@ ov::intel_cpu::RoPENode::RoPENode(const OutputVector& args, const Config& cfg) : constructor_validate_and_infer_types(); } -std::shared_ptr ov::intel_cpu::RoPENode::clone_with_new_inputs( +std::shared_ptr ov::intel_cpu::RoPENode::clone_with_new_inputs( const ov::OutputVector& new_args) const { INTERNAL_OP_SCOPE(RoPENode_with_new_inputs); check_new_args_count(this, new_args); diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp index f5a919f3bde11a..b13e5d7ae83d97 100644 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/op/rope.hpp @@ -4,8 +4,6 @@ #pragma once -#include - #include "openvino/op/op.hpp" namespace ov { diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.cpp index 2833c336ad3939..97b93279110caf 100755 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.cpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.cpp @@ -10,8 +10,6 @@ #include "itt.hpp" -NGRAPH_RTTI_DEFINITION(ov::intel_cpu::SwapConvertTranspose, "SwapConvertTranspose"); - ov::intel_cpu::SwapConvertTranspose::SwapConvertTranspose() { MATCHER_SCOPE(SwapConvertTranspose); ov::element::TypeVector param_precisions{ ov::element::i8, ov::element::u8 }; diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.hpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.hpp index 4154d6adb98f3e..9ea20765aa289d 100755 --- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.hpp +++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/swap_convert_transpose.hpp @@ -11,7 +11,6 @@ namespace intel_cpu { class SwapConvertTranspose : public ov::pass::MatcherPass { public: - NGRAPH_RTTI_DECLARATION; SwapConvertTranspose(); }; diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp index 4e82f5ec8c57a7..7c3568ba419855 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/topk.cpp @@ -78,7 +78,7 @@ void TopKLayerTestGPU::SetUp() { auto topk = std::dynamic_pointer_cast( std::make_shared(params[0], k, axis, mode, sort, ov::element::Type_t::i64, stable)); - ngraph::ResultVector results; + ov::ResultVector results; for (size_t i = 0; i < topk->get_output_size(); i++) { results.push_back(std::make_shared(topk->output(i))); } diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/memory.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/memory.hpp index 30afb3ceb52d4d..4d285d6505ea01 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/memory.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/memory.hpp @@ -49,7 +49,7 @@ class MemoryTest : public testing::WithParamInterface, virtual void ApplyLowLatency(); InferenceEngine::Precision netPrecision; - ngraph::EvaluationContext eval_context; + ov::EvaluationContext eval_context; ngraph::helpers::MemoryTransformation transformation; int64_t iteration_count; diff --git a/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp b/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp index 0973faec365598..0ce03a96ac0fac 100644 --- a/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp +++ b/src/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp @@ -653,10 +653,10 @@ std::string LayerTestsCommon::getRuntimePrecisionByFusedName(const std::string& return ""; } -std::map LayerTestsCommon::getRuntimeInfo() { +std::map LayerTestsCommon::getRuntimeInfo() { const auto execGraph = executableNetwork.GetExecGraphInfo(); const auto function = execGraph.getFunction(); - std::map runtimeInfo; + std::map runtimeInfo; for (const auto& op : function->get_ops()) { runtimeInfo[op->get_friendly_name()] = op->get_rt_info(); } diff --git a/src/tests/functional/shared_test_classes/src/single_layer/memory.cpp b/src/tests/functional/shared_test_classes/src/single_layer/memory.cpp index 5d82ff030e63ec..87a6a2133857ad 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/memory.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/memory.cpp @@ -188,7 +188,7 @@ void MemoryTest::CreateCommonFunc() { auto add = std::make_shared(read_value, param.at(0)); auto assign = CreateAssignOp(add, variable); auto res = std::make_shared(add); - function = std::make_shared(ResultVector{res}, ov::SinkVector{assign}, param, "TestMemory"); + function = std::make_shared(ov::ResultVector{res}, ov::SinkVector{assign}, param, "TestMemory"); } void MemoryTest::ApplyLowLatency() { diff --git a/src/tests/functional/shared_test_classes/src/single_layer/random_uniform.cpp b/src/tests/functional/shared_test_classes/src/single_layer/random_uniform.cpp index 3400fbf9681d60..224ebadf321858 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/random_uniform.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/random_uniform.cpp @@ -77,7 +77,7 @@ void RandomUniformLayerTest::SetUp() { precision, global_seed, op_seed); - ngraph::ResultVector results{std::make_shared(random_uniform)}; + ov::ResultVector results{std::make_shared(random_uniform)}; function = std::make_shared(results, ngraph::ParameterVector{input}, "random_uniform"); } diff --git a/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp b/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp index 086c75205d7c8c..511754f4e93b89 100644 --- a/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp +++ b/src/tests/ov_helpers/ov_models/include/ov_models/builders.hpp @@ -79,7 +79,7 @@ std::shared_ptr makeConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases = false, const std::vector& filterWeights = {}, @@ -93,7 +93,7 @@ std::shared_ptr makeConvolution(const ov::Output& in_data, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases = false, const std::vector& biasesWeights = {}); @@ -105,7 +105,7 @@ std::shared_ptr makeGroupConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, size_t numGroups, bool addBiases = false, @@ -119,7 +119,7 @@ std::shared_ptr makeGroupConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, bool addBiases = false, const std::vector& biasesWeights = {}); @@ -130,7 +130,7 @@ std::shared_ptr makeConvolutionBackpropData(const ov::Output& in const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases = false, const std::vector& outputPadding = {}, @@ -144,7 +144,7 @@ std::shared_ptr makeConvolutionBackpropData(const ov::Output& in const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, bool addBiases = false, const std::vector& outputPadding = {}, const std::vector& biasesWeights = {}); @@ -157,7 +157,7 @@ std::shared_ptr makeConvolutionBackpropData(const ov::Output& in const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases = false, const std::vector& outputPadding = {}, @@ -199,7 +199,7 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ov::Output& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, size_t numGroups, bool addBiases = false, @@ -214,7 +214,7 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ov::Output& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, bool addBiases = false, const std::vector& outputPadding = {}, const std::vector& biasesWeights = {}); @@ -227,7 +227,7 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ov::Output& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, size_t numGroups, bool addBiases = false, @@ -241,7 +241,7 @@ std::shared_ptr makeBinaryConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, float padValue, const std::vector& filterWeihgts = {}); @@ -393,8 +393,8 @@ std::shared_ptr makePooling(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& kernel, - const op::RoundingType& roundingType, - const op::PadType& padType, + const ov::op::RoundingType& roundingType, + const ov::op::PadType& padType, bool excludePad, const ov::test::utils::PoolingTypes& poolType); diff --git a/src/tests/ov_helpers/ov_models/src/binary_convolution.cpp b/src/tests/ov_helpers/ov_models/src/binary_convolution.cpp index 9c29139c399157..fc8703ebd29114 100644 --- a/src/tests/ov_helpers/ov_models/src/binary_convolution.cpp +++ b/src/tests/ov_helpers/ov_models/src/binary_convolution.cpp @@ -19,7 +19,7 @@ std::shared_ptr makeBinaryConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, float padValue, const std::vector& filterWeihgts) { diff --git a/src/tests/ov_helpers/ov_models/src/convolution.cpp b/src/tests/ov_helpers/ov_models/src/convolution.cpp index a1ded216860b86..a1617e6ea961cf 100644 --- a/src/tests/ov_helpers/ov_models/src/convolution.cpp +++ b/src/tests/ov_helpers/ov_models/src/convolution.cpp @@ -21,7 +21,7 @@ std::shared_ptr makeConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases, const std::vector& filterWeights, @@ -58,7 +58,7 @@ std::shared_ptr makeConvolution(const ov::Output& in_data, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases, const std::vector& biasesWeights) { diff --git a/src/tests/ov_helpers/ov_models/src/convolution_backprop_data.cpp b/src/tests/ov_helpers/ov_models/src/convolution_backprop_data.cpp index 1d91c5f0dd6269..14234d7107634e 100644 --- a/src/tests/ov_helpers/ov_models/src/convolution_backprop_data.cpp +++ b/src/tests/ov_helpers/ov_models/src/convolution_backprop_data.cpp @@ -20,7 +20,7 @@ std::shared_ptr makeConvolutionBackpropData(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases, const std::vector& outputPadding, @@ -53,7 +53,7 @@ std::shared_ptr makeConvolutionBackpropData(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, bool addBiases, const std::vector& outputPadding, const std::vector& biasesWeights) { @@ -94,7 +94,7 @@ std::shared_ptr makeConvolutionBackpropData(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, bool addBiases, const std::vector& outputPadding, diff --git a/src/tests/ov_helpers/ov_models/src/group_convolution.cpp b/src/tests/ov_helpers/ov_models/src/group_convolution.cpp index fef06704cca331..4996137128d6c2 100644 --- a/src/tests/ov_helpers/ov_models/src/group_convolution.cpp +++ b/src/tests/ov_helpers/ov_models/src/group_convolution.cpp @@ -20,7 +20,7 @@ std::shared_ptr makeGroupConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, size_t numGroups, bool addBiases, @@ -57,7 +57,7 @@ std::shared_ptr makeGroupConvolution(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, bool addBiases, const std::vector& biasesWeights) { auto conv = diff --git a/src/tests/ov_helpers/ov_models/src/group_convolution_backprop_data.cpp b/src/tests/ov_helpers/ov_models/src/group_convolution_backprop_data.cpp index 246b3ff460bb92..3f85d358e1cce1 100644 --- a/src/tests/ov_helpers/ov_models/src/group_convolution_backprop_data.cpp +++ b/src/tests/ov_helpers/ov_models/src/group_convolution_backprop_data.cpp @@ -20,7 +20,7 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ov::Output& i const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, size_t numGroups, bool addBiases, @@ -59,7 +59,7 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ov::Output& i const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, bool addBiases, const std::vector& outputPadding, const std::vector& biasesWeights) { @@ -99,7 +99,7 @@ std::shared_ptr makeGroupConvolutionBackpropData(const ov::Output& i const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& dilations, - const op::PadType& autoPad, + const ov::op::PadType& autoPad, size_t numOutChannels, size_t numGroups, bool addBiases, diff --git a/src/tests/ov_helpers/ov_models/src/pooling.cpp b/src/tests/ov_helpers/ov_models/src/pooling.cpp index fe1ca80c960848..ba611099b2dc67 100644 --- a/src/tests/ov_helpers/ov_models/src/pooling.cpp +++ b/src/tests/ov_helpers/ov_models/src/pooling.cpp @@ -17,8 +17,8 @@ std::shared_ptr makePooling(const ov::Output& in, const std::vector& padsBegin, const std::vector& padsEnd, const std::vector& kernel, - const op::RoundingType& roundingType, - const op::PadType& padType, + const ov::op::RoundingType& roundingType, + const ov::op::PadType& padType, bool excludePad, const ov::test::utils::PoolingTypes& poolType) { std::shared_ptr pooling; From 67ae660b17625103b60a8854efa1a1a4eb4843b1 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Mon, 29 Jan 2024 18:53:58 +0100 Subject: [PATCH 02/27] [PT FE] Fix aten::index_put for masked_fill case (#22497) * Fix aten::index_put for masked_fill case * Update tests/layer_tests/pytorch_tests/test_index_put_.py * Remove extra includes --- src/frontends/pytorch/src/op/masked_fill.cpp | 15 +++-------- .../transforms/aten_index_put_replacer.cpp | 7 ++++++ .../src/transforms/aten_index_replacer.cpp | 4 +-- src/frontends/pytorch/src/utils.cpp | 10 ++++++++ src/frontends/pytorch/src/utils.hpp | 6 +++++ .../pytorch_tests/test_index_put_.py | 25 ++++++++++++------- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/frontends/pytorch/src/op/masked_fill.cpp b/src/frontends/pytorch/src/op/masked_fill.cpp index 2093e05679044d..7790bf3bdd4990 100644 --- a/src/frontends/pytorch/src/op/masked_fill.cpp +++ b/src/frontends/pytorch/src/op/masked_fill.cpp @@ -3,12 +3,6 @@ // #include "openvino/frontend/pytorch/node_context.hpp" -#include "openvino/op/broadcast.hpp" -#include "openvino/op/constant.hpp" -#include "openvino/op/convert.hpp" -#include "openvino/op/convert_like.hpp" -#include "openvino/op/select.hpp" -#include "openvino/op/shape_of.hpp" #include "utils.hpp" namespace ov { @@ -16,16 +10,15 @@ namespace frontend { namespace pytorch { namespace op { -using namespace ov::op; - OutputVector translate_masked_fill(const NodeContext& context) { num_inputs_check(context, 3, 3); auto data = context.get_input(0); auto mask = context.get_input(1); auto value = context.get_input(2); - value = context.mark_node(std::make_shared(value, data)); - auto bool_mask = context.mark_node(std::make_shared(mask, element::boolean)); - return {context.mark_node(std::make_shared(bool_mask, value, data))}; + ov::pass::NodeRegistry rg; + auto res = masked_fill(rg, data, mask, value); + context.mark_nodes(rg.get()); + return {res}; }; } // namespace op diff --git a/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp b/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp index 8d2b3975769917..d99a961ac4d0b9 100644 --- a/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp +++ b/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp @@ -129,6 +129,13 @@ AtenIndexPutReplacer::AtenIndexPutReplacer() { auto index_dtype = index.get_element_type(); // Do we need to also check u8? if (index_dtype == element::boolean) { + auto value_pshape_rank = values.get_partial_shape().rank(); + if (value_pshape_rank.is_static() && value_pshape_rank.get_length() == 0) { + auto res = masked_fill(rg, input, index, values); + copy_runtime_info_and_name(index_op, rg.get(), rt_copy_from); + index_op->output(0).replace(res); + return true; + } values = rg.make(values, input); // then apply masked scatter auto input_shape = rg.make(input, element::i32); diff --git a/src/frontends/pytorch/src/transforms/aten_index_replacer.cpp b/src/frontends/pytorch/src/transforms/aten_index_replacer.cpp index c88d3cf75aff32..e1229f97a3a201 100644 --- a/src/frontends/pytorch/src/transforms/aten_index_replacer.cpp +++ b/src/frontends/pytorch/src/transforms/aten_index_replacer.cpp @@ -171,10 +171,10 @@ AtenIndexToSelect::AtenIndexToSelect() { cum_adv_index = rg.make(cum_adv_index, element::i32); auto multiplier = input_dims->output(advanced_ids[adv_idx_count - 1]); for (int i = static_cast(adv_idx_count) - 2; i > -1; i--) { - auto m_idx = rg.make(masked_indicies[i], element::i32); + auto input_id = advanced_ids[i]; + auto m_idx = rg.make(masked_indicies[input_id], element::i32); auto adv_index = rg.make(m_idx, multiplier); cum_adv_index = rg.make(cum_adv_index, adv_index); - auto input_id = advanced_ids[i]; multiplier = rg.make(multiplier, input_dims->output(input_id)); } std::shared_ptr gather = rg.make(flatten_input, cum_adv_index, zero); diff --git a/src/frontends/pytorch/src/utils.cpp b/src/frontends/pytorch/src/utils.cpp index e228cedd8d834e..334ee72aa892bd 100644 --- a/src/frontends/pytorch/src/utils.cpp +++ b/src/frontends/pytorch/src/utils.cpp @@ -575,6 +575,16 @@ void copy_runtime_info_and_name(const std::shared_ptr& from, copy_runtime_info(additional_rt_info_src, to); } +// helper ops +Output masked_fill(ov::pass::NodeRegistry& rg, + const Output& data, + const Output& mask, + const Output& value) { + auto _value = rg.make(value, data); + auto bool_mask = rg.make(mask, element::boolean); + return rg.make(bool_mask, _value, data); +} + } // namespace pytorch } // namespace frontend } // namespace ov diff --git a/src/frontends/pytorch/src/utils.hpp b/src/frontends/pytorch/src/utils.hpp index e8a9f49e7d6445..93dc956124ae76 100644 --- a/src/frontends/pytorch/src/utils.hpp +++ b/src/frontends/pytorch/src/utils.hpp @@ -86,6 +86,12 @@ void copy_runtime_info_and_name(const std::shared_ptr& from, ov::NodeVector to, const ov::NodeVector& additional_rt_info_src = {}); +// helper ops +Output masked_fill(ov::pass::NodeRegistry& rg, + const Output& data, + const Output& mask, + const Output& value); + namespace op { template OutputVector inplace_op(const NodeContext& context) { diff --git a/tests/layer_tests/pytorch_tests/test_index_put_.py b/tests/layer_tests/pytorch_tests/test_index_put_.py index dc185596a6812a..369364855f612b 100644 --- a/tests/layer_tests/pytorch_tests/test_index_put_.py +++ b/tests/layer_tests/pytorch_tests/test_index_put_.py @@ -193,20 +193,26 @@ class TestMask_IndexPut(PytorchLayerTest): def _prepare_input(self): return (np.random.randn(100, 5).astype(np.float32), np.random.randn(100, 5).astype(np.float32)) - def create_model(self): - class aten_index_put_mask(torch.nn.Module): - def forward(self, x, y): - x[x < 0] = y[x < 0] - return x + class aten_index_put_mask(torch.nn.Module): + def forward(self, x, y): + x[x < 0] = y[x < 0] + return x - ref_net = None - - return aten_index_put_mask(), ref_net, "aten::index_put_" + class aten_index_put_mask2(torch.nn.Module): + def forward(self, x, y): + x[x < 0] = 0 + return x @pytest.mark.nightly @pytest.mark.precommit def test_nonzero_index_put_(self, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, + self._test(self.aten_index_put_mask(), None, "aten::index_put_", ie_device, precision, + ir_version, trace_model=True, use_convert_model=True) + + @pytest.mark.nightly + @pytest.mark.precommit + def test_index_put_masked_fill(self, ie_device, precision, ir_version): + self._test(self.aten_index_put_mask2(), None, "aten::index_put_", ie_device, precision, ir_version, trace_model=True, use_convert_model=True) @@ -231,3 +237,4 @@ def forward(self, x, y, z): def test_nonzero_kosmos_index_put_(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True) + From 073daded1a08004414da61a3726332bafea1d576 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Mon, 29 Jan 2024 23:56:18 +0100 Subject: [PATCH 03/27] [PT FE] Support aten::relu6_ (#22510) --- src/frontends/pytorch/src/op_table.cpp | 3 +- .../layer_tests/pytorch_tests/test_flatten.py | 2 +- tests/layer_tests/pytorch_tests/test_relu6.py | 34 +++++++++++++++++++ tests/layer_tests/pytorch_tests/test_split.py | 2 +- .../pytorch_tests/test_unsqueeze.py | 2 +- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/layer_tests/pytorch_tests/test_relu6.py diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 82674ea59dbf71..9bc3083fbfdf0e 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -504,8 +504,9 @@ const std::map get_supported_ops_ts() { {"aten::reciprocal", op::translate_reciprocal}, // aten::reflection_pad2d - Supported in limited set of patterns {"aten::relu", op::translate_1to1_match_1_inputs}, - {"aten::relu6", op::translate_relu6}, {"aten::relu_", op::inplace_op>}, + {"aten::relu6", op::translate_relu6}, + {"aten::relu6_", op::inplace_op}, {"aten::remainder", op::translate_remainder}, {"aten::repeat", op::translate_1to1_match_2_inputs}, {"aten::repeat_interleave", op::translate_repeat_interleave}, diff --git a/tests/layer_tests/pytorch_tests/test_flatten.py b/tests/layer_tests/pytorch_tests/test_flatten.py index 31345dc749df52..285c86d812cecf 100644 --- a/tests/layer_tests/pytorch_tests/test_flatten.py +++ b/tests/layer_tests/pytorch_tests/test_flatten.py @@ -37,6 +37,6 @@ def forward(self, x): [2, 3]]) @pytest.mark.nightly @pytest.mark.precommit - def test_relu(self, dim0, dim1, ie_device, precision, ir_version): + def test_flatten(self, dim0, dim1, ie_device, precision, ir_version): self._test(*self.create_model(dim0, dim1), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_relu6.py b/tests/layer_tests/pytorch_tests/test_relu6.py new file mode 100644 index 00000000000000..e705e38c71d939 --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_relu6.py @@ -0,0 +1,34 @@ +# Copyright (C) 2018-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestRelu6(PytorchLayerTest): + def _prepare_input(self): + import numpy as np + return (np.random.randn(1, 3, 224, 224).astype(np.float32),) + + def create_model(self, inplace=False): + import torch + import torch.nn.functional as F + + class aten_relu6(torch.nn.Module): + def __init__(self, inplace): + super(aten_relu6, self).__init__() + self.inplace = inplace + + def forward(self, x): + return x, F.relu6(x, inplace=self.inplace) + + ref_net = None + + return aten_relu6(inplace), ref_net, "aten::relu6" if not inplace else "aten::relu6_" + + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("inplace", [True, False]) + def test_relu6(self, inplace, ie_device, precision, ir_version): + self._test(*self.create_model(inplace), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_split.py b/tests/layer_tests/pytorch_tests/test_split.py index 57627672c5fe5e..8d03760260c312 100644 --- a/tests/layer_tests/pytorch_tests/test_split.py +++ b/tests/layer_tests/pytorch_tests/test_split.py @@ -99,6 +99,6 @@ def forward(self, x, y): @pytest.mark.nightly @pytest.mark.precommit - def test_relu(self, ie_device, precision, ir_version): + def test_split_with_sizes(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_unsqueeze.py b/tests/layer_tests/pytorch_tests/test_unsqueeze.py index 7c40bb3837e450..fc936f2530642f 100644 --- a/tests/layer_tests/pytorch_tests/test_unsqueeze.py +++ b/tests/layer_tests/pytorch_tests/test_unsqueeze.py @@ -40,5 +40,5 @@ def forward(self, x): @pytest.mark.parametrize("dim", [0, 1, -1]) @pytest.mark.nightly @pytest.mark.precommit - def test_relu(self, inplace, dim, ie_device, precision, ir_version): + def test_unsqueeze(self, inplace, dim, ie_device, precision, ir_version): self._test(*self.create_model(inplace, dim), ie_device, precision, ir_version) From 11042db86b5b57d6f6138e512ed45a83265df59c Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Tue, 30 Jan 2024 01:02:56 +0100 Subject: [PATCH 04/27] [PT FE] Apply mark_node that was missing (#22507) * [PT FE] Apply mark_node that was missing * Apply codestyle --- src/frontends/pytorch/src/op/convnd.cpp | 1 + src/frontends/pytorch/src/op/convolution.cpp | 16 ++++++++-------- .../pytorch/src/op/convolution_mode.cpp | 16 ++++++++-------- src/frontends/pytorch/src/op/min_max.cpp | 10 ++++++---- src/frontends/pytorch/src/utils.cpp | 6 ++++-- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/frontends/pytorch/src/op/convnd.cpp b/src/frontends/pytorch/src/op/convnd.cpp index aac9ae08f850cf..22051e9e881ccd 100644 --- a/src/frontends/pytorch/src/op/convnd.cpp +++ b/src/frontends/pytorch/src/op/convnd.cpp @@ -49,6 +49,7 @@ OutputVector translate_convnd(const NodeContext& context) { dilations, pad_type); } + conv = context.mark_node(conv); if (!context.input_is_none(2)) { auto bias = context.get_input(2); auto bias_from_visible_context = context.get_input_from_visible_context(2); diff --git a/src/frontends/pytorch/src/op/convolution.cpp b/src/frontends/pytorch/src/op/convolution.cpp index 7a250115b54a51..e3f784a7af5456 100644 --- a/src/frontends/pytorch/src/op/convolution.cpp +++ b/src/frontends/pytorch/src/op/convolution.cpp @@ -50,17 +50,17 @@ OutputVector translate_convolution(const NodeContext& context) { } } else { if (!transposed) { - conv = context.mark_node(std::make_shared( - context.get_input(0), - context.mark_output(reshape_kernel_for_group(context, context.get_input(1), groups)), - strides, - pads, - pads, - dilations)); + conv = context.mark_node( + std::make_shared(context.get_input(0), + reshape_kernel_for_group(context, context.get_input(1), groups), + strides, + pads, + pads, + dilations)); } else { conv = context.mark_node(std::make_shared( context.get_input(0), - context.mark_output(reshape_kernel_for_group(context, context.get_input(1), groups)), + reshape_kernel_for_group(context, context.get_input(1), groups), strides, pads, pads, diff --git a/src/frontends/pytorch/src/op/convolution_mode.cpp b/src/frontends/pytorch/src/op/convolution_mode.cpp index 7aa9d8f991b97b..d012cfa8a5ea77 100644 --- a/src/frontends/pytorch/src/op/convolution_mode.cpp +++ b/src/frontends/pytorch/src/op/convolution_mode.cpp @@ -37,14 +37,14 @@ OutputVector translate_convolution_mode(const NodeContext& context) { dilations, auto_pad_mode)); } else { - conv = context.mark_node(std::make_shared( - context.get_input(0), - context.mark_output(reshape_kernel_for_group(context, context.get_input(1), groups)), - strides, - pad_const, - pad_const, - dilations, - auto_pad_mode)); + conv = context.mark_node( + std::make_shared(context.get_input(0), + reshape_kernel_for_group(context, context.get_input(1), groups), + strides, + pad_const, + pad_const, + dilations, + auto_pad_mode)); } if (!context.input_is_none(2)) { diff --git a/src/frontends/pytorch/src/op/min_max.cpp b/src/frontends/pytorch/src/op/min_max.cpp index 45b4f5f0155354..928b963f074b31 100644 --- a/src/frontends/pytorch/src/op/min_max.cpp +++ b/src/frontends/pytorch/src/op/min_max.cpp @@ -42,10 +42,11 @@ OutputVector translate_max(const NodeContext& context) { auto keepdims = context.const_input(2); auto values = context.mark_node(std::make_shared(x, axes_node, keepdims)); auto k = context.mark_node(std::make_shared(element::i32, Shape{}, 1)); - auto topk = std::make_shared(x, k, axis_const, v3::TopK::Mode::MAX, v3::TopK::SortType::NONE); + auto topk = + context.mark_node(std::make_shared(x, k, axis_const, v3::TopK::Mode::MAX, v3::TopK::SortType::NONE)); auto indicies = context.mark_node(std::make_shared(topk->output(1), element::i64)); if (!keepdims) { - indicies = std::make_shared(indicies, axes_node); + indicies = context.mark_node(std::make_shared(indicies, axes_node)); } return {values, indicies}; }; @@ -72,10 +73,11 @@ OutputVector translate_min(const NodeContext& context) { auto keepdims = context.const_input(2); auto values = context.mark_node(std::make_shared(x, axes_node, keepdims)); auto k = context.mark_node(std::make_shared(element::i32, Shape{}, 1)); - auto topk = std::make_shared(x, k, axis_const, v3::TopK::Mode::MIN, v3::TopK::SortType::NONE); + auto topk = + context.mark_node(std::make_shared(x, k, axis_const, v3::TopK::Mode::MIN, v3::TopK::SortType::NONE)); auto indicies = context.mark_node(std::make_shared(topk->output(1), element::i64)); if (!keepdims) { - indicies = std::make_shared(indicies, axes_node); + indicies = context.mark_node(std::make_shared(indicies, axes_node)); } return {values, indicies}; }; diff --git a/src/frontends/pytorch/src/utils.cpp b/src/frontends/pytorch/src/utils.cpp index 334ee72aa892bd..20f56b9d421187 100644 --- a/src/frontends/pytorch/src/utils.cpp +++ b/src/frontends/pytorch/src/utils.cpp @@ -94,6 +94,7 @@ Output reshape_kernel_for_group(const NodeContext& context, const Output(OutputVector{groups_const, c_out_value, neg_1_const, remaining_shape}, 0); + auto res = make_shared(kernel, new_kernel_shape, false); context.mark_nodes({axis_0, groups_const, kernel_shape, @@ -105,8 +106,9 @@ Output reshape_kernel_for_group(const NodeContext& context, const Output(kernel, new_kernel_shape, false); + new_kernel_shape, + res}); + return res; } std::shared_ptr get_axes_range(const NodeContext& context, int input_id) { From b0b4f3d28dc6a1ffdf8b7c5c8a3afd466682fec2 Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Tue, 30 Jan 2024 01:06:14 +0100 Subject: [PATCH 05/27] [PT FE] Ignore memory_format in aten::to (#22513) * [PT FE] Ignore memory_format in aten::to * Fix build --- src/frontends/pytorch/src/op/to.cpp | 10 ++----- tests/layer_tests/pytorch_tests/test_to.py | 31 +++++++++++++++------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/frontends/pytorch/src/op/to.cpp b/src/frontends/pytorch/src/op/to.cpp index f10ac4c369298f..0267e0ed20c4d4 100644 --- a/src/frontends/pytorch/src/op/to.cpp +++ b/src/frontends/pytorch/src/op/to.cpp @@ -18,12 +18,10 @@ using namespace ov::op; OutputVector translate_to(const NodeContext& context) { int dtype_idx; - int memory_format_idx; if (context.get_input_size() == 5) { // aten::to.dtype(Tensor(a) self, int dtype, bool non_blocking=False, bool copy=False, int? memory_format=None) // -> (Tensor(a)) dtype_idx = 1; - memory_format_idx = 4; auto node = context.get_input_from_visible_context(dtype_idx).get_node_shared_ptr(); auto fw_node = std::dynamic_pointer_cast(node); if (fw_node && fw_node->get_op_type() == "prim::device") { @@ -43,7 +41,6 @@ OutputVector translate_to(const NodeContext& context) { // memory_format=None) -> (Tensor(a)). // Input with index 1 is device we skip that input. dtype_idx = 2; - memory_format_idx = 5; if (context.input_is_none(dtype_idx)) { // Cast only to device without changing dtype. Return input node unchanged. return {context.get_input(0)}; @@ -52,7 +49,6 @@ OutputVector translate_to(const NodeContext& context) { // aten::to(Tensor(a) self, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? // pin_memory=None, bool non_blocking=False, bool copy=False, MemoryFormat? memory_format=None) dtype_idx = 1; - memory_format_idx = 7; if (context.input_is_none(dtype_idx)) { // Cast only to device without changing dtype. Return input node unchanged. return {context.get_input(0)}; @@ -64,13 +60,11 @@ OutputVector translate_to(const NodeContext& context) { // We ignore both non_blocking and copy inputs since non_blocking argument is used // in Pytorch during training to overlap data transfer from CPU to GPU which does // not have a use case in OV. To copy or not to copy inputs should not be set - // on the frontend level since it can produce unexpected beviour in the later + // on the frontend level since it can produce unexpected behaviour in the later // stages. (e.g. transformations passes) // memory_format sets the desired memory format of returned Tensor. - // memory format should not be set on the frontend level - FRONT_END_OP_CONVERSION_CHECK(context.input_is_none(memory_format_idx), - "aten::to translation do not support memory_format attribute"); + // memory format is ignored since it changes strides of a tensor. In openvino tensors are always contigious auto dtype_ext_node = context.get_input_from_visible_context(dtype_idx).get_node_shared_ptr(); auto dtype_fw_node = std::dynamic_pointer_cast(dtype_ext_node); Output cast; diff --git a/tests/layer_tests/pytorch_tests/test_to.py b/tests/layer_tests/pytorch_tests/test_to.py index 2c3794d001e38c..4add5a615bcb48 100644 --- a/tests/layer_tests/pytorch_tests/test_to.py +++ b/tests/layer_tests/pytorch_tests/test_to.py @@ -10,8 +10,8 @@ class TestAtenTo(PytorchLayerTest): - def _prepare_input(self): - return (np.random.uniform(low=0.0, high=50.0, size=(3,)),) + def _prepare_input(self, input_shape=(3,)): + return (np.random.uniform(low=0.0, high=50.0, size=input_shape),) def create_model(self, type, non_blocking=False, copy=False, memory_format=None): import torch @@ -39,7 +39,8 @@ def forward(self, x): @pytest.mark.precommit def test_aten_to(self, input_type, output_type, ie_device, precision, ir_version): self.input_type = input_type - self._test(*self.create_model(output_type), ie_device, precision, ir_version) + self._test(*self.create_model(output_type), + ie_device, precision, ir_version) # Cartesian product of input/output types @pytest.mark.parametrize("input_type", [np.int32, np.float32, np.float64]) @@ -56,7 +57,8 @@ def test_aten_to(self, input_type, output_type, ie_device, precision, ir_version @pytest.mark.nightly def test_aten_to_non_blocking_arg(self, input_type, output_type, non_blocking, ie_device, precision, ir_version): self.input_type = input_type - self._test(*self.create_model(output_type, non_blocking=non_blocking), ie_device, precision, ir_version) + self._test(*self.create_model(output_type, + non_blocking=non_blocking), ie_device, precision, ir_version) # Cartesian product of input/output types @pytest.mark.parametrize("input_type", [np.int32, np.float32, np.float64]) @@ -72,7 +74,8 @@ def test_aten_to_non_blocking_arg(self, input_type, output_type, non_blocking, i @pytest.mark.nightly def test_aten_to_copy_arg(self, input_type, output_type, copy, ie_device, precision, ir_version): self.input_type = input_type - self._test(*self.create_model(output_type, copy=copy), ie_device, precision, ir_version) + self._test(*self.create_model(output_type, copy=copy), + ie_device, precision, ir_version) # Cartesian product of input/output types @pytest.mark.parametrize("input_type", [np.int32, np.float32, np.float64]) @@ -83,14 +86,19 @@ def test_aten_to_copy_arg(self, input_type, output_type, copy, ie_device, precis [torch.int32, 2], [torch.int64, 3], [torch.float32, 3], - [torch.float64, 4], + [torch.float64, 0], ]) @pytest.mark.nightly def test_aten_to_raise_memory_format_arg(self, input_type, output_type, memory_format, ie_device, precision, ir_version): self.input_type = input_type - with pytest.raises(OpConversionFailure) as e: - self._test(*self.create_model(output_type, memory_format=memory_format), ie_device, precision, ir_version) + input_shape = (3,) + if memory_format == 2: + input_shape = (3, 4, 5, 6) + if memory_format == 3: + input_shape = (3, 4, 5, 6, 7) + self._test(*self.create_model(output_type, memory_format=memory_format), ie_device, + precision, ir_version, kwargs_to_prepare_input={"input_shape": input_shape}) class TestAtenToDevice(PytorchLayerTest): @@ -113,7 +121,9 @@ def forward(self, x, y): @pytest.mark.nightly @pytest.mark.precommit def test_aten_to_device(self, use_trace, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=use_trace) + self._test(*self.create_model(), ie_device, precision, + ir_version, trace_model=use_trace) + class TestAtenToDeviceConst(PytorchLayerTest): def _prepare_input(self): @@ -135,4 +145,5 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit def test_aten_to_device_const(self, use_trace, ie_device, precision, ir_version): - self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=use_trace) + self._test(*self.create_model(), ie_device, precision, + ir_version, trace_model=use_trace) From 052cc50e5fe648846a8e41dc3efea7a2a12c8b7e Mon Sep 17 00:00:00 2001 From: Xuejun Zhai Date: Tue, 30 Jan 2024 10:54:50 +0800 Subject: [PATCH 06/27] Xuejun/deprecated 1.0 part1 (#22442) * [Deprecated API ] Remove api ov_core_read_model_from_memory() Signed-off-by: Zhai, Xuejun * [Deprecated API ] Remove api infer_conv_backprop_output_spatial_shape() Signed-off-by: Zhai, Xuejun * [Deprecated API] Remove api set_cache_dir_for_device() Signed-off-by: Zhai, Xuejun * Revert "[Deprecated API] Remove api set_cache_dir_for_device()" This reverts commit b234fec28e771ee1c8644fb41b5d381b28c7ebe3. --------- Signed-off-by: Zhai, Xuejun Co-authored-by: Ilya Lavrenov --- src/bindings/c/include/openvino/c/ov_core.h | 21 --------------- src/bindings/c/src/ov_core.cpp | 7 ----- src/bindings/c/tests/ov_core_test.cpp | 28 -------------------- src/core/include/openvino/op/convolution.hpp | 22 --------------- src/core/src/op/convolution.cpp | 27 ------------------- 5 files changed, 105 deletions(-) diff --git a/src/bindings/c/include/openvino/c/ov_core.h b/src/bindings/c/include/openvino/c/ov_core.h index 45bbeb35da662d..3c06481c6d8c03 100644 --- a/src/bindings/c/include/openvino/c/ov_core.h +++ b/src/bindings/c/include/openvino/c/ov_core.h @@ -171,27 +171,6 @@ ov_core_read_model_unicode(const ov_core_t* core, ov_model_t** model); #endif -/** - * @brief Reads models from IR / ONNX / PDPD / TF / TFLite formats. - * @ingroup ov_core_c_api - * @deprecated Use ov_core_read_model_from_memory_buffer instead. - * @param core A pointer to the ie_core_t instance. - * @param model_str String with a model in IR / ONNX / PDPD / TF / TFLite format, string is null-terminated. - * @param weights Shared pointer to a constant tensor with weights. - * @param model A pointer to the newly created model. - * Reading ONNX / PDPD / TF / TFLite models does not support loading weights from the @p weights tensors. - * @note Created model object shares the weights with the @p weights object. - * Thus, do not create @p weights on temporary data that can be freed later, since the model - * constant data will point to an invalid memory. - * @return Status code of the operation: OK(0) for success. - */ -OPENVINO_C_API(OPENVINO_DEPRECATED( - "This API is deprecated and will be replaced by ov_core_read_model_from_memory_buffer") ov_status_e) -ov_core_read_model_from_memory(const ov_core_t* core, - const char* model_str, - const ov_tensor_t* weights, - ov_model_t** model); - /** * @brief Reads models from IR / ONNX / PDPD / TF / TFLite formats with models string size. * @ingroup ov_core_c_api diff --git a/src/bindings/c/src/ov_core.cpp b/src/bindings/c/src/ov_core.cpp index 2624b93d8d0b28..a1a907403936c6 100644 --- a/src/bindings/c/src/ov_core.cpp +++ b/src/bindings/c/src/ov_core.cpp @@ -132,13 +132,6 @@ ov_status_e ov_core_read_model_from_memory_buffer(const ov_core_t* core, return ov_status_e::OK; } -ov_status_e ov_core_read_model_from_memory(const ov_core_t* core, - const char* model_str, - const ov_tensor_t* weights, - ov_model_t** model) { - return ov_core_read_model_from_memory_buffer(core, model_str, strlen(model_str), weights, model); -} - ov_status_e ov_core_compile_model(const ov_core_t* core, const ov_model_t* model, const char* device_name, diff --git a/src/bindings/c/tests/ov_core_test.cpp b/src/bindings/c/tests/ov_core_test.cpp index 6d4dbcd28773d4..69762a901d8f69 100644 --- a/src/bindings/c/tests/ov_core_test.cpp +++ b/src/bindings/c/tests/ov_core_test.cpp @@ -78,34 +78,6 @@ TEST_P(ov_core_test, ov_core_read_model_no_bin) { ov_core_free(core); } -OPENVINO_SUPPRESS_DEPRECATED_START -TEST_P(ov_core_test, ov_core_read_model_from_memory) { - ov_core_t* core = nullptr; - OV_EXPECT_OK(ov_core_create(&core)); - EXPECT_NE(nullptr, core); - - std::vector weights_content(content_from_file(bin_file_name.c_str(), true)); - - ov_tensor_t* tensor = nullptr; - ov_shape_t shape; - int64_t dims[2] = {1, (int64_t)weights_content.size()}; - ov_shape_create(2, dims, &shape); - OV_EXPECT_OK(ov_tensor_create_from_host_ptr(ov_element_type_e::U8, shape, weights_content.data(), &tensor)); - EXPECT_NE(nullptr, tensor); - - std::vector xml_content(content_from_file(xml_file_name.c_str(), false)); - ov_model_t* model = nullptr; - OV_EXPECT_OK( - ov_core_read_model_from_memory(core, reinterpret_cast(xml_content.data()), tensor, &model)); - EXPECT_NE(nullptr, model); - - ov_shape_free(&shape); - ov_tensor_free(tensor); - ov_model_free(model); - ov_core_free(core); -} -OPENVINO_SUPPRESS_DEPRECATED_END - TEST_P(ov_core_test, ov_core_read_model_from_memory_buffer_with_size) { ov_core_t* core = nullptr; OV_EXPECT_OK(ov_core_create(&core)); diff --git a/src/core/include/openvino/op/convolution.hpp b/src/core/include/openvino/op/convolution.hpp index de40ae07605ea9..e184ab23e3b313 100644 --- a/src/core/include/openvino/op/convolution.hpp +++ b/src/core/include/openvino/op/convolution.hpp @@ -127,28 +127,6 @@ class OPENVINO_API ConvolutionBackpropData : public util::ConvolutionBackPropBas /// \return The output spatial dimensions shape. const PartialShape get_output_shape() const; void set_output_shape(const Shape& output_shape); - - /// \brief Calculates output spatial features size. - /// - /// \param[in] input_data_shape The input data partial shape - /// \param[in] filters_shape The filters partial shape - /// \param[in] strides The strides values. - /// \param[in] dilations The dilations values. - /// \param[in] pads_begin The paddings at the beginning of axis. - /// \param[in] pads_end The paddings at the end of axis. - /// \param[in] output_padding The output padding values. - /// \param output_spatial_shape The placeholder for computed output spatial partial - /// shape. - /// - OPENVINO_DEPRECATED("This member function is deprecated and will be removed soon.") - void infer_conv_backprop_output_spatial_shape(const std::vector& input_data_shape, - const std::vector& filters_shape, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const CoordinateDiff& output_padding, - std::vector& output_spatial_shape); }; } // namespace v1 } // namespace op diff --git a/src/core/src/op/convolution.cpp b/src/core/src/op/convolution.cpp index 8883a4b87515c6..0bc9a6862cd69e 100644 --- a/src/core/src/op/convolution.cpp +++ b/src/core/src/op/convolution.cpp @@ -160,33 +160,6 @@ void op::v1::ConvolutionBackpropData::set_output_shape(const ov::Shape& shape) { set_argument(2, v0::Constant::create(et, Shape{shape.size()}, shape)); } -void op::v1::ConvolutionBackpropData::infer_conv_backprop_output_spatial_shape( - const vector& input_data_shape, - const vector& filters_shape, - const Strides& strides, - const Strides& dilations, - const CoordinateDiff& pads_begin, - const CoordinateDiff& pads_end, - const CoordinateDiff& output_padding, - vector& output_spatial_shape) { - size_t num_spatial_dims = input_data_shape.size(); - NODE_VALIDATION_CHECK(this, - filters_shape.size() == num_spatial_dims && strides.size() == num_spatial_dims && - dilations.size() == num_spatial_dims && pads_begin.size() == num_spatial_dims && - pads_end.size() == num_spatial_dims && output_padding.size() == num_spatial_dims); - - for (size_t i = 0; i < num_spatial_dims; ++i) { - if (input_data_shape[i].is_static() && filters_shape[i].is_static()) { - int64_t val = strides[i] * (input_data_shape[i].get_length() - 1) + - dilations[i] * (filters_shape[i].get_length() - 1) + 1 - pads_begin[i] - pads_end[i] + - output_padding[i]; - output_spatial_shape.emplace_back(val); - } else { - output_spatial_shape.push_back(Dimension::dynamic()); - } - } -} - void op::v1::ConvolutionBackpropData::validate_and_infer_types() { OV_OP_SCOPE(v1_ConvolutionBackpropData_validate_and_infer_types); const auto& delta_et = get_input_element_type(0); From d7dcf2c5c6bbe63f3d2ca58573c36d5760249e4d Mon Sep 17 00:00:00 2001 From: Sungeun Kim Date: Tue, 30 Jan 2024 13:11:45 +0900 Subject: [PATCH 07/27] [GPU] assert the allocation size of object is larger than max_alloc_mem_size (#22332) * assert the allocation size of object is larger than max_alloc_mem_size * disabled test-case it needs to check max_alloc_mem_size and max_mem_size. * check the exception is occurred or not * kind error message --- .../intel_gpu/src/runtime/ocl/ocl_engine.cpp | 36 +++++++++++-------- .../gpu_dyn_huge_input_range.cpp | 7 ++++ .../shared_test_classes/base/ov_subgraph.hpp | 3 ++ .../src/base/ov_subgraph.cpp | 10 ++++-- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp index b6b1233ceba397..a77a04a50557ce 100644 --- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp +++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp @@ -127,15 +127,28 @@ allocation_type ocl_engine::detect_usm_allocation_type(const void* memory) const bool ocl_engine::check_allocatable(const layout& layout, allocation_type type) { OPENVINO_ASSERT(supports_allocation(type) || type == allocation_type::cl_mem, "[GPU] Unsupported allocation type: ", type); - auto alloc_mem_size = layout.bytes_count(); - auto max_mem_size = get_device_info().max_alloc_mem_size; - if (alloc_mem_size > max_mem_size) { - auto used_mem = get_used_device_memory(allocation_type::usm_device) + get_used_device_memory(allocation_type::usm_host); - GPU_DEBUG_LOG << "[GPU] Mem size info: " << "Required " << alloc_mem_size << " bytes, already occupied : " - << used_mem << " bytes, available memory size is " << get_max_memory_size() << " bytes, but max allocable memory size is " - << max_mem_size << " bytes." << std::endl; + + OPENVINO_ASSERT(layout.bytes_count() <= get_device_info().max_alloc_mem_size, + "[GPU] Exceeded max size of memory object allocation: ", + "requested ", layout.bytes_count(), " bytes, " + "but max alloc size supported by device is ", get_device_info().max_alloc_mem_size, " bytes.", + "Please try to reduce batch size or use lower precision."); + + auto used_mem = get_used_device_memory(allocation_type::usm_device) + get_used_device_memory(allocation_type::usm_host); +#ifdef __unix__ + // Prevent from being killed by Ooo Killer of Linux + OPENVINO_ASSERT(layout.bytes_count() + used_mem <= get_max_memory_size(), + "[GPU] Exceeded max size of memory allocation: ", + "Required ", layout.bytes_count(), " bytes, already occupied : ", used_mem, " bytes, ", + "but available memory size is ", get_max_memory_size(), " bytes"); +#else + if (layout.bytes_count() + used_mem > get_max_memory_size()) { + GPU_DEBUG_COUT << "[Warning] [GPU] Exceeded max size of memory allocation: " << "Required " << layout.bytes_count() << " bytes, already occupied : " + << used_mem << " bytes, but available memory size is " << get_max_memory_size() << " bytes" << std::endl; + GPU_DEBUG_COUT << "Please note that performance might drop due to memory swap." << std::endl; return false; } +#endif return true; } @@ -143,14 +156,7 @@ bool ocl_engine::check_allocatable(const layout& layout, allocation_type type) { memory::ptr ocl_engine::allocate_memory(const layout& layout, allocation_type type, bool reset) { OPENVINO_ASSERT(!layout.is_dynamic() || layout.has_upper_bound(), "[GPU] Can't allocate memory for dynamic layout"); - bool allocatable = check_allocatable(layout, type); - if (!allocatable) { -#ifdef __unix__ - OPENVINO_ASSERT(allocatable, "[GPU] Exceeded max size of memory allocation, check debug message for size info"); -#else - GPU_DEBUG_COUT << "[Warning][GPU] Please note that performance might drop due to memory swap caused by exceeded mem size alloc." << std::endl; -#endif - } + check_allocatable(layout, type); try { memory::ptr res = nullptr; diff --git a/src/plugins/intel_gpu/tests/functional/dynamic_tests/gpu_dyn_huge_input_range.cpp b/src/plugins/intel_gpu/tests/functional/dynamic_tests/gpu_dyn_huge_input_range.cpp index 0184d08d76ec1f..b86ca197523e48 100644 --- a/src/plugins/intel_gpu/tests/functional/dynamic_tests/gpu_dyn_huge_input_range.cpp +++ b/src/plugins/intel_gpu/tests/functional/dynamic_tests/gpu_dyn_huge_input_range.cpp @@ -118,6 +118,7 @@ class DynamicShapeHugeRangeGPUTest : public testing::WithParamInterface stride; std::vector restInputType; size_t inferRequestNum = 0; + bool exception; void SetUp() override { InputShape shapes; @@ -180,11 +181,17 @@ class DynamicShapeHugeRangeGPUTest : public testing::WithParamInterface(results, params, "result"); + + set_callback_exception([this](const std::exception& exp) { + exception = true; + }); } }; TEST_P(DynamicShapeHugeRangeGPUTest, Inference) { run(); + if (!exception) + FAIL() << "This test case is checking the exception that the object allocation is larger than the max_alloc_mem_size."; } std::map emptyAdditionalConfig; diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp index 1653f6ffd4298c..cedac0be53cc07 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/ov_subgraph.hpp @@ -44,6 +44,7 @@ class SubgraphBaseTest : public ov::test::TestsCommon { void update_ref_model(); void match_parameters(); void init_input_shapes(const std::vector& shapes); + void set_callback_exception(std::function callback) { callback_exception = callback; } void TearDown() override { if (this->HasFailure() && !is_reported) { @@ -69,6 +70,8 @@ class SubgraphBaseTest : public ov::test::TestsCommon { std::map, std::shared_ptr> matched_parameters; precisions_map convert_precisions; + std::function callback_exception = nullptr; + constexpr static const double disable_threshold = std::numeric_limits::max(); double abs_threshold = disable_threshold, rel_threshold = disable_threshold; diff --git a/src/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp b/src/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp index 973836336f37cf..c826e5ffcfc9b8 100644 --- a/src/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp +++ b/src/tests/functional/shared_test_classes/src/base/ov_subgraph.cpp @@ -79,8 +79,14 @@ void SubgraphBaseTest::run() { } status = ov::test::utils::PassRate::Statuses::PASSED; } catch (const std::exception& ex) { - status = ov::test::utils::PassRate::Statuses::FAILED; - errorMessage = ex.what(); + if (callback_exception != nullptr) { + // exception will be checked by callback. + callback_exception(ex); + return; + } else { + status = ov::test::utils::PassRate::Statuses::FAILED; + errorMessage = ex.what(); + } } catch (...) { status = ov::test::utils::PassRate::Statuses::FAILED; errorMessage = "Unknown failure occurred."; From 7ad877d68ac22ef91e5855561db8130522c0a42d Mon Sep 17 00:00:00 2001 From: Wilson Seok Date: Tue, 30 Jan 2024 13:14:51 +0900 Subject: [PATCH 08/27] [GPU] Update adaptive_pooling to use nGraph shape inference (#22308) * initial adaptive avg pool shape infer * adaptive max shape infer multiple output and single layer test * exclude unintended cpu single layer test * add comments * keep input format to output --- .../intel_gpu/primitives/adaptive_pooling.hpp | 29 ++ .../intel_gpu/src/graph/adaptive_pooling.cpp | 61 +++- .../src/graph/impls/ocl/adaptive_pooling.cpp | 21 +- .../src/graph/include/adaptive_pooling_inst.h | 19 +- .../cl_kernels/adaptive_pooling_gpu_ref.cl | 19 + .../adaptive_pooling_kernel_ref.cpp | 21 +- .../adaptive_pooling_kernel_ref.h | 1 + .../src/plugin/ops/adaptive_pooling.cpp | 98 +++-- .../dynamic/adaptive_pooling.cpp | 335 ++++++++++++++++++ 9 files changed, 551 insertions(+), 53 deletions(-) create mode 100644 src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/adaptive_pooling.cpp diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/adaptive_pooling.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/adaptive_pooling.hpp index 06c34eba3c2962..39d191246f1a17 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/primitives/adaptive_pooling.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/adaptive_pooling.hpp @@ -49,6 +49,35 @@ struct adaptive_pooling : public primitive_base { indices_output{indices_output}, index_element_type{index_element_type} {} + /// @brief Constructs AdaptiveAvgPooling primitive for dynamic shape. + /// @param id This primitive id. + /// @param input Input primitive id. + /// @param output_shape Output shape (pooled vector) primitive id. + adaptive_pooling(const primitive_id &id, + const input_info &input, + const input_info &output_shape) + : primitive_base(id, {input, output_shape}), + mode{adaptive_pooling_mode::average}, + output_size{tensor(0)} {} + + /// @brief Constructs AdaptiveMaxPooling primitive for dynamic shape. + /// @param id This primitive id. + /// @param input Input primitive id. + /// @param output_shape Output shape (pooled vector) primitive id. + /// @param index_element_type Data type of indices output. + adaptive_pooling(const primitive_id &id, + const input_info &input, + const input_info &output_shape, + data_types index_element_type, + const padding& output_padding = padding(), + data_types output_data_type = data_types::i32, + const size_t num_outputs = 1) + : primitive_base(id, {input, output_shape}, {output_padding}, {optional_data_type{output_data_type}}, num_outputs), + mode{adaptive_pooling_mode::max}, + output_size{tensor(0)}, + indices_output{""}, + index_element_type{index_element_type} {} + adaptive_pooling_mode mode; tensor output_size; primitive_id indices_output; diff --git a/src/plugins/intel_gpu/src/graph/adaptive_pooling.cpp b/src/plugins/intel_gpu/src/graph/adaptive_pooling.cpp index 26778bc232ff40..f003d1a44b62a2 100644 --- a/src/plugins/intel_gpu/src/graph/adaptive_pooling.cpp +++ b/src/plugins/intel_gpu/src/graph/adaptive_pooling.cpp @@ -7,16 +7,71 @@ #include "json_object.h" #include +#include "adaptive_avg_pool_shape_inference.hpp" +#include "adaptive_max_pool_shape_inference.hpp" + namespace cldnn { GPU_DEFINE_PRIMITIVE_TYPE_ID(adaptive_pooling) -layout adaptive_pooling_inst::calc_output_layout(const adaptive_pooling_node& node, kernel_impl_params const& impl_param) { +layout adaptive_pooling_inst::calc_output_layout(adaptive_pooling_node const& node, kernel_impl_params const& impl_param) { const auto data_layout = impl_param.get_input_layout(); const auto prim = impl_param.typed_desc(); return {data_layout.data_type, data_layout.format, prim->output_size}; } -std::string adaptive_pooling_inst::to_string(const adaptive_pooling_node& node) { +template +std::vector adaptive_pooling_inst::calc_output_layouts(adaptive_pooling_node const& /*node*/, const kernel_impl_params& impl_param) { + std::vector layouts; + + const auto prim = impl_param.typed_desc(); + auto input0_layout = impl_param.get_input_layout(0); + auto input1_layout = impl_param.get_input_layout(1); + auto output_format = input0_layout.format; + + std::vector input_shapes = { + input0_layout.get(), + input1_layout.get() + }; + std::vector output_shapes = {ShapeType()}; + std::unordered_map const_data; + + auto& memory_deps = impl_param.memory_deps; + + if (memory_deps.count(1)) { + auto pooledVector_mem = memory_deps.at(1); + cldnn::mem_lock pooledVector_lock(pooledVector_mem, impl_param.get_stream()); + + auto pooledVector_tensor = make_tensor(pooledVector_mem->get_layout(), pooledVector_lock.data()); + + const_data.emplace(1, pooledVector_tensor); + } + + const auto tensor_accessor = ov::make_tensor_accessor(const_data); + if (prim->mode == cldnn::adaptive_pooling_mode::max) { + ov::op::v8::AdaptiveMaxPool op; + + output_shapes = ov::op::v8::shape_infer(&op, input_shapes, tensor_accessor); + + auto dt = prim->get_output_data_type(0).value_or(impl_param.get_input_layout(0).data_type); + auto index_dt = prim->index_element_type; + layouts.push_back(layout{output_shapes[0], dt, output_format}); + layouts.push_back(layout{output_shapes[1], index_dt, output_format}); + } else { + ov::op::v8::AdaptiveAvgPool op; + + output_shapes = ov::op::v8::shape_infer(&op, input_shapes, tensor_accessor); + + auto dt = prim->get_output_data_type(0).value_or(impl_param.get_input_layout(0).data_type); + layouts.push_back(layout{output_shapes[0], dt, output_format}); + } + + return layouts; +} + +template std::vector adaptive_pooling_inst::calc_output_layouts(adaptive_pooling_node const& node, + const kernel_impl_params& impl_param); + +std::string adaptive_pooling_inst::to_string(adaptive_pooling_node const& node) { const auto prim = node.get_primitive(); std::stringstream primitive_description; @@ -32,4 +87,6 @@ std::string adaptive_pooling_inst::to_string(const adaptive_pooling_node& node) return primitive_description.str(); } + +adaptive_pooling_inst::typed_primitive_inst(network& network, adaptive_pooling_node const& node) : parent(network, node) {} } // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/adaptive_pooling.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/adaptive_pooling.cpp index fc4c6d9af09d21..c42d4601a00a8d 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/adaptive_pooling.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/adaptive_pooling.cpp @@ -22,18 +22,6 @@ struct adaptive_pooling_impl : public typed_primitive_impl_ocl return make_unique(*this); } -protected: - kernel_arguments_data get_arguments(const typed_primitive_inst& instance) const override { - kernel_arguments_data args; - const auto num_inputs = instance.inputs_memory_count(); - for (size_t i = 0; i < num_inputs; ++i) { - args.inputs.push_back(instance.input_memory_ptr(i)); - } - - args.outputs = {instance.output_memory_ptr()}; - return args; - } - public: static kernel_params_t get_kernel_params(const kernel_impl_params& impl_param) { const auto& primitive = impl_param.typed_desc(); @@ -56,8 +44,13 @@ struct adaptive_pooling_impl : public typed_primitive_impl_ocl } default: OPENVINO_ASSERT(false, "[GPU] Not supported index element type"); } - - params.inputs.push_back(convert_data_tensor(impl_param.get_input_layout(2))); + bool allow_new_shape_infer = impl_param.get_program().get_config().get_property(ov::intel_gpu::allow_new_shape_infer); + if (allow_new_shape_infer) { + params.outputs_num = 2; + params.outputs.push_back(convert_data_tensor(impl_param.get_output_layout(1))); + } else { + params.inputs.push_back(convert_data_tensor(impl_param.get_input_layout(2))); + } } return {params, optional_params}; diff --git a/src/plugins/intel_gpu/src/graph/include/adaptive_pooling_inst.h b/src/plugins/intel_gpu/src/graph/include/adaptive_pooling_inst.h index a5dbe351277c77..59ac50aa567ab0 100644 --- a/src/plugins/intel_gpu/src/graph/include/adaptive_pooling_inst.h +++ b/src/plugins/intel_gpu/src/graph/include/adaptive_pooling_inst.h @@ -8,6 +8,16 @@ #include namespace cldnn { +template <> +struct typed_program_node : public typed_program_node_base { + using parent = typed_program_node_base; + +public: + using parent::parent; + + program_node& input(size_t idx = 0) const { return get_dependency(idx); } + std::vector get_shape_infer_dependencies() const override { return {1}; } +}; using adaptive_pooling_node = typed_program_node; @@ -17,12 +27,13 @@ class typed_primitive_inst : public typed_primitive_inst_base< using parent::parent; public: - static layout calc_output_layout(const adaptive_pooling_node& node, kernel_impl_params const& impl_param); - static std::string to_string(const adaptive_pooling_node& node); + template + static std::vector calc_output_layouts(adaptive_pooling_node const& /*node*/, const kernel_impl_params& impl_param); + static layout calc_output_layout(adaptive_pooling_node const& node, kernel_impl_params const& impl_param); + static std::string to_string(adaptive_pooling_node const& node); - typed_primitive_inst(network& network, const adaptive_pooling_node& node) : parent(network, node) {} + typed_primitive_inst(network& network, adaptive_pooling_node const& node); }; using adaptive_pooling_inst = typed_primitive_inst; - } // namespace cldnn diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/adaptive_pooling_gpu_ref.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/adaptive_pooling_gpu_ref.cl index f3eaa90f6e5fa9..9ef1748a42526f 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/adaptive_pooling_gpu_ref.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/adaptive_pooling_gpu_ref.cl @@ -16,8 +16,12 @@ KERNEL(adaptive_pooling_gpu)( const __global INPUT0_TYPE* input, __global OUTPUT_TYPE* output #if MAX_POOLING +#if NEW_MULTIPLE_OUTPUTS + , __global OUTPUT1_TYPE* output1 +#else , __global INDICES_TYPE* indices #endif +#endif ) { const uint bf = (uint)get_global_id(2); @@ -36,7 +40,11 @@ KERNEL(adaptive_pooling_gpu)( ACCUMULATOR_TYPE result = INIT_VAL; #if MAX_POOLING +#if NEW_MULTIPLE_OUTPUTS + OUTPUT1_TYPE result_idx = 0; +#else INDICES_TYPE result_idx = 0; +#endif #elif AVG_POOLING uint num_elements = 0; #else @@ -101,6 +109,16 @@ KERNEL(adaptive_pooling_gpu)( #endif #if MAX_POOLING +#if NEW_MULTIPLE_OUTPUTS + #if OUTPUT_DIMS == 5 + const uint index_pos = OUTPUT1_GET_INDEX(b, f, z, y, x); + #else + const uint index_pos = OUTPUT1_GET_INDEX(b, f, y, x); + #endif + + output[output_pos] = result; + output1[index_pos] = result_idx; +#else #if OUTPUT_DIMS == 5 const uint index_pos = INPUT1_GET_INDEX(b, f, z, y, x); #else @@ -109,6 +127,7 @@ KERNEL(adaptive_pooling_gpu)( output[output_pos] = result; indices[index_pos] = result_idx; +#endif #elif AVG_POOLING output[output_pos] = result / TO_ACCUMULATOR_TYPE(max(num_elements, (uint)1)); #else diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.cpp index af9cd1d97db689..d32020fb9f172f 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.cpp @@ -41,8 +41,9 @@ bool AdaptivePoolingRef::Validate(const Params& p, const optional_params& o) con const auto& params = dynamic_cast(p); const auto& inputs = params.inputs; - if (!((params.mode == PoolType::MAX && inputs.size() == 2) || - (params.mode == PoolType::AVG && inputs.size() == 1))) { + if (!((params.mode == PoolType::AVG && inputs.size() == 1) + || (params.mode == PoolType::MAX && inputs.size() == 2) + || (params.mode == PoolType::MAX && inputs.size() == 1 && params.outputs_num == 2))) { return false; } @@ -86,8 +87,15 @@ KernelsData AdaptivePoolingRef::GetKernelsData(const Params& params, const optio cldnn_jit.AddConstant(MakeJitConstant(toString(new_params.mode) + "_POOLING", 1)); + if (new_params.outputs_num == 2) { + cldnn_jit.AddConstant(MakeJitConstant("NEW_MULTIPLE_OUTPUTS", 1)); + } + if (new_params.mode == PoolType::MAX) { - cldnn_jit.Merge(MakeTypeJitConstants(new_params.poolIndexElementType, "INDICES")); + if (new_params.outputs_num == 1) { + // Legacy code of mutable data + cldnn_jit.Merge(MakeTypeJitConstants(new_params.poolIndexElementType, "INDICES")); + } } const auto accumulator_type = new_params.inputs[0].GetDType(); @@ -105,7 +113,12 @@ KernelsData AdaptivePoolingRef::GetKernelsData(const Params& params, const optio arguments.push_back({ArgumentDescriptor::Types::INPUT, 0}); // input data arguments.push_back({ArgumentDescriptor::Types::OUTPUT, 0}); // output if (new_params.mode == PoolType::MAX) { - arguments.push_back({ArgumentDescriptor::Types::INPUT, 1}); // indices + if (new_params.outputs_num == 2) { + arguments.push_back({ArgumentDescriptor::Types::OUTPUT, 1}); // second output + } else { + // Legacy code of mutable data + arguments.push_back({ArgumentDescriptor::Types::INPUT, 1}); // indices + } } KernelsData kernelsData; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.h index 0ba5176da7621d..1c55656d8e8492 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.h +++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/adaptive_pooling/adaptive_pooling_kernel_ref.h @@ -12,6 +12,7 @@ struct adaptive_pooling_params : public base_params { PoolType mode{PoolType::MAX}; Datatype poolIndexElementType = Datatype::INT64; + int64_t outputs_num = 1; }; struct adaptive_pooling_optional_params : public optional_params { diff --git a/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp b/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp index 9f7de35b7cb966..6395535bcc290f 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp @@ -20,10 +20,17 @@ static void CreateAdaptiveAvgPoolOp(ProgramBuilder& p, const std::shared_ptrget_output_shape(0))}; - p.add_primitive(*op, poolPrim); + if (p.use_new_shape_infer()) { + const cldnn::adaptive_pooling poolPrim{layer_name, + inputs[0], + inputs[1]}; + p.add_primitive(*op, poolPrim); + } else { + const cldnn::adaptive_pooling poolPrim{layer_name, + inputs[0], + tensor_from_dims(op->get_output_shape(0))}; + p.add_primitive(*op, poolPrim); + } } static void CreateAdaptiveMaxPoolOp(ProgramBuilder& p, const std::shared_ptr& op) { @@ -32,32 +39,65 @@ static void CreateAdaptiveMaxPoolOp(ProgramBuilder& p, const std::shared_ptrget_output_element_type(1); - const auto indices_shape = op->get_output_shape(1); - const cldnn::layout indices_layout{cldnn::element_type_to_data_type(indices_precision), - cldnn::format::get_default_format(indices_shape.size()), - tensor_from_dims(indices_shape)}; - const auto indices_memory = p.get_engine().allocate_memory(indices_layout); - - const cldnn::primitive_id indices_id_w = layer_type_name + "_md_write"; - const cldnn::mutable_data indices_mutable_prim_w{indices_id_w, indices_memory}; - p.add_primitive(*op, indices_mutable_prim_w); - - inputs.push_back(cldnn::input_info(indices_id_w)); - - const cldnn::adaptive_pooling poolPrim{layer_name, - inputs[0], - tensor_from_dims(op->get_output_shape(0)), - inputs.back().pid, - cldnn::element_type_to_data_type(op->get_index_element_type())}; - p.add_primitive(*op, poolPrim); - - const cldnn::primitive_id indices_id_r = layer_type_name + ".out1"; - const cldnn::mutable_data indices_mutable_prim_r{indices_id_r, {cldnn::input_info(layer_name)}, indices_memory}; - p.add_primitive(*op, indices_mutable_prim_r); + + if (p.use_new_shape_infer()) { + size_t num_outputs = op->get_output_size(); + + auto get_output_paddings = [&]() { + std::vector output_paddings; + for (size_t i = 0; i < num_outputs; i++) + output_paddings.push_back(cldnn::padding()); + return output_paddings; + }; + + auto get_output_data_types = [&]() { + std::vector output_data_types; + for (size_t i = 0; i < num_outputs; i++) { + auto type = op->get_output_element_type(i); + output_data_types.push_back(cldnn::element_type_to_data_type(type)); + } + return output_data_types; + }; + + cldnn::adaptive_pooling poolPrim{layer_type_name, + inputs[0], + inputs[1], + cldnn::element_type_to_data_type(op->get_index_element_type()), + cldnn::padding({0, 0, 0, 0}, 0), + cldnn::element_type_to_data_type(op->get_output_element_type(0)), + num_outputs}; + poolPrim.output_paddings = get_output_paddings(); + poolPrim.output_data_types = get_output_data_types(); + p.add_primitive(*op, poolPrim); + + } else { + const auto layer_name = layer_type_name + ".out0"; + + const auto indices_precision = op->get_output_element_type(1); + const auto indices_shape = op->get_output_shape(1); + const cldnn::layout indices_layout{cldnn::element_type_to_data_type(indices_precision), + cldnn::format::get_default_format(indices_shape.size()), + tensor_from_dims(indices_shape)}; + const auto indices_memory = p.get_engine().allocate_memory(indices_layout); + + const cldnn::primitive_id indices_id_w = layer_type_name + "_md_write"; + const cldnn::mutable_data indices_mutable_prim_w{indices_id_w, indices_memory}; + p.add_primitive(*op, indices_mutable_prim_w); + + inputs.push_back(cldnn::input_info(indices_id_w)); + + const cldnn::adaptive_pooling poolPrim{layer_name, + inputs[0], + tensor_from_dims(op->get_output_shape(0)), + inputs.back().pid, + cldnn::element_type_to_data_type(op->get_index_element_type())}; + p.add_primitive(*op, poolPrim); + + const cldnn::primitive_id indices_id_r = layer_type_name + ".out1"; + const cldnn::mutable_data indices_mutable_prim_r{indices_id_r, {cldnn::input_info(layer_name)}, indices_memory}; + p.add_primitive(*op, indices_mutable_prim_r); } + } REGISTER_FACTORY_IMPL(v8, AdaptiveAvgPool); REGISTER_FACTORY_IMPL(v8, AdaptiveMaxPool); diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/adaptive_pooling.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/adaptive_pooling.cpp new file mode 100644 index 00000000000000..d117e0671921eb --- /dev/null +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/adaptive_pooling.cpp @@ -0,0 +1,335 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// +#include + +#include "common_test_utils/ov_tensor_utils.hpp" +#include "common_test_utils/test_enums.hpp" +#include "ov_models/utils/ov_helpers.hpp" +#include "shared_test_classes/base/ov_subgraph.hpp" + +#include "openvino/op/parameter.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/result.hpp" +#include "openvino/op/adaptive_avg_pool.hpp" +#include "openvino/op/adaptive_max_pool.hpp" + +namespace { +using ov::test::InputShape; +using AdaPoolSpecificParams = std::tuple, // pooled vector + std::vector>; // feature map shape + +using AdaPoolLayerGPUTestParams = std::tuple; // Device name + + +class AdaPoolLayerGPUTest : public testing::WithParamInterface, + virtual public ov::test::SubgraphBaseTest { +public: + static std::string getTestCaseName(testing::TestParamInfo obj) { + AdaPoolLayerGPUTestParams basicParamsSet; + basicParamsSet = obj.param; + std::string targetDevice; + ov::element::Type netPr; + bool isStatic; + AdaPoolSpecificParams adaPar; + std::vector pooledSpatialShape; + std::vector inputShape; + std::string mode; + std::tie(adaPar, mode, isStatic, netPr, targetDevice) = basicParamsSet; + std::tie(pooledSpatialShape, inputShape) = adaPar; + std::ostringstream result; + + result << "AdaPoolTest_"; + result << "IS=("; + for (const auto& shape : inputShape) { + result << ov::test::utils::partialShape2str({shape.first}) << "_"; + } + result << ")_TS=("; + for (const auto& shape : inputShape) { + for (const auto& item : shape.second) { + result << ov::test::utils::vec2str(item) << "_"; + } + } + result << "OS=" << ov::test::utils::vec2str(pooledSpatialShape) << "(spat.)_"; + result << netPr << "_"; + result << mode << "_"; + result << "device=" << targetDevice; + + return result.str(); + } + +protected: + void SetUp() override { + AdaPoolLayerGPUTestParams basicParamsSet; + basicParamsSet = this->GetParam(); + + AdaPoolSpecificParams adaPoolParams; + ov::element::Type netPrecision; + bool isStatic; + std::vector inputShape; + std::tie(adaPoolParams, mode, isStatic, netPrecision, targetDevice) = basicParamsSet; + std::tie(pooledVector, inputShape) = adaPoolParams; + + init_input_shapes(inputShape); + if (!isStatic) { + for (auto& target : targetStaticShapes) { + target.push_back({pooledVector.size()}); + } + } + + function = createFunction(isStatic); + if (function->get_parameters().size() == 2) { + generatePooledVector(); + functionRefs = createFunction(true); + } + } + + void generatePooledVector() { + std::random_device rd; + std::uniform_int_distribution distribution(1, 5); + for (size_t i = 0; i < pooledVector.size(); i++) { + pooledVector[i] = distribution(rd); + } + } + + std::shared_ptr createFunction(bool secondInputConst) { + ov::ParameterVector params{std::make_shared(ov::element::f32, inputDynamicShapes[0])}; + params.front()->set_friendly_name("ParamsInput"); + std::shared_ptr secondInput; + if (secondInputConst) { + // ngraph shape infer for adaptive pooling has seg fault when i32 type of second input + secondInput = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{pooledVector.size()}, pooledVector); + } else { + auto pooledParam = + // ngraph shape infer for adaptive pooling has seg fault when i32 type of second input + std::make_shared(ov::element::i64, ov::Shape{pooledVector.size()}); + pooledParam->set_friendly_name("ParamSecondInput"); + params.push_back(pooledParam); + secondInput = pooledParam; + } + + auto adapoolMax = std::make_shared(params[0], secondInput, ov::element::i64); + auto adapoolAvg = std::make_shared(params[0], secondInput); + + auto function = (mode == "max" ? std::make_shared(adapoolMax->outputs(), params, "AdaPoolMax") + : std::make_shared(adapoolAvg->outputs(), params, "AdaPoolAvg")); + return function; + } + + void validate() override { + auto actualOutputs = get_plugin_outputs(); + if (function->get_parameters().size() == 2) { + auto pos = std::find_if(inputs.begin(), + inputs.end(), + [](const std::pair, ov::Tensor>& params) { + return params.first->get_friendly_name() == "ParamSecondInput"; + }); + OPENVINO_ASSERT(pos != inputs.end()); + inputs.erase(pos); + } + auto expectedOutputs = calculate_refs(); + if (expectedOutputs.empty()) { + return; + } + ASSERT_EQ(actualOutputs.size(), expectedOutputs.size()) + << "model interpreter has " << expectedOutputs.size() << " outputs, while IE " << actualOutputs.size(); + + compare(expectedOutputs, actualOutputs); + } + + void generate_inputs(const std::vector& targetInputStaticShapes) override { + inputs.clear(); + const auto& funcInputs = function->inputs(); + for (size_t i = 0; i < funcInputs.size(); ++i) { + const auto& funcInput = funcInputs[i]; + ov::Tensor tensor; + + if (i == 1) { + tensor = ov::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i]); + auto* dataPtr = tensor.data(); + for (size_t i = 0; i < pooledVector.size(); i++) { + // ngraph shape infer for adaptive pooling has seg fault when i32 type of second input + dataPtr[i] = static_cast(pooledVector[i]); + } + } else { + ov::test::utils::InputGenerateData in_data; + in_data.start_from = 0; + in_data.range = 2560; + in_data.resolution = 256; + tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], in_data); + } + inputs.insert({funcInput.get_node_shared_ptr(), tensor}); + } + } + +private: + std::vector pooledVector; + std::string mode; +}; + +TEST_P(AdaPoolLayerGPUTest, Inference) { + run(); +} + +const std::vector netPrecisions = {ov::element::f32, ov::element::f16}; + +const std::vector> pooled3DVector = {{1}, {3}, {5}}; +const std::vector> pooled4DVector = {{1, 1}, {3, 5}, {5, 5}}; + +const std::vector> pooled5DVector = { + {1, 1, 1}, + {3, 5, 1}, + {3, 5, 3}, +}; + +std::vector> staticInput3DShapeVector = {{{1, 17, 3}, {3, 7, 5}}}; + +const std::vector> input3DShapeVector = { + {{{{-1, 17, -1}, {{1, 17, 3}, {3, 17, 5}, {3, 17, 5}}}}, + {{{{1, 10}, 20, {1, 10}}, {{1, 20, 5}, {2, 20, 4}, {3, 20, 6}}}}}}; + +std::vector> staticInput4DShapeVector = {{{1, 3, 1, 1}, {3, 17, 5, 2}}}; + +const std::vector> input4DShapeVector = { + {{{{-1, 3, -1, -1}, {{1, 3, 1, 1}, {3, 3, 5, 2}, {3, 3, 5, 2}}}}, + {{{{1, 10}, 3, {1, 10}, {1, 10}}, {{2, 3, 10, 6}, {3, 3, 6, 5}, {3, 3, 6, 5}}}}}}; + +std::vector> staticInput5DShapeVector = {{{1, 17, 2, 5, 2}, {3, 17, 4, 5, 4}}}; + +const std::vector> input5DShapeVector = { + {{{{-1, 17, -1, -1, -1}, {{1, 17, 2, 5, 2}, {3, 17, 4, 5, 4}, {3, 17, 4, 5, 4}}}}, + {{{{1, 10}, 3, {1, 10}, {1, 10}, {1, 10}}, {{3, 3, 2, 5, 2}, {1, 3, 4, 5, 4}, {1, 3, 4, 5, 4}}}}}}; + +const auto adaPool3DParams = ::testing::Combine(::testing::ValuesIn(pooled3DVector), // output spatial shape + ::testing::ValuesIn(input3DShapeVector) // feature map shape +); + +const auto adaPool4DParams = ::testing::Combine(::testing::ValuesIn(pooled4DVector), // output spatial shape + ::testing::ValuesIn(input4DShapeVector) // feature map shape +); + +const auto adaPool5DParams = ::testing::Combine(::testing::ValuesIn(pooled5DVector), // output spatial shape + ::testing::ValuesIn(input5DShapeVector) // feature map shape +); + +INSTANTIATE_TEST_SUITE_P(smoke_AdaPoolAvg3DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine( + adaPool3DParams, + ::testing::Values("avg"), + ::testing::Values(false), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AdaPoolAvg4DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine( + adaPool4DParams, + ::testing::Values("avg"), + ::testing::Values(false), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AdaPoolAvg5DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine( + adaPool5DParams, + ::testing::Values("avg"), + ::testing::Values(false), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AdaPoolMax3DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine( + adaPool3DParams, + ::testing::Values("max"), + ::testing::Values(false), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AdaPoolMax4DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine( + adaPool4DParams, + ::testing::Values("max"), + ::testing::Values(false), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_AdaPoolMax5DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine( + adaPool5DParams, + ::testing::Values("max"), + ::testing::Values(false), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +const auto staticAdaPool3DParams = ::testing::Combine( + ::testing::ValuesIn(pooled3DVector), // output spatial shape + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(staticInput3DShapeVector)) // feature map shape +); + +const auto staticAdaPool4DParams = ::testing::Combine( + ::testing::ValuesIn(pooled4DVector), // output spatial shape + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(staticInput4DShapeVector)) // feature map shape +); + +const auto staticAdaPool5DParams = ::testing::Combine( + ::testing::ValuesIn(pooled5DVector), // output spatial shape + ::testing::ValuesIn(ov::test::static_shapes_to_test_representation(staticInput5DShapeVector)) // feature map shape +); + +INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_StaticAdaPoolAvg3DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine(staticAdaPool3DParams, + ::testing::Values("avg"), + ::testing::Values(true), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_StaticAdaPoolAvg4DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine(staticAdaPool4DParams, + ::testing::Values("avg"), + ::testing::Values(true), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_StaticAdaPoolAvg5DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine(staticAdaPool5DParams, + ::testing::Values("avg"), + ::testing::Values(true), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_StaticAdaPoolMax3DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine(staticAdaPool3DParams, + ::testing::Values("max"), + ::testing::Values(true), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_StaticAdaPoolMax4DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine(staticAdaPool4DParams, + ::testing::Values("max"), + ::testing::Values(true), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_StaticAdaPoolMax5DLayoutTest, AdaPoolLayerGPUTest, + ::testing::Combine(staticAdaPool5DParams, + ::testing::Values("max"), + ::testing::Values(true), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(ov::test::utils::DEVICE_GPU)), + AdaPoolLayerGPUTest::getTestCaseName); +} // namespace From a803ba415024d528038f282185495dc3d23df5ab Mon Sep 17 00:00:00 2001 From: "Min, Byungil" Date: Mon, 29 Jan 2024 20:44:35 -0800 Subject: [PATCH 09/27] [GPU] optimize poor scaling for batch8 (#22221) + Opt out qunatize Signed-off-by: Min, Byungil --- .../fuse_primitives_with_layout.cpp | 66 +++++++++++++++++++ .../prepare_primitive_fusing.cpp | 1 + .../src/graph/include/pass_manager.h | 8 +++ src/plugins/intel_gpu/src/graph/program.cpp | 5 ++ .../unit/fusions/eltwise_fusion_test.cpp | 62 +++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 src/plugins/intel_gpu/src/graph/graph_optimizer/fuse_primitives_with_layout.cpp diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/fuse_primitives_with_layout.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/fuse_primitives_with_layout.cpp new file mode 100644 index 00000000000000..a5d2ff3a53ebb7 --- /dev/null +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/fuse_primitives_with_layout.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "program_helpers.h" +#include "pass_manager.h" + +#include "eltwise_inst.h" +#include "quantize_inst.h" + +#include + +using namespace cldnn; + +static bool eltwise_supports_fusings(eltwise_node& node) { + auto out_layout = node.get_output_layout(); + // This condition refers to optimizied kernel EltwiseKernel_fs_b_yx_fsv32 + if (out_layout.data_type == data_types::f16 && out_layout.batch() > 1 && out_layout.format == format::fs_b_yx_fsv32) { + return false; + } + + return true; +} + +void fuse_primitives_with_layout::run(program& p) { + bool need_recalc_processing_order = false; + std::map>> fusing_history; + + auto itr = p.get_processing_order().begin(); + while (itr != p.get_processing_order().end()) { + auto node_itr = itr++; + auto& node = (*node_itr); + + if (node->is_output() || node->is_constant()) + continue; + + // No optimized Eltwise kernel supports fused-operation for fs_b_yx_fsv32 + // Check fusing quantize to eltwsise for this case + auto func_fuse_quantize = [&](quantize_node& node) { + bool should_fuse = false; + auto out_layout = node.get_output_layout(); + if (out_layout.is_dynamic() || node.is_in_shape_of_subgraph()) + return; + + auto& input_node = node.get_dependency(0); + auto in_layout = input_node.get_output_layout(); + if (input_node.get_users().size() != 1 || input_node.get_dependencies().empty() || + in_layout.is_dynamic() || input_node.is_in_shape_of_subgraph()) + return; + + should_fuse |= input_node.is_type() && eltwise_supports_fusings(input_node.as()); + + if (!should_fuse) + return; + + p.fuse_nodes(input_node, node, &fusing_history); + need_recalc_processing_order = true; + }; + + program_helpers::do_for_types(*node, func_fuse_quantize); + } + + // Need to update processing order when peer node processing number is greater than fused node + if (need_recalc_processing_order) + p.get_processing_order().calc_processing_order(p); +} diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp index 242da0c35b3a8a..89f37276f7d56d 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp @@ -552,6 +552,7 @@ void prepare_primitive_fusing::fuse_simple_primitives(program &p) { auto eltwise_supports_fusings = [&](eltwise_node& node) -> bool { auto out_layout = node.get_output_layout(); + // Do not fuse if the estimated format is fs_b_yx_fsv32 because the optimized kernel does not support fusion if (out_layout.data_type == data_types::f16 && out_layout.is_static() && out_layout.batch() > 1 && ((_lo.get_optimization_attributes().fs_b_yx_fsv32_network && !_lo.get_optimization_attributes().use_onednn_impls) || diff --git a/src/plugins/intel_gpu/src/graph/include/pass_manager.h b/src/plugins/intel_gpu/src/graph/include/pass_manager.h index 8c92ec4f5c6886..d667d6ada6810e 100644 --- a/src/plugins/intel_gpu/src/graph/include/pass_manager.h +++ b/src/plugins/intel_gpu/src/graph/include/pass_manager.h @@ -395,4 +395,12 @@ class mark_runtime_skippable_nodes : public base_pass { void run(program& p) override; }; +class fuse_primitives_with_layout : public base_pass { +public: + fuse_primitives_with_layout() : base_pass("fuse_primitives_with_layout") {} + +private: + void run(program& p) override; +}; + } // namespace cldnn diff --git a/src/plugins/intel_gpu/src/graph/program.cpp b/src/plugins/intel_gpu/src/graph/program.cpp index 87bf0e747e4913..36e2cda3ab345b 100644 --- a/src/plugins/intel_gpu/src/graph/program.cpp +++ b/src/plugins/intel_gpu/src/graph/program.cpp @@ -589,6 +589,11 @@ void program::pre_optimize_graph(bool is_internal) { // check if there exists some layout incompatibilities and add an reorder node if required apply_opt_pass(); + // Check fusing primitives based on preferred format or layout optimization + if (optimize_data) { + apply_opt_pass(); + } + // add optimization attributes for onednn primitives apply_opt_pass(); diff --git a/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp index 5f75f4e424b857..b79242f981e402 100644 --- a/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/unit/fusions/eltwise_fusion_test.cpp @@ -588,3 +588,65 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, eltwise_activation, ::testing::ValuesIn(st eltwise_test_params{ CASE_ELTWISE_FP16_FP32_2, 3, 4 }, eltwise_test_params{ CASE_ELTWISE_FP16_FP32_3, 3, 4 } })); + + +class eltwise_quantize_fs_b_yx_fsv32 : public EltwiseFusingTest {}; +TEST_P(eltwise_quantize_fs_b_yx_fsv32, fusing_eltwise_quantize_layout) { + auto p = GetParam(); + create_topologies( + input_layout("input", get_input_layout(p)), + input_layout("input2", get_input_layout2(p)), + data("in_lo", get_mem(get_per_channel_layout(p), min_random, 0)), + data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), + data("out_lo", get_mem(get_single_element_layout(p), -128)), + data("out_hi", get_mem(get_single_element_layout(p), 127)), + eltwise("eltwise", { input_info("input"), input_info("input2") }, p.mode, p.default_type), + quantize("quantize", input_info("eltwise"), input_info("in_lo"), input_info("in_hi"), + input_info("out_lo"), input_info("out_hi"), 256, p.input_type), + reorder("out", input_info("quantize"), format::bfyx, data_types::f32) + ); + + tolerance = default_tolerance(data_types::i8); + execute(p); +} + +#define CASE_ELTWISE_FP16_FS_B_YX { 1, 32, 4, 4 }, data_types::f16, data_types::f16, format::fs_b_yx_fsv32, data_types::f16, format::fs_b_yx_fsv32, eltwise_mode::sum +#define CASE_ELTWISE_FP16_BATCH_FS_B { 8, 32, 4, 4 }, data_types::f16, data_types::f16, format::fs_b_yx_fsv32, data_types::f16, format::fs_b_yx_fsv32, eltwise_mode::sum +#define CASE_ELTWISE_FP16_B_FS_YX { 1, 32, 4, 4 }, data_types::f16, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::b_fs_yx_fsv16, eltwise_mode::sum +#define CASE_ELTWISE_FP16_BATCH_B_FS { 8, 32, 4, 4 }, data_types::f16, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::b_fs_yx_fsv16, eltwise_mode::sum + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, eltwise_quantize_fs_b_yx_fsv32, ::testing::ValuesIn(std::vector{ + eltwise_test_params{ CASE_ELTWISE_FP16_FS_B_YX, 3, 4 }, + eltwise_test_params{ CASE_ELTWISE_FP16_B_FS_YX, 3, 4 }, + eltwise_test_params{ CASE_ELTWISE_FP16_BATCH_FS_B, 4, 4 }, + eltwise_test_params{ CASE_ELTWISE_FP16_BATCH_B_FS, 3, 4 }, +})); + +class eltwise_quantize_fs_b_yx_fsv32_exception : public EltwiseFusingTest {}; +TEST_P(eltwise_quantize_fs_b_yx_fsv32_exception, fusing_eltwise_quantize_layout_exception) { + auto p = GetParam(); + create_topologies( + input_layout("input", get_input_layout(p)), + input_layout("input2", get_input_layout2(p)), + data("in_lo", get_mem(get_per_channel_layout(p), min_random, 0)), + data("in_hi", get_mem(get_per_channel_layout(p), 1, max_random)), + data("out_lo", get_mem(get_single_element_layout(p), -128)), + data("out_hi", get_mem(get_single_element_layout(p), 127)), + eltwise("eltwise", { input_info("input"), input_info("input2") }, p.mode, p.default_type), + quantize("quantize", input_info("eltwise"), input_info("in_lo"), input_info("in_hi"), + input_info("out_lo"), input_info("out_hi"), 256, p.input_type), + activation("activation", input_info("eltwise"), activation_func::negative), + eltwise("eltwise_second", { input_info("quantize"), input_info("activation") }, p.mode, p.default_type), + reorder("out", input_info("eltwise_second"), format::bfyx, data_types::f32) + ); + + tolerance = default_tolerance(data_types::i8); + execute(p); +} + +INSTANTIATE_TEST_SUITE_P(fusings_gpu, eltwise_quantize_fs_b_yx_fsv32_exception, ::testing::ValuesIn(std::vector{ + eltwise_test_params{ CASE_ELTWISE_FP16_FS_B_YX, 6, 6 }, + eltwise_test_params{ CASE_ELTWISE_FP16_B_FS_YX, 6, 6 }, + eltwise_test_params{ CASE_ELTWISE_FP16_BATCH_FS_B, 6, 6 }, + eltwise_test_params{ CASE_ELTWISE_FP16_BATCH_B_FS, 6, 6 }, +})); \ No newline at end of file From 406bd082e1305f81e0b98275f9fb4663f4e03323 Mon Sep 17 00:00:00 2001 From: Fang Xu Date: Tue, 30 Jan 2024 14:04:09 +0800 Subject: [PATCH 10/27] return correct socketid and numaid on windows (#22127) --- src/inference/src/os/win/win_system_conf.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/inference/src/os/win/win_system_conf.cpp b/src/inference/src/os/win/win_system_conf.cpp index 0b905d29401355..17384035973c12 100644 --- a/src/inference/src/os/win/win_system_conf.cpp +++ b/src/inference/src/os/win/win_system_conf.cpp @@ -39,6 +39,18 @@ CPU::CPU() { _proc_type_table, _cpu_mapping_table); _org_proc_type_table = _proc_type_table; + + // ensure that get_org_numa_id and get_org_socket_id can return the correct value + for (size_t i = 0; i < _cpu_mapping_table.size(); i++) { + auto numa_id = _cpu_mapping_table[i][CPU_MAP_NUMA_NODE_ID]; + auto socket_id = _cpu_mapping_table[i][CPU_MAP_SOCKET_ID]; + if (_numaid_mapping_table.find(numa_id) == _numaid_mapping_table.end()) { + _numaid_mapping_table.insert({numa_id, numa_id}); + } + if (_socketid_mapping_table.find(socket_id) == _socketid_mapping_table.end()) { + _socketid_mapping_table.insert({socket_id, socket_id}); + } + } } void parse_processor_info_win(const char* base_ptr, From e7a39bb540bd1ac1f40c19be05a9654f57fbc927 Mon Sep 17 00:00:00 2001 From: Vladimir Paramuzov Date: Tue, 30 Jan 2024 10:19:03 +0400 Subject: [PATCH 11/27] [GPU] Add missing undef and remove some outdated code (#22501) * [GPU] Remove unused get_arguments method * [GPU] Added missing undef --- .../graph/impls/common/wait_for_events.cpp | 4 ---- .../src/graph/impls/ocl/primitive_base.hpp | 19 ------------------- .../impls/onednn/primitive_onednn_base.h | 2 -- .../src/graph/include/primitive_inst.h | 9 --------- .../kernel_selector/kernel_base_opencl.cpp | 1 + 5 files changed, 1 insertion(+), 34 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp b/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp index b08831e0aade6a..d5640833c523dd 100644 --- a/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp @@ -32,10 +32,6 @@ class wait_for_events_impl : public primitive_impl { void init_kernels(const kernels_cache&, const kernel_impl_params&) override {} void set_arguments(primitive_inst& /*instance*/) override {} void set_arguments(primitive_inst& /*instance*/, kernel_arguments_data& /*args*/) override {} - kernel_arguments_data get_arguments(const primitive_inst& /*instance*/) const override { - kernel_arguments_data args; - return args; - } std::vector get_internal_buffer_layouts() const override { return {}; } event::ptr execute(const std::vector& events, primitive_inst& instance) override { diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp b/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp index d4e4927e200f1a..485a8255f15b17 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/primitive_base.hpp @@ -96,9 +96,6 @@ struct typed_primitive_impl_ocl : public typed_primitive_impl { return make_unique(best_kernel); } -private: - using primitive_impl::get_arguments; - protected: virtual kernel_arguments_data get_arguments(const typed_primitive_inst& instance) const { kernel_arguments_data args; @@ -228,22 +225,6 @@ struct typed_primitive_impl_ocl : public typed_primitive_impl { } } - kernel_arguments_data get_arguments_impl(const typed_primitive_inst& instance) const override { - if (_kernels.size()) { - auto args = get_arguments(instance); - args.scalars = &_kernel_data.kernels[0].params.scalars; - - for (const auto& m : instance.get_intermediates_memories()) { - args.intermediates.push_back(m); - } - - return args; - } - - kernel_arguments_data args; - return args; - } - event::ptr execute_impl(const std::vector& events, typed_primitive_inst& instance) override { stream& stream = instance.get_network().get_stream(); diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h index f6d5769b77d218..87f129b8b98495 100644 --- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h +++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h @@ -322,8 +322,6 @@ struct typed_primitive_onednn_impl : public typed_primitive_impl { } private: - using primitive_impl::get_arguments; - std::string get_cache_directory(const ExecutionConfig& config) const { auto path = config.get_property(ov::cache_dir); if (path.empty()) { diff --git a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h index ebe58eb8eef97f..62840e2b9bbb1f 100644 --- a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h +++ b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h @@ -57,7 +57,6 @@ struct primitive_impl { virtual const std::string& get_type_info() const = 0; virtual void set_arguments(primitive_inst& instance) = 0; virtual void set_arguments(primitive_inst& instance, kernel_arguments_data& args) = 0; - virtual kernel_arguments_data get_arguments(const primitive_inst& instance) const = 0; virtual event::ptr execute(const std::vector& events, primitive_inst& instance) = 0; std::string get_kernel_name() const { return _kernel_name; } @@ -509,16 +508,8 @@ struct typed_primitive_impl : public primitive_impl { return set_arguments_impl(reinterpret_cast&>(instance), args); } - kernel_arguments_data get_arguments(const primitive_inst& instance) const override { - return get_arguments_impl(reinterpret_cast&>(instance)); - } - virtual void set_arguments_impl(typed_primitive_inst& /*instance*/) {} virtual void set_arguments_impl(typed_primitive_inst& /*instance*/, kernel_arguments_data& /*args*/) {} - virtual kernel_arguments_data get_arguments_impl(const typed_primitive_inst& /*instance*/) const { - kernel_arguments_data args; - return args; - } virtual event::ptr execute_impl(const std::vector& event, typed_primitive_inst& instance) = 0; }; diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp index 0a5655a4996cff..52853d7012f1cf 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_base_opencl.cpp @@ -103,6 +103,7 @@ std::pair KernelBaseOpenCL::CreateJit(const std::strin .decoration_macro("CONST_ARRAY_REF", "", kernel_id); undefs += "#undef KERNEL\n"; + undefs += "#undef KERNEL_ID\n"; undefs += "#undef FUNC\n"; undefs += "#undef FUNC_CALL\n"; undefs += "#undef CONST_ARRAY_DECL\n"; From 61a1edacd86d15b92d9376832685067d84a44856 Mon Sep 17 00:00:00 2001 From: Xuejun Zhai Date: Tue, 30 Jan 2024 14:26:34 +0800 Subject: [PATCH 12/27] [AUTO Plugin] Clean 1.0 related code in src code (#22256) * [AUTO Plugin] Clean 1.0 related code in src code Signed-off-by: Zhai, Xuejun * [AUTO Plugin] Remove unused code Signed-off-by: Zhai, Xuejun * [AUTO Plugin] Remove unused code Signed-off-by: Zhai, Xuejun * Update src/plugins/auto/tests/unit/auto_unit_test.cpp Co-authored-by: Wang, Yang * Fix build error Signed-off-by: Zhai, Xuejun * Fix test error Signed-off-by: Zhai, Xuejun * Fix review comments Signed-off-by: Zhai, Xuejun * Fix error Signed-off-by: Zhai, Xuejun * validate only Signed-off-by: fishbell * validate only Signed-off-by: fishbell validate only Signed-off-by: fishbell validate only Signed-off-by: fishbell * Remove 1.0 related Signed-off-by: Zhai, Xuejun --------- Signed-off-by: Zhai, Xuejun Signed-off-by: fishbell Co-authored-by: Wang, Yang Co-authored-by: fishbell --- .../c/tests/ov_auto_property_test.cpp | 2 +- src/inference/src/dev/plugin.cpp | 8 +- src/plugins/auto/src/auto_compiled_model.cpp | 30 +--- src/plugins/auto/src/common.hpp | 11 +- .../auto/src/cumulative_compiled_model.cpp | 31 +---- src/plugins/auto/src/plugin.cpp | 130 +----------------- src/plugins/auto/src/plugin.hpp | 3 - src/plugins/auto/src/plugin_config.hpp | 5 - src/plugins/auto/src/schedule.hpp | 2 + .../auto/tests/unit/auto_unit_test.cpp | 8 +- .../tests/unit/compile_model_metric_test.cpp | 62 ++++----- src/plugins/auto/tests/unit/ctput_test.cpp | 9 +- .../tests/unit/include/auto_unit_test.hpp | 3 - .../auto/tests/unit/release_helper_test.cpp | 2 +- 14 files changed, 56 insertions(+), 250 deletions(-) diff --git a/src/bindings/c/tests/ov_auto_property_test.cpp b/src/bindings/c/tests/ov_auto_property_test.cpp index 6750092d845c93..74a47cca725d23 100644 --- a/src/bindings/c/tests/ov_auto_property_test.cpp +++ b/src/bindings/c/tests/ov_auto_property_test.cpp @@ -50,4 +50,4 @@ const std::vector test_property_config = { INSTANTIATE_TEST_SUITE_P(ov_auto_plugin_test_properties, ov_auto_plugin_test, - ::testing::ValuesIn(test_property_config)); \ No newline at end of file + ::testing::ValuesIn(test_property_config)); diff --git a/src/inference/src/dev/plugin.cpp b/src/inference/src/dev/plugin.cpp index 554163858fd8fc..45860d5bc33658 100644 --- a/src/inference/src/dev/plugin.cpp +++ b/src/inference/src/dev/plugin.cpp @@ -17,8 +17,14 @@ OPENVINO_ASSERT(m_ptr != nullptr, "OpenVINO Runtime Plugin was not initialized."); \ try { \ __VA_ARGS__; \ + } catch (const ov::NotImplemented& ex) { \ + OPENVINO_NOT_IMPLEMENTED; \ + } catch (const InferenceEngine::NotImplemented& ex) { \ + OPENVINO_NOT_IMPLEMENTED; \ + } catch (const std::exception& ex) { \ + OPENVINO_THROW(ex.what()); \ } catch (...) { \ - ::InferenceEngine::details::Rethrow(); \ + OPENVINO_THROW("Unexpected exception"); \ } ov::Plugin::~Plugin() { m_ptr = {}; diff --git a/src/plugins/auto/src/auto_compiled_model.cpp b/src/plugins/auto/src/auto_compiled_model.cpp index 1831f35560dfcd..c4f38f70c6abe8 100644 --- a/src/plugins/auto/src/auto_compiled_model.cpp +++ b/src/plugins/auto/src/auto_compiled_model.cpp @@ -36,9 +36,6 @@ std::shared_ptr AutoCompiledModel::get_runtime_model() const { } ov::Any AutoCompiledModel::get_property(const std::string& name) const { - const auto& add_ro_properties = [](const std::string& name, std::vector& properties) { - properties.emplace_back(ov::PropertyName{name, ov::PropertyMutability::RO}); - }; const auto& default_ro_properties = []() { std::vector ro_properties{ov::model_name, ov::supported_properties, @@ -55,13 +52,6 @@ ov::Any AutoCompiledModel::get_property(const std::string& name) const { std::vector rw_properties{}; return rw_properties; }; - const auto& to_string_vector = [](const std::vector& properties) { - std::vector ret; - for (const auto& property : properties) { - ret.emplace_back(property); - } - return ret; - }; if (name == ov::supported_properties) { auto ro_properties = default_ro_properties(); auto rw_properties = default_rw_properties(); @@ -93,15 +83,7 @@ ov::Any AutoCompiledModel::get_property(const std::string& name) const { return all_devices; } else if (name == ov::hint::model_priority) { auto value = m_context->m_model_priority; - if (m_context->m_ov_core->is_new_api()) { - return value ? ((value > 1) ? ov::hint::Priority::LOW : - ov::hint::Priority::MEDIUM) : ov::hint::Priority::HIGH; - } else { - OPENVINO_SUPPRESS_DEPRECATED_START - return value ? ((value > 1) ? CONFIG_VALUE(MODEL_PRIORITY_LOW) : CONFIG_VALUE( - MODEL_PRIORITY_MED)) : CONFIG_VALUE(MODEL_PRIORITY_HIGH); - OPENVINO_SUPPRESS_DEPRECATED_END - } + return value ? ((value > 1) ? ov::hint::Priority::LOW : ov::hint::Priority::MEDIUM) : ov::hint::Priority::HIGH; } else if (name == ov::optimal_number_of_infer_requests) { const unsigned int default_num_for_tput = 4u; const unsigned int default_num_for_latency = 1u; @@ -246,16 +228,6 @@ ov::Any AutoCompiledModel::get_property(const std::string& name) const { return m_scheduler->m_compile_context[CPU].m_compiled_model->get_property(name); return m_scheduler->m_compile_context[ACTUALDEVICE].m_compiled_model->get_property(name); } - OPENVINO_SUPPRESS_DEPRECATED_START - } else if (name == METRIC_KEY(SUPPORTED_METRICS)) { - auto ro_properties = default_ro_properties(); - add_ro_properties(METRIC_KEY(SUPPORTED_METRICS), ro_properties); - add_ro_properties(METRIC_KEY(SUPPORTED_CONFIG_KEYS), ro_properties); - return to_string_vector(ro_properties); - } else if (name == METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { - auto rw_properties = default_rw_properties(); - return to_string_vector(rw_properties); - OPENVINO_SUPPRESS_DEPRECATED_END } else if (name == ov::loaded_from_cache) { std::lock_guard lock(m_context->m_fallback_mutex); std::string device_name; diff --git a/src/plugins/auto/src/common.hpp b/src/plugins/auto/src/common.hpp index e0827181aab86b..61a899f7de140d 100644 --- a/src/plugins/auto/src/common.hpp +++ b/src/plugins/auto/src/common.hpp @@ -7,18 +7,17 @@ #include #include -#include "ie_icore.hpp" + +#include "openvino/runtime/auto/properties.hpp" +#include "openvino/runtime/iasync_infer_request.hpp" #include "openvino/runtime/icompiled_model.hpp" +#include "openvino/runtime/icore.hpp" #include "openvino/runtime/isync_infer_request.hpp" -#include "openvino/runtime/iasync_infer_request.hpp" -#include "openvino/runtime/threading/itask_executor.hpp" #include "openvino/runtime/remote_tensor.hpp" +#include "openvino/runtime/threading/itask_executor.hpp" #include "openvino/runtime/threading/thread_safe_containers.hpp" -#include "utils/log_util.hpp" -#include "openvino/runtime/auto/properties.hpp" #include "transformations/utils/utils.hpp" #include "utils/log_util.hpp" -#include "itt.hpp" #ifdef MULTIUNITTEST #define MOCKTESTMACRO virtual diff --git a/src/plugins/auto/src/cumulative_compiled_model.cpp b/src/plugins/auto/src/cumulative_compiled_model.cpp index 84407cc0c6c79e..3ec7a820256d67 100644 --- a/src/plugins/auto/src/cumulative_compiled_model.cpp +++ b/src/plugins/auto/src/cumulative_compiled_model.cpp @@ -12,7 +12,6 @@ #include "openvino/runtime/exec_model_info.hpp" #include "openvino/runtime/properties.hpp" #include "plugin.hpp" -#include "ie_plugin_config.hpp" namespace ov { namespace auto_plugin { @@ -36,9 +35,6 @@ std::shared_ptr AutoCumuCompiledModel::get_runtime_model() cons } ov::Any AutoCumuCompiledModel::get_property(const std::string& name) const { - const auto& add_ro_properties = [](const std::string& name, std::vector& properties) { - properties.emplace_back(ov::PropertyName{name, ov::PropertyMutability::RO}); - }; const auto& default_ro_properties = []() { std::vector ro_properties{ov::model_name, ov::supported_properties, @@ -55,13 +51,6 @@ ov::Any AutoCumuCompiledModel::get_property(const std::string& name) const { std::vector rw_properties{ov::device::priorities}; return rw_properties; }; - const auto& to_string_vector = [](const std::vector& properties) { - std::vector ret; - for (const auto& property : properties) { - ret.emplace_back(property); - } - return ret; - }; if (name == ov::supported_properties) { auto ro_properties = default_ro_properties(); auto rw_properties = default_rw_properties(); @@ -89,15 +78,7 @@ ov::Any AutoCumuCompiledModel::get_property(const std::string& name) const { return all_devices; } else if (name == ov::hint::model_priority) { auto value = m_context->m_model_priority; - if (m_context->m_ov_core->is_new_api()) { - return value ? ((value > 1) ? ov::hint::Priority::LOW : - ov::hint::Priority::MEDIUM) : ov::hint::Priority::HIGH; - } else { - OPENVINO_SUPPRESS_DEPRECATED_START - return value ? ((value > 1) ? CONFIG_VALUE(MODEL_PRIORITY_LOW) : CONFIG_VALUE( - MODEL_PRIORITY_MED)) : CONFIG_VALUE(MODEL_PRIORITY_HIGH); - OPENVINO_SUPPRESS_DEPRECATED_END - } + return value ? ((value > 1) ? ov::hint::Priority::LOW : ov::hint::Priority::MEDIUM) : ov::hint::Priority::HIGH; } else if (name == ov::optimal_number_of_infer_requests) { std::lock_guard lock(m_context->m_fallback_mutex); unsigned int res = 0u; @@ -129,16 +110,6 @@ ov::Any AutoCumuCompiledModel::get_property(const std::string& name) const { } } OPENVINO_THROW("No valid compiled model found to get", name); - OPENVINO_SUPPRESS_DEPRECATED_START - } else if (name == METRIC_KEY(SUPPORTED_METRICS)) { - auto ro_properties = default_ro_properties(); - add_ro_properties(METRIC_KEY(SUPPORTED_METRICS), ro_properties); - add_ro_properties(METRIC_KEY(SUPPORTED_CONFIG_KEYS), ro_properties); - return to_string_vector(ro_properties); - } else if (name == METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { - auto rw_properties = default_rw_properties(); - return to_string_vector(rw_properties); - OPENVINO_SUPPRESS_DEPRECATED_END } else if (name == ov::loaded_from_cache) { bool loaded_from_cache = true; std::lock_guard lock(m_context->m_fallback_mutex); diff --git a/src/plugins/auto/src/plugin.cpp b/src/plugins/auto/src/plugin.cpp index be04f7b50298bb..6d655e92806ce9 100644 --- a/src/plugins/auto/src/plugin.cpp +++ b/src/plugins/auto/src/plugin.cpp @@ -23,7 +23,6 @@ #include "cumulative_schedule.hpp" #include "itt.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" -#include "ie_ngraph_utils.hpp" namespace { const std::string get_model_precision(const std::shared_ptr &model) { @@ -96,30 +95,6 @@ std::shared_ptr Plugin::import_model(std::istream& model, OPENVINO_NOT_IMPLEMENTED; } -ov::AnyMap Plugin::pre_process_config(const ov::AnyMap& orig_config) const { - ov::AnyMap properties = orig_config; - for (auto& property : properties) { - // for model_priority, the values need to be converted - if (property.first == ov::hint::model_priority.name()) { - ov::Any converted_val{nullptr}; - auto legacy_val = property.second.as(); - OPENVINO_SUPPRESS_DEPRECATED_START - if (legacy_val == InferenceEngine::PluginConfigParams::MODEL_PRIORITY_HIGH) { - converted_val = ov::hint::Priority::HIGH; - } else if (legacy_val == InferenceEngine::PluginConfigParams::MODEL_PRIORITY_MED) { - converted_val = ov::hint::Priority::MEDIUM; - } else if (legacy_val == InferenceEngine::PluginConfigParams::MODEL_PRIORITY_LOW) { - converted_val = ov::hint::Priority::LOW; - OPENVINO_SUPPRESS_DEPRECATED_END - } else { - converted_val = legacy_val; - } - property.second = std::move(converted_val); - } - } - return properties; -} - std::vector Plugin::parse_meta_devices(const std::string& priorities, const ov::AnyMap& properties) const { std::vector meta_devices; @@ -184,10 +159,6 @@ std::vector Plugin::parse_meta_devices(const std::string& pri try { auto device_id = get_core()->get_property(device_name, ov::device::id); return device_id; - } catch (const InferenceEngine::Exception&) { - // some may throw IE exceptions - LOG_DEBUG_TAG("get default device id failed for ", device_name.c_str()); - return ""; } catch (ov::Exception&) { LOG_DEBUG_TAG("get default device id failed for ", device_name.c_str()); return ""; @@ -264,11 +235,7 @@ std::vector Plugin::parse_meta_devices(const std::string& pri full_device_name = get_core()->get_property(device_name_with_id, ov::device::full_name); } catch (ov::Exception&) { LOG_DEBUG_TAG("get full device name failed for ", device_name_with_id.c_str()); - OPENVINO_SUPPRESS_DEPRECATED_START - } catch (InferenceEngine::Exception&) { - LOG_DEBUG_TAG("get full device name failed for ", device_name_with_id.c_str()); } - OPENVINO_SUPPRESS_DEPRECATED_END } if (full_device_name.empty()) { @@ -292,14 +259,7 @@ std::vector Plugin::parse_meta_devices(const std::string& pri device_name_with_id.c_str(), default_device_id.c_str(), unique_name.c_str()); - OPENVINO_SUPPRESS_DEPRECATED_START - } catch (const InferenceEngine::Exception&) { - LOG_DEBUG_TAG("Failed to create meta device for deviceNameWithID:%s, defaultDeviceID:%s, uniqueName:%s", - device_name_with_id.c_str(), - default_device_id.c_str(), - unique_name.c_str()); } - OPENVINO_SUPPRESS_DEPRECATED_END } if (enable_device_priority) { device_priority++; @@ -310,13 +270,7 @@ std::vector Plugin::parse_meta_devices(const std::string& pri } ov::Any Plugin::get_property(const std::string& name, const ov::AnyMap& arguments) const { - OPENVINO_SUPPRESS_DEPRECATED_START - if (METRIC_KEY(SUPPORTED_METRICS) == name) { - return m_plugin_config.supported_ro_properties(get_device_name()); - } else if (METRIC_KEY(SUPPORTED_CONFIG_KEYS) == name) { - return m_plugin_config.supported_rw_properties(get_device_name()); - OPENVINO_SUPPRESS_DEPRECATED_END - } else if (ov::supported_properties == name) { + if (ov::supported_properties == name) { auto ret = m_plugin_config.supported_properties(get_device_name()); return ret; } else if (name == ov::internal::supported_properties.name()) { @@ -338,33 +292,13 @@ ov::Any Plugin::get_property(const std::string& name, const ov::AnyMap& argument } return capabilities; } - auto val = m_plugin_config.get_property(name); - if (!is_new_api()) { - if (name == ov::hint::model_priority.name()) { // need to convert priority values to old API - ov::Any legacy_val{nullptr}; - if (!val.empty()) { - switch (val.as()) { - OPENVINO_SUPPRESS_DEPRECATED_START - case ov::hint::Priority::LOW: legacy_val = InferenceEngine::PluginConfigParams::MODEL_PRIORITY_LOW; break; - case ov::hint::Priority::MEDIUM: legacy_val = InferenceEngine::PluginConfigParams::MODEL_PRIORITY_MED; break; - case ov::hint::Priority::HIGH: legacy_val = InferenceEngine::PluginConfigParams::MODEL_PRIORITY_HIGH; break; - OPENVINO_SUPPRESS_DEPRECATED_END - default: OPENVINO_ASSERT(false, "Unsupported model priority value"); - } - } - return legacy_val; - } else { - return val; - } - } else { - return val; - } - return val; + return m_plugin_config.get_property(name); } void Plugin::set_property(const ov::AnyMap& properties) { // with setConfig, only multi/auto supported internal configs can be accepted - m_plugin_config.set_property(pre_process_config(properties)); + auto property_to_set = properties; + m_plugin_config.set_property(property_to_set); } // ! [plugin:create_plugin_engine] @@ -412,7 +346,7 @@ std::shared_ptr Plugin::compile_model_impl(const std::string load_config.set_property(ov::hint::performance_mode(ov::hint::PerformanceMode::LATENCY)); } // updateFromMap will check config valid - load_config.set_user_property(pre_process_config(properties)); + load_config.set_user_property(properties); load_config.apply_user_properties(); if (!work_mode_auto) { if (iter_config != properties.end() && iter_config->second.as() != "THROUGHPUT") { @@ -470,56 +404,6 @@ std::shared_ptr Plugin::compile_model_impl(const std::string ppp_model = cloned_model->clone(); ov::preprocess::PrePostProcessor preproc(ppp_model); - OPENVINO_SUPPRESS_DEPRECATED_START - // temp solution to resolve the precision/layout mismatch between new/old api - if (!is_new_api()) { - for (size_t i = 0; i < ppp_model->inputs().size(); i++) { - ov::Output input(ppp_model->input(i).get_node(), ppp_model->input(i).get_index()); - auto& rt_info = input.get_rt_info(); - auto it = rt_info.find("ie_legacy_td"); - if (it != rt_info.end()) { - auto& td = it->second.as(); - auto element_type = InferenceEngine::details::convertPrecision(td.getPrecision()); - if (element_type != input.get_element_type()) { - preproc.input(i).tensor().set_element_type(element_type); - } - if (td.getLayout() != InferenceEngine::Layout::BLOCKED && - td.getLayout() != InferenceEngine::Layout::SCALAR) { - std::stringstream stream; - stream << td.getLayout(); - if (td.getLayout() == InferenceEngine::Layout::NHWC) { - preproc.input(i).tensor().set_layout(ov::Layout{stream.str()}); - if (input.get_partial_shape().is_static() && input.get_shape().size() == 4) - preproc.input(i).model().set_layout("NCHW"); - } - } - } - } - for (size_t i = 0; i < ppp_model->outputs().size(); i++) { - ov::Output output(ppp_model->output(i).get_node(), ppp_model->output(i).get_index()); - auto& rt_info = output.get_rt_info(); - auto it = rt_info.find("ie_legacy_td"); - if (it != rt_info.end()) { - auto& td = it->second.as(); - auto element_type = InferenceEngine::details::convertPrecision(td.getPrecision()); - if (element_type != output.get_element_type()) { - preproc.output(i).tensor().set_element_type(element_type); - } - if (td.getLayout() != InferenceEngine::Layout::BLOCKED && - td.getLayout() != InferenceEngine::Layout::SCALAR) { - std::stringstream stream; - stream << td.getLayout(); - if (stream.str() == "NHWC") { - if (output.get_partial_shape().is_static() && output.get_shape().size() == 4) - preproc.output(i).model().set_layout("NCHW"); - preproc.output(i).postprocess().convert_layout(ov::Layout{stream.str()}); - } - } - } - } - preproc.build(); - } - OPENVINO_SUPPRESS_DEPRECATED_END } else { // AUTO / MULTI don't support caching explicitly, but can redirect this functionality to actual HW plugin LOG_INFO_TAG("compile model with model path"); @@ -569,11 +453,7 @@ std::shared_ptr Plugin::compile_model_impl(const std::string device_context._so = auto_s_context->m_hw_compiled_model._so; } catch (ov::NotImplemented&) { LOG_INFO_TAG("underlying hardware does not support hardware context"); - OPENVINO_SUPPRESS_DEPRECATED_START - } catch (InferenceEngine::Exception&) { - LOG_INFO_TAG("underlying hardware does not support hardware context"); } - OPENVINO_SUPPRESS_DEPRECATED_END if (is_cumulative) { impl = std::make_shared(ppp_model, shared_from_this(), device_context, auto_s_context, scheduler); } else { diff --git a/src/plugins/auto/src/plugin.hpp b/src/plugins/auto/src/plugin.hpp index 47e7e85a9df571..af667b059e09e7 100644 --- a/src/plugins/auto/src/plugin.hpp +++ b/src/plugins/auto/src/plugin.hpp @@ -67,9 +67,6 @@ class Plugin : public ov::IPlugin { const ov::SoPtr& context, const ov::AnyMap& properties) const override; -protected: - ov::AnyMap pre_process_config(const ov::AnyMap& orig_config) const; - private: std::shared_ptr compile_model_impl(const std::string& model_path, const std::shared_ptr& model, diff --git a/src/plugins/auto/src/plugin_config.hpp b/src/plugins/auto/src/plugin_config.hpp index 2c1f54a8517bce..e276dd1e53c5ad 100644 --- a/src/plugins/auto/src/plugin_config.hpp +++ b/src/plugins/auto/src/plugin_config.hpp @@ -12,7 +12,6 @@ #include #include #include -#include namespace ov { namespace auto_plugin { @@ -177,10 +176,6 @@ class PluginConfig { if (iter.second.as() == ov::PropertyMutability::RO) supported_ro_properties.push_back(iter.first); } - OPENVINO_SUPPRESS_DEPRECATED_START - supported_ro_properties.push_back(METRIC_KEY(SUPPORTED_METRICS)); - supported_ro_properties.push_back(METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - OPENVINO_SUPPRESS_DEPRECATED_END auto multi_supported_ro_properties = supported_ro_properties; return plugin_name == "AUTO" ? supported_ro_properties : multi_supported_ro_properties; } diff --git a/src/plugins/auto/src/schedule.hpp b/src/plugins/auto/src/schedule.hpp index c7c8c8c7baaa77..7291f1ff0ffafb 100644 --- a/src/plugins/auto/src/schedule.hpp +++ b/src/plugins/auto/src/schedule.hpp @@ -6,6 +6,8 @@ #pragma once #include "common.hpp" +#include "itt.hpp" + namespace ov { namespace auto_plugin { using Stage = std::pair, ov::threading::Task>; diff --git a/src/plugins/auto/tests/unit/auto_unit_test.cpp b/src/plugins/auto/tests/unit/auto_unit_test.cpp index e4c7e8135774cc..86e04e6a9b4b70 100644 --- a/src/plugins/auto/tests/unit/auto_unit_test.cpp +++ b/src/plugins/auto/tests/unit/auto_unit_test.cpp @@ -123,9 +123,7 @@ ov::mock_auto_plugin::tests::AutoTest::AutoTest() { core = std::make_shared>(); // replace core with mock Icore plugin->set_core(core); - std::vector supportConfigs = {"SUPPORTED_CONFIG_KEYS", "NUM_STREAMS"}; - ON_CALL(*core, get_property(_, StrEq(METRIC_KEY(SUPPORTED_CONFIG_KEYS)), _)) - .WillByDefault(Return(ov::Any(supportConfigs))); + std::vector supportConfigs = {ov::supported_properties.name(), ov::num_streams.name()}; std::vector supportedProps = {ov::compilation_num_threads}; ON_CALL(*core, get_property(_, StrEq(ov::supported_properties.name()), _)) .WillByDefault(RETURN_MOCK_VALUE(supportedProps)); @@ -155,12 +153,10 @@ ov::mock_auto_plugin::tests::AutoTest::AutoTest() { .WillByDefault(RETURN_MOCK_VALUE(iGpuType)); ON_CALL(*core, get_property(StrEq("GPU.1"), StrEq(ov::device::type.name()), _)) .WillByDefault(RETURN_MOCK_VALUE(dGpuType)); - const std::vector metrics = {METRIC_KEY(SUPPORTED_CONFIG_KEYS), - ov::device::full_name.name(), + const std::vector metrics = {ov::device::full_name.name(), ov::device::id.name()}; const char igpuFullDeviceName[] = "Intel(R) Gen9 HD Graphics (iGPU)"; const char dgpuFullDeviceName[] = "Intel(R) Iris(R) Xe MAX Graphics (dGPU)"; - ON_CALL(*core, get_property(_, StrEq(METRIC_KEY(SUPPORTED_METRICS)), _)).WillByDefault(RETURN_MOCK_VALUE(metrics)); ON_CALL(*core, get_property(_, ov::supported_properties.name(), _)).WillByDefault(Return(ov::Any(supportedProps))); ON_CALL(*core, get_property(StrEq("GPU"), StrEq(ov::device::full_name.name()), _)) .WillByDefault(RETURN_MOCK_VALUE(igpuFullDeviceName)); diff --git a/src/plugins/auto/tests/unit/compile_model_metric_test.cpp b/src/plugins/auto/tests/unit/compile_model_metric_test.cpp index 772dca30497ae4..e5bc33284b9f34 100644 --- a/src/plugins/auto/tests/unit/compile_model_metric_test.cpp +++ b/src/plugins/auto/tests/unit/compile_model_metric_test.cpp @@ -100,7 +100,7 @@ class ExecNetworkget_propertyOptimalNumInferReq : public tests::AutoTest, using modelPrioPerfHintTestParams = std::tuple; @@ -111,7 +111,7 @@ class ExecNetworkget_propertyOtherTest : public tests::AutoTest, bool isNewAPI; bool actualSleep; std::string actualDeviceName; - std::string performanceMode; + ov::Any performanceMode; ov::Any modelPriority; std::tie(isNewAPI, actualSleep, actualDeviceName, performanceMode, modelPriority) = obj.param; std::ostringstream result; @@ -130,7 +130,7 @@ class ExecNetworkget_propertyOtherTest : public tests::AutoTest, << "false"; } result << "_actualDeviceName_" << actualDeviceName; - result << "_performanceMode_" << performanceMode; + result << "_performanceMode_" << performanceMode.as(); result << "_modelPriority" << modelPriority.as(); return result.str(); } @@ -186,7 +186,7 @@ TEST_P(ExecNetworkget_propertyOptimalNumInferReq, OPTIMAL_NUMBER_OF_INFER_REQUES metaConfig.insert(ov::hint::num_requests(gpuPerfHintNum)); } if (isThroughput) { - metaConfig.insert(ov::hint::performance_mode("THROUGHPUT")); + metaConfig.insert(ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT)); metaDevices.push_back({ov::test::utils::DEVICE_CPU, metaConfig, cpuCustomerNum, ""}); metaDevices.push_back({actualDeviceName, metaConfig, actualCustomerNum, ""}); // enable autoBatch @@ -365,7 +365,7 @@ class ExecNetworkGetMetricOtherTest : public tests::AutoTest, bool isNewAPI; bool actualSleep; std::string actualDeviceName; - std::string performanceMode; + ov::Any performanceMode; ov::Any modelPriority; std::tie(isNewAPI, actualSleep, actualDeviceName, performanceMode, modelPriority) = obj.param; std::ostringstream result; @@ -384,7 +384,7 @@ class ExecNetworkGetMetricOtherTest : public tests::AutoTest, << "false"; } result << "_actualDeviceName_" << actualDeviceName; - result << "_performanceMode_" << performanceMode; + result << "_performanceMode_" << performanceMode.as(); result << "_modelPriority" << modelPriority.as(); return result.str(); } @@ -396,18 +396,22 @@ TEST_P(ExecNetworkGetMetricOtherTest, modelPriority_perfHint_exclusiveAsyncReq_t bool isNewAPI; bool actualSleep; std::string actualDeviceName; - std::string performanceHint; + ov::Any performanceHint; ov::Any modelPriority; std::tie(isNewAPI, actualSleep, actualDeviceName, performanceHint, modelPriority) = this->GetParam(); config.insert(ov::device::priorities(ov::test::utils::DEVICE_CPU + std::string(",") + actualDeviceName)); - config.insert(ov::hint::performance_mode(performanceHint)); + config.insert(ov::hint::performance_mode(performanceHint.as())); config.insert({ov::hint::model_priority.name(), modelPriority.as()}); if (isNewAPI) { ON_CALL(*core.get(), is_new_api()).WillByDefault(Return(true)); } - metaDevices.push_back({ov::test::utils::DEVICE_CPU, {ov::hint::performance_mode(performanceHint)}, 3, ""}); - metaDevices.push_back({actualDeviceName, {ov::hint::performance_mode(performanceHint)}, 2, ""}); + metaDevices.push_back({ov::test::utils::DEVICE_CPU, + {ov::hint::performance_mode(performanceHint.as())}, + 3, + ""}); + metaDevices.push_back( + {actualDeviceName, {ov::hint::performance_mode(performanceHint.as())}, 2, ""}); ON_CALL(*plugin, select_device(_, _, _)).WillByDefault(Return(metaDevices[1])); ON_CALL(*plugin, parse_meta_devices(_, _)).WillByDefault(Return(metaDevices)); @@ -450,36 +454,24 @@ TEST_P(ExecNetworkGetMetricOtherTest, modelPriority_perfHint_exclusiveAsyncReq_t auto AutoExecNetwork = plugin->compile_model(model, config); auto result = AutoExecNetwork->get_property(ov::hint::performance_mode.name()).as(); - EXPECT_EQ(result, performanceHint); + EXPECT_EQ(result, performanceHint.as()); auto resPriority = AutoExecNetwork->get_property(ov::hint::model_priority.name()).as(); EXPECT_EQ(resPriority, modelPriority.as()); } const std::vector modelPrioPerfHintConfig = { - modelPrioPerfHintTestParams{false, - true, - ov::test::utils::DEVICE_GPU, - "THROUGHPUT", - CONFIG_VALUE(MODEL_PRIORITY_LOW)}, - modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, "LATENCY", CONFIG_VALUE(MODEL_PRIORITY_LOW)}, - modelPrioPerfHintTestParams{false, - true, - ov::test::utils::DEVICE_GPU, - "THROUGHPUT", - CONFIG_VALUE(MODEL_PRIORITY_MED)}, - modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, "LATENCY", CONFIG_VALUE(MODEL_PRIORITY_MED)}, - modelPrioPerfHintTestParams{false, - true, - ov::test::utils::DEVICE_GPU, - CONFIG_VALUE(THROUGHPUT), - CONFIG_VALUE(MODEL_PRIORITY_HIGH)}, - modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, "LATENCY", CONFIG_VALUE(MODEL_PRIORITY_HIGH)}, - modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "THROUGHPUT", "LOW"}, - modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "LATENCY", "LOW"}, - modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "THROUGHPUT", "MEDIUM"}, - modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "LATENCY", "MEDIUM"}, - modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "THROUGHPUT", "HIGH"}, - modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "LATENCY", "HIGH"}}; + modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::Priority::LOW}, + modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, "LATENCY", ov::hint::Priority::LOW}, + modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::Priority::MEDIUM}, + modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, "LATENCY", ov::hint::Priority::MEDIUM}, + modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::Priority::HIGH}, + modelPrioPerfHintTestParams{false, true, ov::test::utils::DEVICE_GPU, "LATENCY", ov::hint::Priority::HIGH}, + modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::Priority::LOW}, + modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "LATENCY", ov::hint::Priority::LOW}, + modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::Priority::MEDIUM}, + modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "LATENCY", ov::hint::Priority::MEDIUM}, + modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, ov::hint::PerformanceMode::THROUGHPUT, ov::hint::Priority::HIGH}, + modelPrioPerfHintTestParams{true, true, ov::test::utils::DEVICE_GPU, "LATENCY", ov::hint::Priority::HIGH}}; INSTANTIATE_TEST_SUITE_P(smoke_Auto_BehaviorTests, ExecNetworkGetMetricOtherTest, diff --git a/src/plugins/auto/tests/unit/ctput_test.cpp b/src/plugins/auto/tests/unit/ctput_test.cpp index 4b9cfd987b0133..75ebfdda5d7e3f 100644 --- a/src/plugins/auto/tests/unit/ctput_test.cpp +++ b/src/plugins/auto/tests/unit/ctput_test.cpp @@ -3,7 +3,6 @@ // #include "include/auto_unit_test.hpp" - using namespace ov::mock_auto_plugin; using Config = std::map; using ConfigParams = std::tuple>; @@ -50,7 +49,7 @@ TEST_P(LoadNetworkWithCTPUTMockTest, CTPUTSingleDevLogicTest) { if (targetDevices.size() == 1) { std::string targetDevice = targetDevices[0]; - config.insert({InferenceEngine::MultiDeviceConfigParams::KEY_MULTI_DEVICE_PRIORITIES, targetDevices[0]}); + config.insert({ov::device::priorities.name(), targetDevices[0]}); // Call single device logic and performance hint is THROUGHPUT EXPECT_CALL(*core, compile_model(::testing::Matcher&>(_), @@ -95,7 +94,7 @@ TEST_P(LoadNetworkWithCTPUTMockTestExeDevice, CTPUTSingleDevExecutionDevie) { std::tie(targetDevices) = this->GetParam(); plugin->set_device_name("AUTO"); - config.insert({{CONFIG_KEY(PERFORMANCE_HINT), InferenceEngine::PluginConfigParams::CUMULATIVE_THROUGHPUT}}); + config.insert({{ov::hint::performance_mode.name(), ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT}}); config.insert(ov::device::priorities(targetDevices[0])); // Call single device logic and performance hint is THROUGHPUT ASSERT_NO_THROW(exeNetwork = plugin->compile_model(model, config)); @@ -175,13 +174,13 @@ TEST_P(AutoCTPUTCallMulti, CTPUTDeviceLoadFailedNoExceptionThrowTest) { targetDev += ((deviceName == targetDevices.back()) ? "" : ","); } std::shared_ptr exeNetwork; - config.insert({{CONFIG_KEY(PERFORMANCE_HINT), InferenceEngine::PluginConfigParams::CUMULATIVE_THROUGHPUT}}); + config.insert({{ov::hint::performance_mode.name(), ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT}}); config.insert(ov::device::priorities(targetDev)); ON_CALL(*core, compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(loadFailedDevice)), ::testing::Matcher(_))) - .WillByDefault(Throw(InferenceEngine::GeneralError{""})); + .WillByDefault(Throw(ov::Exception{"GeneralError"})); if (loadFailedDevice != ov::test::utils::DEVICE_CPU) { EXPECT_CALL(*core, compile_model(::testing::Matcher&>(_), diff --git a/src/plugins/auto/tests/unit/include/auto_unit_test.hpp b/src/plugins/auto/tests/unit/include/auto_unit_test.hpp index 02043f1e45a1d7..46e4532cff19da 100644 --- a/src/plugins/auto/tests/unit/include/auto_unit_test.hpp +++ b/src/plugins/auto/tests/unit/include/auto_unit_test.hpp @@ -40,9 +40,6 @@ MATCHER_P(ComparePerfHint, perfHint, "Check if perf hint expects.") { return perfHint == arg_perfHint.as(); } -#define IE_SET_METRIC(key, name, ...) \ - typename ::InferenceEngine::Metrics::MetricType<::InferenceEngine::Metrics::key>::type name = __VA_ARGS__; - #define RETURN_MOCK_VALUE(value) \ InvokeWithoutArgs([value]() { \ return ov::Any(value); \ diff --git a/src/plugins/auto/tests/unit/release_helper_test.cpp b/src/plugins/auto/tests/unit/release_helper_test.cpp index 41af9cb5a804d1..d576e22299ff31 100644 --- a/src/plugins/auto/tests/unit/release_helper_test.cpp +++ b/src/plugins/auto/tests/unit/release_helper_test.cpp @@ -195,7 +195,7 @@ TEST_P(AutoReleaseHelperTest, releaseResource) { compile_model(::testing::Matcher&>(_), ::testing::Matcher(StrEq(ov::test::utils::DEVICE_CPU)), _)) - .WillByDefault(Throw(InferenceEngine::GeneralError{""})); + .WillByDefault(Throw(ov::Exception{"GeneralError"})); } metaDevices = {{ov::test::utils::DEVICE_CPU, {}, -1}, {ov::test::utils::DEVICE_GPU, {}, -1}}; DeviceInformation devInfo; From 7af56f1859568e25997d5b921a4423f204953af8 Mon Sep 17 00:00:00 2001 From: River Li Date: Tue, 30 Jan 2024 14:49:40 +0800 Subject: [PATCH 13/27] [Core] remove ie_paramater (#22443) * [Core] remove ie_paramater * Remove DefaultConfigurationTest * fix build error --- .../ie_iexecutable_network_internal.hpp | 9 ++-- .../interface/ie_iplugin_internal.hpp | 5 +-- src/inference/dev_api/ie_icore.hpp | 11 +++-- .../include/ie/cpp/ie_executable_network.hpp | 13 +++--- src/inference/include/ie/ie_core.hpp | 4 +- .../include/ie/ie_iexecutable_network.hpp | 9 ++-- src/inference/include/ie/ie_parameter.hpp | 44 ------------------- src/inference/src/any_copy.hpp | 1 - .../src/cpp/ie_executable_network.cpp | 6 +-- .../src/cpp/ie_executable_network_base.hpp | 6 +-- .../ie_iexecutable_network_internal.cpp | 7 ++- .../interface/ie_iplugin_internal.cpp | 5 +-- src/inference/src/dev/converter_utils.cpp | 14 +++--- src/inference/src/ie_common.cpp | 1 - src/inference/src/ie_core.cpp | 4 +- .../ov_plugin/auto_batching_tests.cpp | 1 + .../mock_iexecutable_network_internal.hpp | 6 +-- .../interface/mock_iinference_plugin.hpp | 8 +--- .../mocks/mock_iexecutable_network.hpp | 9 ++-- 19 files changed, 50 insertions(+), 113 deletions(-) delete mode 100644 src/inference/include/ie/ie_parameter.hpp diff --git a/src/inference/dev_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp b/src/inference/dev_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp index 8d2c8c831f361e..34a70ac4dae776 100644 --- a/src/inference/dev_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp +++ b/src/inference/dev_api/cpp_interfaces/interface/ie_iexecutable_network_internal.hpp @@ -11,7 +11,6 @@ #include "cpp/ie_cnn_network.h" #include "cpp_interfaces/interface/ie_ivariable_state_internal.hpp" -#include "ie_parameter.hpp" #include "openvino/runtime/so_ptr.hpp" namespace ov { @@ -132,23 +131,23 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(IExecutableNetw /** * @brief Sets configuration for current executable network - * @param config Map of pairs: (config parameter name, config parameter value) + * @param config Map of pairs: (config name, config ov::Any value) */ - virtual void SetConfig(const std::map& config); + virtual void SetConfig(const ov::AnyMap& config); /** * @brief Gets configuration dedicated to plugin behaviour * @param name A config key, can be found in ie_plugin_config.hpp * @return A value of config corresponding to config key */ - virtual Parameter GetConfig(const std::string& name) const; + virtual ov::Any GetConfig(const std::string& name) const; /** * @brief Gets general runtime metric for dedicated hardware * @param name A metric name to request * @return A metric value corresponding to metric key */ - virtual Parameter GetMetric(const std::string& name) const; + virtual ov::Any GetMetric(const std::string& name) const; /** * @brief Raises the flag that model was loaded from cache diff --git a/src/inference/dev_api/cpp_interfaces/interface/ie_iplugin_internal.hpp b/src/inference/dev_api/cpp_interfaces/interface/ie_iplugin_internal.hpp index cafff6d53bc905..01b9dfc76ed4f0 100644 --- a/src/inference/dev_api/cpp_interfaces/interface/ie_iplugin_internal.hpp +++ b/src/inference/dev_api/cpp_interfaces/interface/ie_iplugin_internal.hpp @@ -17,7 +17,6 @@ #include "blob_factory.hpp" #include "cpp/ie_cnn_network.h" #include "ie_input_info.hpp" -#include "ie_parameter.hpp" #include "openvino/core/extension.hpp" #include "openvino/runtime/iplugin.hpp" #include "openvino/runtime/so_ptr.hpp" @@ -204,7 +203,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(IInferencePlugi * @param options - configuration details for config * @return Value of config corresponding to config key */ - virtual Parameter GetConfig(const std::string& name, const std::map& options) const; + virtual ov::Any GetConfig(const std::string& name, const ov::AnyMap& options) const; /** * @brief Gets general runtime metric for dedicated hardware @@ -212,7 +211,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(IInferencePlugi * @param options - configuration details for metric * @return Metric value corresponding to metric key */ - virtual Parameter GetMetric(const std::string& name, const std::map& options) const; + virtual ov::Any GetMetric(const std::string& name, const ov::AnyMap& options) const; /** * @deprecated Use ImportNetwork(std::istream& networkModel, const std::map& config) diff --git a/src/inference/dev_api/ie_icore.hpp b/src/inference/dev_api/ie_icore.hpp index be2b85118de466..e0a612dc1dbfed 100644 --- a/src/inference/dev_api/ie_icore.hpp +++ b/src/inference/dev_api/ie_icore.hpp @@ -15,7 +15,6 @@ #include "cpp/ie_cnn_network.h" #include "cpp_interfaces/interface/ie_iexecutable_network_internal.hpp" -#include "ie_parameter.hpp" #include "openvino/runtime/icore.hpp" #include "openvino/runtime/properties.hpp" @@ -51,7 +50,7 @@ class ICore : public ov::ICore { * * @param network CNNNetwork object acquired from Core::ReadNetwork * @param deviceName Name of device to load network to - * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load + * @param config Optional map of pairs: (config name, config value) relevant only for this load * operation * @return An executable network reference */ @@ -68,7 +67,7 @@ class ICore : public ov::ICore { * @param modelStr String data of model * @param weights Model's weights * @param deviceName Name of device to load network to - * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load + * @param config Optional map of pairs: (config name, config value) relevant only for this load * operation * @param val Optional callback to perform validation of loaded CNNNetwork, if ReadNetwork is triggered * @return An executable network reference @@ -88,7 +87,7 @@ class ICore : public ov::ICore { * * @param modelPath Path to model * @param deviceName Name of device to load network to - * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load + * @param config Optional map of pairs: (config name, config value) relevant only for this load * operation * @param val Optional callback to perform validation of loaded CNNNetwork, if ReadNetwork is triggered * @return An executable network reference @@ -102,7 +101,7 @@ class ICore : public ov::ICore { * @brief Creates an executable network from a previously exported network * @param networkModel network model stream * @param deviceName Name of device load executable network on - * @param config Optional map of pairs: (config parameter name, config parameter value) relevant only for this load + * @param config Optional map of pairs: (config name, config value) relevant only for this load * operation* * @return An executable network reference */ @@ -115,7 +114,7 @@ class ICore : public ov::ICore { * * @param deviceName A name of a device to query * @param network Network object to query - * @param config Optional map of pairs: (config parameter name, config parameter value) + * @param config Optional map of pairs: (config name, config value) * @return An object containing a map of pairs a layer name -> a device name supporting this layer. */ virtual QueryNetworkResult QueryNetwork(const CNNNetwork& network, diff --git a/src/inference/include/ie/cpp/ie_executable_network.hpp b/src/inference/include/ie/cpp/ie_executable_network.hpp index 80ee0cbab45338..a5c33c142ac8f3 100644 --- a/src/inference/include/ie/cpp/ie_executable_network.hpp +++ b/src/inference/include/ie/cpp/ie_executable_network.hpp @@ -29,7 +29,6 @@ #include "cpp/ie_cnn_network.h" #include "cpp/ie_infer_request.hpp" #include "ie_iexecutable_network.hpp" -#include "ie_parameter.hpp" namespace ov { class Core; @@ -142,9 +141,9 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(ExecutableNetwo /** * @brief Sets configuration for current executable network * - * @param config Map of pairs: (config parameter name, config parameter value) + * @param config Map of pairs: (config name, config value) */ - void SetConfig(const std::map& config); + void SetConfig(const ov::AnyMap& config); /** @brief Gets configuration for current executable network. * @@ -155,9 +154,9 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(ExecutableNetwo * device. * * @param name config key, can be found in ie_plugin_config.hpp - * @return Configuration parameter value + * @return Configuration ov::Any value */ - Parameter GetConfig(const std::string& name) const; + ov::Any GetConfig(const std::string& name) const; /** * @brief Gets general runtime metric for an executable network. @@ -166,9 +165,9 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(ExecutableNetwo * which executable network is running or all other properties which cannot be changed dynamically. * * @param name metric name to request - * @return Metric parameter value + * @return Metric ov::Any value */ - Parameter GetMetric(const std::string& name) const; + ov::Any GetMetric(const std::string& name) const; /** * @brief Checks if current ExecutableNetwork object is not initialized diff --git a/src/inference/include/ie/ie_core.hpp b/src/inference/include/ie/ie_core.hpp index d8d2242d9f2060..d2488780f04ea1 100644 --- a/src/inference/include/ie/ie_core.hpp +++ b/src/inference/include/ie/ie_core.hpp @@ -235,7 +235,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(Core) { * @param name - config key. * @return Value of config corresponding to config key. */ - Parameter GetConfig(const std::string& deviceName, const std::string& name) const; + ov::Any GetConfig(const std::string& deviceName, const std::string& name) const; /** * @brief Gets general runtime metric for dedicated hardware. @@ -248,7 +248,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED INFERENCE_ENGINE_API_CLASS(Core) { * @param options - optional parameters to get a metric value * @return Metric value corresponding to metric key. */ - Parameter GetMetric(const std::string& deviceName, const std::string& name, const ParamMap& options = {}) const; + ov::Any GetMetric(const std::string& deviceName, const std::string& name, const ov::AnyMap& options = {}) const; /** * @brief Returns devices available for neural networks inference diff --git a/src/inference/include/ie/ie_iexecutable_network.hpp b/src/inference/include/ie/ie_iexecutable_network.hpp index 989167885c5d9d..b7c9b0736f495d 100644 --- a/src/inference/include/ie/ie_iexecutable_network.hpp +++ b/src/inference/include/ie/ie_iexecutable_network.hpp @@ -29,7 +29,6 @@ #include "ie_icnn_network.hpp" #include "ie_iinfer_request.hpp" #include "ie_input_info.hpp" -#include "ie_parameter.hpp" namespace InferenceEngine { @@ -123,11 +122,11 @@ class INFERENCE_ENGINE_1_0_DEPRECATED IExecutableNetwork : public std::enable_sh /** * @brief Sets configuration for current executable network * - * @param config Map of pairs: (config parameter name, config parameter value) + * @param config Map of pairs: (config name, config value) * @param resp Pointer to the response message that holds a description of an error if any occurred * @return code of the operation. InferenceEngine::OK if succeeded */ - virtual StatusCode SetConfig(const std::map& config, ResponseDesc* resp) noexcept = 0; + virtual StatusCode SetConfig(const ov::AnyMap& config, ResponseDesc* resp) noexcept = 0; /** @brief Gets configuration for current executable network. * @@ -142,7 +141,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED IExecutableNetwork : public std::enable_sh * @param resp Pointer to the response message that holds a description of an error if any occurred * @return code of the operation. InferenceEngine::OK if succeeded */ - virtual StatusCode GetConfig(const std::string& name, Parameter& result, ResponseDesc* resp) const noexcept = 0; + virtual StatusCode GetConfig(const std::string& name, ov::Any& result, ResponseDesc* resp) const noexcept = 0; /** * @brief Gets general runtime metric for an executable network. @@ -155,7 +154,7 @@ class INFERENCE_ENGINE_1_0_DEPRECATED IExecutableNetwork : public std::enable_sh * @param resp Pointer to the response message that holds a description of an error if any occurred * @return code of the operation. InferenceEngine::OK if succeeded */ - virtual StatusCode GetMetric(const std::string& name, Parameter& result, ResponseDesc* resp) const noexcept = 0; + virtual StatusCode GetMetric(const std::string& name, ov::Any& result, ResponseDesc* resp) const noexcept = 0; protected: virtual ~IExecutableNetwork() = default; diff --git a/src/inference/include/ie/ie_parameter.hpp b/src/inference/include/ie/ie_parameter.hpp deleted file mode 100644 index 5141f5ab931d40..00000000000000 --- a/src/inference/include/ie/ie_parameter.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief A header file for the Parameter class - * @file ie_parameter.hpp - */ -#pragma once - -#if !defined(IN_OV_COMPONENT) && !defined(IE_LEGACY_HEADER_INCLUDED) -# define IE_LEGACY_HEADER_INCLUDED -# ifdef _MSC_VER -# pragma message( \ - "The Inference Engine API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html") -# else -# warning("The Inference Engine API is deprecated and will be removed in the 2024.0 release. For instructions on transitioning to the new API, please refer to https://docs.openvino.ai/latest/openvino_2_0_transition_guide.html") -# endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ie_blob.h" -#include "openvino/core/any.hpp" -#include "openvino/core/except.hpp" - -namespace InferenceEngine { - -/** - * @brief Alias for type that can store any value - */ -using Parameter = ov::Any; -using ParamMap = ov::AnyMap; - -} // namespace InferenceEngine diff --git a/src/inference/src/any_copy.hpp b/src/inference/src/any_copy.hpp index 9af954f25a048c..f9121035edd028 100644 --- a/src/inference/src/any_copy.hpp +++ b/src/inference/src/any_copy.hpp @@ -4,7 +4,6 @@ #pragma once -#include #include #include #include diff --git a/src/inference/src/cpp/ie_executable_network.cpp b/src/inference/src/cpp/ie_executable_network.cpp index 63b74987546228..4f0f88febf2817 100644 --- a/src/inference/src/cpp/ie_executable_network.cpp +++ b/src/inference/src/cpp/ie_executable_network.cpp @@ -80,15 +80,15 @@ CNNNetwork ExecutableNetwork::GetExecGraphInfo() { EXEC_NET_CALL_STATEMENT(return CNNNetwork{_impl->GetExecGraphInfo()}); } -void ExecutableNetwork::SetConfig(const std::map& config) { +void ExecutableNetwork::SetConfig(const ov::AnyMap& config) { EXEC_NET_CALL_STATEMENT(_impl->SetConfig(config)); } -Parameter ExecutableNetwork::GetConfig(const std::string& name) const { +ov::Any ExecutableNetwork::GetConfig(const std::string& name) const { EXEC_NET_CALL_STATEMENT(return {_impl->GetConfig(name), {_so}}); } -Parameter ExecutableNetwork::GetMetric(const std::string& name) const { +ov::Any ExecutableNetwork::GetMetric(const std::string& name) const { EXEC_NET_CALL_STATEMENT(return {_impl->GetMetric(name), {_so}}); } diff --git a/src/inference/src/cpp/ie_executable_network_base.hpp b/src/inference/src/cpp/ie_executable_network_base.hpp index f1a5cffa38b0f6..d62e8fc3ee2eb9 100644 --- a/src/inference/src/cpp/ie_executable_network_base.hpp +++ b/src/inference/src/cpp/ie_executable_network_base.hpp @@ -68,15 +68,15 @@ class ExecutableNetworkBase : public IExecutableNetwork { TO_STATUS(graphPtr = CNNNetwork{_impl->GetExecGraphInfo()}); } - StatusCode SetConfig(const std::map& config, ResponseDesc* resp) noexcept override { + StatusCode SetConfig(const ov::AnyMap& config, ResponseDesc* resp) noexcept override { TO_STATUS(_impl->SetConfig(config)); } - StatusCode GetConfig(const std::string& name, Parameter& result, ResponseDesc* resp) const noexcept override { + StatusCode GetConfig(const std::string& name, ov::Any& result, ResponseDesc* resp) const noexcept override { TO_STATUS(result = _impl->GetConfig(name)); } - StatusCode GetMetric(const std::string& name, Parameter& result, ResponseDesc* resp) const noexcept override { + StatusCode GetMetric(const std::string& name, ov::Any& result, ResponseDesc* resp) const noexcept override { TO_STATUS(result = _impl->GetMetric(name)); } diff --git a/src/inference/src/cpp_interfaces/interface/ie_iexecutable_network_internal.cpp b/src/inference/src/cpp_interfaces/interface/ie_iexecutable_network_internal.cpp index 967765102002f7..33b85be225558a 100644 --- a/src/inference/src/cpp_interfaces/interface/ie_iexecutable_network_internal.cpp +++ b/src/inference/src/cpp_interfaces/interface/ie_iexecutable_network_internal.cpp @@ -15,7 +15,6 @@ #include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include "ie_icore.hpp" #include "ie_ngraph_utils.hpp" -#include "ie_parameter.hpp" #include "openvino/core/node.hpp" namespace InferenceEngine { @@ -96,15 +95,15 @@ std::shared_ptr IExecutableNetworkInternal::GetPointerToSo() { return _so; } -void IExecutableNetworkInternal::SetConfig(const std::map&) { +void IExecutableNetworkInternal::SetConfig(const ov::AnyMap&) { IE_THROW(NotImplemented); } -Parameter IExecutableNetworkInternal::GetConfig(const std::string&) const { +ov::Any IExecutableNetworkInternal::GetConfig(const std::string&) const { IE_THROW(NotImplemented); } -Parameter IExecutableNetworkInternal::GetMetric(const std::string&) const { +ov::Any IExecutableNetworkInternal::GetMetric(const std::string&) const { IE_THROW(NotImplemented); } diff --git a/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp b/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp index 08d22fd16ab2f8..e9959917224d11 100644 --- a/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp +++ b/src/inference/src/cpp_interfaces/interface/ie_iplugin_internal.cpp @@ -28,7 +28,6 @@ #include "ie_input_info.hpp" #include "ie_memcpy.h" #include "ie_ngraph_utils.hpp" -#include "ie_parameter.hpp" #include "openvino/core/deprecated.hpp" #include "openvino/core/except.hpp" #include "openvino/core/model.hpp" @@ -183,11 +182,11 @@ void IInferencePlugin::SetProperties(const ov::AnyMap& config) { SetConfig(any_copy(config)); } -Parameter IInferencePlugin::GetConfig(const std::string&, const std::map&) const { +ov::Any IInferencePlugin::GetConfig(const std::string&, const ov::AnyMap&) const { IE_THROW(NotImplemented); } -Parameter IInferencePlugin::GetMetric(const std::string&, const std::map&) const { +ov::Any IInferencePlugin::GetMetric(const std::string&, const ov::AnyMap&) const { IE_THROW(NotImplemented); } diff --git a/src/inference/src/dev/converter_utils.cpp b/src/inference/src/dev/converter_utils.cpp index 6aca89c09c6e8e..f2201b2d752dae 100644 --- a/src/inference/src/dev/converter_utils.cpp +++ b/src/inference/src/dev/converter_utils.cpp @@ -257,15 +257,11 @@ class IInferencePluginWrapper : public InferenceEngine::IInferencePlugin { m_plugin->set_property(config); } - InferenceEngine::Parameter GetConfig( - const std::string& name, - const std::map& options) const override { + ov::Any GetConfig(const std::string& name, const ov::AnyMap& options) const override { return m_plugin->get_property(name, options); } - InferenceEngine::Parameter GetMetric( - const std::string& name, - const std::map& options) const override { + ov::Any GetMetric(const std::string& name, const ov::AnyMap& options) const override { return m_plugin->get_property(name, options); } @@ -373,15 +369,15 @@ class IExecutableNetworkWrapper : public InferenceEngine::IExecutableNetworkInte return m_model->get_runtime_model()->clone(); } - void SetConfig(const std::map& config) override { + void SetConfig(const ov::AnyMap& config) override { m_model->set_property(config); } - InferenceEngine::Parameter GetConfig(const std::string& name) const override { + ov::Any GetConfig(const std::string& name) const override { return m_model->get_property(name); } - InferenceEngine::Parameter GetMetric(const std::string& name) const override { + ov::Any GetMetric(const std::string& name) const override { // Add legacy supported properties if (METRIC_KEY(SUPPORTED_METRICS) == name || METRIC_KEY(SUPPORTED_CONFIG_KEYS) == name) { try { diff --git a/src/inference/src/ie_common.cpp b/src/inference/src/ie_common.cpp index 702fe9641c8b4a..b15e49a9d8b371 100644 --- a/src/inference/src/ie_common.cpp +++ b/src/inference/src/ie_common.cpp @@ -12,7 +12,6 @@ #include #include "ie_blob.h" -#include "ie_parameter.hpp" #include "openvino/core/except.hpp" #include "openvino/runtime/exception.hpp" diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 49b64ed72114a7..83bde0a46bd099 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -275,7 +275,7 @@ void Core::SetConfig(const std::map& config, const std } } -Parameter Core::GetConfig(const std::string& deviceName, const std::string& name) const { +ov::Any Core::GetConfig(const std::string& deviceName, const std::string& name) const { // HETERO case { if (deviceName.find("HETERO:") == 0) { @@ -311,7 +311,7 @@ Parameter Core::GetConfig(const std::string& deviceName, const std::string& name } } -Parameter Core::GetMetric(const std::string& deviceName, const std::string& name, const ParamMap& options) const { +ov::Any Core::GetMetric(const std::string& deviceName, const std::string& name, const ov::AnyMap& options) const { try { return _impl->GetMetric(deviceName, name, options); } catch (const ov::Exception& ex) { diff --git a/src/plugins/auto_batch/tests/functional/behavior/ov_plugin/auto_batching_tests.cpp b/src/plugins/auto_batch/tests/functional/behavior/ov_plugin/auto_batching_tests.cpp index 7bf21f888e0153..1cdb6ecfb85934 100644 --- a/src/plugins/auto_batch/tests/functional/behavior/ov_plugin/auto_batching_tests.cpp +++ b/src/plugins/auto_batch/tests/functional/behavior/ov_plugin/auto_batching_tests.cpp @@ -3,6 +3,7 @@ // #include "behavior/ov_plugin/auto_batching_tests.hpp" + #include "behavior/compiled_model/properties.hpp" using namespace ov::test::behavior; diff --git a/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp b/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp index 501ddc34bd6ccf..e6a8143a619ba9 100644 --- a/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp +++ b/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iexecutable_network_internal.hpp @@ -25,9 +25,9 @@ class MockIExecutableNetworkInternal : public IExecutableNetworkInternal { void Export(std::ostream&) override{}; MOCK_METHOD0(GetExecGraphInfo, std::shared_ptr(void)); - MOCK_METHOD1(SetConfig, void(const std::map& config)); - MOCK_CONST_METHOD1(GetConfig, Parameter(const std::string& name)); - MOCK_CONST_METHOD1(GetMetric, Parameter(const std::string& name)); + MOCK_METHOD1(SetConfig, void(const ov::AnyMap& config)); + MOCK_CONST_METHOD1(GetConfig, ov::Any(const std::string& name)); + MOCK_CONST_METHOD1(GetMetric, ov::Any(const std::string& name)); void WrapOstreamExport(std::ostream& networkModel) { IExecutableNetworkInternal::Export(networkModel); } diff --git a/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp b/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp index c5df4baefb87dd..e1aa040aad5523 100644 --- a/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp +++ b/src/tests/test_utils/unit_test_utils/mocks/cpp_interfaces/interface/mock_iinference_plugin.hpp @@ -33,12 +33,8 @@ class MockIInferencePlugin : public InferenceEngine::IInferencePlugin { MOCK_METHOD(void, SetCore, (std::weak_ptr), (noexcept)); MOCK_METHOD(std::shared_ptr, GetCore, (), (const, noexcept)); MOCK_METHOD(bool, IsNewAPI, (), (const, noexcept)); - MOCK_CONST_METHOD2(GetConfig, - InferenceEngine::Parameter(const std::string&, - const std::map&)); - MOCK_CONST_METHOD2(GetMetric, - InferenceEngine::Parameter(const std::string&, - const std::map&)); + MOCK_CONST_METHOD2(GetConfig, ov::Any(const std::string&, const ov::AnyMap&)); + MOCK_CONST_METHOD2(GetMetric, ov::Any(const std::string&, const ov::AnyMap&)); MOCK_METHOD2( ImportNetwork, std::shared_ptr(std::istream&, diff --git a/src/tests/test_utils/unit_test_utils/mocks/mock_iexecutable_network.hpp b/src/tests/test_utils/unit_test_utils/mocks/mock_iexecutable_network.hpp index c3a2b428acbfe2..ba38ce6960fe72 100644 --- a/src/tests/test_utils/unit_test_utils/mocks/mock_iexecutable_network.hpp +++ b/src/tests/test_utils/unit_test_utils/mocks/mock_iexecutable_network.hpp @@ -28,17 +28,14 @@ class MockIExecutableNetwork : public IExecutableNetwork { MOCK_METHOD(StatusCode, Export, (const std::string&, ResponseDesc*), (noexcept)); MOCK_METHOD(StatusCode, Export, (std::ostream&, ResponseDesc*), (noexcept)); MOCK_METHOD(StatusCode, GetExecGraphInfo, (ICNNNetwork::Ptr&, ResponseDesc*), (noexcept)); - MOCK_METHOD(StatusCode, - SetConfig, - ((const std::map& config), ResponseDesc* resp), - (noexcept)); + MOCK_METHOD(StatusCode, SetConfig, ((const ov::AnyMap& config), ResponseDesc* resp), (noexcept)); MOCK_METHOD(StatusCode, GetConfig, - (const std::string& name, Parameter& result, ResponseDesc* resp), + (const std::string& name, ov::Any& result, ResponseDesc* resp), (const, noexcept)); MOCK_METHOD(StatusCode, GetMetric, - (const std::string& name, Parameter& result, ResponseDesc* resp), + (const std::string& name, ov::Any& result, ResponseDesc* resp), (const, noexcept)); }; From 329489c5388f5ba9658aa97ff6b42954d9d9a930 Mon Sep 17 00:00:00 2001 From: Vishniakov Nikolai Date: Tue, 30 Jan 2024 08:14:45 +0100 Subject: [PATCH 14/27] [JS OV] Extend js bindings supported platforms (#21995) * Fix npm variables list * Fix typo * Provide instructions for js bindings arm compilation * Remove extra spaces * Set optimal scope of flags for both archs * Support windows compilation * Extend .gitignore * Unify compilation instruction * Exclude async infer from windows build * Enable js on windows * Activate js validation in windows workflow * Fix precision --- .github/workflows/windows.yml | 3 +- cmake/features.cmake | 3 +- src/bindings/js/node/.gitignore | 4 + src/bindings/js/node/CMakeLists.txt | 17 +- src/bindings/js/node/README.md | 21 ++- .../js/node/include/infer_request.hpp | 4 + src/bindings/js/node/src/compiled_model.cpp | 4 +- src/bindings/js/node/src/core_wrap.cpp | 2 +- src/bindings/js/node/src/helper.cpp | 16 +- src/bindings/js/node/src/infer_request.cpp | 11 +- src/bindings/js/node/src/model_wrap.cpp | 4 +- .../js/node/tests/infer_request.test.js | 54 ++++--- src/bindings/js/node/thirdparty/node-lib.def | 147 ++++++++++++++++++ .../js/node/thirdparty/win_delay_load_hook.cc | 52 +++++++ 14 files changed, 294 insertions(+), 48 deletions(-) create mode 100644 src/bindings/js/node/thirdparty/node-lib.def create mode 100644 src/bindings/js/node/thirdparty/win_delay_load_hook.cc diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 4f76bbce04faba..c063329a7f11c9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -201,8 +201,7 @@ jobs: cmake --build ${{ env.BUILD_DIR }} --parallel --config ${{ env.CMAKE_BUILD_TYPE }} --verbose - name: CMake configure, build and install - OpenVINO JS API - if: ${{ 'false' }} # 128689 - # if: fromJSON(needs.smart_ci.outputs.affected_components).JS_API + if: fromJSON(needs.smart_ci.outputs.affected_components).JS_API run: cmake -DCPACK_GENERATOR=NPM -DENABLE_SYSTEM_TBB=OFF -UTBB* -S ${{ env.OPENVINO_REPO }} -B ${{ env.BUILD_DIR }} diff --git a/cmake/features.cmake b/cmake/features.cmake index aadd1db976e3d0..9e4e507600e1af 100644 --- a/cmake/features.cmake +++ b/cmake/features.cmake @@ -177,8 +177,7 @@ ov_dependent_option (ENABLE_SYSTEM_SNAPPY "Enables use of system version of Snap ov_dependent_option (ENABLE_PYTHON_PACKAGING "Enables packaging of Python API in APT / YUM" OFF "ENABLE_PYTHON;UNIX" OFF) -ov_dependent_option (ENABLE_JS "Enables JS API building" ON - "NOT WIN32" OFF) +ov_option(ENABLE_JS "Enables JS API building" ON) ov_option(ENABLE_OPENVINO_DEBUG "Enable output for OPENVINO_DEBUG statements" OFF) diff --git a/src/bindings/js/node/.gitignore b/src/bindings/js/node/.gitignore index ad4dbf11d8e0b5..6bbca841fe2db9 100644 --- a/src/bindings/js/node/.gitignore +++ b/src/bindings/js/node/.gitignore @@ -3,3 +3,7 @@ dist build types ov_runtime + + +*.exp +*.lib diff --git a/src/bindings/js/node/CMakeLists.txt b/src/bindings/js/node/CMakeLists.txt index 1bf6eca9ee8501..d4e01834749e99 100644 --- a/src/bindings/js/node/CMakeLists.txt +++ b/src/bindings/js/node/CMakeLists.txt @@ -12,6 +12,14 @@ if(CMAKE_COMPILER_IS_GNUCXX AND LINUX AND CMAKE_CXX_COMPILER_VERSION VERSION_LES return() endif() +if(WIN32) + set(CMAKE_JS_LIB ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/node.lib) + set(CMAKE_JS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/win_delay_load_hook.cc) + + set(CMAKE_JS_NODELIB_DEF ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/node-lib.def) + set(CMAKE_JS_NODELIB_TARGET ${CMAKE_JS_LIB}) +endif() + cmake_minimum_required(VERSION 3.14) project(ov_node_addon) @@ -57,6 +65,8 @@ add_library(${PROJECT_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/addon.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/element_type.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/partial_shape_wrap.cpp + + ${CMAKE_JS_SRC} ) target_include_directories(${PROJECT_NAME} PRIVATE @@ -65,7 +75,12 @@ target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) -target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime) +target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${CMAKE_JS_LIB}) + +if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET) + # Generate node.lib + execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS}) +endif() if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG) ov_add_compiler_flags(-Wno-missing-declarations) diff --git a/src/bindings/js/node/README.md b/src/bindings/js/node/README.md index f9ba10c4eff70f..544eb7e60f27f3 100644 --- a/src/bindings/js/node/README.md +++ b/src/bindings/js/node/README.md @@ -11,8 +11,25 @@ - Make sure that all submodules are updated `git submodule update --init --recursive` - Create build dir `mkdir build && cd build` -- To get binaries for openvinojs-node package run: - `cmake -DCPACK_GENERATOR=NPM -DENABLE_SYSTEM_TBB=OFF -UTBB* -DCMAKE_INSTALL_PREFIX=../src/bindings/js/node/bin ..` +- To configure binaries building run: + + ### Linux x86, Linux arm, Mac x86, Mac arm + ```bash + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_FASTER_BUILD=ON \ + -DCPACK_GENERATOR=NPM \ + -DENABLE_SYSTEM_TBB=OFF -UTBB* \ + -DENABLE_TESTS=OFF \ + -DENABLE_SAMPLES=OFF \ + -DENABLE_WHEEL=OFF \ + -DENABLE_PYTHON=OFF \ + -DENABLE_INTEL_GPU=OFF \ + -DCMAKE_INSTALL_PREFIX=../src/bindings/js/node/bin \ + .. + ``` + +- To get binaries for openvinojs-node package run compilation: `make --jobs=$(nproc --all) install` - Go to npm package folder `cd ../src/bindings/js/node` - Now you can install dependencies packages and transpile ts to js code. Run `npm install` diff --git a/src/bindings/js/node/include/infer_request.hpp b/src/bindings/js/node/include/infer_request.hpp index 1aaee2107af29e..f39489b23ef4ad 100644 --- a/src/bindings/js/node/include/infer_request.hpp +++ b/src/bindings/js/node/include/infer_request.hpp @@ -3,6 +3,7 @@ #pragma once #include + #include #include "openvino/runtime/infer_request.hpp" @@ -101,8 +102,11 @@ class InferRequestWrap : public Napi::ObjectWrap { /** @brief Checks incoming Napi::Value and calls overloaded infer() method */ Napi::Value infer_dispatch(const Napi::CallbackInfo& info); +// 128760 +#ifndef _WIN32 /** @brief Checks incoming Napi::Value and asynchronously returns the result of inference. */ Napi::Value infer_async(const Napi::CallbackInfo& info); +#endif /** @brief Infers specified inputs in synchronous mode. * @param inputs An object with a collection of pairs key (input_name) and a value (tensor, tensor's data) diff --git a/src/bindings/js/node/src/compiled_model.cpp b/src/bindings/js/node/src/compiled_model.cpp index 82deba2a7d93ea..070d397b3696fc 100644 --- a/src/bindings/js/node/src/compiled_model.cpp +++ b/src/bindings/js/node/src/compiled_model.cpp @@ -70,7 +70,7 @@ Napi::Value CompiledModelWrap::get_outputs(const Napi::CallbackInfo& info) { auto cm_outputs = _compiled_model.outputs(); // Output Napi::Array js_outputs = Napi::Array::New(info.Env(), cm_outputs.size()); - size_t i = 0; + uint32_t i = 0; for (auto& out : cm_outputs) js_outputs[i++] = Output::wrap(info.Env(), out); @@ -104,7 +104,7 @@ Napi::Value CompiledModelWrap::get_inputs(const Napi::CallbackInfo& info) { auto cm_inputs = _compiled_model.inputs(); // Output Napi::Array js_inputs = Napi::Array::New(info.Env(), cm_inputs.size()); - size_t i = 0; + uint32_t i = 0; for (auto& out : cm_inputs) js_inputs[i++] = Output::wrap(info.Env(), out); diff --git a/src/bindings/js/node/src/core_wrap.cpp b/src/bindings/js/node/src/core_wrap.cpp index 1378d2e59ca0ac..eb139572b87731 100644 --- a/src/bindings/js/node/src/core_wrap.cpp +++ b/src/bindings/js/node/src/core_wrap.cpp @@ -221,7 +221,7 @@ Napi::Value CoreWrap::get_available_devices(const Napi::CallbackInfo& info) { const auto& devices = _core.get_available_devices(); Napi::Array js_devices = Napi::Array::New(info.Env(), devices.size()); - size_t i = 0; + uint32_t i = 0; for (const auto& dev : devices) js_devices[i++] = dev; diff --git a/src/bindings/js/node/src/helper.cpp b/src/bindings/js/node/src/helper.cpp index 3484c3b1b8b91b..02a51aef5e7339 100644 --- a/src/bindings/js/node/src/helper.cpp +++ b/src/bindings/js/node/src/helper.cpp @@ -67,7 +67,7 @@ std::vector js_to_cpp>(const Napi::CallbackInfo& inf std::vector nativeArray; - for (size_t i = 0; i < arrayLength; ++i) { + for (uint32_t i = 0; i < arrayLength; ++i) { Napi::Value arrayItem = array[i]; if (!arrayItem.IsNumber()) { OPENVINO_THROW(std::string("Passed array must contain only numbers.")); @@ -107,7 +107,7 @@ std::unordered_set js_to_cpp>( std::unordered_set nativeArray; - for (size_t i = 0; i < arrayLength; ++i) { + for (uint32_t i = 0; i < arrayLength; ++i) { Napi::Value arrayItem = array[i]; if (!arrayItem.IsString()) { OPENVINO_THROW(std::string("Passed array must contain only strings.")); @@ -199,7 +199,7 @@ std::map js_to_cpp>( const auto& config = elem.ToObject(); const auto& keys = config.GetPropertyNames(); - for (size_t i = 0; i < keys.Length(); ++i) { + for (uint32_t i = 0; i < keys.Length(); ++i) { const std::string& option = static_cast(keys[i]).ToString(); properties_to_cpp[option] = js_to_cpp(config.Get(option), {napi_string}); } @@ -216,7 +216,7 @@ Napi::String cpp_to_js(const Napi::CallbackIn template <> Napi::Array cpp_to_js(const Napi::CallbackInfo& info, const ov::Shape shape) { auto arr = Napi::Array::New(info.Env(), shape.size()); - for (size_t i = 0; i < shape.size(); ++i) + for (uint32_t i = 0; i < shape.size(); ++i) arr[i] = shape[i]; return arr; } @@ -226,7 +226,7 @@ Napi::Array cpp_to_js(const Napi::CallbackInfo& i size_t size = shape.size(); Napi::Array dimensions = Napi::Array::New(info.Env(), size); - for (size_t i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { ov::Dimension dim = shape[i]; if (dim.is_static()) { @@ -254,7 +254,7 @@ Napi::Array cpp_to_js(const Napi::CallbackInfo& info // Indexes looks wierd, but clear assignment, // like: interval[0] = value doesn't work here - size_t indexes[] = {0, 1}; + uint32_t indexes[] = {0, 1}; interval[indexes[0]] = dim.get_min_length(); interval[indexes[1]] = dim.get_max_length(); @@ -270,13 +270,13 @@ ov::TensorVector parse_input_data(const Napi::Value& input) { ov::TensorVector parsed_input; if (input.IsArray()) { auto inputs = input.As(); - for (size_t i = 0; i < inputs.Length(); ++i) { + for (uint32_t i = 0; i < inputs.Length(); ++i) { parsed_input.emplace_back(cast_to_tensor(static_cast(inputs[i]))); } } else if (input.IsObject()) { auto inputs = input.ToObject(); const auto& keys = inputs.GetPropertyNames(); - for (size_t i = 0; i < keys.Length(); ++i) { + for (uint32_t i = 0; i < keys.Length(); ++i) { auto value = inputs.Get(static_cast(keys[i]).ToString().Utf8Value()); parsed_input.emplace_back(cast_to_tensor(static_cast(value))); } diff --git a/src/bindings/js/node/src/infer_request.cpp b/src/bindings/js/node/src/infer_request.cpp index 2a61411fb8d420..427c47d853ff48 100644 --- a/src/bindings/js/node/src/infer_request.cpp +++ b/src/bindings/js/node/src/infer_request.cpp @@ -30,7 +30,10 @@ Napi::Function InferRequestWrap::get_class(Napi::Env env) { InstanceMethod("getInputTensor", &InferRequestWrap::get_input_tensor), InstanceMethod("getOutputTensor", &InferRequestWrap::get_output_tensor), InstanceMethod("infer", &InferRequestWrap::infer_dispatch), + // 128760 +#ifndef _WIN32 InstanceMethod("inferAsync", &InferRequestWrap::infer_async), +#endif InstanceMethod("getCompiledModel", &InferRequestWrap::get_compiled_model), }); } @@ -171,7 +174,7 @@ Napi::Value InferRequestWrap::infer_dispatch(const Napi::CallbackInfo& info) { } void InferRequestWrap::infer(const Napi::Array& inputs) { - for (size_t i = 0; i < inputs.Length(); ++i) { + for (uint32_t i = 0; i < inputs.Length(); ++i) { auto tensor = value_to_tensor(inputs[i], _infer_request, i); _infer_request.set_input_tensor(i, tensor); } @@ -181,7 +184,7 @@ void InferRequestWrap::infer(const Napi::Array& inputs) { void InferRequestWrap::infer(const Napi::Object& inputs) { const auto& keys = inputs.GetPropertyNames(); - for (size_t i = 0; i < keys.Length(); ++i) { + for (uint32_t i = 0; i < keys.Length(); ++i) { auto input_name = static_cast(keys[i]).ToString().Utf8Value(); auto value = inputs.Get(input_name); auto tensor = value_to_tensor(value, _infer_request, input_name); @@ -194,7 +197,8 @@ void InferRequestWrap::infer(const Napi::Object& inputs) { Napi::Value InferRequestWrap::get_compiled_model(const Napi::CallbackInfo& info) { return CompiledModelWrap::wrap(info.Env(), _infer_request.get_compiled_model()); } - +// 128760 +#ifndef _WIN32 void FinalizerCallback(Napi::Env env, void* finalizeData, TsfnContext* context) { context->native_thread.join(); delete context; @@ -256,3 +260,4 @@ Napi::Value InferRequestWrap::infer_async(const Napi::CallbackInfo& info) { context->native_thread = std::thread(performInferenceThread, context); return context->deferred.Promise(); } +#endif diff --git a/src/bindings/js/node/src/model_wrap.cpp b/src/bindings/js/node/src/model_wrap.cpp index 9ba601cc728daa..35c41eb4432dc5 100644 --- a/src/bindings/js/node/src/model_wrap.cpp +++ b/src/bindings/js/node/src/model_wrap.cpp @@ -99,7 +99,7 @@ Napi::Value ModelWrap::get_inputs(const Napi::CallbackInfo& info) { auto cm_inputs = _model->inputs(); // Output Napi::Array js_inputs = Napi::Array::New(info.Env(), cm_inputs.size()); - size_t i = 0; + uint32_t i = 0; for (auto& input : cm_inputs) js_inputs[i++] = Output::wrap(info.Env(), input); @@ -110,7 +110,7 @@ Napi::Value ModelWrap::get_outputs(const Napi::CallbackInfo& info) { auto cm_outputs = _model->outputs(); // Output Napi::Array js_outputs = Napi::Array::New(info.Env(), cm_outputs.size()); - size_t i = 0; + uint32_t i = 0; for (auto& out : cm_outputs) js_outputs[i++] = Output::wrap(info.Env(), out); diff --git a/src/bindings/js/node/tests/infer_request.test.js b/src/bindings/js/node/tests/infer_request.test.js index 513a2a3324bcbf..159b34f938f6e2 100644 --- a/src/bindings/js/node/tests/infer_request.test.js +++ b/src/bindings/js/node/tests/infer_request.test.js @@ -2,6 +2,7 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 +const os = require('node:os'); const { addon: ov } = require('..'); const assert = require('assert'); const { describe, it } = require('node:test'); @@ -78,35 +79,38 @@ describe('InferRequest', () => { }); }); - it('Test inferAsync(inputData: { [inputName: string]: Tensor })', () => { - inferRequestAsync.inferAsync({ data: tensor }).then(result => { - assert.ok(result['fc_out'] instanceof ov.Tensor); - assert.deepStrictEqual(Object.keys(result), ['fc_out']); - assert.deepStrictEqual(result['fc_out'].data.length, 10);} - ); - }); + // 128760 + if (os.platform() !== 'win32') { + it('Test inferAsync(inputData: { [inputName: string]: Tensor })', () => { + inferRequestAsync.inferAsync({ data: tensor }).then(result => { + assert.ok(result['fc_out'] instanceof ov.Tensor); + assert.deepStrictEqual(Object.keys(result), ['fc_out']); + assert.deepStrictEqual(result['fc_out'].data.length, 10);} + ); + }); - it('Test inferAsync(inputData: Tensor[])', () => { - inferRequestAsync.inferAsync([ tensor ]).then(result => { - assert.ok(result['fc_out'] instanceof ov.Tensor); - assert.deepStrictEqual(Object.keys(result), ['fc_out']); - assert.deepStrictEqual(result['fc_out'].data.length, 10); + it('Test inferAsync(inputData: Tensor[])', () => { + inferRequestAsync.inferAsync([ tensor ]).then(result => { + assert.ok(result['fc_out'] instanceof ov.Tensor); + assert.deepStrictEqual(Object.keys(result), ['fc_out']); + assert.deepStrictEqual(result['fc_out'].data.length, 10); + }); }); - }); - it('Test inferAsync([data]) throws: Cannot create a tensor from the passed Napi::Value.', () => { - assert.throws( - () => inferRequestAsync.inferAsync(['string']).then(), - /Cannot create a tensor from the passed Napi::Value./ - ); - }); + it('Test inferAsync([data]) throws: Cannot create a tensor from the passed Napi::Value.', () => { + assert.throws( + () => inferRequestAsync.inferAsync(['string']).then(), + /Cannot create a tensor from the passed Napi::Value./ + ); + }); - it('Test inferAsync({ data: "string"}) throws: Cannot create a tensor from the passed Napi::Value.', () => { - assert.throws( - () => inferRequestAsync.inferAsync({data: 'string'}).then(), - /Cannot create a tensor from the passed Napi::Value./ - ); - }); + it('Test inferAsync({ data: "string"}) throws: Cannot create a tensor from the passed Napi::Value.', () => { + assert.throws( + () => inferRequestAsync.inferAsync({data: 'string'}).then(), + /Cannot create a tensor from the passed Napi::Value./ + ); + }); + } it('Test setInputTensor(tensor)', () => { inferRequest.setInputTensor(tensor); diff --git a/src/bindings/js/node/thirdparty/node-lib.def b/src/bindings/js/node/thirdparty/node-lib.def new file mode 100644 index 00000000000000..8d46bbec841109 --- /dev/null +++ b/src/bindings/js/node/thirdparty/node-lib.def @@ -0,0 +1,147 @@ +NAME NODE.EXE +EXPORTS +napi_async_destroy +napi_async_init +napi_cancel_async_work +napi_create_async_work +napi_create_buffer +napi_create_buffer_copy +napi_create_external_buffer +napi_delete_async_work +napi_fatal_error +napi_get_buffer_info +napi_get_node_version +napi_is_buffer +napi_make_callback +napi_module_register +napi_queue_async_work +napi_adjust_external_memory +napi_call_function +napi_close_escapable_handle_scope +napi_close_handle_scope +napi_coerce_to_bool +napi_coerce_to_number +napi_coerce_to_object +napi_coerce_to_string +napi_create_array +napi_create_array_with_length +napi_create_arraybuffer +napi_create_dataview +napi_create_double +napi_create_error +napi_create_external +napi_create_external_arraybuffer +napi_create_function +napi_create_int32 +napi_create_int64 +napi_create_object +napi_create_promise +napi_create_range_error +napi_create_reference +napi_create_string_latin1 +napi_create_string_utf16 +napi_create_string_utf8 +napi_create_symbol +napi_create_type_error +napi_create_typedarray +napi_create_uint32 +napi_define_class +napi_define_properties +napi_delete_element +napi_delete_property +napi_delete_reference +napi_escape_handle +napi_get_and_clear_last_exception +napi_get_array_length +napi_get_arraybuffer_info +napi_get_boolean +napi_get_cb_info +napi_get_dataview_info +napi_get_element +napi_get_global +napi_get_last_error_info +napi_get_named_property +napi_get_new_target +napi_get_null +napi_get_property +napi_get_property_names +napi_get_prototype +napi_get_reference_value +napi_get_typedarray_info +napi_get_undefined +napi_get_value_bool +napi_get_value_double +napi_get_value_external +napi_get_value_int32 +napi_get_value_int64 +napi_get_value_string_latin1 +napi_get_value_string_utf16 +napi_get_value_string_utf8 +napi_get_value_uint32 +napi_get_version +napi_has_element +napi_has_named_property +napi_has_own_property +napi_has_property +napi_instanceof +napi_is_array +napi_is_arraybuffer +napi_is_dataview +napi_is_error +napi_is_exception_pending +napi_is_promise +napi_is_typedarray +napi_new_instance +napi_open_escapable_handle_scope +napi_open_handle_scope +napi_reference_ref +napi_reference_unref +napi_reject_deferred +napi_remove_wrap +napi_resolve_deferred +napi_run_script +napi_set_element +napi_set_named_property +napi_set_property +napi_strict_equals +napi_throw +napi_throw_error +napi_throw_range_error +napi_throw_type_error +napi_typeof +napi_unwrap +napi_wrap +napi_get_uv_event_loop +napi_add_env_cleanup_hook +napi_close_callback_scope +napi_fatal_exception +napi_open_callback_scope +napi_remove_env_cleanup_hook +napi_acquire_threadsafe_function +napi_call_threadsafe_function +napi_create_threadsafe_function +napi_get_threadsafe_function_context +napi_ref_threadsafe_function +napi_release_threadsafe_function +napi_unref_threadsafe_function +napi_add_finalizer +napi_create_date +napi_get_date_value +napi_is_date +napi_create_bigint_int64 +napi_create_bigint_uint64 +napi_create_bigint_words +napi_get_all_property_names +napi_get_instance_data +napi_get_value_bigint_int64 +napi_get_value_bigint_uint64 +napi_get_value_bigint_words +napi_set_instance_data +napi_detach_arraybuffer +napi_is_detached_arraybuffer +napi_add_async_cleanup_hook +napi_remove_async_cleanup_hook +napi_check_object_type_tag +napi_object_freeze +napi_object_seal +napi_type_tag_object diff --git a/src/bindings/js/node/thirdparty/win_delay_load_hook.cc b/src/bindings/js/node/thirdparty/win_delay_load_hook.cc new file mode 100644 index 00000000000000..9e652fa4df06b3 --- /dev/null +++ b/src/bindings/js/node/thirdparty/win_delay_load_hook.cc @@ -0,0 +1,52 @@ +/* + * When this file is linked to a DLL, it sets up a delay-load hook that + * intervenes when the DLL is trying to load 'node.exe' or 'iojs.exe' + * dynamically. Instead of trying to locate the .exe file it'll just return + * a handle to the process image. + * + * This allows compiled addons to work when node.exe or iojs.exe is renamed. + */ + +#ifdef _MSC_VER + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif + +#include + +#include +#include + +static HMODULE node_dll = NULL; +static HMODULE nw_dll = NULL; + +static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo* info) { + if (event == dliNotePreGetProcAddress) { + FARPROC ret = NULL; + ret = GetProcAddress(node_dll, info->dlp.szProcName); + if (ret) + return ret; + ret = GetProcAddress(nw_dll, info->dlp.szProcName); + return ret; + } + if (event == dliStartProcessing) { + node_dll = GetModuleHandleA("node.dll"); + nw_dll = GetModuleHandleA("nw.dll"); + return NULL; + } + if (event != dliNotePreLoadLibrary) + return NULL; + + if (_stricmp(info->szDll, "node.exe") != 0) + return NULL; + + // Fall back to the current process + if(!node_dll) node_dll = GetModuleHandleA(NULL); + + return (FARPROC) node_dll; +} + +decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook; + +#endif From 831abf98f181bd134af7b599bf89bc3224214ecf Mon Sep 17 00:00:00 2001 From: Jan Iwaszkiewicz Date: Tue, 30 Jan 2024 08:20:13 +0100 Subject: [PATCH 15/27] [PyOV] Fix for affix decorator, allow Output instances (#22504) --- .../src/openvino/runtime/utils/decorators.py | 2 +- .../python/tests/test_graph/test_affix_ops.py | 57 ++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/bindings/python/src/openvino/runtime/utils/decorators.py b/src/bindings/python/src/openvino/runtime/utils/decorators.py index d29a31938526b2..991edc519dbe9c 100644 --- a/src/bindings/python/src/openvino/runtime/utils/decorators.py +++ b/src/bindings/python/src/openvino/runtime/utils/decorators.py @@ -44,7 +44,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Node: for node_name in node_names: # Apply only on auto-generated nodes. Create such node and apply affixes. # Any Node instance supplied by the user is keeping the name as-is. - if node_name in arg_mapping and not isinstance(arg_mapping[node_name], Node): + if node_name in arg_mapping and not isinstance(arg_mapping[node_name], (Node, Output)): arg_mapping[node_name] = _apply_affix(as_node(arg_mapping[node_name]), prefix=kwargs.get("prefix", ""), suffix=kwargs.get("suffix", ""), diff --git a/src/bindings/python/tests/test_graph/test_affix_ops.py b/src/bindings/python/tests/test_graph/test_affix_ops.py index 717ce1d11cc0f0..7e42b38172cc0c 100644 --- a/src/bindings/python/tests/test_graph/test_affix_ops.py +++ b/src/bindings/python/tests/test_graph/test_affix_ops.py @@ -18,7 +18,7 @@ "XYZ", "_custom_suffix", ]) -def test_fake_quantize_affix_fails(prefix_string, suffix_string): +def test_affix_not_applied_on_nodes(prefix_string, suffix_string): levels = np.int32(4) data_shape = [1, 2, 3, 4] bound_shape = [] @@ -61,6 +61,61 @@ def test_fake_quantize_affix_fails(prefix_string, suffix_string): assert output_high_name == parameter_output_high.friendly_name +@pytest.mark.parametrize("prefix_string", [ + "ABC", + "custom_prefix_", +]) +@pytest.mark.parametrize("suffix_string", [ + "XYZ", + "_custom_suffix", +]) +def test_affix_not_applied_on_output(prefix_string, suffix_string): + levels = np.int32(4) + data_shape = [1, 2, 3, 4] + bound_shape = [] + + p1 = ov.parameter(data_shape, name="A", dtype=np.float32) + p2 = ov.parameter(data_shape, name="B", dtype=np.float32) + + data_name = "AplusB" + data = ov.add(p1, p2, name=data_name) + data_output = data.output(0) + + input_low_name = "input_low" + parameter_input_low = ov.parameter(bound_shape, name=input_low_name, dtype=np.float32) + + input_high_name = "input_high" + parameter_input_high = ov.parameter(bound_shape, name=input_high_name, dtype=np.float32) + + output_low_name = "output_low" + parameter_output_low = ov.parameter(bound_shape, name=output_low_name, dtype=np.float32) + + output_high_name = "output_high" + parameter_output_high = ov.parameter(bound_shape, name=output_high_name, dtype=np.float32) + + model = ov.fake_quantize( + data_output, + parameter_input_low, + parameter_input_high, + parameter_output_low, + parameter_output_high, + levels, + prefix=prefix_string, + suffix=suffix_string, + ) + + # Check if node was created correctly + assert model.get_type_name() == "FakeQuantize" + assert model.get_output_size() == 1 + assert list(model.get_output_shape(0)) == [1, 2, 3, 4] + + assert data_name == data_output.get_node().friendly_name + assert input_low_name == parameter_input_low.friendly_name + assert input_high_name == parameter_input_high.friendly_name + assert output_low_name == parameter_output_low.friendly_name + assert output_high_name == parameter_output_high.friendly_name + + @pytest.mark.parametrize("prefix_string", [ "", "ABC", From 2ae120f8f1f89cbaddc0c741c2ce1c5af293a5c4 Mon Sep 17 00:00:00 2001 From: hyunback kim Date: Tue, 30 Jan 2024 16:26:41 +0900 Subject: [PATCH 16/27] [GPU] Fix wrong weight conversion. (#22405) * [GPU] Fix wrong weight conversion. os_is_zyx_isv8_osv16_isv2 has issue, output incorrect in lnl. Signed-off-by: hyunback * Add os_is_(z)yx_isa8_osv16_isv2 Signed-off-by: hyunback --------- Signed-off-by: hyunback --- .../include/intel_gpu/runtime/format.hpp | 2 + .../impls/ocl/kernel_selector_helper.cpp | 8 ++++ .../include/batch_headers/fetch_weights.cl | 47 +++++++++++++++++++ .../cl_kernels/reorder_weights.cl | 8 ++++ .../kernel_selector_common.cpp | 2 + .../src/kernel_selector/tensor_type.cpp | 4 ++ .../src/kernel_selector/tensor_type.h | 2 + src/plugins/intel_gpu/src/runtime/format.cpp | 2 + 8 files changed, 75 insertions(+) diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp index 0d66106523eaa5..dc756006c18264 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp @@ -156,6 +156,8 @@ struct format { is_os_yx_isv16_osv8, ///< format used for weights for blocked deconvolution is_os_yx_isv16_osv4, ///< format used for weights for blocked deconvolution is_os_yx_isv16_osv2, ///< format used for weights for blocked deconvolution + os_is_yx_isa8_osv16_isv2, ///< format used for weights for blocked 2D onednn convolution + os_is_zyx_isa8_osv16_isv2, ///< format used for weights for blocked 3D onednn convolution os_is_yx_isv8_osv16_isv2, ///< format used for weights for blocked 2D convolution os_is_zyx_isv8_osv16_isv2, ///< format used for weights for blocked 3D convolution ///< os - output feature maps slice, i - input feature maps, diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp index d82832731badb6..fff672088f233e 100644 --- a/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp +++ b/src/plugins/intel_gpu/src/graph/impls/ocl/kernel_selector_helper.cpp @@ -578,6 +578,10 @@ kernel_selector::weights_layout to_weights_layout(format f, bool is_grouped) { return kernel_selector::weights_layout::iy_xs_os_xsv2_osv16__ao32; case format::os_is_osv32_isv32_swizzled_by_4: return kernel_selector::weights_layout::os_is_osv32_isv32_swizzled_by_4; + case format::os_is_zyx_isa8_osv16_isv2: + return kernel_selector::weights_layout::os_is_zyx_isa8_osv16_isv2; + case format::os_is_yx_isa8_osv16_isv2: + return kernel_selector::weights_layout::os_is_yx_isa8_osv16_isv2; case format::os_is_zyx_isv8_osv16_isv2: return kernel_selector::weights_layout::os_is_zyx_isv8_osv16_isv2; case format::os_is_yx_isv8_osv16_isv2: @@ -912,6 +916,10 @@ cldnn::format::type from_weights_layout(kernel_selector::weights_layout l) { return cldnn::format::os_is_yx_osv2_isv32; case kernel_selector::weights_layout::os_is_zyx_osv8_isv4: return cldnn::format::os_is_zyx_osv8_isv4; + case kernel_selector::weights_layout::os_is_zyx_isa8_osv16_isv2: + return cldnn::format::os_is_zyx_isa8_osv16_isv2; + case kernel_selector::weights_layout::os_is_yx_isa8_osv16_isv2: + return cldnn::format::os_is_yx_isa8_osv16_isv2; case kernel_selector::weights_layout::os_is_zyx_isv8_osv16_isv2: return cldnn::format::os_is_zyx_isv8_osv16_isv2; case kernel_selector::weights_layout::os_zyxi_osv16: diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl index 9274eb5cab193f..492086141aea7d 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/include/batch_headers/fetch_weights.cl @@ -326,6 +326,53 @@ inline uint get_os_is_zyx_isv8_osv16_isv2_index(uint g, uint o, uint i, uint z, return idx; } +#define GET_FILTER_OS_IS_YX_ISA8_OSV16_ISV2_INDEX(prefix, o, i, y, x) \ + get_os_is_zyx_isa8_osv16_isv2_index( \ + o, i, 0, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _IFM_NUM), \ + CAT(prefix, _OFM_NUM), \ + CAT(prefix, _OFFSET) \ + ) + +#define GET_FILTER_OS_IS_ZYX_ISA8_OSV16_ISV2_INDEX(prefix, o, i, z, y, x) \ + get_os_is_zyx_isa8_osv16_isv2_index( \ + o, i, z, y, x, \ + CAT(prefix, _SIZE_X), \ + CAT(prefix, _SIZE_Y), \ + CAT(prefix, _SIZE_Z), \ + CAT(prefix, _IFM_NUM), \ + CAT(prefix, _OFM_NUM), \ + CAT(prefix, _OFFSET) \ + ) + +inline uint get_os_is_zyx_isa8_osv16_isv2_index(uint o, uint i, uint z, uint y, uint x, uint size_x, + uint size_y, uint size_z, uint size_ifm, uint size_ofm, uint offset) +{ + const uint isv2_idx = i % 2; + const uint osv_idx = o % 16; + const uint isv1_idx = (i / 2) % 8; + const uint is_idx = i / 16; + const uint os_idx = o / 16; + + const uint if_16_aligned = ((size_ifm + 15) / 16); + const uint of_16_aligned = ((size_ofm + 15) / 16); + + size_t idx = offset + + isv2_idx + + osv_idx * 2 + + isv1_idx * 16 * 2 + + x * 8 * 16 * 2 + + y * size_x * 8 * 16 * 2 + + z * size_y * size_x * 8 * 16 * 2 + + is_idx * size_z * size_y * size_x * 2 * 16 * 8 + + os_idx * if_16_aligned * size_z * size_y * size_x * 2 * 16 * 8; + + return idx; +} + inline uint get_os_zyxi_osv16_index(uint o, uint i, uint z, uint y, uint x, uint i_size, uint o_size, uint x_size, uint y_size, uint z_size) { const size_t idx = o%16 + (o / 16)*i_size*x_size*y_size*z_size*16 + diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl index 6fc451580b291a..dbc584eba22714 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl +++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/reorder_weights.cl @@ -454,6 +454,10 @@ inline uint FUNC(get_input_index)(uint g, uint o, uint i, uint z, uint y, uint x return GET_FILTER_OS_IS_ZYX_OSV32_ISV16_INDEX(INPUT0, o, i, z, y, x); #elif defined INPUT0_LAYOUT_OS_IS_ZYX_OSV64_ISV16 return GET_FILTER_OS_IS_ZYX_OSV64_ISV16_INDEX(INPUT0, o, i, z, y, x); +#elif defined INPUT0_LAYOUT_OS_IS_YX_ISA8_OSV16_ISV2 + return GET_FILTER_OS_IS_YX_ISA8_OSV16_ISV2_INDEX(INPUT0, o, i, z, y, x); +#elif defined INPUT0_LAYOUT_OS_IS_ZYX_ISA8_OSV16_ISV2 + return GET_FILTER_OS_IS_ZYX_ISA8_OSV16_ISV2_INDEX(INPUT0, o, i, z, y, x); #elif defined INPUT0_LAYOUT_GS_OI_YXS_GSV16_YXSV4 return GET_FILTER_GS_OI_YXS_GSV16_YXSV4_INDEX(INPUT0, g, o, i, y, x); #elif defined INPUT0_LAYOUT_GS_OI_YXS_GSV32_YXSV4 @@ -725,6 +729,10 @@ inline uint FUNC(get_output_index)(uint g, uint o, uint i, uint z, uint y, uint return GET_FILTER_GS_OI_YXS_GSV4_YXSV4_INDEX(OUTPUT, g, o, i, y, x); #elif defined OUTPUT_LAYOUT_G_OS_IS_YX_ISV16_OSV16 return GET_FILTER_G_OS_IS_YX_ISV16_OSV16_INDEX(OUTPUT, g, o, i, y, x, SUB_GROUP_SIZE); +#elif defined OUTPUT_LAYOUT_OS_IS_YX_ISA8_OSV16_ISV2 + return GET_FILTER_OS_IS_YX_ISA8_OSV16_ISV2_INDEX(OUTPUT, o, i, y, x); +#elif defined OUTPUT_LAYOUT_OS_IS_ZYX_ISA8_OSV16_ISV2 + return GET_FILTER_OS_IS_ZYX_ISA8_OSV16_ISV2_INDEX(OUTPUT, o, i, z, y, x); #elif defined OUTPUT_LAYOUT_OS_IS_YX_OSV16_ISV2 return GET_FILTER_OS_IS_YX_OSV16_ISV2_INDEX(OUTPUT, o, i, y, x); #elif defined OUTPUT_LAYOUT_OS_IS_YX_OSV16_ISV16 diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp index 542036ee9b12ad..a56f49b468b7fd 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/kernel_selector_common.cpp @@ -371,6 +371,8 @@ std::string toString(WeightsLayout layout) { case WeightsLayout::is_os_yx_osv8_isv4: return "IS_OS_YX_OSV8_ISV4"; case WeightsLayout::is_os_yx_osa8_isv16_osv4: return "IS_OS_YX_OSA8_ISV16_OSV4"; case WeightsLayout::os_is_yx_isa8_osv8_isv2: return "OS_IS_YX_ISA8_OSV8_ISV2"; + case WeightsLayout::os_is_yx_isa8_osv16_isv2: return "OS_IS_YX_ISA8_OSV16_ISV2"; + case WeightsLayout::os_is_zyx_isa8_osv16_isv2: return "OS_IS_ZYX_ISA8_OSV16_ISV2"; case WeightsLayout::os_is_zyx_isv8_osv16_isv2: return "OS_IS_ZYX_ISV8_OSV16_ISV2"; case WeightsLayout::os_zyxi_osv16: return "OS_ZYXI_OSV16"; case WeightsLayout::os_is_yx_isv8_osv16_isv2: return "OS_IS_YX_ISV8_OSV16_ISV2"; diff --git a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp index ad2fa28b220e47..f6ca2a01254f27 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp +++ b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.cpp @@ -163,6 +163,8 @@ WeightsTensor::WeightsChannelArray WeightsTensor::weightsChannelArray {{ { WeightsLayout::is_os_yx_isa4_osa8_isv8_osv4, { 0, 1, -1, 3, 2, -1 } }, { WeightsLayout::is_os_yx_osa4_isa8_osv8_isv4, { 0, 1, -1, 3, 2, -1 } }, { WeightsLayout::os_is_osv32_isv32_swizzled_by_4, { -1, -1, -1, 0, 1, -1 } }, + { WeightsLayout::os_is_zyx_isa8_osv16_isv2, { 0, 1, 2, 3, 4, -1 } }, + { WeightsLayout::os_is_yx_isa8_osv16_isv2, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_is_zyx_isv8_osv16_isv2, { 0, 1, 2, 3, 4, -1 } }, { WeightsLayout::os_is_yx_isv8_osv16_isv2, { 0, 1, -1, 2, 3, -1 } }, { WeightsLayout::os_is_zyx_isa8_osv8_isv2, { 0, 1, 2, 3, 4, -1 } }, @@ -833,11 +835,13 @@ NDims WeightsTensor::GetSimpleDims(const std::vector& d, WeightsLayout l newDims[2] = RoundUp(newDims[2], 16); newDims[3] = RoundUp(newDims[3], 2); break; + case os_is_yx_isa8_osv16_isv2: case os_is_yx_isv8_osv16_isv2: assert(newDims.size() == 4); newDims[2] = RoundUp(newDims[2], 16); newDims[3] = RoundUp(newDims[3], 16); break; + case os_is_zyx_isa8_osv16_isv2: case os_is_zyx_isv8_osv16_isv2: assert(newDims.size() == 5); newDims[3] = RoundUp(newDims[3], 16); diff --git a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h index 28322dafc8a7a6..d16dee409c91b4 100644 --- a/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h +++ b/src/plugins/intel_gpu/src/kernel_selector/tensor_type.h @@ -109,7 +109,9 @@ enum WeightsLayout { is_os_yx_isv16_osv8, is_os_yx_isv16_osv4, is_os_yx_isv16_osv2, + os_is_zyx_isa8_osv16_isv2, // aligned os_is_zyx_isv8_osv16_isv2, + os_is_yx_isa8_osv16_isv2, // aligned os_is_yx_isv8_osv16_isv2, os_is_yx_isv16_osv16, os_zyxi_osv16, diff --git a/src/plugins/intel_gpu/src/runtime/format.cpp b/src/plugins/intel_gpu/src/runtime/format.cpp index d850837f025dd3..5a4872c19200bd 100644 --- a/src/plugins/intel_gpu/src/runtime/format.cpp +++ b/src/plugins/intel_gpu/src/runtime/format.cpp @@ -151,8 +151,10 @@ static const std::map format_traits_map { FMT_TRAITS(os_is_yx_isa8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 32}, {0, 32}}), FMT_TRAITS(os_is_yx_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 8}, {0, 8}, {1, 2}}), FMT_TRAITS(os_is_osv32_isv32_swizzled_by_4, 1, 1, 0, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 32}}), + FMT_TRAITS(os_is_zyx_isa8_osv16_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 16}, {1, 2}}), // aligned FMT_TRAITS(os_is_zyx_isv8_osv16_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 16}, {1, 2}}), FMT_TRAITS(os_zyxi_osv16, 1, 1, 3, 0, {0, 2, 3, 4, 1}, "ozyxi", "oixyz", {{0, 16}}), + FMT_TRAITS(os_is_yx_isa8_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 8}, {0, 16}, {1, 2}}), // aligned FMT_TRAITS(os_is_yx_isv8_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 8}, {0, 16}, {1, 2}}), FMT_TRAITS(os_is_yx_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 16}, {1, 2}}), FMT_TRAITS(os_is_yx_osv16_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 16}, {1, 16}}), From ca9f75e12de7ca6a572d553cd7da943be3adbd50 Mon Sep 17 00:00:00 2001 From: Alicja Miloszewska Date: Tue, 30 Jan 2024 09:59:01 +0100 Subject: [PATCH 17/27] [JS OV] Update includes (#22438) * Add "node/include/" to includes. Change target_include_directories * Include headers where there are needed * Remove typeinfo * Run clang_format_fix_all * Add #include --------- Co-authored-by: Vishniakov Nikolai --- src/bindings/js/node/CMakeLists.txt | 2 +- src/bindings/js/node/include/async_reader.hpp | 1 - src/bindings/js/node/include/core_wrap.hpp | 2 -- src/bindings/js/node/include/element_type.hpp | 2 -- src/bindings/js/node/include/helper.hpp | 1 - src/bindings/js/node/include/model_wrap.hpp | 3 --- src/bindings/js/node/include/node_output.hpp | 1 - .../js/node/include/partial_shape_wrap.hpp | 2 -- .../preprocess/pre_post_process_wrap.hpp | 7 ------- .../js/node/include/preprocess/preprocess.hpp | 17 ++++++---------- .../include/preprocess/preprocess_steps.hpp | 7 +++---- .../include/preprocess/resize_algorithm.hpp | 2 -- src/bindings/js/node/include/tensor.hpp | 6 ------ src/bindings/js/node/src/addon.cpp | 20 +++++++++---------- src/bindings/js/node/src/async_reader.cpp | 4 +++- src/bindings/js/node/src/compiled_model.cpp | 10 +++++----- src/bindings/js/node/src/core_wrap.cpp | 15 ++++++++------ src/bindings/js/node/src/element_type.cpp | 5 ++--- src/bindings/js/node/src/errors.cpp | 2 +- src/bindings/js/node/src/helper.cpp | 4 ++-- src/bindings/js/node/src/infer_request.cpp | 13 ++++++------ src/bindings/js/node/src/model_wrap.cpp | 7 ++++--- src/bindings/js/node/src/node_output.cpp | 8 ++++---- .../js/node/src/partial_shape_wrap.cpp | 6 ++++-- .../js/node/src/preprocess/input_info.cpp | 10 +++++----- .../node/src/preprocess/input_model_info.cpp | 8 +++----- .../node/src/preprocess/input_tensor_info.cpp | 6 +++--- .../js/node/src/preprocess/output_info.cpp | 6 +++--- .../src/preprocess/output_tensor_info.cpp | 6 +++--- .../src/preprocess/pre_post_process_wrap.cpp | 7 +++++-- .../js/node/src/preprocess/preprocess.cpp | 6 ++++-- .../node/src/preprocess/preprocess_steps.cpp | 2 +- .../node/src/preprocess/resize_algorithm.cpp | 6 ++---- src/bindings/js/node/src/tensor.cpp | 8 ++++++-- 34 files changed, 96 insertions(+), 116 deletions(-) diff --git a/src/bindings/js/node/CMakeLists.txt b/src/bindings/js/node/CMakeLists.txt index d4e01834749e99..cb713db9c753dc 100644 --- a/src/bindings/js/node/CMakeLists.txt +++ b/src/bindings/js/node/CMakeLists.txt @@ -72,7 +72,7 @@ add_library(${PROJECT_NAME} SHARED target_include_directories(${PROJECT_NAME} PRIVATE "${node-api-headers_SOURCE_DIR}/include" "${node-addon-api_SOURCE_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${CMAKE_CURRENT_SOURCE_DIR}/.." ) target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${CMAKE_JS_LIB}) diff --git a/src/bindings/js/node/include/async_reader.hpp b/src/bindings/js/node/include/async_reader.hpp index 55081889184232..b5872184328b52 100644 --- a/src/bindings/js/node/include/async_reader.hpp +++ b/src/bindings/js/node/include/async_reader.hpp @@ -5,7 +5,6 @@ #include -#include "model_wrap.hpp" #include "openvino/runtime/core.hpp" #include "read_model_args.hpp" diff --git a/src/bindings/js/node/include/core_wrap.hpp b/src/bindings/js/node/include/core_wrap.hpp index b746b6788dc7fd..13732e26d7a918 100644 --- a/src/bindings/js/node/include/core_wrap.hpp +++ b/src/bindings/js/node/include/core_wrap.hpp @@ -7,8 +7,6 @@ #include -#include "async_reader.hpp" -#include "errors.hpp" #include "openvino/runtime/core.hpp" class CoreWrap : public Napi::ObjectWrap { diff --git a/src/bindings/js/node/include/element_type.hpp b/src/bindings/js/node/include/element_type.hpp index 25ecac6f863c3b..7ff79a433a8214 100644 --- a/src/bindings/js/node/include/element_type.hpp +++ b/src/bindings/js/node/include/element_type.hpp @@ -4,8 +4,6 @@ #pragma once #include -#include "helper.hpp" - namespace element { /** @brief Exports JavaScript element enum. */ Napi::Object init(Napi::Env env, Napi::Object exports); diff --git a/src/bindings/js/node/include/helper.hpp b/src/bindings/js/node/include/helper.hpp index e94f5eae314cd6..796eaee4014046 100644 --- a/src/bindings/js/node/include/helper.hpp +++ b/src/bindings/js/node/include/helper.hpp @@ -7,7 +7,6 @@ #include #include -#include "element_type.hpp" #include "openvino/core/type/element_type.hpp" #include "openvino/openvino.hpp" diff --git a/src/bindings/js/node/include/model_wrap.hpp b/src/bindings/js/node/include/model_wrap.hpp index cedb965045b1f0..39c2a078b0d646 100644 --- a/src/bindings/js/node/include/model_wrap.hpp +++ b/src/bindings/js/node/include/model_wrap.hpp @@ -5,11 +5,8 @@ #include -#include "compiled_model.hpp" -#include "errors.hpp" #include "openvino/core/model.hpp" #include "openvino/runtime/core.hpp" -#include "tensor.hpp" class ModelWrap : public Napi::ObjectWrap { public: diff --git a/src/bindings/js/node/include/node_output.hpp b/src/bindings/js/node/include/node_output.hpp index e7038690fe05cf..0e1561d85f5edf 100644 --- a/src/bindings/js/node/include/node_output.hpp +++ b/src/bindings/js/node/include/node_output.hpp @@ -5,7 +5,6 @@ #include -#include "helper.hpp" #include "openvino/core/node_output.hpp" template diff --git a/src/bindings/js/node/include/partial_shape_wrap.hpp b/src/bindings/js/node/include/partial_shape_wrap.hpp index d52baf3ab01d67..236012bd291141 100644 --- a/src/bindings/js/node/include/partial_shape_wrap.hpp +++ b/src/bindings/js/node/include/partial_shape_wrap.hpp @@ -5,8 +5,6 @@ #include -#include "errors.hpp" -#include "helper.hpp" #include "openvino/core/partial_shape.hpp" class PartialShapeWrap : public Napi::ObjectWrap { diff --git a/src/bindings/js/node/include/preprocess/pre_post_process_wrap.hpp b/src/bindings/js/node/include/preprocess/pre_post_process_wrap.hpp index a751a3c7588472..8e525b22431fb6 100644 --- a/src/bindings/js/node/include/preprocess/pre_post_process_wrap.hpp +++ b/src/bindings/js/node/include/preprocess/pre_post_process_wrap.hpp @@ -5,14 +5,7 @@ #include -#include "element_type.hpp" -#include "errors.hpp" -#include "helper.hpp" -#include "model_wrap.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" -#include "openvino/openvino.hpp" -#include "preprocess/input_info.hpp" -#include "preprocess/output_info.hpp" class PrePostProcessorWrap : public Napi::ObjectWrap { public: diff --git a/src/bindings/js/node/include/preprocess/preprocess.hpp b/src/bindings/js/node/include/preprocess/preprocess.hpp index eb0c172abd0d31..b88b0ac554f251 100644 --- a/src/bindings/js/node/include/preprocess/preprocess.hpp +++ b/src/bindings/js/node/include/preprocess/preprocess.hpp @@ -5,16 +5,11 @@ #include -#include "openvino/openvino.hpp" - -#include "preprocess/resize_algorithm.hpp" -#include "preprocess/pre_post_process_wrap.hpp" - namespace preprocess { - /** @brief This method is called during initialization of OpenVINO native add-on. - * It exports JavaScript preprocess property. - */ - Napi::Object init(Napi::Env env, Napi::Object exports); +/** @brief This method is called during initialization of OpenVINO native add-on. + * It exports JavaScript preprocess property. + */ +Napi::Object init(Napi::Env env, Napi::Object exports); - Napi::Value add_preprocess_namespace(const Napi::CallbackInfo& info); -}; +Napi::Value add_preprocess_namespace(const Napi::CallbackInfo& info); +}; // namespace preprocess diff --git a/src/bindings/js/node/include/preprocess/preprocess_steps.hpp b/src/bindings/js/node/include/preprocess/preprocess_steps.hpp index e44885962549a7..e0e4be559385c4 100644 --- a/src/bindings/js/node/include/preprocess/preprocess_steps.hpp +++ b/src/bindings/js/node/include/preprocess/preprocess_steps.hpp @@ -5,11 +5,10 @@ #include -#include "errors.hpp" -#include "helper.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" #include "openvino/core/preprocess/preprocess_steps.hpp" - class PreProcessSteps : public Napi::ObjectWrap { public: PreProcessSteps(const Napi::CallbackInfo& info); @@ -18,7 +17,7 @@ class PreProcessSteps : public Napi::ObjectWrap { Napi::Value resize(const Napi::CallbackInfo& info); - void set_preprocess_info(ov::preprocess::PreProcessSteps& info) ; + void set_preprocess_info(ov::preprocess::PreProcessSteps& info); private: ov::preprocess::PreProcessSteps* _preprocess_info; diff --git a/src/bindings/js/node/include/preprocess/resize_algorithm.hpp b/src/bindings/js/node/include/preprocess/resize_algorithm.hpp index 493ea634d616e1..781c05bafdd488 100644 --- a/src/bindings/js/node/include/preprocess/resize_algorithm.hpp +++ b/src/bindings/js/node/include/preprocess/resize_algorithm.hpp @@ -4,7 +4,5 @@ #pragma once #include -#include "helper.hpp" - /** \brief Creates JS object to represent C++ enum class ResizeAlgorithm */ Napi::Value enumResizeAlgorithm(const Napi::CallbackInfo& info); diff --git a/src/bindings/js/node/include/tensor.hpp b/src/bindings/js/node/include/tensor.hpp index e531be6671a9bf..91285a77097b61 100644 --- a/src/bindings/js/node/include/tensor.hpp +++ b/src/bindings/js/node/include/tensor.hpp @@ -5,12 +5,6 @@ #include -#include "element_type.hpp" -#include "errors.hpp" -#include "helper.hpp" -#include "openvino/core/shape.hpp" -#include "openvino/core/type/element_type.hpp" -#include "openvino/runtime/compiled_model.hpp" #include "openvino/runtime/tensor.hpp" class TensorWrap : public Napi::ObjectWrap { diff --git a/src/bindings/js/node/src/addon.cpp b/src/bindings/js/node/src/addon.cpp index 3b619104edb0a9..64d5273eebaef6 100644 --- a/src/bindings/js/node/src/addon.cpp +++ b/src/bindings/js/node/src/addon.cpp @@ -1,20 +1,20 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "addon.hpp" +#include "node/include/addon.hpp" #include -#include "compiled_model.hpp" -#include "core_wrap.hpp" -#include "element_type.hpp" -#include "infer_request.hpp" -#include "model_wrap.hpp" -#include "node_output.hpp" +#include "node/include/compiled_model.hpp" +#include "node/include/core_wrap.hpp" +#include "node/include/element_type.hpp" +#include "node/include/infer_request.hpp" +#include "node/include/model_wrap.hpp" +#include "node/include/node_output.hpp" +#include "node/include/partial_shape_wrap.hpp" +#include "node/include/preprocess/preprocess.hpp" +#include "node/include/tensor.hpp" #include "openvino/openvino.hpp" -#include "partial_shape_wrap.hpp" -#include "preprocess/preprocess.hpp" -#include "tensor.hpp" void init_class(Napi::Env env, Napi::Object exports, diff --git a/src/bindings/js/node/src/async_reader.cpp b/src/bindings/js/node/src/async_reader.cpp index f9e104d67053fa..bcdd6b84e94ec1 100644 --- a/src/bindings/js/node/src/async_reader.cpp +++ b/src/bindings/js/node/src/async_reader.cpp @@ -1,7 +1,9 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "async_reader.hpp" +#include "node/include/async_reader.hpp" + +#include "node/include/model_wrap.hpp" void ReaderWorker::Execute() { ov::Core core; diff --git a/src/bindings/js/node/src/compiled_model.cpp b/src/bindings/js/node/src/compiled_model.cpp index 070d397b3696fc..fa7c959fd01db8 100644 --- a/src/bindings/js/node/src/compiled_model.cpp +++ b/src/bindings/js/node/src/compiled_model.cpp @@ -1,12 +1,12 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "compiled_model.hpp" +#include "node/include/compiled_model.hpp" -#include "addon.hpp" -#include "errors.hpp" -#include "infer_request.hpp" -#include "node_output.hpp" +#include "node/include/addon.hpp" +#include "node/include/errors.hpp" +#include "node/include/infer_request.hpp" +#include "node/include/node_output.hpp" CompiledModelWrap::CompiledModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info), diff --git a/src/bindings/js/node/src/core_wrap.cpp b/src/bindings/js/node/src/core_wrap.cpp index eb139572b87731..743fbb811f8a6d 100644 --- a/src/bindings/js/node/src/core_wrap.cpp +++ b/src/bindings/js/node/src/core_wrap.cpp @@ -1,12 +1,15 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "core_wrap.hpp" - -#include "addon.hpp" -#include "compiled_model.hpp" -#include "model_wrap.hpp" -#include "read_model_args.hpp" +#include "node/include/core_wrap.hpp" + +#include "node/include/addon.hpp" +#include "node/include/async_reader.hpp" +#include "node/include/compiled_model.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" +#include "node/include/model_wrap.hpp" +#include "node/include/read_model_args.hpp" CoreWrap::CoreWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info), _core{} {} diff --git a/src/bindings/js/node/src/element_type.cpp b/src/bindings/js/node/src/element_type.cpp index 54458dc028732f..6b8a7956168ca6 100644 --- a/src/bindings/js/node/src/element_type.cpp +++ b/src/bindings/js/node/src/element_type.cpp @@ -1,10 +1,9 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "element_type.hpp" +#include "node/include/element_type.hpp" -#include -#include +#include "node/include/helper.hpp" namespace element { Napi::Object init(Napi::Env env, Napi::Object exports) { diff --git a/src/bindings/js/node/src/errors.cpp b/src/bindings/js/node/src/errors.cpp index ce527bed1586fd..62b20d107781a4 100644 --- a/src/bindings/js/node/src/errors.cpp +++ b/src/bindings/js/node/src/errors.cpp @@ -1,7 +1,7 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "errors.hpp" +#include "node/include/errors.hpp" void reportError(const Napi::Env& env, std::string msg) { Napi::Error::New(env, msg).ThrowAsJavaScriptException(); diff --git a/src/bindings/js/node/src/helper.cpp b/src/bindings/js/node/src/helper.cpp index 02a51aef5e7339..c22398985ab54f 100644 --- a/src/bindings/js/node/src/helper.cpp +++ b/src/bindings/js/node/src/helper.cpp @@ -1,9 +1,9 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "helper.hpp" +#include "node/include/helper.hpp" -#include "tensor.hpp" +#include "node/include/tensor.hpp" const std::vector& get_supported_types() { static const std::vector supported_element_types = diff --git a/src/bindings/js/node/src/infer_request.cpp b/src/bindings/js/node/src/infer_request.cpp index 427c47d853ff48..713c9b9e969113 100644 --- a/src/bindings/js/node/src/infer_request.cpp +++ b/src/bindings/js/node/src/infer_request.cpp @@ -1,15 +1,16 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "infer_request.hpp" +#include "node/include/infer_request.hpp" #include -#include -#include "addon.hpp" -#include "compiled_model.hpp" -#include "node_output.hpp" -#include "tensor.hpp" +#include "node/include/addon.hpp" +#include "node/include/compiled_model.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" +#include "node/include/node_output.hpp" +#include "node/include/tensor.hpp" namespace { std::mutex infer_mutex; diff --git a/src/bindings/js/node/src/model_wrap.cpp b/src/bindings/js/node/src/model_wrap.cpp index 35c41eb4432dc5..f81c2b027db56f 100644 --- a/src/bindings/js/node/src/model_wrap.cpp +++ b/src/bindings/js/node/src/model_wrap.cpp @@ -1,10 +1,11 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "model_wrap.hpp" +#include "node/include/model_wrap.hpp" -#include "addon.hpp" -#include "node_output.hpp" +#include "node/include/addon.hpp" +#include "node/include/errors.hpp" +#include "node/include/node_output.hpp" ModelWrap::ModelWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info), diff --git a/src/bindings/js/node/src/node_output.cpp b/src/bindings/js/node/src/node_output.cpp index 4c2fba452c4cd4..444b35255ccc74 100644 --- a/src/bindings/js/node/src/node_output.cpp +++ b/src/bindings/js/node/src/node_output.cpp @@ -1,11 +1,11 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "node_output.hpp" +#include "node/include/node_output.hpp" -#include "addon.hpp" -#include "helper.hpp" -#include "partial_shape_wrap.hpp" +#include "node/include/addon.hpp" +#include "node/include/helper.hpp" +#include "node/include/partial_shape_wrap.hpp" Output::Output(const Napi::CallbackInfo& info) : Napi::ObjectWrap>(info), _output{} {} diff --git a/src/bindings/js/node/src/partial_shape_wrap.cpp b/src/bindings/js/node/src/partial_shape_wrap.cpp index 7f7ef05e53d3cd..f9632d2f2b20f7 100644 --- a/src/bindings/js/node/src/partial_shape_wrap.cpp +++ b/src/bindings/js/node/src/partial_shape_wrap.cpp @@ -1,9 +1,11 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "partial_shape_wrap.hpp" +#include "node/include/partial_shape_wrap.hpp" -#include "addon.hpp" +#include "node/include/addon.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" PartialShapeWrap::PartialShapeWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { const size_t attrs_length = info.Length(); diff --git a/src/bindings/js/node/src/preprocess/input_info.cpp b/src/bindings/js/node/src/preprocess/input_info.cpp index 09165c4c617083..d1504d83dd7233 100644 --- a/src/bindings/js/node/src/preprocess/input_info.cpp +++ b/src/bindings/js/node/src/preprocess/input_info.cpp @@ -1,12 +1,12 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/input_info.hpp" +#include "node/include/preprocess/input_info.hpp" -#include "errors.hpp" -#include "preprocess/input_model_info.hpp" -#include "preprocess/input_tensor_info.hpp" -#include "preprocess/preprocess_steps.hpp" +#include "node/include/errors.hpp" +#include "node/include/preprocess/input_model_info.hpp" +#include "node/include/preprocess/input_tensor_info.hpp" +#include "node/include/preprocess/preprocess_steps.hpp" InputInfo::InputInfo(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info){}; diff --git a/src/bindings/js/node/src/preprocess/input_model_info.cpp b/src/bindings/js/node/src/preprocess/input_model_info.cpp index 91dd706edd80c2..5756154fc8f368 100644 --- a/src/bindings/js/node/src/preprocess/input_model_info.cpp +++ b/src/bindings/js/node/src/preprocess/input_model_info.cpp @@ -1,12 +1,10 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/input_model_info.hpp" +#include "node/include/preprocess/input_model_info.hpp" -#include - -#include "errors.hpp" -#include "helper.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" InputModelInfo::InputModelInfo(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info){}; diff --git a/src/bindings/js/node/src/preprocess/input_tensor_info.cpp b/src/bindings/js/node/src/preprocess/input_tensor_info.cpp index 5416b56cacc13d..38ab2779ffc275 100644 --- a/src/bindings/js/node/src/preprocess/input_tensor_info.cpp +++ b/src/bindings/js/node/src/preprocess/input_tensor_info.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/input_tensor_info.hpp" +#include "node/include/preprocess/input_tensor_info.hpp" -#include "errors.hpp" -#include "helper.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" InputTensorInfo::InputTensorInfo(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info){}; diff --git a/src/bindings/js/node/src/preprocess/output_info.cpp b/src/bindings/js/node/src/preprocess/output_info.cpp index 9fa81e615119b1..3422228f70a979 100644 --- a/src/bindings/js/node/src/preprocess/output_info.cpp +++ b/src/bindings/js/node/src/preprocess/output_info.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/output_info.hpp" +#include "node/include/preprocess/output_info.hpp" -#include "errors.hpp" -#include "preprocess/output_tensor_info.hpp" +#include "node/include/errors.hpp" +#include "node/include/preprocess/output_tensor_info.hpp" OutputInfo::OutputInfo(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info){}; diff --git a/src/bindings/js/node/src/preprocess/output_tensor_info.cpp b/src/bindings/js/node/src/preprocess/output_tensor_info.cpp index f544f2477f3238..32886187d5f9e1 100644 --- a/src/bindings/js/node/src/preprocess/output_tensor_info.cpp +++ b/src/bindings/js/node/src/preprocess/output_tensor_info.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/output_tensor_info.hpp" +#include "node/include/preprocess/output_tensor_info.hpp" -#include "errors.hpp" -#include "helper.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" OutputTensorInfo::OutputTensorInfo(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info){}; diff --git a/src/bindings/js/node/src/preprocess/pre_post_process_wrap.cpp b/src/bindings/js/node/src/preprocess/pre_post_process_wrap.cpp index b715647c8f2b58..c8a4c801471d05 100644 --- a/src/bindings/js/node/src/preprocess/pre_post_process_wrap.cpp +++ b/src/bindings/js/node/src/preprocess/pre_post_process_wrap.cpp @@ -1,9 +1,12 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/pre_post_process_wrap.hpp" +#include "node/include/preprocess/pre_post_process_wrap.hpp" -#include "addon.hpp" +#include "node/include/errors.hpp" +#include "node/include/model_wrap.hpp" +#include "node/include/preprocess/input_info.hpp" +#include "node/include/preprocess/output_info.hpp" PrePostProcessorWrap::PrePostProcessorWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { diff --git a/src/bindings/js/node/src/preprocess/preprocess.cpp b/src/bindings/js/node/src/preprocess/preprocess.cpp index 983f6e706f34f6..5ccd1c65d52f68 100644 --- a/src/bindings/js/node/src/preprocess/preprocess.cpp +++ b/src/bindings/js/node/src/preprocess/preprocess.cpp @@ -1,9 +1,11 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/preprocess.hpp" +#include "node/include/preprocess/preprocess.hpp" -#include "addon.hpp" +#include "node/include/addon.hpp" +#include "node/include/preprocess/pre_post_process_wrap.hpp" +#include "node/include/preprocess/resize_algorithm.hpp" namespace preprocess { Napi::Object init(Napi::Env env, Napi::Object exports) { diff --git a/src/bindings/js/node/src/preprocess/preprocess_steps.cpp b/src/bindings/js/node/src/preprocess/preprocess_steps.cpp index 29ccd067d209f2..75b3c077799658 100644 --- a/src/bindings/js/node/src/preprocess/preprocess_steps.cpp +++ b/src/bindings/js/node/src/preprocess/preprocess_steps.cpp @@ -1,7 +1,7 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/preprocess_steps.hpp" +#include "node/include/preprocess/preprocess_steps.hpp" PreProcessSteps::PreProcessSteps(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info){}; diff --git a/src/bindings/js/node/src/preprocess/resize_algorithm.cpp b/src/bindings/js/node/src/preprocess/resize_algorithm.cpp index 1447d5ee972965..cfaa32c28c9153 100644 --- a/src/bindings/js/node/src/preprocess/resize_algorithm.cpp +++ b/src/bindings/js/node/src/preprocess/resize_algorithm.cpp @@ -1,11 +1,9 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "preprocess/resize_algorithm.hpp" +#include "node/include/preprocess/resize_algorithm.hpp" -#include - -#include "openvino/runtime/core.hpp" +#include Napi::Value enumResizeAlgorithm(const Napi::CallbackInfo& info) { auto enumObj = Napi::Object::New(info.Env()); diff --git a/src/bindings/js/node/src/tensor.cpp b/src/bindings/js/node/src/tensor.cpp index 1c9f67240c416d..a062db821cdbd5 100644 --- a/src/bindings/js/node/src/tensor.cpp +++ b/src/bindings/js/node/src/tensor.cpp @@ -1,9 +1,13 @@ // Copyright (C) 2018-2023 Intel Corporation // SPDX-License-Identifier: Apache-2.0 -#include "tensor.hpp" +#include "node/include/tensor.hpp" -#include "addon.hpp" +#include "node/include/addon.hpp" +#include "node/include/errors.hpp" +#include "node/include/helper.hpp" +#include "openvino/core/shape.hpp" +#include "openvino/core/type/element_type.hpp" TensorWrap::TensorWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { if (info.Length() == 0) { From 3afad96899558945b5809ac99db946a910ed0610 Mon Sep 17 00:00:00 2001 From: Tingqian Li Date: Tue, 30 Jan 2024 17:11:52 +0800 Subject: [PATCH 18/27] [CPU] keep infer-precision for f32=>i32 convert (#22284) * fix debug-log, add regex infer-prec pattern, keep infer-prec for convert * simplify the condition * add test case --- .../docs/debug_capabilities/infer_prc.md | 53 ++++++++++- src/plugins/intel_cpu/src/graph.cpp | 30 ++++++- .../intel_cpu/src/utils/debug_capabilities.h | 89 +++++++++++++++---- .../subgraph_tests/src/convert_range.cpp | 45 ++++++++-- 4 files changed, 189 insertions(+), 28 deletions(-) diff --git a/src/plugins/intel_cpu/docs/debug_capabilities/infer_prc.md b/src/plugins/intel_cpu/docs/debug_capabilities/infer_prc.md index b97e55fb368b68..aefd735a057e8c 100644 --- a/src/plugins/intel_cpu/docs/debug_capabilities/infer_prc.md +++ b/src/plugins/intel_cpu/docs/debug_capabilities/infer_prc.md @@ -2,7 +2,56 @@ When developing/debugging accuracy issue related to inference precision feature, you can define following environment variables to control the type & number of nodes for which the specified inference precision is enforced: - - `OV_CPU_INFER_PRC_TYPES` : comma separated list of node types for which infer-precision is enforced. use node type with prefix `-` as negative pattern to disable particular node types from enforcement; - - `OV_CPU_INFER_PRC_CNT` : total number of nodes allowed to enforce; +- `OV_CPU_INFER_PRC_POS_PATTERN` : positive regex pattern to filter node type & orgname. +- `OV_CPU_INFER_PRC_NEG_PATTERN` : negative regex pattern to filter after pos-pattern was matched. +- `OV_CPU_INFER_PRC_CNT` : total number of nodes allowed to enforce; Just adjust these two settings before each run until accuracy issue happens/disappears, from the log we can spot the first node introduces issue when enabled. + +When any of these pattern env-var was set to a valid raw C++ regular expression string, console output will show the nodes finally passed the filter. +so we suggest first `export OV_CPU_INFER_PRC_POS_PATTERN=".*"` to see the full list of nodes, and then add filters one by one. + +for example, for a LLM model we set pos-pattern as ".*" first and following log was generated on console: + +```bash +OV_CPU_INFER_PRC_POS_PATTERN=".*" +infer precision enforced Types: Broadcast,Concatenation,Convert,Eltwise,FullyConnected,Gather,Math,Range,Reduce,Reshape,RoPE,ScaledDotProductAttention,ShapeOf,Transpose, total number of nodes: 1918 + ... +Eltwise : + Eltwise@__module.model.layers.0.input_layernorm/aten::pow/Power + Eltwise@__module.model.layers.0.input_layernorm/aten::add/Add + Eltwise@__module.model.layers.0.input_layernorm/aten::rsqrt/Sqrt + Eltwise@__module.model.layers.0.input_layernorm/aten::rsqrt/Divide + Eltwise@__module.model.layers.0.input_layernorm/aten::mul/Multiply + Eltwise@__module.model.layers.0.input_layernorm/aten::mul/Multiply_1 + ... +FullyConnected : + FullyConnected@__module.model.layers.0.self_attn.q_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.0.self_attn.k_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.0.self_attn.v_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.0.self_attn.o_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.0.mlp.gate_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.0.mlp.up_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.0.mlp.down_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.1.self_attn.q_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.1.self_attn.k_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.1.self_attn.v_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.1.self_attn.o_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.1.mlp.gate_proj/aten::linear/MatMul + FullyConnected@__module.model.layers.1.mlp.up_proj/aten::linear/MatMul + ... +``` + +then we save the log and replace ".*" with the pattern that we selectivly enables to see whether accuracy issue is fixed, for example +suppose we only enables `input_layernorm` for all layers we set pos-pattern as `"__module\.model\.layers\.(\d+)\.input_layernorm/"`, notice +the escape for regex reserved special char . and sub-pattern (\d+) for matching all layer indices. + +if the accuracy issue is gone, we can add more nodes to this pattern, for example we can add `self_attn.q_proj` from all layers, the our pattern +becomes `"__module\.model\.layers\.(\d+)\.input_layernorm/|__module\.model\.layers\.(\d+)\.self_attn\.q_proj/`, then run test again to see whether +the accuracy issue appears. if not, repeat above procedure. + +we can use neg-pattern to elimite nodes from being enforced bf16/f16, for example, set the pattern above to neg-pattern so only matched nodes +are eliminated, and check if accuracy is gone, if not, add more nodes into the pattern. + +notice that the actual string being matched with pattern is in the format of `NodeType@orginialLayers`, so by using `"^FullyConnected@"` as the pattern we can +select all nodes with specific type - `FullyConnected` instead of with specific original layer name. diff --git a/src/plugins/intel_cpu/src/graph.cpp b/src/plugins/intel_cpu/src/graph.cpp index 1520512aa2a870..b441a478bd5002 100644 --- a/src/plugins/intel_cpu/src/graph.cpp +++ b/src/plugins/intel_cpu/src/graph.cpp @@ -1584,7 +1584,7 @@ bool Graph::InsertNode(NodePtr parent, NodePtr child, NodePtr node, int parentPo // Apply inference precision configuration void Graph::EnforceInferencePrecision() { - CPU_DEBUG_CAP_ENABLE(static EnforceInferPrcDebug inferPrecDebug); + CPU_DEBUG_CAP_ENABLE(EnforceInferPrcDebug inferPrecDebug); const auto inferPrec = getConfig().inferencePrecision; @@ -1652,10 +1652,9 @@ void Graph::EnforceInferencePrecision() { continue; #ifdef CPU_DEBUG_CAPS - if (!inferPrecDebug.enabled(NameFromType(node->getType()), node->getName())) + if (!inferPrecDebug.enabled(NameFromType(node->getType()), node->getName(), node->getOriginalLayers())) continue; #endif - DEBUG_LOG("#", node->getExecIndex(), " ", node->getName(), " is enforced to use", inferPrec); for (size_t i = 0; i < node->getOriginalInputsNumber(); i++) { auto keepOriginalInputPrecisionAtPort = [](const NodePtr& node, const size_t inPort) { @@ -1675,12 +1674,27 @@ void Graph::EnforceInferencePrecision() { if (parent->getType() == Type::Input && one_of(node->getType(), Type::Eltwise, Type::Subgraph)) return true; + // exclude Convert after Range since it may cause precision loss when integter type to LP. + if (parent->getType() == Type::Range && node->getType() == Type::Convert) { + return true; + } + return false; }; if (keepOriginalInputPrecisionAtPort(node, i)) continue; + DEBUG_LOG("#", + node->getExecIndex(), + " ", + node->getTypeStr(), + " : ", + node->getName(), + " input[", + i, + "] is enforced to use", + inferPrec); node->setOriginalInputPrecisionAtPort(i, inferPrec); } @@ -1695,6 +1709,16 @@ void Graph::EnforceInferencePrecision() { if (child->getType() == Type::Range && node->getType() == Type::Convert) continue; + DEBUG_LOG("#", + node->getExecIndex(), + " ", + node->getTypeStr(), + " : ", + node->getName(), + " output[", + i, + "] is enforced to use", + inferPrec); node->setOriginalOutputPrecisionAtPort(i, inferPrec); } } diff --git a/src/plugins/intel_cpu/src/utils/debug_capabilities.h b/src/plugins/intel_cpu/src/utils/debug_capabilities.h index f593bfa36dc3d7..01d6872231c970 100644 --- a/src/plugins/intel_cpu/src/utils/debug_capabilities.h +++ b/src/plugins/intel_cpu/src/utils/debug_capabilities.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "onednn/dnnl.h" #include @@ -160,10 +161,11 @@ static inline std::ostream& _write_all_to_stream(std::ostream& os, const T& arg, /* * important debugging tools for accuracy issues - * OV_CPU_INFER_PRC_TYPES : comma separated list of node types for which infer-precision is enforced + * OV_CPU_INFER_PRC_POS_PATTERN : positive regex pattern to filter node type & orgname. + * OV_CPU_INFER_PRC_NEG_PATTERN : negative regex pattern to filter after pos-pattern was matched. * OV_CPU_INFER_PRC_CNT : number of nodes totally allowed to enforced * adjust these two settings until accuracy issue happens/disappears - * from the log we can spot the first node having issue when enabled f16 + * from the log we can spot the node having issue when enabled bf16/f16 */ struct EnforceInferPrcDebug { std::string safe_getenv(const char* name, const char* default_value = "") { @@ -174,25 +176,80 @@ struct EnforceInferPrcDebug { return value; } - std::string nodeTypes = safe_getenv("OV_CPU_INFER_PRC_TYPES", ""); + bool pattern_verbose; + const char* str_pos_pattern; + const char* str_neg_pattern; + std::regex pos_pattern; + std::regex neg_pattern; + std::map> all_enabled_nodes; int count_limit = atoi(safe_getenv("OV_CPU_INFER_PRC_CNT", "9999999").c_str()); int count = 0; - bool enabled(std::string type, std::string name) { - if (nodeTypes.size() == 0) - return true; - auto idx = nodeTypes.find(type + ","); - if (idx != std::string::npos) { - // negative pattern - if (idx > 0 && nodeTypes[idx-1] == '-') - return false; - if (count < count_limit) { - std::cout << " infer precision enforced: [" << count << "/" << count_limit << "] : " << type << " " << name << std::endl; - count++; - return true; + EnforceInferPrcDebug() { + str_pos_pattern = std::getenv("OV_CPU_INFER_PRC_POS_PATTERN"); + str_neg_pattern = std::getenv("OV_CPU_INFER_PRC_NEG_PATTERN"); + if (str_pos_pattern || str_neg_pattern) { + pattern_verbose = true; + } else { + pattern_verbose = false; + } + if (str_pos_pattern) + pos_pattern = std::regex(str_pos_pattern); + if (str_neg_pattern) + neg_pattern = std::regex(str_neg_pattern); + } + + ~EnforceInferPrcDebug() { + if (pattern_verbose) { + if (str_pos_pattern) + std::cout << "OV_CPU_INFER_PRC_POS_PATTERN=\"" << str_pos_pattern << "\"" << std::endl; + if (str_neg_pattern) + std::cout << "OV_CPU_INFER_PRC_NEG_PATTERN=\"" << str_neg_pattern << "\"" << std::endl; + std::cout << "infer precision enforced Types: "; + size_t total_cnt = 0; + for (auto& ent : all_enabled_nodes) { + std::cout << ent.first << ","; + total_cnt += ent.second.size(); + } + std::cout << " total number of nodes: " << total_cnt << std::endl; + for (auto& ent : all_enabled_nodes) { + std::cout << ent.first << " : " << std::endl; + for (auto& name : ent.second) { + std::cout << "\t" << name << std::endl; + } + } + std::cout << std::endl; + } + } + + bool enabled(std::string type, std::string name, std::string org_names) { + std::string tag = type + "@" + org_names; + std::smatch match; + bool matched = true; + // filter using pos pattern + if (str_pos_pattern) { + matched = std::regex_search(tag, match, pos_pattern); + } + // filter using neg pattern + if (matched && str_neg_pattern) { + matched = !std::regex_search(tag, match, neg_pattern); + } + + // limit by CNT + if (matched && count > count_limit) { + matched = false; + } + + if (matched) { + auto it = all_enabled_nodes.find(type); + if (it == all_enabled_nodes.end()) { + all_enabled_nodes.insert({type, {tag}}); + } else { + it->second.push_back(tag); } + count++; } - return false; + return matched; } }; diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/convert_range.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/convert_range.cpp index e06008fbacb950..4b2161ae588d4f 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/convert_range.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/convert_range.cpp @@ -30,16 +30,29 @@ namespace test { \ | / / Range / | / - \ / - \ / - \ / - MatMul - | - Result + /\ / + / \ / + (No reorder) \ / + / \ / + Convert MatMul + | | + (INT) Result + const | + | | + (FP32) | + \ / + Gather() + | + MatMul + | + Result This test is needed to cover logic that allows to avoid computational error for subgraph: "[I32] -> Convert -> [F32] -> Range" due to precision lowering for floating point path inside "EnforceInferencePrecision" pass". TODO: Incorrect subgraph is generated by ONNX FE + ticket 117861. + + Also test logic to avoid enforcing F32 input of convert to lower precision in subgraph :" Range -> [F32] -> Convert -> + [I32]" in ticket 129874 */ using ConvertRangeSubgraphCPUTestParams = std::tuple< @@ -100,17 +113,35 @@ class ConvertRangeSubgraphCPUTest: public testing::WithParamInterface(range, input_params[1], false, true); auto result = std::make_shared(matmul); result->set_friendly_name("output"); - ov::ResultVector output_results = {result}; + + // second branch ensure convert after range doesn't use low-precision float as input + auto convert2 = std::make_shared(range, ov::element::i32); + convert2->set_friendly_name("convert_to_i32"); + auto const0 = std::make_shared(ov::element::f32, ov::Shape{}, 0.1f); + auto data = std::make_shared(const0, shapeof); + auto gather2 = std::make_shared(data, convert2, one); + auto matmul2 = std::make_shared(gather2, input_params[1], false, true); + auto result2 = std::make_shared(matmul2); + ov::ResultVector output_results = {result, result2}; function = std::make_shared(output_results, input_params, "convert_range"); }; void checkResults() { + bool found_range = false; + bool found_convert = false; for (const auto& n : compiledModel.get_runtime_model()->get_ordered_ops()) { if (n->get_friendly_name() == "float32_range") { ASSERT_EQ(n->get_input_element_type(1), ElementType::f32); + found_range = true; + } + if (n->get_friendly_name() == "convert_to_i32") { + ASSERT_EQ(n->get_input_element_type(0), ElementType::f32); + found_convert = true; } } + ASSERT_TRUE(found_range); + ASSERT_TRUE(found_convert); } }; From e2533e812662666793daf60c05af29c15530c1d0 Mon Sep 17 00:00:00 2001 From: Anastasiia Pnevskaia Date: Tue, 30 Jan 2024 10:18:36 +0100 Subject: [PATCH 19/27] Fixed Telemetry initialization. (#22464) --- .../tools/mo/utils/telemetry_utils.py | 42 +++++++++++++++---- .../ovc/openvino/tools/ovc/telemetry_utils.py | 41 ++++++++++++++---- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/tools/mo/openvino/tools/mo/utils/telemetry_utils.py b/tools/mo/openvino/tools/mo/utils/telemetry_utils.py index e2cdd0b53f61d0..7056c861f18fad 100644 --- a/tools/mo/openvino/tools/mo/utils/telemetry_utils.py +++ b/tools/mo/openvino/tools/mo/utils/telemetry_utils.py @@ -22,13 +22,41 @@ def init_mo_telemetry(app_name='Model Optimizer'): - return tm.Telemetry(tid=get_tid(), - app_name=app_name, - app_version=get_rt_version(), - backend='ga4', - enable_opt_in_dialog=False, - disable_in_ci=True - ) + return init_telemetry_class(tid=get_tid(), + app_name=app_name, + app_version=get_rt_version(), + backend='ga4', + enable_opt_in_dialog=False, + disable_in_ci=True + ) + + +def init_telemetry_class(tid, + app_name, + app_version, + backend, + enable_opt_in_dialog, + disable_in_ci): + # Init telemetry class + telemetry = tm.Telemetry(tid=tid, + app_name=app_name, + app_version=app_version, + backend=backend, + enable_opt_in_dialog=enable_opt_in_dialog, + disable_in_ci=disable_in_ci) + + # Telemetry is a singleton class and if it was already initialized in another tool + # some parameters will be incorrect, including app_name. + # In this case we need to force reinitialisation of telemetry. + if hasattr(telemetry, "backend") and telemetry.backend.app_name != app_name: + telemetry.init(tid=tid, + app_name=app_name, + app_version=app_version, + backend=backend, + enable_opt_in_dialog=enable_opt_in_dialog, + disable_in_ci=disable_in_ci) + return telemetry + def send_framework_info(framework: str): """ diff --git a/tools/ovc/openvino/tools/ovc/telemetry_utils.py b/tools/ovc/openvino/tools/ovc/telemetry_utils.py index b1d9d05efe1ce0..544ca1fe413687 100644 --- a/tools/ovc/openvino/tools/ovc/telemetry_utils.py +++ b/tools/ovc/openvino/tools/ovc/telemetry_utils.py @@ -17,13 +17,40 @@ def init_mo_telemetry(app_name='Model Conversion API'): - return tm.Telemetry(tid=get_tid(), - app_name=app_name, - app_version=get_rt_version(), - backend='ga4', - enable_opt_in_dialog=False, - disable_in_ci=True - ) + return init_telemetry_class(tid=get_tid(), + app_name=app_name, + app_version=get_rt_version(), + backend='ga4', + enable_opt_in_dialog=False, + disable_in_ci=True + ) + + +def init_telemetry_class(tid, + app_name, + app_version, + backend, + enable_opt_in_dialog, + disable_in_ci): + # Init telemetry class + telemetry = tm.Telemetry(tid=tid, + app_name=app_name, + app_version=app_version, + backend=backend, + enable_opt_in_dialog=enable_opt_in_dialog, + disable_in_ci=disable_in_ci) + + # Telemetry is a singleton class and if it was already initialized in another tool + # some parameters will be incorrect, including app_name. + # In this case we need to force reinitialisation of telemetry. + if hasattr(telemetry, "backend") and telemetry.backend.app_name != app_name: + telemetry.init(tid=tid, + app_name=app_name, + app_version=app_version, + backend=backend, + enable_opt_in_dialog=enable_opt_in_dialog, + disable_in_ci=disable_in_ci) + return telemetry def send_framework_info(framework: str): From cb679a73c9959c05e2c1ad0e01b12d13d71771a9 Mon Sep 17 00:00:00 2001 From: Yury Gaydaychuk Date: Tue, 30 Jan 2024 11:48:14 +0100 Subject: [PATCH 20/27] [Commit Slider] Map of cashed path added as utility + Test infra (#21919) * extended as util * resolver added * map generating added in config option * fix minor bug * test infra added * minor fixes * refactoring 1 * minor fix * tests refactored * csv builder utility added * print csv as default * code review --- .../tools/commit_slider/commit_slider.py | 36 ++-- .../tools/commit_slider/tests/__init__.py | 10 + .../commit_slider/tests/commit_slider_test.py | 29 +++ .../tools/commit_slider/tests/test_data.py | 97 +++++++++ .../tools/commit_slider/tests/test_util.py | 187 ++++++++++++++++++ .../tests/tests_res/fbv_main.cpp | 26 +++ .../tests/tests_res/fvv_main.cpp | 26 +++ .../tests/tests_res/tests_res.json | 56 ++++++ .../tools/commit_slider/utils/cfg.json | 14 +- .../tools/commit_slider/utils/common_mode.py | 26 ++- .../tools/commit_slider/utils/helpers.py | 59 +++++- .../tools/commit_slider/utils/log_parser.py | 110 +++++++++++ .../tools/commit_slider/utils/map_builder.py | 27 +++ .../tools/commit_slider/utils/modes.py | 8 +- 14 files changed, 685 insertions(+), 26 deletions(-) create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/__init__.py create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/commit_slider_test.py create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/test_data.py create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/test_util.py create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fbv_main.cpp create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fvv_main.cpp create mode 100644 src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/tests_res.json create mode 100644 src/plugins/intel_cpu/tools/commit_slider/utils/log_parser.py create mode 100644 src/plugins/intel_cpu/tools/commit_slider/utils/map_builder.py diff --git a/src/plugins/intel_cpu/tools/commit_slider/commit_slider.py b/src/plugins/intel_cpu/tools/commit_slider/commit_slider.py index efea2c39856429..632bfed3e52e1f 100644 --- a/src/plugins/intel_cpu/tools/commit_slider/commit_slider.py +++ b/src/plugins/intel_cpu/tools/commit_slider/commit_slider.py @@ -1,20 +1,27 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + import subprocess import os import shutil import sys -from shutil import copytree +from distutils.dir_util import copy_tree from utils.helpers import safeClearDir, getParams args, cfgData, customCfgPath = getParams() -if args.__dict__["isWorkingDir"]: +if args.utility != "no_utility": + from utils.helpers import runUtility + runUtility(cfgData, args) + +elif args.isWorkingDir: # rerun script from work directory from utils.modes import Mode from utils.helpers import CfgError from utils.helpers import checkArgAndGetCommits commitList = [] - if args.__dict__["commitSeq"] is None: + if args.commitSeq is None: if "getCommitListCmd" in cfgData["runConfig"]["commitList"]: commitListCmd = cfgData["runConfig"]["commitList"] commitListCmd = commitListCmd["getCommitListCmd"] @@ -31,7 +38,7 @@ else: raise CfgError("Commit list is mandatory") else: - commitList = checkArgAndGetCommits(args.__dict__["commitSeq"], cfgData) + commitList = checkArgAndGetCommits(args.commitSeq, cfgData) commitList.reverse() p = Mode.factory(cfgData) @@ -45,7 +52,7 @@ else: safeClearDir(workPath, cfgData) curPath = os.getcwd() - copytree(curPath, workPath) + copy_tree(curPath, workPath) scriptName = os.path.basename(__file__) argString = " ".join(sys.argv) formattedCmd = "{py} {workPath}/{argString} -wd".format( @@ -57,16 +64,21 @@ tempLogPath = cfgData["logPath"].format(workPath=workPath) permLogPath = cfgData["logPath"].format(workPath=curPath) safeClearDir(permLogPath, cfgData) - copytree(tempLogPath, permLogPath) + copy_tree(tempLogPath, permLogPath) tempCachePath = cfgData["cachePath"].format(workPath=workPath) permCachePath = cfgData["cachePath"].format(workPath=curPath) safeClearDir(permCachePath, cfgData) - copytree(tempCachePath, permCachePath) + copy_tree(tempCachePath, permCachePath) + + try: + shutil.copyfile( + os.path.join(workPath, customCfgPath), + os.path.join(curPath, customCfgPath), + follow_symlinks=True, + ) + except shutil.SameFileError: + # prevent exception raising if cfg set up from outer location + pass - shutil.copyfile( - os.path.join(workPath, customCfgPath), - os.path.join(curPath, customCfgPath), - follow_symlinks=True, - ) safeClearDir(workPath, cfgData) diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/__init__.py b/src/plugins/intel_cpu/tools/commit_slider/tests/__init__.py new file mode 100644 index 00000000000000..e1fb161f858720 --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/__init__.py @@ -0,0 +1,10 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import pytest + + +skip_commit_slider_devtest = pytest.mark.skip( + reason="Test is used to check stability of commit_slider after development changes" + "and does not suppose regular checks.") + diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/commit_slider_test.py b/src/plugins/intel_cpu/tools/commit_slider/tests/commit_slider_test.py new file mode 100644 index 00000000000000..3b7b86077f1330 --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/commit_slider_test.py @@ -0,0 +1,29 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import sys +from unittest import TestCase +from tests import skip_commit_slider_devtest + +sys.path.append('./') +from test_util import getExpectedCommit +from test_util import getActualCommit +from test_data import TestData + + +class CommitSliderTest(TestCase): + @skip_commit_slider_devtest + def testFirstValidVersion(self): + breakCommit, updatedData = getExpectedCommit( + TestData(TestData.TestCase.FirstValidVersion)) + actualCommit = getActualCommit(updatedData) + + self.assertEqual(breakCommit, actualCommit) + + @skip_commit_slider_devtest + def testFirstBadVersion(self): + breakCommit, updatedData = getExpectedCommit( + TestData(TestData.TestCase.FirstBadVersion)) + actualCommit = getActualCommit(updatedData) + + self.assertEqual(breakCommit, actualCommit) diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/test_data.py b/src/plugins/intel_cpu/tools/commit_slider/tests/test_data.py new file mode 100644 index 00000000000000..90ee2f90bc8e57 --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/test_data.py @@ -0,0 +1,97 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from enum import Enum +import json + +class TestData(): + __test__ = False + actualDataReceived = False # prevent slider running before config actualized + + def getTestCase(): + return TestData.TestCase.DeadTest + + def getTestName(): + raise NotImplementedError("getTestName() is not implemented") + + def fillActualData(self, markedVersionList): + # redefine for non trivial cases + self.start=markedVersionList[0]['commit'] + self.end=markedVersionList[-1]['commit'] + + def formatConfig(self, content): + # redefine for non trivial cases + return content.format( + appCmd="./{}".format(self.repoName), + appPath="tests/{}/build".format(self.repoName), + buildPath="tests/{}/build".format(self.repoName), + gitPath="tests/{}".format(self.repoName), + start=self.start, + end=self.end + ) + + @staticmethod + def checkTestSet(): + testCases = [td.getTestCase() for td in TestData.__subclasses__()] + if len(testCases) != len(set(testCases)): + raise TestError("Test cases don't differ correctly") + elif TestData.TestCase.DeadTest in testCases: + raise TestError("Test containing undefined getTestCase() found") + + @staticmethod + def getTestByCase(tc): + TestData.checkTestSet() + foundTest = [td for td in TestData.__subclasses__() + if td.getTestCase() == tc] + if not foundTest: + raise TestError("Test {} is not found".format(tc)) + return foundTest[0] + + @staticmethod + def factory(testCase): + return TestData.getTestByCase(testCase)(testCase) + + class TestCase(Enum): + DeadTest = 0, + FirstBadVersion = 1, + FirstValidVersion = 2 + + def __init__(self, testCase): + # mapping json to test data holder + with open("tests_res/tests_res.json") as cfgFile: + rsc = json.load(cfgFile) + self.testName = TestData.getTestByCase(testCase).getTestName() + self.commonRsc = rsc['CommonRes'] + [setattr(self, key, rsc[self.testName][key]) for key in [ + 'testCfg', 'patchedFile', 'repoName' + ]] + [setattr(self, key, self.commonRsc[key]) for key in [ + 'repoStructure', 'cachePath', 'logPath', + 'mainFile', 'repoPath' + ]] + self.patternPrefix = self.commonRsc['patchGeneratorPrefix'] + self.patternPostfix = self.commonRsc['patchGeneratorPostfix'] + self.pattern = "{pre}(.+?){post}".format( + pre=self.patternPrefix, + post=self.patternPostfix) + + +class FirstBadVersionData(TestData): + def getTestCase(): + return TestData.TestCase.FirstBadVersion + + def getTestName(): + return "FirstBadVersion" + + +class FirstValidVersion(TestData): + def getTestCase(): + return TestData.TestCase.FirstValidVersion + + def getTestName(): + return "FirstValidVersion" + + +class TestError(Exception): + __test__ = False + pass \ No newline at end of file diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/test_util.py b/src/plugins/intel_cpu/tools/commit_slider/tests/test_util.py new file mode 100644 index 00000000000000..54610ebcbfecc7 --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/test_util.py @@ -0,0 +1,187 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import os +import subprocess +import re +import json +import sys +import shutil +from os import path +from test_data import TestData +from test_data import TestError + +sys.path.append('../') +from utils.helpers import getMeaningfullCommitTail + +def getVersionList(td: TestData): + with open(td.patchedFile, 'r') as file: + data = file.read() + + # extract patch list + stats_re = re.compile(td.pattern, re.MULTILINE | re.DOTALL) + patchJSONList = stats_re.findall(data) + if not patchJSONList: + raise Exception("Wrong patchlist in {}".format(td.patchedFile)) + + patchJSONList = patchJSONList[0] + patchList = json.loads(patchJSONList) + prefixPos = re.search(td.patternPrefix, data, re.DOTALL).span()[0] + postfixPos = re.search(td.patternPostfix, data, re.DOTALL).span()[1] + + # apply patches and fill version list + versionList = [] + for patch in patchList: + state = 'EMPTY' + if 'state' in patch: + state = patch['state'] + sub = patch['str'] + newData = data[:prefixPos] + sub + "\n" + data[postfixPos + 1:] + newVersion = { + "content": newData, + "state": state, + "comment": patch['comment']} + versionList.append(newVersion) + + return versionList + + +def makeRepoContent(td: TestData): + fullPath = path.join(td.repoPath, td.repoName) + + td.repoStructure['files'] = formatJSON( + td.repoStructure['files'], + td, + lambda content: content.format( + repoName=td.repoName, + mainFile=td.mainFile) + ) + for file in td.repoStructure['files']: + filePath = path.join(fullPath, file['name']) + with open(filePath, "w") as textFile: + textFile.write(file['content']) + + for dir in td.repoStructure['dirs']: + dir = path.join(fullPath, dir) + if os.path.exists(dir): + shutil.rmtree(dir) + os.makedirs(dir) + +def runCmd(cmd, cwd, verbose=False): + if verbose: + print("run command: {}".format(cmd)) + + proc = subprocess.Popen( + cmd.split(), + cwd=cwd, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + encoding="utf-8",errors="replace" + ) + + output = [] + for line in proc.stdout: + if verbose: + sys.stdout.write(line) + output.append(line) + proc.wait() + proc.communicate() + return output + + +def formatJSON(content, td: TestData, formatLambda): + if isinstance(content, dict): + for k, value in content.items(): + content[k] = formatJSON(value, td, formatLambda) + elif isinstance(content, list): + for id, item in enumerate(content): + content[id] = formatJSON(item, td, formatLambda) + elif isinstance(content, str): + content = formatLambda(content) + else: + # bool or digit object + pass + return content + + +def createRepo(td: TestData): + repoName = td.repoName + repoPath = td.repoPath + repoPath = os.path.abspath(repoPath) + runCmd("mkdir {}".format(repoName), repoPath) + innerPath = path.join(repoPath, repoName) + runCmd("git init", innerPath) + + makeRepoContent(td) + + for file in td.repoStructure['files']: + cmd = "git add {}".format(file['name']) + runCmd(cmd, innerPath) + + return commitPatchList(getVersionList(td), innerPath, td.mainFile) + +def commitPatchList(versionList, innerPath, fileName): + markedVersionList = [] + + for version in versionList: + with open(path.join(innerPath, fileName), "w") as textFile: + textFile.write(version['content']) + + runCmd("git add {}".format(fileName), innerPath) + runCmd("git commit -m \"{}\"".format(version['comment']), innerPath) + hash = runCmd("git rev-parse HEAD", innerPath)[0] + + markedVersion = { + "commit": hash.strip(), + "state": version['state'], + "comment": version['comment'] + } + markedVersionList.append(markedVersion) + + return markedVersionList + + +def getExpectedCommit(td: TestData): + markedVersionList = createRepo(td) + breakCommit = markedVersionList[[ + i for i in range( + len(markedVersionList) + ) if markedVersionList[i]['state'] == 'BREAK'][0]]['commit'] + breakCommit = getMeaningfullCommitTail(breakCommit) + + td.fillActualData(markedVersionList) + td.actualDataReceived = True + + return breakCommit, td + +def getActualCommit(td: TestData): + if not td.actualDataReceived: + raise TestError("Running actual commit before expected.") + + # prepare config + cfg = formatJSON(td.testCfg, td, td.formatConfig) + testCfg = "test_cfg.json" + + with open(testCfg, "w+") as customCfg: + customCfg.truncate(0) + json.dump(cfg, customCfg) + customCfg.close() + + # run slider and check output + sliderOutput = runCmd( + "python3.8 commit_slider.py -cfg tests/{}".format(testCfg), + "../") + + sliderOutput = '\n'.join(map(str, sliderOutput)) + foundCommit = re.search( + "Break commit: (.*),", sliderOutput, flags=re.MULTILINE + ).group(1) + + # clear temp data + [shutil.rmtree(dir) for dir in [ + td.repoName, + td.cachePath, + td.logPath]] + os.remove(testCfg) + + return foundCommit \ No newline at end of file diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fbv_main.cpp b/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fbv_main.cpp new file mode 100644 index 00000000000000..ee753b0f8b72ac --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fbv_main.cpp @@ -0,0 +1,26 @@ +#include + +int main () { + const char *patchGenerator = R"V0G0N( +[ + { + "str": "std::cout << \"prefix\\nsuccess_1\\n\";", + "comment": "success_1" + }, + { + "str": "std::cout << \"prefix\\nsuccess_2\\n\";", + "comment": "success_2" + }, + { + "str": "std::cout << \"prefix\\nfailed_1\\n\";", + "comment": "error_1", + "state": "BREAK" + }, + { + "str": "std::cout << \"prefix\\nfailed_2\\n\";", + "comment": "error_2" + } +] +)V0G0N"; + return 0; +} \ No newline at end of file diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fvv_main.cpp b/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fvv_main.cpp new file mode 100644 index 00000000000000..3465ea516969ee --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/fvv_main.cpp @@ -0,0 +1,26 @@ +#include + +int main () { + const char *patchGenerator = R"V0G0N( +[ + { + "str": "std::cout << \"prefix\\nfailed_1\\n\";", + "comment": "error_1" + }, + { + "str": "std::cout << \"prefix\\nfailed_2\\n\";", + "comment": "error_2" + }, + { + "str": "std::cout << \"prefixsuccess_1\\n\\n\";", + "comment": "success_1", + "state": "BREAK" + }, + { + "str": "std::cout << \"prefix\\nsuccess_2\\n\";", + "comment": "success_2" + } +] +)V0G0N"; + return 0; +} \ No newline at end of file diff --git a/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/tests_res.json b/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/tests_res.json new file mode 100644 index 00000000000000..1a620c6fa74cc0 --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/tests/tests_res/tests_res.json @@ -0,0 +1,56 @@ +{ + "CommonRes": { + "repoPath": "./", + "cachePath": "../slider_cache", + "logPath": "../log", + "patchGeneratorPrefix": "const char \\*patchGenerator = R\"V0G0N\\(", + "patchGeneratorPostfix": "\\)V0G0N\";", + "mainFile": "main.cpp", + "repoStructure": { + "files": [ + {"name": "CMakeLists.txt", "content": "cmake_minimum_required(VERSION 3.10)\nset(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\n\nproject({repoName} VERSION 1.0)\nadd_executable(\"${{PROJECT_NAME}}\" \"{mainFile}\")"}, + {"name": ".gitignore", "content": "/build\n"}, + {"name": "{mainFile}", "content": ""} + ], + "dirs": ["build"] + } + }, + "FirstBadVersion": { + "repoName": "firstBadVersion", + "patchedFile": "tests_res/fbv_main.cpp", + "testCfg": { + "appCmd" : "{appCmd}", + "appPath": "{appPath}", + "gitPath" : "{gitPath}", + "buildPath" : "{buildPath}", + "verboseOutput": false, + "runConfig" : { + "commitList" : { + "getCommitListCmd" : "git log {start}..{end} --boundary --pretty=\"%h\"" + }, + "mode" : "checkOutput", + "traversal" : "firstFailedVersion", + "stopPattern" : "(.)*failed(.)*" + } + } + }, + "FirstValidVersion": { + "repoName": "firstValidVersion", + "patchedFile": "tests_res/fvv_main.cpp", + "testCfg": { + "appCmd" : "{appCmd}", + "appPath": "{appPath}", + "gitPath" : "{gitPath}", + "buildPath" : "{buildPath}", + "verboseOutput": false, + "runConfig" : { + "commitList" : { + "getCommitListCmd" : "git log {start}..{end} --boundary --pretty=\"%h\"" + }, + "mode" : "checkOutput", + "traversal" : "firstFixedVersion", + "stopPattern" : "(.)*failed(.)*" + } + } + } +} \ No newline at end of file diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/cfg.json b/src/plugins/intel_cpu/tools/commit_slider/utils/cfg.json index e20d9bdf44d9ef..10559c8d81356c 100644 --- a/src/plugins/intel_cpu/tools/commit_slider/utils/cfg.json +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/cfg.json @@ -11,12 +11,16 @@ "allBreaks" : "AllBreakVersions", "bruteForce" : "BruteForce" }, + "utilMap" : { + "map_builder" : "printMap", + "log_parser" : "logParser" + }, "extendBuildCommand" : false, "commandList" : [ {"cmd" : "git checkout -- .", "catchMsg" : "(.)*error: (.)*", "path" : "{gitPath}"}, {"cmd" : "git clean -fxd", "path" : "{gitPath}", "tag" : "clean"}, {"cmd" : "mkdir -p build", "path" : "{gitPath}"}, - {"cmd" : "git checkout {commit}", "catchMsg" : "error", "path" : "{gitPath}"}, + {"cmd" : "git checkout {commit}", "catchMsg" : "(.)*error: (.)*", "path" : "{gitPath}"}, {"cmd" : "git submodule init", "path" : "{gitPath}"}, {"cmd" : "git submodule update --recursive", "path" : "{buildPath}"}, {"cmd" : "{makeCmd}", "catchMsg" : "CMake Error", "path" : "{buildPath}"}, @@ -69,8 +73,9 @@ "winWorkPath" : "%tmp%\\commit_slider", "clearCache" : false, "checkIfBordersDiffer" : true, - "printCSV" : false, + "printCSV" : true, "usePrevRunCache" : false, + "verboseOutput": false, "serviceConfig" : { "comment" : "For inner purpose. Data will be overwritten during script running." }, @@ -80,11 +85,14 @@ "appPath" : "path, substituted by job" }, "cachedPathConfig": { - "enabled" : true, + "enabled" : false, "scheme" : "optional | mandatory", "comment" : "'mandatory' skips lacking hash-appPath pair for given key, 'optional' tries to handle it by building", "passCmdList": true, "changeAppPath": true, + "generateMap": false, + "commonPath": "", + "subPath": "", "cashMap" : {} } } \ No newline at end of file diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/common_mode.py b/src/plugins/intel_cpu/tools/commit_slider/utils/common_mode.py index 6d2180ff03eee6..f4e0c8531a5fba 100644 --- a/src/plugins/intel_cpu/tools/commit_slider/utils/common_mode.py +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/common_mode.py @@ -1,5 +1,9 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + from abc import ABC import utils.helpers as util +import utils.map_builder as mapBuilder import json import os from enum import Enum @@ -30,6 +34,9 @@ def __init__(self, cfg) -> None: "commonLogger", logPath, "common_log.log" ) + def isPerformanceBased(self): + return False + def createCash(self): # In common case we use json. # Create cash is overrided if we need special algo for caching. @@ -98,7 +105,7 @@ def prepareRun(self, list, cfg): canReduce, newList = util.getReducedInterval(list, cfg) if canReduce: if (self.traversal.isComparative() and - self.mode.checkIfListBordersDiffer(newList, cfg) or + self.checkIfListBordersDiffer(newList, cfg) or not self.traversal.isComparative()): self.commonLogger.info( "Initial interval reduced to cashed {c1}..{c2}".format( @@ -112,6 +119,11 @@ def prepareRun(self, list, cfg): def normalizeCfg(self, cfg): if not self.traversal.isComparative(): cfg["checkIfBordersDiffer"] = False + cashCfg = cfg["cachedPathConfig"] + if (cashCfg["enabled"] and cashCfg["generateMap"]): + cfg["cachedPathConfig"]["cashMap"] = mapBuilder( + cashCfg["commonPath"], cashCfg["subPath"] + ) if "modeName" in cfg["skipMode"]: errorHandlingMode = cfg["skipMode"]["modeName"] if errorHandlingMode == "skip": @@ -130,7 +142,9 @@ def normalizeCfg(self, cfg): def postRun(self, list): util.returnToActualVersion(self.cfg) - if "printCSV" in self.cfg and self.cfg["printCSV"]: + if "printCSV" in self.cfg\ + and self.cfg["printCSV"]\ + and self.isPerformanceBased(): fields = ['linId', 'logId', 'hash', 'value'] rows = [] linearId = 0 @@ -267,9 +281,9 @@ def prepBypass(self, curList, list, cfg): # try to reduce interval by cashed borders canReduce, newList = util.getReducedInterval(curList, cfg) if canReduce: - if (self.traversal.isComparative() and + if (self.isComparative() and self.mode.checkIfListBordersDiffer(newList, cfg) or - not self.traversal.isComparative()): + not self.isComparative()): self.mode.commonLogger.info( "Interval {c1}..{c2} reduced to cashed {c1_}..{c2_}".format( c1=curList[0], c2=curList[-1], @@ -338,7 +352,7 @@ def bypass(self, curList, list, cfg) -> int: if "sampleCommit" in cfg["serviceConfig"]: sampleCommit = cfg["serviceConfig"]["sampleCommit"] if curLen <= 2: - isBad = self.mode.compareCommits( + isBad = not self.mode.compareCommits( sampleCommit, curList[0], list, cfg) breakCommit = curList[-1] if isBad else curList[0] pc = Mode.CommitPath.PathCommit( @@ -349,7 +363,7 @@ def bypass(self, curList, list, cfg) -> int: self.mode.commitPath.accept(self, pc) return mid = (int)((curLen - 1) / 2) - isBad = self.mode.compareCommits( + isBad = not self.mode.compareCommits( sampleCommit, curList[mid], list, cfg) if isBad: self.wrappedBypass( diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py b/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py index aa12097f1079b7..af61c27691e88f 100644 --- a/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/helpers.py @@ -1,3 +1,6 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + import importlib import shutil import os @@ -31,15 +34,32 @@ def getParams(): action="store_true", help="flag if current directory is working", ) - args = parser.parse_args() + parser.add_argument( + "-u", + "--utility", + dest="utility", + help="run utility with specified name", + default="no_utility", + ) + args, additionalArgs = parser.parse_known_args() + + argHolder = DictHolder(args.__dict__) presetCfgPath = "utils/cfg.json" customCfgPath = "" - customCfgPath = args.__dict__["configuration"] + customCfgPath = argHolder.configuration presetCfgData = None with open(presetCfgPath) as cfgFile: presetCfgData = json.load(cfgFile) cfgFile.close() + + if argHolder.utility != "no_utility": + it = iter(additionalArgs) + addDict = dict(zip(it, it)) + mergedArgs = {**(args.__dict__), **addDict} + argHolder = DictHolder(mergedArgs) + return argHolder, presetCfgData, presetCfgPath + customCfgData = None with open(customCfgPath) as cfgFile: customCfgData = json.load(cfgFile) @@ -50,7 +70,7 @@ def getParams(): presetCfgData[key] = newVal presetCfgData = absolutizePaths(presetCfgData) - return args, presetCfgData, customCfgPath + return argHolder, presetCfgData, customCfgPath def getBlobDiff(file1, file2): @@ -205,7 +225,8 @@ def runCommandList(commit, cfgData): encoding="utf-8", errors="replace" ) for line in proc.stdout: - sys.stdout.write(line) + if cfgData["verboseOutput"]: + sys.stdout.write(line) commitLogger.info(line) if "catchMsg" in cmd: isErrFound = re.search(cmd["catchMsg"], line) @@ -424,6 +445,18 @@ def safeClearDir(path, cfg): return +def runUtility(cfg, args): + modName = args.utility + try: + mod = importlib.import_module( + "utils.{un}".format(un=modName)) + utilName = checkAndGetUtilityByName(cfg, modName) + utility = getattr(mod, utilName) + utility(args) + except ModuleNotFoundError as e: + raise CfgError("No utility {} found".format(modName)) + + class CfgError(Exception): pass @@ -473,9 +506,27 @@ def checkAndGetClassnameByConfig(cfg, mapName, specialCfg): return map[keyName] +def checkAndGetUtilityByName(cfg, utilName): + if not (utilName in cfg["utilMap"]): + raise CfgError( + "{utilName} is not registered in config".format( + utilName=utilName + ) + ) + else: + return cfg["utilMap"][utilName] + + def checkAndGetSubclass(clName, parentClass): cl = [cl for cl in parentClass.__subclasses__() if cl.__name__ == clName] if not (cl.__len__() == 1): raise CfgError("Class {clName} doesn't exist".format(clName=clName)) else: return cl[0] + + +class DictHolder: + def __init__(self, dict: dict = None): + if dict is not None: + for k, v in dict.items(): + setattr(self, k, v) diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/log_parser.py b/src/plugins/intel_cpu/tools/commit_slider/utils/log_parser.py new file mode 100644 index 00000000000000..20e08ee77613bf --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/log_parser.py @@ -0,0 +1,110 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import re +import zipfile +import os +import csv +import shutil +from utils.helpers import CfgError + + +def getMap(hashPatternList, intervalPatternList): + intervalPos = 2 # as in 'Check interval i1..i2' pattern + hashMap = {} + + for i, x in enumerate(intervalPatternList): + leftHash = hashPatternList[i].split()\ + [intervalPos].split("..")[0] + rightHash = hashPatternList[i].split()\ + [intervalPos].split("..")[1] + + leftInd = (x.split()[2]).split("..")[0] + rightInd = (x.split()[2]).split("..")[1] + + hashMap[leftInd] = leftHash + hashMap[rightInd] = rightHash + + return hashMap + +def extractPatterns(dirName): + data = "" + + with open(os.path.join(dirName, "logcommon_log.log")) as file: + data = file.read() + intervalPattern = "[A-Za-z0-9]*\.\.[A-Za-z0-9]*" + + pattern = "Check commits {}".format(intervalPattern) + stats_re = re.compile(pattern, re.MULTILINE | re.DOTALL) + hashPatternList = stats_re.findall(data) + + pattern = "Check interval {}".format(intervalPattern) + stats_re = re.compile(pattern, re.MULTILINE | re.DOTALL) + intervalPatternList = stats_re.findall(data) + + return hashPatternList, intervalPatternList + +def prepareCSVData(hashMap, dirName): + throughputPattern = "Throughput:\s*([0-9]*[.][0-9]*)\s*FPS" + csvData = [] + + for k, v in hashMap.items(): + logFileName = "logcommit_{}.log".format(v) + + if logFileName not in os.listdir(dirName): + raise LookupError("No {} in logs".format(logFileName)) + + with open(os.path.join(dirName, logFileName)) as logFile: + data = logFile.read() + + foundThroughput = re.search( + throughputPattern, data, flags=re.MULTILINE + ).group(1) + + csvData.append({ + "id": k, + "hash": v, + "throughput": foundThroughput + }) + + csvData.sort(key=lambda x: int(x['id'])) + + return csvData + +def makeCSV(csvData): + fields = ['id', 'hash', 'throughput'] + rows = [] + + for item in csvData: + row = [item['id'], item['hash'], item['throughput']] + rows.append(row) + + with open("csv_report.csv", 'w') as csvfile: + csvwriter = csv.writer(csvfile) + csvwriter.writerow(fields) + csvwriter.writerows(rows) + +def logParser(args, zipName="archive", dirName = "artifacts"): + if "-path" not in args: + raise CfgError("No 'path' for log parser provided") + elif "-zip_name" in args: + zipName = args["-zip_name"] + path = str(args["-path"]) + + clearArtifacts = False + + if path.endswith('.zip'): + clearArtifacts = True + with zipfile.ZipFile(path, 'r') as zip_ref: + zip_ref.extractall(dirName) + dirName = os.path.join(dirName, zipName) + else: + dirName = path + + hashPatternList, intervalPatternList = extractPatterns(dirName) + hashMap = getMap(hashPatternList, intervalPatternList) + csvData = prepareCSVData(hashMap, dirName) + makeCSV(csvData) + + if clearArtifacts: + shutil.rmtree(dirName) diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/map_builder.py b/src/plugins/intel_cpu/tools/commit_slider/utils/map_builder.py new file mode 100644 index 00000000000000..40c022111a18bb --- /dev/null +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/map_builder.py @@ -0,0 +1,27 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from os import walk, path +import json +from utils.helpers import CfgError + +def buildMap(commonPath, subPath=None): + precomPath = commonPath + items = next(walk(precomPath), (None, None, []))[1] + map = {} + for item in items: + item = item.replace('"', '') + curPath = path.join(precomPath, item) + if (subPath is not None and subPath): + curPath = path.join(curPath, subPath) + map[item] = curPath + return json.dumps(map) + + +def printMap(args): + if "-path" not in args: + raise CfgError("No 'path' for map builder provided") + if "-subPath" in args: + print(buildMap(args["-path"], args["-subPath"])) + else: + print(buildMap(args["-path"])) diff --git a/src/plugins/intel_cpu/tools/commit_slider/utils/modes.py b/src/plugins/intel_cpu/tools/commit_slider/utils/modes.py index 4ccc05c3c40dff..9d615f0cb359ed 100644 --- a/src/plugins/intel_cpu/tools/commit_slider/utils/modes.py +++ b/src/plugins/intel_cpu/tools/commit_slider/utils/modes.py @@ -1,3 +1,6 @@ +# Copyright (C) 2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + import os from utils.helpers import fetchAppOutput, getActualPath from utils.helpers import getMeaningfullCommitTail @@ -39,7 +42,7 @@ def checkCfg(self, cfg): raise CfgError("stopPattern is not configured") def compareCommits(self, lCommit, rCommit, list, cfg): - isLeftBorderFailed = self.getPseudoMetric(lCommit, cfg) + isLeftBorderFailed = bool(self.getPseudoMetric(lCommit, cfg)) isRightBorderGood = not self.getPseudoMetric(rCommit, cfg) curCommit = rCommit.replace('"', "") commitLogger = getCommitLogger(cfg, curCommit) @@ -82,6 +85,9 @@ def __init__(self, cfg): self.perfRel = 0 self.createCash() + def isPerformanceBased(self): + return True + def prepareRun(self, list, cfg): super().prepareRun(list, cfg) sampleCommit = list[0] From b0e507c6c34dea3c81a5deb2492d1e41bc7b4e53 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Tue, 30 Jan 2024 15:34:21 +0400 Subject: [PATCH 21/27] Removed runtime::Tensor alias (#22429) * Removed AllocatorImpl, runtime::Tensor alias * Update OMZ * Updated submodule --- .../include/openvino/runtime/allocator.hpp | 8 +-- src/core/include/openvino/runtime/tensor.hpp | 5 -- src/core/src/preprocess/preprocess_impls.hpp | 2 +- .../functional/single_layer_tests/gather.cpp | 2 +- .../single_layer_tests/grid_sample.cpp | 2 +- .../non_max_suppression.cpp | 2 +- .../functional/single_layer_tests/rdft.cpp | 6 +- .../single_layer_tests/shape_ops.cpp | 4 +- .../functional/single_layer_tests/unique.cpp | 2 +- .../subgraph_tests/src/reshape_inplace.cpp | 4 +- .../dynamic/grid_sample.cpp | 2 +- .../dynamic/non_max_suppression.cpp | 2 +- .../dynamic_smoke_test_with_empty_tensor.cpp | 2 +- src/plugins/template/backend/executable.hpp | 16 ++--- .../functional/op_reference/interpolate.cpp | 8 +-- .../tests/functional/op_reference/memory.cpp | 8 +-- .../functional/op_reference/region_yolo.cpp | 4 +- .../src/read_ir/read_ir.cpp | 2 +- .../infer_request_dynamic.hpp | 2 +- .../ov_infer_request/iteration_chaining.hpp | 2 +- .../infer_request_dynamic.cpp | 16 ++--- .../behavior/ov_infer_request/io_tensor.cpp | 4 +- .../ov_infer_request/iteration_chaining.cpp | 2 +- .../base/utils/compare_results.hpp | 4 +- .../base/utils/generate_inputs.hpp | 2 +- .../subgraph/stateful_model.hpp | 12 ++-- ...imental_detectron_prior_grid_generator.cpp | 4 +- .../src/single_op/activation.cpp | 4 +- .../shared_test_classes/src/single_op/dft.cpp | 2 +- .../src/single_op/rdft.cpp | 2 +- .../include/common_test_utils/data_utils.hpp | 2 +- .../common_test_utils/ov_tensor_utils.hpp | 62 +++++++++---------- .../common_test_utils/src/data_utils.cpp | 4 +- .../common_test_utils/src/ov_tensor_utils.cpp | 36 +++++------ thirdparty/open_model_zoo | 2 +- 35 files changed, 116 insertions(+), 127 deletions(-) diff --git a/src/core/include/openvino/runtime/allocator.hpp b/src/core/include/openvino/runtime/allocator.hpp index a8721b72554306..f92be30a434d40 100644 --- a/src/core/include/openvino/runtime/allocator.hpp +++ b/src/core/include/openvino/runtime/allocator.hpp @@ -14,9 +14,9 @@ #include "openvino/core/any.hpp" #include "openvino/core/core_visibility.hpp" -#include "openvino/core/deprecated.hpp" namespace ov { + class Tensor; /** @@ -158,10 +158,4 @@ class OPENVINO_API Allocator { explicit operator bool() const noexcept; }; -OPENVINO_SUPPRESS_DEPRECATED_START -namespace runtime { -using ov::Allocator; -} // namespace runtime -OPENVINO_SUPPRESS_DEPRECATED_END - } // namespace ov diff --git a/src/core/include/openvino/runtime/tensor.hpp b/src/core/include/openvino/runtime/tensor.hpp index 43f63402e49da2..61b829fafb2ac1 100644 --- a/src/core/include/openvino/runtime/tensor.hpp +++ b/src/core/include/openvino/runtime/tensor.hpp @@ -259,9 +259,4 @@ class OPENVINO_API Tensor { */ using TensorVector = std::vector; -namespace runtime { -using ov::Tensor; -using ov::TensorVector; -} // namespace runtime - } // namespace ov diff --git a/src/core/src/preprocess/preprocess_impls.hpp b/src/core/src/preprocess/preprocess_impls.hpp index 4d72a826a286e3..0bf89fe0918441 100644 --- a/src/core/src/preprocess/preprocess_impls.hpp +++ b/src/core/src/preprocess/preprocess_impls.hpp @@ -218,7 +218,7 @@ class InputTensorInfo::InputTensorInfoImpl : public TensorInfoImplBase { m_shape_set = true; } - void set_from(const ov::runtime::Tensor& runtime_tensor) { + void set_from(const ov::Tensor& runtime_tensor) { set_shape(runtime_tensor.get_shape()); set_element_type(runtime_tensor.get_element_type()); } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp index 3362bda02fdb78..02f92d7fc2f0b9 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp @@ -128,7 +128,7 @@ class GatherLayerTestCPU : public testing::WithParamInterfaceget_friendly_name() == "data") { diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/grid_sample.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/grid_sample.cpp index 3ef7ef621e0f3d..3a0f80868543c2 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/grid_sample.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/grid_sample.cpp @@ -136,7 +136,7 @@ class GridSampleLayerTestCPU : public testing::WithParamInterfaceget_friendly_name() == "data") { diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/non_max_suppression.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/non_max_suppression.cpp index 00b7c82bd1be15..567634cc6b9597 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/non_max_suppression.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/non_max_suppression.cpp @@ -96,7 +96,7 @@ class NmsLayerCPUTest : public testing::WithParamInterface, virtual p auto node = funcInputs[2].get_node_shared_ptr(); auto it = inputs.find(node); if (it == inputs.end()) return; - auto tensor = ov::runtime::Tensor(node->get_element_type(), targetInputStaticShapes[2], &maxOutBoxesPerClass); + auto tensor = ov::Tensor(node->get_element_type(), targetInputStaticShapes[2], &maxOutBoxesPerClass); inputs[node] = tensor; } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/rdft.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/rdft.cpp index 18471afff43294..06b58627ebfa40 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/rdft.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/rdft.cpp @@ -152,21 +152,21 @@ class RDFTTestCPU : public testing::WithParamInterfaceinputs(); auto funcInput = funcInputs.begin(); inputs.clear(); - runtime::Tensor data_tensor = test::utils::create_and_fill_tensor_normal_distribution(funcInput->get_element_type(), + ov::Tensor data_tensor = test::utils::create_and_fill_tensor_normal_distribution(funcInput->get_element_type(), targetInputStaticShapes[0], 0, 1, 0); inputs.insert({funcInput->get_node_shared_ptr(), data_tensor}); funcInput++; if (!constAxes && funcInput != funcInputs.end()) { ASSERT_TRUE(inputIdx < axes.size()); - auto tensor = ov::runtime::Tensor{funcInput->get_element_type(), Shape{axes[inputIdx].size()}}; + auto tensor = ov::Tensor{funcInput->get_element_type(), Shape{axes[inputIdx].size()}}; std::memcpy(tensor.data(), axes[inputIdx].data(), axes[inputIdx].size() * sizeof(axes[0][0])); inputs.insert({funcInput->get_node_shared_ptr(), tensor}); funcInput++; } if (!constSignalSizes && funcInput != funcInputs.end()) { ASSERT_TRUE(inputIdx < signalSizes.size()); - auto tensor = ov::runtime::Tensor{funcInput->get_element_type(), Shape{signalSizes[inputIdx].size()}}; + auto tensor = ov::Tensor{funcInput->get_element_type(), Shape{signalSizes[inputIdx].size()}}; std::memcpy(tensor.data(), signalSizes[inputIdx].data(), signalSizes[inputIdx].size() * sizeof(signalSizes[0][0])); inputs.insert({funcInput->get_node_shared_ptr(), tensor}); } diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp index 576869d3fec977..bd3a32e13e93e5 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/shape_ops.cpp @@ -83,11 +83,11 @@ class ShapeOpsCPUTest : public testing::WithParamInterface, const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; - ov::runtime::Tensor tensor; + ov::Tensor tensor; if (i == 1) { #define RESHAPE_TEST_CASE(INT_TYPE) \ case ov::element::Type_t::INT_TYPE: { \ - tensor = ov::runtime::Tensor{ov::element::INT_TYPE, targetInputStaticShapes[i]}; \ + tensor = ov::Tensor{ov::element::INT_TYPE, targetInputStaticShapes[i]}; \ auto inputData = tensor.data::value_type>(); \ ASSERT_TRUE(idx < data.size()); \ for (size_t j = 0lu; j < data[idx].size(); ++j) { \ diff --git a/src/plugins/intel_cpu/tests/functional/single_layer_tests/unique.cpp b/src/plugins/intel_cpu/tests/functional/single_layer_tests/unique.cpp index 9ad0401f789ade..0d96d3af3cc00b 100644 --- a/src/plugins/intel_cpu/tests/functional/single_layer_tests/unique.cpp +++ b/src/plugins/intel_cpu/tests/functional/single_layer_tests/unique.cpp @@ -120,7 +120,7 @@ class UniqueLayerTestCPU : public testing::WithParamInterfaceget_friendly_name() == "data") { int32_t range = std::accumulate(targetInputStaticShapes[0].begin(), targetInputStaticShapes[0].end(), 1, std::multiplies()); diff --git a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/reshape_inplace.cpp b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/reshape_inplace.cpp index 7a6ed5be8aa8b5..52c588f962c42e 100644 --- a/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/reshape_inplace.cpp +++ b/src/plugins/intel_cpu/tests/functional/subgraph_tests/src/reshape_inplace.cpp @@ -57,9 +57,9 @@ class InPlaceReshapeFromConstantCheck : public SubgraphBaseTest { const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; - ov::runtime::Tensor tensor; + ov::Tensor tensor; if (i == 1) { - tensor = ov::runtime::Tensor{ov::element::i32, targetInputStaticShapes[i]}; + tensor = ov::Tensor{ov::element::i32, targetInputStaticShapes[i]}; auto inputData = tensor.data::value_type>(); const std::vector data = {38, 38, 15, 4}; for (size_t j = 0lu; j < data.size(); ++j) { diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/grid_sample.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/grid_sample.cpp index 8c432154f730b3..6b0251cb21c4aa 100644 --- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/grid_sample.cpp +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/grid_sample.cpp @@ -99,7 +99,7 @@ class GridSampleLayerTestGPU : public testing::WithParamInterfaceget_friendly_name() == "data") { diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/non_max_suppression.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/non_max_suppression.cpp index ffda0040d446e4..1937b18bc73460 100644 --- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/non_max_suppression.cpp +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/non_max_suppression.cpp @@ -103,7 +103,7 @@ class NmsLayerGPUTest : public testing::WithParamInterface, auto node = funcInputs[2].get_node_shared_ptr(); auto it = inputs.find(node); if (it == inputs.end()) return; - auto tensor = ov::runtime::Tensor(node->get_element_type(), targetInputStaticShapes[2], &maxOutBoxesPerClass); + auto tensor = ov::Tensor(node->get_element_type(), targetInputStaticShapes[2], &maxOutBoxesPerClass); inputs[node] = tensor; } diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_smoke_test_with_empty_tensor.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_smoke_test_with_empty_tensor.cpp index 88ceb3ea6db14b..d9407640327cb8 100644 --- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_smoke_test_with_empty_tensor.cpp +++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/dynamic_smoke_test_with_empty_tensor.cpp @@ -54,7 +54,7 @@ class EmptyTensorDynamicGPUTest : public testing::WithParamInterfaceinputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { auto node = funcInputs[i].get_node_shared_ptr(); - auto tensor = ov::runtime::Tensor(node->get_element_type(), targetInputStaticShapes[i]); + auto tensor = ov::Tensor(node->get_element_type(), targetInputStaticShapes[i]); if (i == 0) { // All zero inputs for non_zero op auto tensor_ptr = static_cast(tensor.data()); diff --git a/src/plugins/template/backend/executable.hpp b/src/plugins/template/backend/executable.hpp index 2259cc5192a4c0..347c4493f04bc4 100644 --- a/src/plugins/template/backend/executable.hpp +++ b/src/plugins/template/backend/executable.hpp @@ -19,16 +19,16 @@ class Executable { Executable(); virtual ~Executable(); - /// \param outputs vector of runtime::Tensor used as outputs - /// \param inputs vector of runtime::Tensor used as inputs + /// \param outputs vector of Tensor used as outputs + /// \param inputs vector of Tensor used as inputs /// \param collect_performance Enable per operation performance statistic /// \returns true if iteration is successful, false otherwise virtual bool call(std::vector& outputs, const std::vector& inputs, bool collect_performance = false) = 0; - /// \param outputs vector of runtime::Tensor used as outputs - /// \param inputs vector of runtime::Tensor used as inputs + /// \param outputs vector of Tensor used as outputs + /// \param inputs vector of Tensor used as inputs /// \param context Evaluation context /// \param collect_performance Enable per operation performance statistic /// \returns true if iteration is successful, false otherwise @@ -41,14 +41,14 @@ class Executable { virtual void cancel() = 0; /// \brief Executes a single iteration of a Function. - /// \param outputs vector of runtime::Tensor used as outputs - /// \param inputs vector of runtime::Tensor used as inputs + /// \param outputs vector of Tensor used as outputs + /// \param inputs vector of Tensor used as inputs /// \returns true if iteration is successful, false otherwise bool call_with_validate(std::vector& outputs, const std::vector& inputs); /// \brief Validates a Function. - /// \param outputs vector of runtime::Tensor used as outputs - /// \param inputs vector of runtime::Tensor used as inputs + /// \param outputs vector of Tensor used as outputs + /// \param inputs vector of Tensor used as inputs void validate(const std::vector& outputs, const std::vector& inputs); /// \brief Query the input Parameters diff --git a/src/plugins/template/tests/functional/op_reference/interpolate.cpp b/src/plugins/template/tests/functional/op_reference/interpolate.cpp index 7eaed35bde1878..4805f4364c9401 100644 --- a/src/plugins/template/tests/functional/op_reference/interpolate.cpp +++ b/src/plugins/template/tests/functional/op_reference/interpolate.cpp @@ -50,8 +50,8 @@ struct InterpolateV1Params { Shape outShape; element::Type inType; element::Type outType; - runtime::Tensor inData; - runtime::Tensor outData; + ov::Tensor inData; + ov::Tensor outData; std::shared_ptr outShapeInput; op::v0::Interpolate::Attributes attrs; }; @@ -82,8 +82,8 @@ struct InterpolateV4Params { Shape outShape; element::Type inType; element::Type outType; - runtime::Tensor inData; - runtime::Tensor outData; + ov::Tensor inData; + ov::Tensor outData; std::vector outShapeInput; element::Type outShapeInputType; std::vector scales; diff --git a/src/plugins/template/tests/functional/op_reference/memory.cpp b/src/plugins/template/tests/functional/op_reference/memory.cpp index d2fad1ec59ad14..ffc1444c41a23c 100644 --- a/src/plugins/template/tests/functional/op_reference/memory.cpp +++ b/src/plugins/template/tests/functional/op_reference/memory.cpp @@ -36,8 +36,8 @@ struct ReadValueAssignParams { Shape m_output_shape; element::Type m_input_type; element::Type m_output_type; - runtime::Tensor m_input_data; - runtime::Tensor m_expected_data; + ov::Tensor m_input_data; + ov::Tensor m_expected_data; std::string m_variable_id; }; @@ -245,8 +245,8 @@ struct MemoryTestParams { ov::Shape m_output_shape; ov::element::Type m_input_type; ov::element::Type m_output_type; - ov::runtime::Tensor m_input_data; - ov::runtime::Tensor m_expected_data; + ov::Tensor m_input_data; + ov::Tensor m_expected_data; std::vector m_variable_id; size_t m_count_runs; size_t m_reset_on_run; diff --git a/src/plugins/template/tests/functional/op_reference/region_yolo.cpp b/src/plugins/template/tests/functional/op_reference/region_yolo.cpp index f1160722810f69..3e12ab8e4384ef 100644 --- a/src/plugins/template/tests/functional/op_reference/region_yolo.cpp +++ b/src/plugins/template/tests/functional/op_reference/region_yolo.cpp @@ -67,8 +67,8 @@ struct RegionYoloParams { ov::PartialShape inputShape; ov::element::Type inType; ov::element::Type outType; - ov::runtime::Tensor inputData; - ov::runtime::Tensor refData; + ov::Tensor inputData; + ov::Tensor refData; std::string testcaseName; }; diff --git a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/read_ir/read_ir.cpp b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/read_ir/read_ir.cpp index 5704638abe3094..10db7aebd9d195 100644 --- a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/read_ir/read_ir.cpp +++ b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/read_ir/read_ir.cpp @@ -312,7 +312,7 @@ std::vector ReadIRTest::calculate_refs() { size_t pos = 0; for (const auto& output : functionRefs->outputs()) { - auto out_tensor = ov::runtime::Tensor(output.get_element_type(), output.get_shape(), &ref_buffer[pos]); + auto out_tensor = ov::Tensor(output.get_element_type(), output.get_shape(), &ref_buffer[pos]); pos += out_tensor.get_byte_size(); } } diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/infer_request_dynamic.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/infer_request_dynamic.hpp index ea36010c8ba189..6c309643c99334 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/infer_request_dynamic.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/infer_request_dynamic.hpp @@ -41,7 +41,7 @@ class OVInferRequestDynamicTests : public testing::WithParamInterface ie = utils::PluginCache::get().core(); std::shared_ptr function; diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/iteration_chaining.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/iteration_chaining.hpp index a9711fd97a7ea5..725899cd075c44 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/iteration_chaining.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_infer_request/iteration_chaining.hpp @@ -39,7 +39,7 @@ struct OVIterationChaining : public OVInferRequestTests { private: static std::shared_ptr getIterativeFunction(); - bool checkOutput(const ov::runtime::Tensor& in, const ov::runtime::Tensor& actual); + bool checkOutput(const ov::Tensor& in, const ov::Tensor& actual); }; } // namespace behavior diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp index 7390c0726747fb..8ea45c7e788116 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/infer_request_dynamic.cpp @@ -44,7 +44,7 @@ void OVInferRequestDynamicTests::SetUp() { APIBaseTest::SetUp(); } -bool OVInferRequestDynamicTests::checkOutput(const ov::runtime::Tensor& in, const ov::runtime::Tensor& actual) { +bool OVInferRequestDynamicTests::checkOutput(const ov::Tensor& in, const ov::Tensor& actual) { bool result = true; auto net = ie->compile_model(function, ov::test::utils::DEVICE_TEMPLATE); ov::InferRequest req; @@ -96,7 +96,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetwork) { ov::test::utils::InputGenerateData in_data; in_data.start_from = -50; in_data.range = 100; - ov::runtime::Tensor inTensor = ov::test::utils::create_and_fill_tensor(element::f32, shape, in_data); + ov::Tensor inTensor = ov::test::utils::create_and_fill_tensor(element::f32, shape, in_data); OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); OV_ASSERT_NO_THROW(req.set_tensor("input_tensor", inTensor)); OV_ASSERT_NO_THROW(req.infer()); @@ -115,7 +115,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetworkSetUnexpectedOutputTensorB auto execNet = ie->compile_model(function, target_device, configuration); // Create InferRequest ov::InferRequest req; - ov::runtime::Tensor tensor, otensor; + ov::Tensor tensor, otensor; const std::string outputname = function->outputs().back().get_any_name(); OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); ov::test::utils::InputGenerateData in_data; @@ -144,7 +144,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetworkSetOutputTensorPreAllocate auto execNet = ie->compile_model(function, target_device, configuration); // Create InferRequest ov::InferRequest req; - ov::runtime::Tensor tensor; + ov::Tensor tensor; const std::string outputname = function->outputs().back().get_any_name(); OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); ov::test::utils::InputGenerateData in_data; @@ -153,7 +153,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetworkSetOutputTensorPreAllocate tensor = ov::test::utils::create_and_fill_tensor(element::f32, refShape, in_data); OV_ASSERT_NO_THROW(req.set_tensor("input_tensor", tensor)); float ptr[5000]; - ov::runtime::Tensor otensor(element::f32, refOutShape, ptr); + ov::Tensor otensor(element::f32, refOutShape, ptr); OV_ASSERT_NO_THROW(req.set_tensor(outputname, otensor)); OV_ASSERT_NO_THROW(req.infer()); ASSERT_EQ(req.get_tensor(outputname).data(), ptr); @@ -172,7 +172,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetworkSetOutputShapeBeforeInfer) auto execNet = ie->compile_model(function, target_device, configuration); // Create InferRequest ov::InferRequest req; - ov::runtime::Tensor tensor, otensor; + ov::Tensor tensor, otensor; const std::string outputname = function->outputs().back().get_any_name(); OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); ov::test::utils::InputGenerateData in_data; @@ -199,7 +199,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetworkGetOutputThenSetOutputTens auto execNet = ie->compile_model(function, target_device, configuration); // Create InferRequest ov::InferRequest req; - ov::runtime::Tensor tensor; + ov::Tensor tensor; const std::string outputname = function->outputs().back().get_any_name(); OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); ov::test::utils::InputGenerateData in_data; @@ -213,7 +213,7 @@ TEST_P(OVInferRequestDynamicTests, InferDynamicNetworkGetOutputThenSetOutputTens ASSERT_TRUE(checkOutput(req.get_tensor("input_tensor"), req.get_tensor(outputname))); // then, set output tensor float ptr[5000]; - ov::runtime::Tensor otensor(element::f32, refOutShape, ptr); + ov::Tensor otensor(element::f32, refOutShape, ptr); OV_ASSERT_NO_THROW(req.set_tensor(outputname, otensor)); OV_ASSERT_NO_THROW(req.infer()); ASSERT_EQ(req.get_tensor(outputname).data(), ptr); diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp index c716486a369951..e5820ae8d58c79 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/io_tensor.cpp @@ -235,7 +235,7 @@ TEST_P(OVInferRequestIOTensorTest, InferStaticNetworkSetChangedInputTensorThrow) OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); OV_ASSERT_NO_THROW(req.infer()); // Get input_tensor - ov::runtime::Tensor tensor; + ov::Tensor tensor; OV_ASSERT_NO_THROW(tensor = req.get_tensor(function->inputs().back().get_any_name())); // Set shape OV_ASSERT_NO_THROW(tensor.set_shape(shape2)); @@ -258,7 +258,7 @@ TEST_P(OVInferRequestIOTensorTest, InferStaticNetworkSetChangedOutputTensorThrow OV_ASSERT_NO_THROW(req = execNet.create_infer_request()); OV_ASSERT_NO_THROW(req.infer()); // Get output_tensor - ov::runtime::Tensor tensor; + ov::Tensor tensor; OV_ASSERT_NO_THROW(tensor = req.get_tensor(function->outputs().back().get_any_name());); // Set shape OV_ASSERT_NO_THROW(tensor.set_shape(shape2)); diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/iteration_chaining.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/iteration_chaining.cpp index 2e77ec5475e29f..1bb87fccfaf32d 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/iteration_chaining.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_infer_request/iteration_chaining.cpp @@ -78,7 +78,7 @@ void OVIterationChaining::TearDown() { OVInferRequestTests::TearDown(); } -bool OVIterationChaining::checkOutput(const ov::runtime::Tensor& in, const ov::runtime::Tensor& actual) { +bool OVIterationChaining::checkOutput(const ov::Tensor& in, const ov::Tensor& actual) { bool result = true; auto net = core->compile_model(function, ov::test::utils::DEVICE_TEMPLATE); ov::InferRequest req; diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/compare_results.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/compare_results.hpp index 226d608bb687d2..0db366b4e7b034 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/compare_results.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/compare_results.hpp @@ -13,8 +13,8 @@ namespace utils { using CompareMap = std::map &node, size_t port, - const ov::runtime::Tensor &expected, - const ov::runtime::Tensor &actual, + const ov::Tensor &expected, + const ov::Tensor &actual, double absThreshold, double relThreshold)>>; diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp index df2a47513e17de..6e1af8f967a6b8 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/base/utils/generate_inputs.hpp @@ -17,7 +17,7 @@ void reset_const_ranges(); std::vector color_test_image(size_t height, size_t width, int b_step, ov::preprocess::ColorFormat format); -using InputsMap = std::map& node, size_t port, const ov::element::Type& elemType, diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/stateful_model.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/stateful_model.hpp index 70016ea8b6c840..807238dc6fa966 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/stateful_model.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/subgraph/stateful_model.hpp @@ -113,7 +113,7 @@ class StaticShapeStatefulModel : public StatefulModelTest { inputs.clear(); const auto& funcInputs = function->inputs(); const auto& funcInput = funcInputs.front(); - auto tensor = ov::runtime::Tensor{ov::element::f32, funcInput.get_shape()}; + auto tensor = ov::Tensor{ov::element::f32, funcInput.get_shape()}; auto inputData = tensor.data::value_type>(); inputData[0] = input_vals[i]; inputs.insert({funcInput.get_node_shared_ptr(), tensor}); @@ -222,7 +222,7 @@ class StaticShapeTwoStatesModel : public StatefulModelTest { inputs.clear(); const auto& funcInputs = function->inputs(); const auto& funcInput = funcInputs.front(); - auto tensor = ov::runtime::Tensor{testPrc, funcInput.get_shape()}; + auto tensor = ov::Tensor{testPrc, funcInput.get_shape()}; auto inputData = tensor.data::value_type>(); inputData[0] = input_vals[i]; inputs.insert({funcInput.get_node_shared_ptr(), tensor}); @@ -336,7 +336,7 @@ class DynamicShapeStatefulModel : public StatefulModelTest { auto states = inferRequest.query_state(); ASSERT_FALSE(states.empty()); - auto init_tensor = ov::runtime::Tensor{testPrc, ov::Shape{1, 1}}; + auto init_tensor = ov::Tensor{testPrc, ov::Shape{1, 1}}; auto init_data = init_tensor.data::value_type>(); init_data[0] = vec_state[0]; states.front().set_state(init_tensor); @@ -348,7 +348,7 @@ class DynamicShapeStatefulModel : public StatefulModelTest { auto &input_shape = shapes.front(); const auto& funcInputs = function->inputs(); const auto& funcInput = funcInputs.front(); - auto tensor = ov::runtime::Tensor{testPrc, input_shape}; + auto tensor = ov::Tensor{testPrc, input_shape}; auto input_data = tensor.data::value_type>(); for (size_t i = 0; i < input_shape.front(); ++i) { input_data[i] = input_vals[i]; @@ -507,7 +507,7 @@ class DynamicShapeStatefulModelStateAsInp : public StatefulModelTest { auto states = inferRequest.query_state(); ASSERT_FALSE(states.empty()); - auto init_tensor = ov::runtime::Tensor{testPrc, ov::Shape{1, 1}}; + auto init_tensor = ov::Tensor{testPrc, ov::Shape{1, 1}}; auto init_data = init_tensor.data::value_type>(); init_data[0] = vec_state[0]; states.front().set_state(init_tensor); @@ -519,7 +519,7 @@ class DynamicShapeStatefulModelStateAsInp : public StatefulModelTest { auto &input_shape = shapes.front(); const auto& funcInputs = function->inputs(); for (auto&& funcInput : funcInputs) { - auto tensor = ov::runtime::Tensor{testPrc, input_shape}; + auto tensor = ov::Tensor{testPrc, input_shape}; auto input_data = tensor.data::value_type>(); for (size_t i = 0; i < input_shape[1]; ++i) { input_data[i] = input_vals[i]; diff --git a/src/tests/functional/shared_test_classes/src/single_layer/experimental_detectron_prior_grid_generator.cpp b/src/tests/functional/shared_test_classes/src/single_layer/experimental_detectron_prior_grid_generator.cpp index f3bf7d8bcf9edc..b11f0b530b1b4d 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/experimental_detectron_prior_grid_generator.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/experimental_detectron_prior_grid_generator.cpp @@ -74,7 +74,7 @@ void ExperimentalDetectronPriorGridGeneratorLayerTest::SetUp() { namespace { template -ov::runtime::Tensor generateTensorByShape(const Shape &shape) { +ov::Tensor generateTensorByShape(const Shape &shape) { return ov::test::utils::create_tensor( ov::element::from(), shape, @@ -98,7 +98,7 @@ void ExperimentalDetectronPriorGridGeneratorLayerTest::generate_inputs(const std inputs.insert({funcInputs[i].get_node_shared_ptr(), inputTensors.second[i]}); } for (auto j = i; j < funcInputs.size(); ++j) { - ov::runtime::Tensor inputTensor = (netPrecision == element::f16) + ov::Tensor inputTensor = (netPrecision == element::f16) ? generateTensorByShape(targetInputStaticShapes[j]) : generateTensorByShape( targetInputStaticShapes[j]); diff --git a/src/tests/functional/shared_test_classes/src/single_op/activation.cpp b/src/tests/functional/shared_test_classes/src/single_op/activation.cpp index d4f52dfd61fe71..e459d217052cbc 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/activation.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/activation.cpp @@ -111,7 +111,7 @@ void ActivationLayerTest::generate_inputs(const std::vector& targetIn const auto& funcInputs = function->inputs(); auto funcInput = funcInputs.begin(); inputs.clear(); - runtime::Tensor data_tensor = ov::test::utils::create_and_fill_tensor_act_dft(funcInput->get_element_type(), + Tensor data_tensor = ov::test::utils::create_and_fill_tensor_act_dft(funcInput->get_element_type(), targetInputStaticShapes[0], data_range, data_start_from, @@ -132,7 +132,7 @@ void ActivationParamLayerTest::generate_inputs(const std::vector& tar const auto& funcInputs = function->inputs(); for (size_t i = 0; i < funcInputs.size(); ++i) { const auto& funcInput = funcInputs[i]; - runtime::Tensor data_tensor; + Tensor data_tensor; const std::string& name = funcInput.get_node()->get_friendly_name(); if (0 == name.compare("negativeSlope")) { ov::test::utils::InputGenerateData in_data; diff --git a/src/tests/functional/shared_test_classes/src/single_op/dft.cpp b/src/tests/functional/shared_test_classes/src/single_op/dft.cpp index 654a7185be1431..94a4c6d9f95e97 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/dft.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/dft.cpp @@ -52,7 +52,7 @@ void DFTLayerTest::generate_inputs(const std::vector& targetInputStat } inputs.clear(); - runtime::Tensor data_tensor = ov::test::utils::create_and_fill_tensor_act_dft(funcInput->get_element_type(), + Tensor data_tensor = ov::test::utils::create_and_fill_tensor_act_dft(funcInput->get_element_type(), targetInputStaticShapes[0], inGenData.range, inGenData.start_from, inGenData.resolution, inGenData.seed); inputs.insert({funcInput->get_node_shared_ptr(), data_tensor}); diff --git a/src/tests/functional/shared_test_classes/src/single_op/rdft.cpp b/src/tests/functional/shared_test_classes/src/single_op/rdft.cpp index bbadca390fb492..361845d61ecd79 100644 --- a/src/tests/functional/shared_test_classes/src/single_op/rdft.cpp +++ b/src/tests/functional/shared_test_classes/src/single_op/rdft.cpp @@ -51,7 +51,7 @@ void RDFTLayerTest::generate_inputs(const std::vector& targetInputSta } inputs.clear(); - runtime::Tensor data_tensor = ov::test::utils::create_and_fill_tensor_act_dft(funcInput->get_element_type(), + Tensor data_tensor = ov::test::utils::create_and_fill_tensor_act_dft(funcInput->get_element_type(), targetInputStaticShapes[0], inGenData.range, inGenData.start_from, inGenData.resolution, inGenData.seed); inputs.insert({funcInput->get_node_shared_ptr(), data_tensor}); diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp index a64ae64f01e9e7..45471f0249fa28 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/data_utils.hpp @@ -170,7 +170,7 @@ void fill_psroi(ov::Tensor& tensor, int spatialBinsY, const std::string& mode); -void fill_data_roi(ov::runtime::Tensor& tensor, +void fill_data_roi(ov::Tensor& tensor, const uint32_t range, const int height, const int width, diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/ov_tensor_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/ov_tensor_utils.hpp index 3c9d97eeb72822..0bd6140e2133ad 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/ov_tensor_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/ov_tensor_utils.hpp @@ -36,46 +36,46 @@ ov::Tensor create_and_fill_tensor(const ov::element::Type element_type, const int seed = 1); template -static ov::runtime::Tensor create_tensor(const ov::element::Type& element_type, - const ov::Shape& shape, - const std::vector& values, - const size_t size = 0) { +static ov::Tensor create_tensor(const ov::element::Type& element_type, + const ov::Shape& shape, + const std::vector& values, + const size_t size = 0) { const size_t real_size = size ? size : values.size() * sizeof(T) / element_type.size(); - ov::runtime::Tensor tensor{element_type, shape}; + ov::Tensor tensor{element_type, shape}; std::memcpy(tensor.data(), values.data(), std::min(real_size * element_type.size(), sizeof(T) * values.size())); return tensor; } -ov::runtime::Tensor create_and_fill_tensor_act_dft(const ov::element::Type element_type, - const ov::Shape& shape, - const uint32_t range = 10, - const double_t start_from = 0, - const int32_t resolution = 1, - const int seed = 1); +ov::Tensor create_and_fill_tensor_act_dft(const ov::element::Type element_type, + const ov::Shape& shape, + const uint32_t range = 10, + const double_t start_from = 0, + const int32_t resolution = 1, + const int seed = 1); -ov::runtime::Tensor create_and_fill_tensor_unique_sequence(const ov::element::Type element_type, - const ov::Shape& shape, - const int32_t start_from = 0, - const int32_t resolution = 1, - const int seed = 1); +ov::Tensor create_and_fill_tensor_unique_sequence(const ov::element::Type element_type, + const ov::Shape& shape, + const int32_t start_from = 0, + const int32_t resolution = 1, + const int seed = 1); -ov::runtime::Tensor create_and_fill_tensor_normal_distribution(const ov::element::Type element_type, - const ov::Shape& shape, - const float mean, - const float stddev, - const int seed = 1); +ov::Tensor create_and_fill_tensor_normal_distribution(const ov::element::Type element_type, + const ov::Shape& shape, + const float mean, + const float stddev, + const int seed = 1); -ov::runtime::Tensor create_and_fill_tensor_consistently(const ov::element::Type element_type, - const ov::Shape& shape, - const uint32_t range, - const int32_t start_from, - const int32_t resolution); +ov::Tensor create_and_fill_tensor_consistently(const ov::element::Type element_type, + const ov::Shape& shape, + const uint32_t range, + const int32_t start_from, + const int32_t resolution); -ov::runtime::Tensor create_and_fill_tensor_real_distribution(const ov::element::Type element_type, - const ov::Shape& shape, - const float min, - const float max, - const int seed); +ov::Tensor create_and_fill_tensor_real_distribution(const ov::element::Type element_type, + const ov::Shape& shape, + const float min, + const float max, + const int seed); void compare(const ov::Tensor& expected, const ov::Tensor& actual, diff --git a/src/tests/test_utils/common_test_utils/src/data_utils.cpp b/src/tests/test_utils/common_test_utils/src/data_utils.cpp index dc43186c7f3142..c9c25f82235cec 100644 --- a/src/tests/test_utils/common_test_utils/src/data_utils.cpp +++ b/src/tests/test_utils/common_test_utils/src/data_utils.cpp @@ -338,7 +338,7 @@ void fill_psroi(ov::Tensor& tensor, } template -inline void fill_data_roi_impl(ov::runtime::Tensor& tensor, +inline void fill_data_roi_impl(ov::Tensor& tensor, const uint32_t range, const int height, const int width, @@ -384,7 +384,7 @@ inline void fill_data_roi_impl(ov::runtime::Tensor& tensor, } } -void fill_data_roi(ov::runtime::Tensor& tensor, +void fill_data_roi(ov::Tensor& tensor, const uint32_t range, const int height, const int width, diff --git a/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp b/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp index 281310fb4e83c7..ee85e0c88cebad 100644 --- a/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp +++ b/src/tests/test_utils/common_test_utils/src/ov_tensor_utils.cpp @@ -174,12 +174,12 @@ ov::Tensor create_and_fill_tensor_unique_sequence(const ov::element::Type elemen return tensor; } -ov::runtime::Tensor create_and_fill_tensor_normal_distribution(const ov::element::Type element_type, - const ov::Shape& shape, - const float mean, - const float stddev, - const int seed) { - auto tensor = ov::runtime::Tensor{element_type, shape}; +ov::Tensor create_and_fill_tensor_normal_distribution(const ov::element::Type element_type, + const ov::Shape& shape, + const float mean, + const float stddev, + const int seed) { + auto tensor = ov::Tensor{element_type, shape}; #define CASE(X) \ case X: \ fill_data_ptr_normal_random_float(tensor.data::value_type>(), \ @@ -218,12 +218,12 @@ ov::runtime::Tensor create_and_fill_tensor_normal_distribution(const ov::element return tensor; } -ov::runtime::Tensor create_and_fill_tensor_real_distribution(const ov::element::Type element_type, - const ov::Shape& shape, - const float min, - const float max, - const int seed) { - auto tensor = ov::runtime::Tensor{element_type, shape}; +ov::Tensor create_and_fill_tensor_real_distribution(const ov::element::Type element_type, + const ov::Shape& shape, + const float min, + const float max, + const int seed) { + auto tensor = ov::Tensor{element_type, shape}; #define CASE(X) \ case X: \ fill_data_ptr_real_random_float(tensor.data::value_type>(), \ @@ -258,12 +258,12 @@ ov::runtime::Tensor create_and_fill_tensor_real_distribution(const ov::element:: return tensor; } -ov::runtime::Tensor create_and_fill_tensor_consistently(const ov::element::Type element_type, - const ov::Shape& shape, - const uint32_t range, - const int32_t start_from, - const int32_t resolution) { - auto tensor = ov::runtime::Tensor{element_type, shape}; +ov::Tensor create_and_fill_tensor_consistently(const ov::element::Type element_type, + const ov::Shape& shape, + const uint32_t range, + const int32_t start_from, + const int32_t resolution) { + auto tensor = ov::Tensor{element_type, shape}; #define CASE(X) \ case X: \ fill_data_ptr_consistently(tensor.data::value_type>(), \ diff --git a/thirdparty/open_model_zoo b/thirdparty/open_model_zoo index e8fb4cd86a516c..126fac1894c806 160000 --- a/thirdparty/open_model_zoo +++ b/thirdparty/open_model_zoo @@ -1 +1 @@ -Subproject commit e8fb4cd86a516ce5765290e9665f8afe87b79b2e +Subproject commit 126fac1894c806190a0e0a9737b5fc692d7f4baa From 688279ab372c6e49016a399b4fd6d83b885388c6 Mon Sep 17 00:00:00 2001 From: Roman Kazantsev Date: Tue, 30 Jan 2024 15:45:26 +0400 Subject: [PATCH 22/27] [TF FE] Support LookupTableFindV2 for integer keys (#22517) * [TF FE] Support LookupTableFindV2 for integer keys Signed-off-by: Kazantsev, Roman * Update src/frontends/tensorflow/include/openvino/frontend/tensorflow/variable.hpp * Update src/frontends/tensorflow/src/hash_table.hpp * Update src/frontends/tensorflow/src/op/lookup_table_find.cpp * Fix build * Override get_value for HashTable Signed-off-by: Kazantsev, Roman * Fix translator for lookup_table_find Signed-off-by: Kazantsev, Roman * Update lookup_table_find to support unsorted keys with holes Signed-off-by: Kazantsev, Roman * Test both HashTable v1 and v2 Signed-off-by: Kazantsev, Roman --------- Signed-off-by: Kazantsev, Roman --- .../tensorflow/docs/supported_ops.md | 8 +- .../openvino/frontend/tensorflow/variable.hpp | 16 ++- src/frontends/tensorflow/src/hash_table.hpp | 113 ++++++++++++++++++ .../tensorflow/src/op/hash_table.cpp | 9 +- .../tensorflow/src/op/lookup_table_find.cpp | 103 ++++++++++++++++ .../tensorflow/src/op/lookup_table_import.cpp | 42 +++++++ src/frontends/tensorflow/src/op_table.cpp | 6 + .../include/helper_ops/hash_table.hpp | 35 ------ .../test_tf_LookupTableFind.py | 81 +++++++++++++ 9 files changed, 369 insertions(+), 44 deletions(-) create mode 100644 src/frontends/tensorflow/src/hash_table.hpp create mode 100644 src/frontends/tensorflow/src/op/lookup_table_find.cpp create mode 100644 src/frontends/tensorflow/src/op/lookup_table_import.cpp delete mode 100644 src/frontends/tensorflow_common/include/helper_ops/hash_table.hpp create mode 100644 tests/layer_tests/tensorflow_tests/test_tf_LookupTableFind.py diff --git a/src/frontends/tensorflow/docs/supported_ops.md b/src/frontends/tensorflow/docs/supported_ops.md index 27d61a8bf7ad69..a717aca899d91a 100644 --- a/src/frontends/tensorflow/docs/supported_ops.md +++ b/src/frontends/tensorflow/docs/supported_ops.md @@ -594,10 +594,10 @@ A "supported operation" is one that TensorFlow Frontend can convert to the OpenV | LogicalOr | YES | | | LookupTableExport | NO | | | LookupTableExportV2 | NO | | -| LookupTableFind | NO | | -| LookupTableFindV2 | NO | | -| LookupTableImport | NO | | -| LookupTableImportV2 | NO | | +| LookupTableFind | YES | | +| LookupTableFindV2 | YES | | +| LookupTableImport | YES | | +| LookupTableImportV2 | YES | | | LookupTableInsert | YES | | | LookupTableInsertV2 | YES | | | LookupTableRemoveV2 | NO | | diff --git a/src/frontends/tensorflow/include/openvino/frontend/tensorflow/variable.hpp b/src/frontends/tensorflow/include/openvino/frontend/tensorflow/variable.hpp index e8f783c994f153..88f4ca551a2fb2 100644 --- a/src/frontends/tensorflow/include/openvino/frontend/tensorflow/variable.hpp +++ b/src/frontends/tensorflow/include/openvino/frontend/tensorflow/variable.hpp @@ -4,6 +4,7 @@ #pragma once +#include "openvino/frontend/tensorflow/decoder.hpp" #include "openvino/op/util/framework_node.hpp" namespace ov { @@ -15,6 +16,17 @@ class Variable : public ov::op::util::FrameworkNode { using Ptr = std::shared_ptr; OPENVINO_OP("TFVariable", "ov::frontend::tensorflow", ::ov::op::util::FrameworkNode); + Variable(const std::string& name, const std::shared_ptr& decoder) + : ov::op::util::FrameworkNode(ov::OutputVector{}, 1), + m_name(name), + m_shape(ov::Shape{}), + m_type(ov::element::dynamic), + m_decoder(decoder), + m_is_initialized(false), + m_init_counter(0) { + validate_and_infer_types(); + } + Variable(const std::string& name, const ov::Shape& shape, const ov::element::Type& type, @@ -60,7 +72,7 @@ class Variable : public ov::op::util::FrameworkNode { return m_is_initialized; } - ov::Output get_value() const { + virtual ov::Output get_value() { FRONT_END_GENERAL_CHECK( m_is_initialized, "[TensorFlow Frontend] internal error: get_value() is called for uninitialized variable"); @@ -75,7 +87,7 @@ class Variable : public ov::op::util::FrameworkNode { return m_init_counter; } -private: +protected: std::string m_name; ov::Shape m_shape; ov::element::Type m_type; diff --git a/src/frontends/tensorflow/src/hash_table.hpp b/src/frontends/tensorflow/src/hash_table.hpp new file mode 100644 index 00000000000000..74407e6e323548 --- /dev/null +++ b/src/frontends/tensorflow/src/hash_table.hpp @@ -0,0 +1,113 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include "openvino/core/node_output.hpp" +#include "openvino/core/type/element_type.hpp" +#include "openvino/frontend/tensorflow/variable.hpp" + +namespace ov { +namespace frontend { +namespace tensorflow { + +// this class describes TensorFlow table produced by operations tf.raw_ops.HashTable, tf.raw_ops.HashTableV2, +// tf.raw_ops.MutableHashTable and stores a dictionary of keys mapped to values +// Objects of this class is fed to Lookup* operations for initialization and searching values by keys +// Types of keys and values can be different +class HashTable : public Variable { +public: + using Ptr = std::shared_ptr; + OPENVINO_OP("TFHashTable", "ov::frontend::tensorflow", Variable); + + HashTable(const std::string& name, + const ov::element::Type& key_type, + const ov::element::Type& value_type, + const std::shared_ptr& decoder = nullptr) + : Variable(name, decoder), + m_key_type(key_type), + m_value_type(value_type) { + validate_and_infer_types(); + } + + HashTable(const HashTable& other, const ov::Output& keys, const ov::Output& values) + : HashTable(other) { + m_keys = keys; + m_values = values; + // reset names of tensor corresponding to variable value + // that is because variable can have multiple values during inference + m_keys.set_names({}); + m_values.set_names({}); + m_is_initialized = true; + ++m_init_counter; + } + + // it must be used only for cloning + // other ways are illegal + HashTable(const std::string& name, + const ov::element::Type& key_type, + const ov::element::Type& value_type, + const ov::Output& keys, + const ov::Output& values, + bool is_initialized, + uint64_t init_counter, + const std::shared_ptr& decoder = nullptr) + : Variable(name, decoder), + m_key_type(key_type), + m_value_type(value_type), + m_keys(keys), + m_values(values) { + m_init_counter = init_counter; + m_is_initialized = is_initialized; + validate_and_infer_types(); + } + + void validate_and_infer_types() override { + // this is a type of resource so its shape and type is not applicable + set_output_type(0, ov::element::dynamic, ov::PartialShape::dynamic()); + } + + std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override { + auto hash_table_node = std::make_shared(m_name, + m_key_type, + m_value_type, + m_keys, + m_values, + m_is_initialized, + m_init_counter, + m_decoder); + hash_table_node->set_attrs(get_attrs()); + return hash_table_node; + } + + ov::Output get_values() const { + FRONT_END_GENERAL_CHECK(m_is_initialized, + "[TensorFlow Frontend] internal error: get_values() is called for uninitialized table"); + return m_values; + } + + ov::Output get_keys() const { + FRONT_END_GENERAL_CHECK(m_is_initialized, + "[TensorFlow Frontend] internal error: get_values() is called for uninitialized table"); + return m_keys; + } + + ov::Output get_value() override { + return output(0); + } + + ov::element::Type get_key_type() const { + return m_key_type; + } + +private: + ov::element::Type m_key_type; + ov::element::Type m_value_type; + ov::Output m_keys; + ov::Output m_values; +}; + +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow/src/op/hash_table.cpp b/src/frontends/tensorflow/src/op/hash_table.cpp index cf68ccb287ee33..6d5d023ad627e0 100644 --- a/src/frontends/tensorflow/src/op/hash_table.cpp +++ b/src/frontends/tensorflow/src/op/hash_table.cpp @@ -2,12 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "helper_ops/hash_table.hpp" +#include "hash_table.hpp" #include "common_op_table.hpp" #include "openvino/frontend/tensorflow/node_context.hpp" #include "utils.hpp" +using namespace ov; using namespace std; namespace ov { @@ -17,9 +18,11 @@ namespace op { OutputVector translate_hash_table_op(const ov::frontend::tensorflow::NodeContext& node) { default_op_checks(node, 0, {"MutableHashTable", "MutableHashTableV2", "HashTable", "HashTableV2"}); + auto node_name = node.get_name(); + auto key_dtype = node.get_attribute("key_dtype"); + auto value_dtype = node.get_attribute("value_dtype"); - auto hash_table = make_shared(node.get_decoder()); - set_node_name(node.get_name(), hash_table); + auto hash_table = make_shared(node_name, key_dtype, value_dtype, node.get_decoder()); return {hash_table}; } diff --git a/src/frontends/tensorflow/src/op/lookup_table_find.cpp b/src/frontends/tensorflow/src/op/lookup_table_find.cpp new file mode 100644 index 00000000000000..b9c9647469062e --- /dev/null +++ b/src/frontends/tensorflow/src/op/lookup_table_find.cpp @@ -0,0 +1,103 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "hash_table.hpp" +#include "openvino/frontend/tensorflow/node_context.hpp" +#include "openvino/frontend/tensorflow/variable.hpp" +#include "openvino/op/concat.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/equal.hpp" +#include "openvino/op/gather.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/range.hpp" +#include "openvino/op/reduce_logical_or.hpp" +#include "openvino/op/reduce_max.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/select.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/unsqueeze.hpp" + +using namespace std; +using namespace ov; +using namespace ov::op; +using namespace ov::frontend::tensorflow; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { +OutputVector translate_lookup_table_find_op(const NodeContext& node) { + default_op_checks(node, 3, {"LookupTableFind", "LookupTableFindV2"}); + auto table_handle = as_type_ptr(node.get_input_by_reference(0).get_node_shared_ptr()); + TENSORFLOW_OP_VALIDATION( + node, + table_handle, + "[TensorFlow Frontend] internal error: LookupTableFind operation expects table_handle by the first input"); + TENSORFLOW_OP_VALIDATION( + node, + table_handle->is_initialized(), + "[TensorFlow Frontend] internal error: LookupTableFind operation expects initialized table_handle"); + auto keys = node.get_input(1); + auto default_value = node.get_input(2); + + auto key_type = table_handle->get_key_type(); + TENSORFLOW_OP_VALIDATION( + node, + key_type.is_integral_number(), + "[TensorFlow Frontend] internal error: LookupTableFind is only supported for integer keys"); + + auto all_keys = table_handle->get_keys(); + auto all_values = table_handle->get_values(); + + // reshape both all values and keys to 1D tensor to work it further + auto target_shape = make_shared(element::i32, Shape{1}, vector{-1}); + all_keys = make_shared(all_keys, target_shape, false); + all_values = make_shared(all_values, target_shape, false); + + // update all values with default value and all keys + auto default_value_shape = make_shared(element::i32, Shape{1}, vector{1}); + default_value = make_shared(default_value, default_value_shape, false); + all_values = make_shared(OutputVector{all_values, default_value}, 0); + auto num_keys = make_shared(all_keys, element::i64)->output(0); + auto scalar_shape = make_shared(element::i32, Shape{0}, vector{}); + num_keys = make_shared(num_keys, scalar_shape, false); + num_keys = make_shared(num_keys, key_type); + + // compute mask which keys are not valid and for which default value must be used + auto unsqueeze_axis = make_shared(element::i32, Shape{1}, vector{-1}); + auto unsqueeze_keys = make_shared(keys, unsqueeze_axis); + auto equal_mask = make_shared(all_keys, unsqueeze_keys)->output(0); + auto reduce_equal_mask = make_shared(equal_mask, unsqueeze_axis, false); + + // map keys to new keys from range [0, n], n index will be for out-of-range keys + // 1. generate mask-01 of shape [keys_shape, len(all_keys)], + // where 0 - not found key, 1 - found key + auto const_zero = make_shared(key_type, Shape{}, 0); + auto const_one = make_shared(key_type, Shape{}, 1); + auto mask01 = make_shared(equal_mask, const_one, const_zero); + // 2. generate a range [0, n-1] that will be multiplied to mask for computation of new keys + auto new_all_keys = make_shared(const_zero, num_keys, const_one, key_type); + // 3. compute new keys + auto reduce_axis = make_shared(element::i32, Shape{1}, vector{-1}); + auto new_keys = make_shared(mask01, new_all_keys)->output(0); + new_keys = make_shared(new_keys, reduce_axis, false); + + // replace invalid keys with key_for_default_value + new_keys = make_shared(reduce_equal_mask, new_keys, num_keys); + + // at this point all keys are sorted and are from the range [0, n] + // and keys are also mapped to this range + auto gather_axis = make_shared(element::i32, Shape{1}, vector{0}); + auto lookup_values = make_shared(all_values, new_keys, gather_axis); + set_node_name(node.get_name(), lookup_values); + + return {lookup_values}; +} + +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow/src/op/lookup_table_import.cpp b/src/frontends/tensorflow/src/op/lookup_table_import.cpp new file mode 100644 index 00000000000000..421fe81be18f5f --- /dev/null +++ b/src/frontends/tensorflow/src/op/lookup_table_import.cpp @@ -0,0 +1,42 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "common_op_table.hpp" +#include "hash_table.hpp" +#include "openvino/frontend/tensorflow/node_context.hpp" +#include "openvino/frontend/tensorflow/variable.hpp" + +using namespace std; +using namespace ov; +using namespace ov::op; +using namespace ov::frontend::tensorflow; + +namespace ov { +namespace frontend { +namespace tensorflow { +namespace op { +OutputVector translate_lookup_table_import_op(const NodeContext& node) { + default_op_checks(node, 3, {"LookupTableImport", "LookupTableImportV2"}); + auto table_handle = node.get_input_by_reference(0); + auto keys = node.get_input(1); + auto values = node.get_input(2); + if (auto ref = as_type_ptr(table_handle.get_node_shared_ptr())) { + auto new_table = make_shared(*ref, keys, values); + + // since this operation produces new state of the variable + // it needs to update variables map + auto variables_state_map = node.get_variable_state_map(); + TENSORFLOW_OP_VALIDATION(node, + variables_state_map, + "[TensorFlow Frontend] internal error: variable state map is nullptr"); + variables_state_map->update_variable_state_map_for_node(node.get_name(), new_table); + } + + return {}; +} + +} // namespace op +} // namespace tensorflow +} // namespace frontend +} // namespace ov diff --git a/src/frontends/tensorflow/src/op_table.cpp b/src/frontends/tensorflow/src/op_table.cpp index fd9b6f848aea7a..33b5abdab9dfc4 100644 --- a/src/frontends/tensorflow/src/op_table.cpp +++ b/src/frontends/tensorflow/src/op_table.cpp @@ -95,6 +95,8 @@ TF_OP_CONVERTER(translate_hash_table_op); TF_OP_CONVERTER(translate_if_op); TF_OP_CONVERTER(translate_iterator_get_next_op); TF_OP_CONVERTER(translate_iterator_op); +TF_OP_CONVERTER(translate_lookup_table_import_op); +TF_OP_CONVERTER(translate_lookup_table_find_op); TF_OP_CONVERTER(translate_loop_cond_op); TF_OP_CONVERTER(translate_merge_op); TF_OP_CONVERTER(translate_mergev2checkpoint_op); @@ -287,6 +289,10 @@ const std::map get_supported_ops() { {"ListDiff", CreatorFunction(translate_list_diff_op)}, {"LogSoftmax", CreatorFunction(translate_log_softmax_op)}, {"Log1p", CreatorFunction(translate_log_1p_op)}, + {"LookupTableFind", CreatorFunction(translate_lookup_table_find_op)}, + {"LookupTableFindV2", CreatorFunction(translate_lookup_table_find_op)}, + {"LookupTableImport", CreatorFunction(translate_lookup_table_import_op)}, + {"LookupTableImportV2", CreatorFunction(translate_lookup_table_import_op)}, {"LookupTableInsert", CreatorFunction(translate_no_op)}, {"LookupTableInsertV2", CreatorFunction(translate_no_op)}, {"LRN", CreatorFunction(translate_lrn_op)}, diff --git a/src/frontends/tensorflow_common/include/helper_ops/hash_table.hpp b/src/frontends/tensorflow_common/include/helper_ops/hash_table.hpp deleted file mode 100644 index 6f517c97750d32..00000000000000 --- a/src/frontends/tensorflow_common/include/helper_ops/hash_table.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "helper_ops/internal_operation.hpp" - -namespace ov { -namespace frontend { -namespace tensorflow { - -class HashTable : public InternalOperation { -public: - OPENVINO_OP("HashTable", "ov::frontend::tensorflow", InternalOperation); - - HashTable(const std::shared_ptr& decoder = nullptr) - : InternalOperation(decoder, OutputVector{}, 1, "HashTable") { - validate_and_infer_types(); - } - - void validate_and_infer_types() override { - set_output_type(0, ov::element::dynamic, ov::PartialShape::dynamic()); - } - - std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override { - auto hash_table_node = std::make_shared(m_decoder); - hash_table_node->set_attrs(get_attrs()); - return hash_table_node; - } -}; - -} // namespace tensorflow -} // namespace frontend -} // namespace ov diff --git a/tests/layer_tests/tensorflow_tests/test_tf_LookupTableFind.py b/tests/layer_tests/tensorflow_tests/test_tf_LookupTableFind.py new file mode 100644 index 00000000000000..ec49f728e7da7c --- /dev/null +++ b/tests/layer_tests/tensorflow_tests/test_tf_LookupTableFind.py @@ -0,0 +1,81 @@ +# Copyright (C) 2018-2024 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import tensorflow as tf +from common.tf_layer_test_class import CommonTFLayerTest +from common.utils.tf_utils import mix_array_with_value + +rng = np.random.default_rng() + + +class TestLookupTableFindOps(CommonTFLayerTest): + def _prepare_input(self, inputs_info): + assert 'keys' in inputs_info, "Test error: inputs_info must contain `x`" + keys_shape = inputs_info['keys'] + inputs_data = {} + if np.issubdtype(self.keys_type, np.integer): + data = rng.choice(self.all_keys, keys_shape) + inputs_data['keys'] = mix_array_with_value(data, self.invalid_key) + else: + raise "Unsupported type {}".format(self.keys_type) + + return inputs_data + + def create_lookup_table_find_net(self, hash_table_type, keys_shape, keys_type, values_type, + all_keys, all_values, default_value, invalid_key): + hash_table_op = tf.raw_ops.HashTable if hash_table_type == 0 else tf.raw_ops.HashTableV2 + import_table_op = tf.raw_ops.LookupTableImport if hash_table_type == 0 else tf.raw_ops.LookupTableImportV2 + lookup_table_op = tf.raw_ops.LookupTableFind if hash_table_type == 0 else tf.raw_ops.LookupTableFindV2 + + self.keys_type = keys_type + self.all_keys = all_keys + self.invalid_key = invalid_key + tf.compat.v1.reset_default_graph() + # Create the graph and model + with tf.compat.v1.Session() as sess: + keys = tf.compat.v1.placeholder(keys_type, keys_shape, 'keys') + all_keys = tf.constant(all_keys, dtype=keys_type) + all_values = tf.constant(all_values, dtype=values_type) + default_value = tf.constant(default_value, dtype=values_type) + hash_table = hash_table_op(key_dtype=keys_type, value_dtype=values_type) + import_hash_table = import_table_op(table_handle=hash_table, keys=all_keys, + values=all_values) + with tf.control_dependencies([import_hash_table]): + lookup_table_op(table_handle=hash_table, keys=keys, + default_value=default_value, + name='LookupTableFind') + + tf.compat.v1.global_variables_initializer() + tf_net = sess.graph_def + + return tf_net, None + + test_data = [ + dict(keys_type=np.int32, values_type=np.float32, all_keys=[0, 1, 2, 3, 4, 5], + all_values=[2.0, 13.0, -2.0, 0.0, 3.0, 1.0], default_value=-100.0, invalid_key=-100), + dict(keys_type=np.int64, values_type=np.int32, all_keys=[0, 1, 2, 3, 4, 5], + all_values=[2, 13, -2, 0, 3, 1], default_value=-100, invalid_key=-100), + dict(keys_type=np.int32, values_type=np.float32, all_keys=[2, 0, 3, -2, 4, 10], + all_values=[2.0, 13.0, -2.0, 0.0, 3.0, 1.0], default_value=-100.0, invalid_key=1000), + dict(keys_type=np.int64, values_type=np.float32, all_keys=[2, 0, 3, -2, 4, 10], + all_values=[2.0, 13.0, -2.0, 0.0, 3.0, 1.0], default_value=-100.0, invalid_key=1000), + pytest.param( + dict(keys_type=np.int32, values_type=tf.string, all_keys=[20, 10, 33, -22, 44, 11], + all_values=['PyTorch', 'TensorFlow', 'JAX', 'Lightning', 'MindSpore', 'OpenVINO'], + default_value='UNKNOWN', invalid_key=1000), + marks=pytest.mark.skip(reason='130688: Gather string support needed')) + ] + + @pytest.mark.parametrize("hash_table_type", [0, 1]) + @pytest.mark.parametrize("keys_shape", [[], [2], [3, 4], [3, 2, 1, 4]]) + @pytest.mark.parametrize("params", test_data) + @pytest.mark.precommit_tf_fe + @pytest.mark.nightly + def test_lookup_table_find(self, hash_table_type, keys_shape, params, ie_device, precision, ir_version, temp_dir, + use_new_frontend): + self._test(*self.create_lookup_table_find_net(hash_table_type=hash_table_type, + keys_shape=keys_shape, **params), + ie_device, precision, ir_version, temp_dir=temp_dir, + use_new_frontend=use_new_frontend) From d018779adda8067952e020e9d946b11924d00fdb Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Tue, 30 Jan 2024 12:50:18 +0100 Subject: [PATCH 23/27] [PT FE] torch.export support (#22397) * [PT FE] torch.export support * Apply code style * Fix build * Support torch <2.2 * Support more operations * Update tests/model_hub_tests/torch_tests/torch_utils.py * Support for model operations * Support is_causal as kwarg for SDPA * Update src/frontends/pytorch/src/op/addcmul.cpp * Update tests/model_hub_tests/torch_tests/test_timm.py * Support only decoder passed to convert_model * Fix tests * Update src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py * Update src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py Co-authored-by: Ekaterina Aidova * Apply suggestions from code review * Apply suggestions from code review * Improve testing with caching model * Apply suggestions from code review --------- Co-authored-by: Ekaterina Aidova --- .github/workflows/job_python_unit_tests.yml | 9 + .../openvino/frontend/pytorch/fx_decoder.py | 219 ++++++++++----- .../openvino/frontend/pytorch/ts_decoder.py | 12 + .../src/openvino/frontend/pytorch/utils.py | 5 + .../pyopenvino/frontend/pytorch/decoder.hpp | 17 +- .../python/src/pyopenvino/utils/utils.cpp | 2 + .../openvino/frontend/pytorch/decoder.hpp | 18 +- .../frontend/pytorch/node_context.hpp | 31 ++- src/frontends/pytorch/src/frontend.cpp | 1 + src/frontends/pytorch/src/node_context.cpp | 2 +- .../pytorch/src/op/adaptive_poolnd.cpp | 15 + src/frontends/pytorch/src/op/add.cpp | 8 +- src/frontends/pytorch/src/op/addcmul.cpp | 21 +- src/frontends/pytorch/src/op/addmm.cpp | 34 ++- src/frontends/pytorch/src/op/batch_norm.cpp | 132 +++++---- src/frontends/pytorch/src/op/div.cpp | 46 +++- src/frontends/pytorch/src/op/expand.cpp | 2 +- src/frontends/pytorch/src/op/full.cpp | 15 + src/frontends/pytorch/src/op/gelu.cpp | 29 +- src/frontends/pytorch/src/op/glu.cpp | 2 +- src/frontends/pytorch/src/op/index.cpp | 260 +++++++++++++++++- src/frontends/pytorch/src/op/leaky_relu.cpp | 32 +++ src/frontends/pytorch/src/op/mean.cpp | 26 +- src/frontends/pytorch/src/op/pad.cpp | 50 +++- .../pytorch/src/op/scalar_tensor.cpp | 34 +++ .../src/op/scaled_dot_product_attention.cpp | 40 ++- .../pytorch/src/op/slice_scatter.cpp | 68 +++++ src/frontends/pytorch/src/op/split.cpp | 16 +- src/frontends/pytorch/src/op/sub.cpp | 16 +- src/frontends/pytorch/src/op/to.cpp | 10 + src/frontends/pytorch/src/op_table.cpp | 86 +++++- .../pytorch/src/translate_session.cpp | 19 +- src/frontends/pytorch/src/utils.cpp | 2 +- src/frontends/pytorch/src/utils.hpp | 15 +- tests/layer_tests/pytest.ini | 1 + .../pytorch_tests/pytorch_layer_test_class.py | 66 +++-- .../pytorch_tests/test_adaptive_avg_pool.py | 3 + .../pytorch_tests/test_adaptive_max_pool.py | 3 + .../layer_tests/pytorch_tests/test_addcmul.py | 1 + tests/layer_tests/pytorch_tests/test_addmm.py | 2 + tests/layer_tests/pytorch_tests/test_and.py | 4 + .../pytorch_tests/test_as_strided.py | 3 + .../pytorch_tests/test_batch_norm.py | 1 + .../pytorch_tests/test_broadcast_tensors.py | 1 + tests/layer_tests/pytorch_tests/test_clone.py | 1 + .../pytorch_tests/test_conv_transposend.py | 3 + .../pytorch_tests/test_convolution.py | 2 + .../layer_tests/pytorch_tests/test_device.py | 2 + tests/layer_tests/pytorch_tests/test_div.py | 2 + .../pytorch_tests/test_embedding.py | 1 + tests/layer_tests/pytorch_tests/test_eq.py | 1 + .../layer_tests/pytorch_tests/test_expand.py | 3 + .../layer_tests/pytorch_tests/test_flatten.py | 1 + .../pytorch_tests/test_floor_divide.py | 2 + tests/layer_tests/pytorch_tests/test_gelu.py | 1 + tests/layer_tests/pytorch_tests/test_glu.py | 1 + .../pytorch_tests/test_group_norm.py | 1 + tests/layer_tests/pytorch_tests/test_index.py | 27 ++ tests/layer_tests/pytorch_tests/test_mm.py | 3 + tests/layer_tests/pytorch_tests/test_mul.py | 2 + .../layer_tests/pytorch_tests/test_permute.py | 2 + .../layer_tests/pytorch_tests/test_reshape.py | 1 + .../pytorch_tests/test_reshape_as.py | 1 + .../pytorch_tests/test_resolve_conj_neg.py | 2 + .../test_scaled_dot_product_attention.py | 22 +- .../layer_tests/pytorch_tests/test_select.py | 1 + tests/layer_tests/pytorch_tests/test_silu.py | 1 + .../layer_tests/pytorch_tests/test_softmax.py | 2 + tests/layer_tests/pytorch_tests/test_sub.py | 1 + .../pytorch_tests/test_tensor_split.py | 1 + .../layer_tests/pytorch_tests/test_type_as.py | 1 + .../pytorch_tests/test_unflatten.py | 2 + .../layer_tests/pytorch_tests/test_unfold.py | 1 + .../torch_tests/requirements.txt | 1 + .../torch_tests/test_aliked.py | 2 +- .../torch_tests/test_detectron2.py | 2 +- .../model_hub_tests/torch_tests/test_edsr.py | 2 +- .../torch_tests/test_gfpgan.py | 2 +- .../torch_tests/test_hf_transformers.py | 2 +- .../torch_tests/test_speech-transformer.py | 2 +- .../model_hub_tests/torch_tests/test_timm.py | 10 +- .../torch_tests/test_torchbench.py | 2 +- .../torch_tests/test_torchvision_models.py | 13 +- .../torch_tests/torch_utils.py | 43 ++- tools/ovc/openvino/tools/ovc/convert_impl.py | 5 +- .../moc_frontend/pytorch_frontend_utils.py | 9 +- 86 files changed, 1282 insertions(+), 283 deletions(-) create mode 100644 src/frontends/pytorch/src/op/leaky_relu.cpp create mode 100644 src/frontends/pytorch/src/op/scalar_tensor.cpp create mode 100644 src/frontends/pytorch/src/op/slice_scatter.cpp diff --git a/.github/workflows/job_python_unit_tests.yml b/.github/workflows/job_python_unit_tests.yml index a04e2004eaf470..e20a055eb5b4ba 100644 --- a/.github/workflows/job_python_unit_tests.yml +++ b/.github/workflows/job_python_unit_tests.yml @@ -216,6 +216,15 @@ jobs: TEST_DEVICE: CPU TEST_PRECISION: FP32 + - name: PyTorch torch.export Layer Tests + if: ${{ fromJSON(inputs.affected-components).PyTorch_FE.test && runner.arch != 'ARM64' }} # Ticket: 126287 + run: | + python3 -m pytest ${LAYER_TESTS_INSTALL_DIR}/pytorch_tests -m precommit_torch_export --junitxml=${INSTALL_TEST_DIR}/TEST-pytorch.xml + env: + TEST_DEVICE: CPU + TEST_PRECISION: FP32 + PYTORCH_TRACING_MODE: EXPORT + - name: PyTorch torch.compile TORCHFX Layer Tests if: ${{ fromJSON(inputs.affected-components).PyTorch_FE.test && runner.os != 'macOS' }} run: | diff --git a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py index 09375329cb7770..cb6b6beb0e2ede 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py @@ -11,6 +11,7 @@ import torch + class TorchFXPythonDecoder (Decoder): def __init__(self, pt_module, fx_gm, nodes=None, mark_node_callback=None, input_shapes=[], input_types=[]): @@ -23,56 +24,96 @@ def __init__(self, pt_module, fx_gm, nodes=None, mark_node_callback=None, input_ self.input_types = input_types self.input_shapes = input_shapes + self._input_signature = [] + self._output_names = [] + if issubclass(type(pt_module), torch.fx.graph_module.GraphModule): + self._input_is_list = None self._nodes = list(pt_module.graph.nodes) self._inputs = [] self._outputs = [] for i in range(len(self._nodes)): if self._nodes[i].op == 'placeholder': self._inputs.append(i) + self._input_signature.append(self._nodes[i].name) elif self._nodes[i].op == 'output': # Instead of putting output index, refer to its target args = self._nodes[i].args if isinstance(args[0], tuple): args = args[0] - for output in args: - self._outputs.append(self._nodes.index(output)) + if isinstance(args[0], dict): + for name, output in args[0].items(): + self._outputs.append(self._nodes.index(output)) + self._output_names.append(name) + else: + for output in args: + self._outputs.append(self._nodes.index(output)) elif issubclass(type(pt_module), torch.fx.Node): - - self._nodes = nodes # passed from outer context + self._nodes = nodes # passed from outer context # FIXME: Quadratic complexity nodes*nodes considering the outer loop over all nodes for i in range(len(self._nodes)): if self._nodes[i] == pt_module: self._outputs = [i] - # code constant or None input as a tuple to diffirentiate it from regular input - # negative index is used to mark inputs initialized by inline constants, there are no such inputs in the graph - self._inputs = [self._nodes.index(arg) if arg in self._nodes else (arg,) for arg in pt_module.args] + # None in inputs mean the input is inlined or None (also considered inlined) + self._inputs = [self._nodes.index( + arg) if arg in self._nodes else (arg,) for arg in pt_module.args] - # FIXME: Find a better way to pass nested tuples to OV frontend. This is a temprary solution to flatten arguments. + # FIXME: Find a better way to pass nested tuples to OV frontend. This is a temporary solution to flatten arguments. new_inputs = [] for i in range(len(pt_module.args)): - expand_list = False - if isinstance(pt_module.args[i], list): + if isinstance(pt_module.args[i], list) and any([isinstance(a, torch.fx.Node) for a in pt_module.args[i]]): for arg in pt_module.args[i]: if arg in self._nodes: - expand_list = True - break; - if expand_list: - for arg in pt_module.args[i]: - new_inputs.append(self._nodes.index(arg)) + new_inputs.append(self._nodes.index(arg)) + else: + new_inputs.append((arg,)) else: new_inputs.append(self._inputs[i]) self._inputs = new_inputs + def inputs(self): + # Consider 0 a special case which may mean the input is inlined, but not guaranteed + return [x if not isinstance(x, tuple) else 0 for x in self._inputs] + + def is_input_inlined(self, index): + return isinstance(self._inputs[index], tuple) + + @staticmethod + def arg_to_constant(arg): + if isinstance(arg, list): + if len(arg) > 0: + return make_constant(pt_to_ov_type_map[type( + arg[0]).__name__], Shape([len(arg)]), arg) + else: + # TODO: which type should we use if list is empty? Need a signaling value here + return make_constant(int, Shape([0]), []) + elif isinstance(arg, bool): + return make_constant(OVType.boolean, Shape([]), [arg]) + elif isinstance(arg, int): + arg = maybe_convert_max_int(arg) + return make_constant(OVType.i32, Shape( + []), [arg]) # TODO: i32? why not i64? + elif isinstance(arg, float): + return make_constant(OVType.f32, Shape( + []), [arg]) # TODO: f32? why not f64? + return None + + def inlined_input(self, index): + assert index < len(self._inputs), "Requested input doesn't exist" + assert isinstance(self._inputs[index], tuple), "Requested input which is not inlined" + assert self._inputs[index][0] is not None, "Requested None inlined input" + constant = None + arg = self._inputs[index][0] + constant = self.arg_to_constant(arg) - def inputs(self): - return [x if x is not None else 100000 for x in self._inputs] + assert constant is not None, "Constant wasn't created for inlined input" + return constant.outputs() def input(self, index): # TODO: remove return self.inputs()[index] # TODO: find specialized method @@ -81,6 +122,8 @@ def get_input_debug_name(self, index): return "input"+str(index) def get_input_signature_name(self, index: int) -> str: + if self._input_signature is not None and index < len(self._input_signature): + return self._input_signature[index] return self.get_input_debug_name(index) def get_input_shape(self, index): @@ -89,6 +132,16 @@ def get_input_shape(self, index): input = self._raw_input(index) return self.get_shape_for_value(input) + def get_input_strides(self, index: int) -> list: + raw_input = self._raw_input(index) + if isinstance(raw_input, torch.fx.node.Node) and hasattr(raw_input, "meta"): + meta = raw_input.meta + if "tensor_meta" in meta and hasattr(meta["tensor_meta"], "stride"): + strides = list(meta["tensor_meta"].stride) + if strides: + return strides + return [] + def get_input_type(self, index): if index < len(self.input_types): return OVAny(pt_to_ov_type_map[str(self.input_types[index])]) @@ -96,7 +149,10 @@ def get_input_type(self, index): return self.get_type_for_value(input) def get_output_debug_name(self, index): - return "output"+str(index) + if self._output_names is not None and index < len(self._output_names): + return self._output_names[index] + name = getattr(self.pt_module, "name", "output") + return name + ":" + str(index) def get_output_shape(self, index): output = self._raw_output(index) @@ -106,52 +162,58 @@ def get_output_type(self, index): output = self._raw_output(index) return self.get_type_for_value(output) - def _get_known_type_for_value(self, type): - ''' - Returns known/unknown types wrapped as OVAny - ''' - # Check for simple scalar types first - # TODO: Don't use str, use native types - if type is None: - return OVAny(OVType.dynamic) - if str(type) in pt_to_ov_type_map: - return OVAny(pt_to_ov_type_map[str(type)]) - elif type.__class__ is torch.TensorType: - # Tensor type, parse element type - # TODO: replace string by native type - # return OVAny(PartialShape([1,2,3])) - return OVAny(DecoderType.Tensor(self._get_known_type_for_value(type.dtype()))) - elif type.__class__ is torch.ListType: - element_type = type.getElementType() - return OVAny(DecoderType.List(self._get_known_type_for_value(element_type))) - else: - # Not yet recognized - return OVAny(OVType.dynamic) - #pt_type_class = value.type().__class__ - # if pt_type_class is torch.ListType: - def get_shape_for_value(self, value): - if value and ('tensor_meta' in value.meta.keys()): - return PartialShape(value.meta['tensor_meta'].shape) - return PartialShape([1]) + if value and hasattr(value, "meta") and ('tensor_meta' in value.meta.keys()): + if value.meta['tensor_meta']: + return PartialShape(len(value.meta['tensor_meta'].shape) * [-1]) + return PartialShape.dynamic() def get_type_for_value(self, value): if issubclass(type(value), torch.fx.Node): if ('tensor_meta' in value.meta.keys()): - pt_type = value.meta['tensor_meta'].dtype - if str(pt_type) in pt_to_ov_type_map: - ov_type = pt_to_ov_type_map[str(pt_type)] - return OVAny(ov_type) + if value.meta['tensor_meta'] and isinstance(value.meta['tensor_meta'], torch.Tensor): + pt_type = value.meta['tensor_meta'].dtype + if str(pt_type) in pt_to_ov_type_map: + ov_type = pt_to_ov_type_map[str(pt_type)] + return OVAny(ov_type) else: - return OVAny(OVType.f32) + return OVAny(OVType.dynamic) elif isinstance(value, int): return OVAny(OVType.i32) elif isinstance(value, float): return OVAny(OVType.f32) elif isinstance(value, bool): return OVAny(OVType.boolean) - else: - return OVAny(OVType.f32) + return OVAny(OVType.dynamic) + + def get_attribute(self, name): + if name in self.pt_module.kwargs: + attr = self.pt_module.kwargs[name] + if isinstance(attr, torch.dtype): + return OVAny(pt_to_ov_type_map[str(attr)]) + if isinstance(attr, torch.device): + return OVAny(attr.type) + if isinstance(attr, str): + return OVAny(attr) + # Numeric attrs convert to Constant + constant = self.arg_to_constant(attr) + if constant is not None: + return OVAny(constant.output(0)) + # so that has_attribute return True if attribute exist + return OVAny(DecoderType.PyNone()) + return OVAny(None) + + def get_named_input(self, name): + """ + Returns id of kwargs input. Such input can be Node or a constant value, + this function is only used for to return node index. If the input is + constant, get_attribute should be used. + """ + if name in self.pt_module.kwargs: + arg = self.pt_module.kwargs[name] + if isinstance(arg, torch.fx.Node): + return self._nodes.index(arg) + raise RuntimeError("This input is not a Node") def get_subgraph_size(self): if issubclass(type(self.pt_module), torch.fx.Node): @@ -165,8 +227,11 @@ def visit_subgraph(self, node_visitor): # make sure topological order is satisfied for node in self._nodes: if node.op == 'placeholder' or node.op == 'output': - continue # skipping non-operational nodes - decoder = TorchFXPythonDecoder(node, self.fx_gm, self._nodes, mark_node_callback=self.mark_node_callback) + continue # skipping non-operational nodes + if node.op == 'call_function' and str(node.target) in ["aten._assert_async.msg"]: + continue + decoder = TorchFXPythonDecoder( + node, self.fx_gm, self._nodes, mark_node_callback=self.mark_node_callback) self.m_decoders.append(decoder) node_visitor(decoder) @@ -176,7 +241,8 @@ def get_subgraphs(self): return list(self.pt_module.blocks()) def get_subgraph_decoder(self, index): - decoder = TorchFXPythonDecoder(self.get_subgraphs()[index], self.fx_gm, mark_node_callback=self.mark_node_callback) + decoder = TorchFXPythonDecoder(self.get_subgraphs( + )[index], self.fx_gm, mark_node_callback=self.mark_node_callback) self.m_decoders.append(decoder) return decoder @@ -202,7 +268,7 @@ def _raw_output(self, index): return self._raw_outputs()[index] def _raw_inputs(self): - return [self._nodes[x] if x is not None and x < len(self._nodes) else x for x in self._inputs] + return [self._nodes[x] if not isinstance(x, tuple) and x < len(self._nodes) else x[0] for x in self._inputs] def _raw_input(self, index): return self._raw_inputs()[index] @@ -214,6 +280,10 @@ def output(self, index): return self.outputs()[index] def mark_node(self, node): + name = self.get_op_type() + if "FrameworkNode" not in node.get_type_name(): + name += "/" + node.get_type_name() + node.set_friendly_name(name) if self.mark_node_callback is not None: self.mark_node_callback(self, node) return node @@ -223,10 +293,9 @@ def as_constant(self): if self.pt_module.op == 'get_attr': # Extract Constant from FX module field ret = fetch_attr(self.fx_gm, self.pt_module.target) - ov_const = op.Constant(ret.numpy(), shared_memory=True) + ov_const = op.Constant(ret.numpy(force=True), shared_memory=True) return ov_const.outputs() - if not self.get_op_type() == 'prim::Constant': return None pt_value = self._raw_output(0) @@ -258,7 +327,8 @@ def as_constant_tensor(self, pt_value): ivalue = pt_value.toIValue() if pt_value.isCompleteTensor(): try: - ivalue = ivalue.to(memory_format=torch.contiguous_format).detach().cpu() + ivalue = ivalue.to( + memory_format=torch.contiguous_format).detach().cpu() except: print("[ WARNING ] Tensor couldn't detach") if str(pt_value.type().dtype()) in pt_to_py_type_map: @@ -273,12 +343,15 @@ def as_constant_tensor(self, pt_value): # this is only possible with adding a new ctor for Constant Python binding # TODO Check strides and pass them somehow values = ivalue.data_ptr() - ov_const = make_constant(ovtype, ovshape.get_shape(), values) + ov_const = make_constant( + ovtype, ovshape.get_shape(), values) except: # old variant that makes a slow data copying - print(f"[ WARNING ] Constant wasn't able to convert from data_ptr.") + print( + f"[ WARNING ] Constant wasn't able to convert from data_ptr.") values = ivalue.flatten().tolist() - ov_const = make_constant(ovtype, ovshape.get_shape(), values) + ov_const = make_constant( + ovtype, ovshape.get_shape(), values) return ov_const.outputs() else: # Incomplete tensor can be scalar @@ -294,14 +367,17 @@ def as_constant_tensor(self, pt_value): try: ovshape = PartialShape(ivalue.size()) ovtype = pt_to_ov_type_map[str(ivalue.type())] - ov_const = make_constant(ovtype, ovshape.get_shape(), ivalue.data_ptr()) + ov_const = make_constant( + ovtype, ovshape.get_shape(), ivalue.data_ptr()) except: # old variant that makes a slow data copying - print(f"[ WARNING ] Constant wasn't able to convert from data_ptr.") - nvalues = ivalue.numpy() + print( + f"[ WARNING ] Constant wasn't able to convert from data_ptr.") + nvalues = ivalue.numpy(force=True) ovtype = np_to_ov_type_map[str(nvalues.dtype)] ovshape = PartialShape(nvalues.shape) - ov_const = make_constant(ovtype, ovshape.get_shape(), nvalues.flatten().tolist()) + ov_const = make_constant( + ovtype, ovshape.get_shape(), nvalues.flatten().tolist()) return ov_const.outputs() return None @@ -325,7 +401,7 @@ def as_constant_list(self, pt_value): return ov_const.outputs() def input_is_none(self, index): - if index >= len(self.inputs()) or self._raw_input(index) is None: + if index >= len(self._inputs) or (isinstance(self._inputs[index], tuple) and self._inputs[index][0] is None): return True else: r_input = self._raw_input(index) @@ -342,7 +418,8 @@ def inlined_inputs(self, index): arg = self._inputs[i][0] if isinstance(arg, list): if len(arg) > 0: - constant = make_constant(pt_to_ov_type_map[type(arg[0]).__name__], Shape([len(arg)]), arg) + constant = make_constant(pt_to_ov_type_map[type( + arg[0]).__name__], Shape([len(arg)]), arg) else: # TODO: which type should we use if list is empty? Need a signaling value here constant = make_constant(int, Shape([0]), []) @@ -350,9 +427,11 @@ def inlined_inputs(self, index): constant = make_constant(OVType.boolean, Shape([]), [arg]) elif isinstance(arg, int): arg = maybe_convert_max_int(arg) - constant = make_constant(OVType.i32, Shape([]), [arg]) # TODO: i32? why not i64? + constant = make_constant(OVType.i32, Shape( + []), [arg]) # TODO: i32? why not i64? elif isinstance(arg, float): - constant = make_constant(OVType.f32, Shape([]), [arg]) # TODO: f32? why not f64? + constant = make_constant(OVType.f32, Shape( + []), [arg]) # TODO: f32? why not f64? if constant is None: if arg is None: diff --git a/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py b/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py index 7c2c53e68b0065..bad0ce8633ff11 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/ts_decoder.py @@ -406,6 +406,18 @@ def may_produce_alias(self, in_index: int, out_index: int) -> bool: def inlined_inputs(self, index): return [] + def inlined_input(self, index): + return [] + + def is_input_inlined(self, index): + return False + + def get_attribute(self, name): + return OVAny(None) + + def get_named_input(self, name): + raise RuntimeError("There is no named inputs in TS graph") + @staticmethod def _transform_tensor_list_constants_to_listconstruct(graph: torch.Graph): # Function replaces prim::Constant containing List of Tensors with diff --git a/src/bindings/python/src/openvino/frontend/pytorch/utils.py b/src/bindings/python/src/openvino/frontend/pytorch/utils.py index 0225603e78ae54..157592f3aabee0 100644 --- a/src/bindings/python/src/openvino/frontend/pytorch/utils.py +++ b/src/bindings/python/src/openvino/frontend/pytorch/utils.py @@ -137,8 +137,13 @@ def graph_has_ops(graph, op_types:list) -> bool: "torch.bool": OVType.boolean, "torch.DoubleTensor": OVType.f64, "torch.FloatTensor": OVType.f32, + "torch.HalfTensor": OVType.f16, + "torch.BFloat16Tensor": OVType.bf16, "torch.IntTensor": OVType.i32, "torch.LongTensor": OVType.i64, + "torch.ShortTensor": OVType.i16, + "torch.CharTensor": OVType.i8, + "torch.ByteTensor": OVType.u8, "torch.BoolTensor": OVType.boolean, "torch.quint8": OVType.u8, "torch.qint8": OVType.i8, diff --git a/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp b/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp index 9e372203158ed8..91c3c979d79172 100644 --- a/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp +++ b/src/bindings/python/src/pyopenvino/frontend/pytorch/decoder.hpp @@ -110,8 +110,21 @@ class PyDecoder : public ov::frontend::pytorch::TorchDecoder { PYBIND11_OVERRIDE_PURE(bool, TorchDecoder, may_produce_alias, in_index, out_index); } - ov::OutputVector inlined_inputs(size_t start_index) const override { - PYBIND11_OVERRIDE_PURE(ov::OutputVector, TorchDecoder, inlined_inputs, start_index); } + ov::OutputVector inlined_input(size_t index) const override { + PYBIND11_OVERRIDE_PURE(ov::OutputVector, TorchDecoder, inlined_input, index); + } + + bool is_input_inlined(size_t index) const override { + PYBIND11_OVERRIDE_PURE(bool, TorchDecoder, is_input_inlined, index); + } + + ov::Any get_attribute(const std::string &name) const override{ + PYBIND11_OVERRIDE_PURE(ov::Any, TorchDecoder, get_attribute, name); + } + + size_t get_named_input(const std::string &name) const override{ + PYBIND11_OVERRIDE_PURE(size_t, TorchDecoder, get_named_input, name); + } const std::string& decoder_type_name() const override { PYBIND11_OVERRIDE_PURE(const std::string&, TorchDecoder, decoder_type_name); diff --git a/src/bindings/python/src/pyopenvino/utils/utils.cpp b/src/bindings/python/src/pyopenvino/utils/utils.cpp index 906c19ae820864..57a17ad6fb57a5 100644 --- a/src/bindings/python/src/pyopenvino/utils/utils.cpp +++ b/src/bindings/python/src/pyopenvino/utils/utils.cpp @@ -375,6 +375,8 @@ ov::Any py_object_to_any(const py::object& py_obj) { return py::cast(py_obj); } else if (py::isinstance(py_obj)) { return py::cast(py_obj); + } else if (py::isinstance>(py_obj)) { + return py::cast>(py_obj); // FrontEnd Decoder } else if (py::isinstance(py_obj)) { return py::cast>(py_obj); diff --git a/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp b/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp index d5878783c314af..43243ab6c647b4 100644 --- a/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp +++ b/src/frontends/pytorch/include/openvino/frontend/pytorch/decoder.hpp @@ -19,7 +19,7 @@ class TorchDecoder : public IDecoder { // fundamental types like int, float etc. virtual Any const_input(size_t index) const = 0; - // Using size_t for input/output unuque ids are in sync with torch code, see def in + // Using size_t for input/output unique ids are in sync with torch code, see def in // torch/include/torch/csrc/jit/ir/ir.h, Value::unique_ // TODO: set of input and output methods are not aligned; also they are not aligned with the rest of FEs @@ -89,7 +89,7 @@ class TorchDecoder : public IDecoder { virtual size_t output(size_t index) const = 0; // Embed mapping to/from the original node representation from/to node passed as a parameter - // the representation of this mapping is specific for particular decored type and may be NOP + // the representation of this mapping is specific for particular decorated type and may be NOP // returns the same node as syntactically convenient way to make nested sentences in code virtual std::shared_ptr mark_node(std::shared_ptr ov_node) const = 0; @@ -109,9 +109,19 @@ class TorchDecoder : public IDecoder { /// Returns new nodes for inputs inlined in the op itself // Used in Torch.FX decoder - virtual OutputVector inlined_inputs(size_t start_index) const = 0; + virtual OutputVector inlined_input(size_t index) const = 0; - /// Returns the id of the deccoder type (0: TorchFX, 1: TorchScript) + /// Returns if input is inlined + // Used in Torch.FX decoder + virtual bool is_input_inlined(size_t index) const = 0; + + /// Returns named attribute as Any. For example kwargs input for FX graph + virtual ov::Any get_attribute(const std::string& name) const = 0; + + /// Returns index of named input. For example kwargs input for FX graph + virtual size_t get_named_input(const std::string& name) const = 0; + + /// Returns the id of the decoder type ("fx": TorchFX, "ts": TorchScript) virtual const std::string& decoder_type_name() const = 0; }; diff --git a/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp b/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp index ae8f0b34a86895..307f04391d4e79 100644 --- a/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp +++ b/src/frontends/pytorch/include/openvino/frontend/pytorch/node_context.hpp @@ -51,12 +51,36 @@ class NodeContext : public frontend::NodeContext { // Search for input in tensor map and return an output port for already converted op // TODO: int due to base class uses it, but naturally it should be size_t for PT Output get_input(int index) const override { - FRONT_END_GENERAL_CHECK(!input_is_none(index), "Input is none with index: ", index); + size_t index_ = static_cast(index); + FRONT_END_GENERAL_CHECK(!input_is_none(index_), "Input doesn't exist with index: ", index); auto input = m_decoder_inputs.at(index); + if (input == 0) { + // Case when input can be inlined (possible only for fx decoder) + if (m_decoder->is_input_inlined(index_)) { + auto inlined_input = m_decoder->inlined_input(index_); + FRONT_END_GENERAL_CHECK(inlined_input.size() == 1, "Incorrect inlined input with index:", index); + return inlined_input[0]; + } + } FRONT_END_GENERAL_CHECK(m_tensor_map->count(input), "No tensor corresponding input: ", input, " exist."); return m_tensor_map->at(input); } + Output get_input(const std::string& name) const override { + FRONT_END_GENERAL_CHECK(has_attribute(name), "Input with name ", name, " doesn't exist"); + auto attr = get_attribute_as_any(name); + if (attr.is>()) { + // Case when input is constant value + return attr.as>(); + } else if (attr.is()) { + // None means input is unknown type, most likely a Node + auto input = m_decoder->get_named_input(name); + FRONT_END_GENERAL_CHECK(m_tensor_map->count(input), "No tensor corresponding input: ", input, " exist."); + return m_tensor_map->at(input); + } + FRONT_END_GENERAL_CHECK(false, "Input has type which can't be converted to ov::Node."); + } + Any get_values_from_const_input(int index) const override; // TODO: upstream to base class @@ -112,9 +136,8 @@ class NodeContext : public frontend::NodeContext { return ov_output; } - Any get_attribute_as_any(const std::string&) const override { - throw std::runtime_error( - "There is no any named attributes in PyTorch node, query by attribute name is not implemented"); + Any get_attribute_as_any(const std::string& name) const override { + return m_decoder->get_attribute(name); } void mutate_input(size_t index, Output ov_output) const; diff --git a/src/frontends/pytorch/src/frontend.cpp b/src/frontends/pytorch/src/frontend.cpp index ee9a9919045f72..fa00b94a4c6158 100644 --- a/src/frontends/pytorch/src/frontend.cpp +++ b/src/frontends/pytorch/src/frontend.cpp @@ -194,6 +194,7 @@ void FrontEnd::normalize(const std::shared_ptr& model) const { manager.register_pass(); manager.register_pass(); manager.register_pass(); + // TODO: remove AtenIndexToSelect when problem with dynamic input rank is gone. manager.register_pass(); manager.register_pass(); manager.register_pass(); diff --git a/src/frontends/pytorch/src/node_context.cpp b/src/frontends/pytorch/src/node_context.cpp index 0ebd26d3b8e901..ff6bb045e7f15a 100644 --- a/src/frontends/pytorch/src/node_context.cpp +++ b/src/frontends/pytorch/src/node_context.cpp @@ -109,7 +109,7 @@ Output NodeContext::get_tensor_from_model_or_create_input(size_t index) co } Output NodeContext::get_input_from_visible_context(size_t index) const { - FRONT_END_GENERAL_CHECK(index < get_input_size(), "Index is lower then number of inputs."); + FRONT_END_GENERAL_CHECK(index < get_input_size(), "Index ", index, " is lower then number of inputs."); auto input_tensor = get_input(static_cast(index)); auto input_node = input_tensor.get_node_shared_ptr(); if (std::dynamic_pointer_cast(input_node)) { diff --git a/src/frontends/pytorch/src/op/adaptive_poolnd.cpp b/src/frontends/pytorch/src/op/adaptive_poolnd.cpp index 9c349e50c8ed86..bc6b17cbed093d 100644 --- a/src/frontends/pytorch/src/op/adaptive_poolnd.cpp +++ b/src/frontends/pytorch/src/op/adaptive_poolnd.cpp @@ -117,6 +117,21 @@ OutputVector translate_adaptive_max_pool1d(const NodeContext& context) { return translate_adaptive_max_pool_base(context, const_tile_params, const_neg_1); }; +OutputVector translate_adaptive_max_pool3d_fx(const NodeContext& context) { + auto outs = translate_adaptive_max_pool3d(context); + return {context.mark_node(make_list_construct(outs))}; +}; + +OutputVector translate_adaptive_max_pool2d_fx(const NodeContext& context) { + auto outs = translate_adaptive_max_pool2d(context); + return {context.mark_node(make_list_construct(outs))}; +}; + +OutputVector translate_adaptive_max_pool1d_fx(const NodeContext& context) { + auto outs = translate_adaptive_max_pool1d(context); + return {context.mark_node(make_list_construct(outs))}; +}; + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/add.cpp b/src/frontends/pytorch/src/op/add.cpp index 33699ad90fa39c..ab2933bd6f7910 100644 --- a/src/frontends/pytorch/src/op/add.cpp +++ b/src/frontends/pytorch/src/op/add.cpp @@ -34,8 +34,14 @@ OutputVector translate_add_common(const NodeContext& context, bool inplace) { } else { align_eltwise_input_types(context, lhs, rhs, true); } + Output alpha; if (!context.input_is_none(2)) { - auto converted_alpha = context.mark_node(std::make_shared(context.get_input(2), rhs)); + alpha = context.get_input(2); + } else if (context.has_attribute("alpha")) { + alpha = context.get_attribute>("alpha"); + } + if (alpha.get_node_shared_ptr()) { + auto converted_alpha = context.mark_node(std::make_shared(alpha, rhs)); rhs = context.mark_node(std::make_shared(converted_alpha, rhs)); } auto add = context.mark_node(std::make_shared(lhs, rhs)); diff --git a/src/frontends/pytorch/src/op/addcmul.cpp b/src/frontends/pytorch/src/op/addcmul.cpp index 7933acfde1d176..9ebe2a24875f25 100644 --- a/src/frontends/pytorch/src/op/addcmul.cpp +++ b/src/frontends/pytorch/src/op/addcmul.cpp @@ -17,15 +17,30 @@ namespace op { using namespace ov::op; -OutputVector translate_addcmul(const NodeContext& context) { - num_inputs_check(context, 4, 4); +namespace { +OutputVector addcmul_common(const NodeContext& context, const Output& value) { const auto eltwise_mult = std::make_shared(context.get_input(1), context.get_input(2)); - const auto value = context.get_input(3); const auto converted_value = std::make_shared(value, context.get_input(1)); const auto scalar_mult = std::make_shared(eltwise_mult, converted_value); context.mark_nodes({eltwise_mult, converted_value, scalar_mult}); return {context.mark_node(std::make_shared(context.get_input(0), scalar_mult))}; }; +} // namespace + +OutputVector translate_addcmul(const NodeContext& context) { + num_inputs_check(context, 4, 4); + const auto value = context.get_input(3); + return addcmul_common(context, value); +}; + +OutputVector translate_addcmul_fx(const NodeContext& context) { + num_inputs_check(context, 3, 3); + Output value = context.mark_node(v0::Constant::create(element::f32, Shape{}, {1})); + if (context.has_attribute("value")) { + value = context.get_input("value"); + } + return addcmul_common(context, value); +}; } // namespace op } // namespace pytorch diff --git a/src/frontends/pytorch/src/op/addmm.cpp b/src/frontends/pytorch/src/op/addmm.cpp index 731014c6c27c5c..097737ec93ecf1 100644 --- a/src/frontends/pytorch/src/op/addmm.cpp +++ b/src/frontends/pytorch/src/op/addmm.cpp @@ -16,12 +16,22 @@ namespace op { using namespace ov::op; -OutputVector translate_addmm(const NodeContext& context) { - num_inputs_check(context, 3, 5); +namespace { +OutputVector translate_addmm_common(const NodeContext& context, const Output beta, const Output alpha) { auto input = context.get_input(0); auto m1 = context.get_input(1); auto m2 = context.get_input(2); auto mm = context.mark_node(std::make_shared(m1, m2)); + auto beta_converted = context.mark_node(std::make_shared(beta, input)); + auto alpha_converted = context.mark_node(std::make_shared(alpha, mm)); + auto input_beta = context.mark_node(std::make_shared(input, beta_converted)); + auto mm_alpha = context.mark_node(std::make_shared(mm, alpha_converted)); + return {context.mark_node(std::make_shared(input_beta, mm_alpha))}; +}; +} // namespace + +OutputVector translate_addmm(const NodeContext& context) { + num_inputs_check(context, 3, 5); auto one = context.mark_node(v0::Constant::create(element::f32, Shape{}, {1})); ov::Output alpha = one; ov::Output beta = one; @@ -31,11 +41,21 @@ OutputVector translate_addmm(const NodeContext& context) { if (!context.input_is_none(4)) { alpha = context.get_input(4); } - auto beta_converted = context.mark_node(std::make_shared(beta, input)); - auto alpha_converted = context.mark_node(std::make_shared(alpha, mm)); - auto input_beta = context.mark_node(std::make_shared(input, beta_converted)); - auto mm_alpha = context.mark_node(std::make_shared(mm, alpha_converted)); - return {context.mark_node(std::make_shared(input_beta, mm_alpha))}; + return {translate_addmm_common(context, beta, alpha)}; +}; + +OutputVector translate_addmm_fx(const NodeContext& context) { + num_inputs_check(context, 3, 3); + auto one = context.mark_node(v0::Constant::create(element::f32, Shape{}, {1})); + ov::Output alpha = one; + ov::Output beta = one; + if (context.has_attribute("beta")) { + beta = context.get_input("beta"); + } + if (context.has_attribute("alpha")) { + alpha = context.get_input("alpha"); + } + return {translate_addmm_common(context, beta, alpha)}; }; } // namespace op diff --git a/src/frontends/pytorch/src/op/batch_norm.cpp b/src/frontends/pytorch/src/op/batch_norm.cpp index 126588eb952a6b..5d10222eceb890 100644 --- a/src/frontends/pytorch/src/op/batch_norm.cpp +++ b/src/frontends/pytorch/src/op/batch_norm.cpp @@ -17,6 +17,7 @@ #include "openvino/op/subtract.hpp" #include "openvino/op/unsqueeze.hpp" #include "openvino/op/util/framework_node.hpp" +#include "openvino/pass/graph_rewrite.hpp" #include "utils.hpp" namespace ov { @@ -37,91 +38,112 @@ Output broadcast_const_to_channel_dim(const NodeContext& context, auto channel_dim_exp = context.mark_node(std::make_shared(channel_dim, zero_i)); return context.mark_node(std::make_shared(value, channel_dim_exp)); } + +OutputVector make_batch_norm(const NodeContext& context, + const Output& input, + const Output& weight, + const Output& bias, + const Output& running_mean, + const Output& running_var, + float epsilon) { + Output w = weight; + Output b = bias; + Output mean = running_mean; + Output var = running_var; + if (!w.get_node_shared_ptr()) { + auto one_f = context.mark_node(v0::Constant::create(element::f32, Shape{}, {1})); + w = broadcast_const_to_channel_dim(context, input, one_f); + } + if (!b.get_node_shared_ptr()) { + auto zero_f = context.mark_node(v0::Constant::create(element::f32, Shape{}, {0})); + b = broadcast_const_to_channel_dim(context, input, zero_f); + } + auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + auto zero_1d = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); + auto one = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); + auto two = context.mark_node(v0::Constant::create(element::i32, Shape{}, {2})); + Output rank = std::get<1>(get_shape_rank(context, input, true)); + auto after_channel_dims = context.mark_node(std::make_shared(two, rank, one)); + auto axes = context.mark_node(std::make_shared(OutputVector{zero_1d, after_channel_dims}, 0)); + if (!mean.get_node_shared_ptr()) { + mean = context.mark_node(std::make_shared(input, axes, false)); + } + if (!var.get_node_shared_ptr()) { + auto current_mean = context.mark_node(std::make_shared(input, axes, true)); + auto sub_v = context.mark_node(std::make_shared(input, current_mean)); + auto sqr_sub = context.mark_node(std::make_shared(sub_v, sub_v)); + var = context.mark_node(std::make_shared(sqr_sub, axes, false)); + } + return {context.mark_node(std::make_shared(input, w, b, mean, var, epsilon))}; +} } // namespace -OutputVector translate_batch_norm_common(const NodeContext& context, bool training) { +OutputVector translate_batch_norm(const NodeContext& context) { // Schema: aten::batch_norm(Tensor input, Tensor? weight, Tensor? bias, Tensor? running_mean, Tensor? running_var, // bool training, float momentum, float eps, bool cudnn_enabled) -> Tensor - - // batch_norm_legit_no_training Schema: aten::batch_norm(Tensor input, Tensor? weight, Tensor? bias, Tensor? - // running_mean, Tensor? running_var, float momentum, float eps) -> Tensor - - auto input = context.get_input(0); + num_inputs_check(context, 7, 9); Output weight; Output bias; Output running_mean; Output running_var; - Output current_mean; - Output current_var; if (!context.input_is_none(1)) { weight = context.get_input(1); - } else { - auto one_f = context.mark_node(v0::Constant::create(element::f32, Shape{}, {1})); - weight = broadcast_const_to_channel_dim(context, input, one_f); } if (!context.input_is_none(2)) { bias = context.get_input(2); - } else { - auto zero_f = context.mark_node(v0::Constant::create(element::f32, Shape{}, {0})); - bias = broadcast_const_to_channel_dim(context, input, zero_f); } // index 3 running_mean and index 4 running_var can be none for training case only, check that not training before // if training for batch norm activated, but model in eval mode, it uses current statistics instead of running - if (training) { - auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); - auto zero_1d = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); - auto one = context.mark_node(v0::Constant::create(element::i32, Shape{}, {1})); - auto two = context.mark_node(v0::Constant::create(element::i32, Shape{}, {2})); - auto input_shape = context.mark_node(std::make_shared(input, element::i32)); - auto rank_unsq = context.mark_node(std::make_shared(input_shape, element::i32)); - auto rank = context.mark_node(std::make_shared(rank_unsq, zero)); - auto after_channel_dims = context.mark_node(std::make_shared(two, rank, one)); - auto axes = context.mark_node(std::make_shared(OutputVector{zero_1d, after_channel_dims}, 0)); - current_mean = context.mark_node(std::make_shared(input, axes, false)); - auto mean = context.mark_node(std::make_shared(input, axes, true)); - auto sub_v = context.mark_node(std::make_shared(input, mean)); - auto sqr_sub = context.mark_node(std::make_shared(sub_v, sub_v)); - current_var = context.mark_node(std::make_shared(sqr_sub, axes, false)); - } + auto training = context.const_input(5); if (!training) { running_mean = context.get_input(3); - } else { - running_mean = current_mean; - } - if (!training) { running_var = context.get_input(4); - } else { - running_var = current_var; } // Input with index 6 is momentum, it is used only for updating running_mean accumulation during training - // In batch_norm_legit_no_training, momentum is index 5 and epsilon is 6 - float epsilon; - if (context.get_input_size() == 7) { - epsilon = context.const_input(6); - } else { - epsilon = context.const_input(7); - } + float epsilon = context.const_input(7); // Input with index 8 is flag "cudnn_enabled" we can ignore it - return {context.mark_node( - std::make_shared(input, weight, bias, running_mean, running_var, epsilon))}; -}; - -OutputVector translate_batch_norm(const NodeContext& context) { - num_inputs_check(context, 7, 9); - auto training = context.const_input(5); - return translate_batch_norm_common(context, training); + return make_batch_norm(context, context.get_input(0), weight, bias, running_mean, running_var, epsilon); } OutputVector translate_batch_norm_legit_fx(const NodeContext& context) { - num_inputs_check(context, 7, 9); - auto training = context.const_input(5); - auto output = translate_batch_norm_common(context, training); + auto output = translate_batch_norm(context); return {context.mark_node(make_list_construct(output))}; } OutputVector translate_batch_norm_legit_no_training_fx(const NodeContext& context) { num_inputs_check(context, 7, 9); - auto output = translate_batch_norm_common(context, false); + Output weight; + Output bias; + if (!context.input_is_none(1)) { + weight = context.get_input(1); + } + if (!context.input_is_none(2)) { + bias = context.get_input(2); + } + auto running_mean = context.get_input(3); + auto running_var = context.get_input(4); + float epsilon = context.const_input(6); + auto output = make_batch_norm(context, context.get_input(0), weight, bias, running_mean, running_var, epsilon); + return {context.mark_node(make_list_construct(output))}; +} + +OutputVector translate_batch_norm_legit_no_stats_fx(const NodeContext& context) { + num_inputs_check(context, 6, 6); + // torch.ops.aten._native_batch_norm_legit.no_stats(arg2_1, arg0_1, arg1_1, True, 0.1, 5e-05) + Output weight; + if (!context.input_is_none(1)) { + weight = context.get_input(1); + } + Output bias; + if (!context.input_is_none(2)) { + bias = context.get_input(2); + } + auto training = context.const_input(3); + FRONT_END_OP_CONVERSION_CHECK(training, + "aten._native_batch_norm_legit.no_stats can only be used when training=True."); + // index 4 momentum is used during training only + auto eps = context.const_input(5); + auto output = make_batch_norm(context, context.get_input(0), weight, bias, {}, {}, eps); return {context.mark_node(make_list_construct(output))}; } diff --git a/src/frontends/pytorch/src/op/div.cpp b/src/frontends/pytorch/src/op/div.cpp index dbbb6c89af7e6c..477c9ced2bb462 100644 --- a/src/frontends/pytorch/src/op/div.cpp +++ b/src/frontends/pytorch/src/op/div.cpp @@ -17,14 +17,13 @@ namespace frontend { namespace pytorch { namespace op { -OutputVector translate_div_common(const NodeContext& context, bool inplace) { - num_inputs_check(context, 2, 3); - auto x = context.get_input(0); - auto y = context.get_input(1); - std::string rounding_mode = ""; - if (!context.input_is_none(2)) { - rounding_mode = context.const_input(2); - } +OutputVector translate_div_common(const NodeContext& context, + const Output& lhs, + const Output& rhs, + const std::string& rounding_mode, + bool inplace) { + auto x = lhs; + auto y = rhs; if (rounding_mode.empty()) { // if no rounding mode and both inputs are ints cast BOTH to fp32 const auto x_dtype = x.get_element_type(); @@ -36,7 +35,7 @@ OutputVector translate_div_common(const NodeContext& context, bool inplace) { } if (inplace) { if (x.get_element_type().is_dynamic() || x.get_element_type() != y.get_element_type()) - y = context.mark_node(std::make_shared(x, y)); + y = context.mark_node(std::make_shared(y, x)); } else { align_eltwise_input_types(context, x, y, true); } @@ -55,11 +54,36 @@ OutputVector translate_div_common(const NodeContext& context, bool inplace) { }; OutputVector translate_div(const NodeContext& context) { - return translate_div_common(context, false); + num_inputs_check(context, 2, 3); + auto x = context.get_input(0); + auto y = context.get_input(1); + std::string rounding_mode = ""; + if (!context.input_is_none(2)) { + rounding_mode = context.const_input(2); + } + return translate_div_common(context, x, y, rounding_mode, false); }; OutputVector translate_div_(const NodeContext& context) { - return translate_div_common(context, true); + num_inputs_check(context, 2, 3); + auto x = context.get_input(0); + auto y = context.get_input(1); + std::string rounding_mode = ""; + if (!context.input_is_none(2)) { + rounding_mode = context.const_input(2); + } + return translate_div_common(context, x, y, rounding_mode, true); +}; + +OutputVector translate_div_fx(const NodeContext& context) { + num_inputs_check(context, 2, 2); + auto x = context.get_input(0); + auto y = context.get_input(1); + std::string rounding_mode = ""; + if (context.has_attribute("rounding_mode")) { + rounding_mode = context.get_attribute("rounding_mode"); + } + return translate_div_common(context, x, y, rounding_mode, false); }; } // namespace op diff --git a/src/frontends/pytorch/src/op/expand.cpp b/src/frontends/pytorch/src/op/expand.cpp index 0b0690404129c6..7fcb7a898a48bc 100644 --- a/src/frontends/pytorch/src/op/expand.cpp +++ b/src/frontends/pytorch/src/op/expand.cpp @@ -49,7 +49,7 @@ OutputVector translate_expand_fx(const NodeContext& context) { // output shapes are same. This should be removed after a proper optimization is // implemented. auto sizes_const = context.const_input(1); - if (x.get_shape() == sizes_const) { + if (x.get_partial_shape().is_static() && x.get_shape() == sizes_const) { return {x}; } auto sizes = context.get_input(1); diff --git a/src/frontends/pytorch/src/op/full.cpp b/src/frontends/pytorch/src/op/full.cpp index a86b5bf37251d8..70ff0ba980a7a0 100644 --- a/src/frontends/pytorch/src/op/full.cpp +++ b/src/frontends/pytorch/src/op/full.cpp @@ -71,6 +71,21 @@ OutputVector translate_full(const NodeContext& context) { return {base_translate_full_with_convert(context, sizes, value, dtype_id)}; }; +OutputVector translate_full_fx(const NodeContext& context) { + // aten.full.default([16, 16], 0, dtype = torch.float32, layout = torch.strided, device = device(type='cpu'), + // pin_memory = False) + num_inputs_check(context, 2, 2); + auto sizes = context.get_input(0); + auto value = context.get_input(1); + + auto filled_tensor = base_translate_full(context, sizes, value); + if (context.has_attribute("dtype")) { + auto dtype = context.get_attribute("dtype"); + filled_tensor = context.mark_node(std::make_shared(filled_tensor, dtype)); + } + return {filled_tensor}; +}; + OutputVector translate_full_like(const NodeContext& context) { num_inputs_check(context, 2, 7); auto input = context.get_input(0); diff --git a/src/frontends/pytorch/src/op/gelu.cpp b/src/frontends/pytorch/src/op/gelu.cpp index 4f7fc810596b6c..64afb511b31dc3 100644 --- a/src/frontends/pytorch/src/op/gelu.cpp +++ b/src/frontends/pytorch/src/op/gelu.cpp @@ -12,13 +12,9 @@ namespace frontend { namespace pytorch { namespace op { -OutputVector translate_gelu(const NodeContext& context) { - num_inputs_check(context, 1, 2); +namespace { +OutputVector translate_gelu_common(const NodeContext& context, const std::string& approximate) { auto x = context.get_input(0); - std::string approximate = "none"; - if (!context.input_is_none(1)) { - approximate = context.const_input(1); - } if (approximate == "none") { return {context.mark_node(std::make_shared(x, ov::op::GeluApproximationMode::ERF))}; } @@ -27,6 +23,27 @@ OutputVector translate_gelu(const NodeContext& context) { } FRONT_END_OP_CONVERSION_CHECK(false, "Unsupported approximate for Gelu: ", approximate); }; +} // namespace + +OutputVector translate_gelu(const NodeContext& context) { + num_inputs_check(context, 1, 2); + auto x = context.get_input(0); + std::string approximate = "none"; + if (!context.input_is_none(1)) { + approximate = context.const_input(1); + } + return translate_gelu_common(context, approximate); +}; + +OutputVector translate_gelu_fx(const NodeContext& context) { + num_inputs_check(context, 1, 1); + auto x = context.get_input(0); + std::string approximate = "none"; + if (context.has_attribute("approximate")) { + approximate = context.get_attribute("approximate"); + } + return translate_gelu_common(context, approximate); +}; } // namespace op } // namespace pytorch diff --git a/src/frontends/pytorch/src/op/glu.cpp b/src/frontends/pytorch/src/op/glu.cpp index dbe979fb1f2870..779c81c4904f29 100644 --- a/src/frontends/pytorch/src/op/glu.cpp +++ b/src/frontends/pytorch/src/op/glu.cpp @@ -17,7 +17,7 @@ namespace op { using namespace ov::op; OutputVector translate_glu(const NodeContext& context) { - num_inputs_check(context, 2, 2); + num_inputs_check(context, 1, 2); auto x = context.get_input(0); auto dim = context.input_is_none(1) ? context.mark_node(v0::Constant::create(element::i32, Shape{}, {-1})) : context.get_input(1); diff --git a/src/frontends/pytorch/src/op/index.cpp b/src/frontends/pytorch/src/op/index.cpp index e739476619ff7f..a9aaf62257d71b 100644 --- a/src/frontends/pytorch/src/op/index.cpp +++ b/src/frontends/pytorch/src/op/index.cpp @@ -3,9 +3,20 @@ // #include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/add.hpp" #include "openvino/op/concat.hpp" #include "openvino/op/convert.hpp" +#include "openvino/op/gather.hpp" #include "openvino/op/gather_nd.hpp" +#include "openvino/op/multiply.hpp" +#include "openvino/op/non_zero.hpp" +#include "openvino/op/reduce_prod.hpp" +#include "openvino/op/reshape.hpp" +#include "openvino/op/shape_of.hpp" +#include "openvino/op/slice.hpp" +#include "openvino/op/split.hpp" +#include "openvino/op/transpose.hpp" +#include "pt_framework_node.hpp" #include "utils.hpp" namespace ov { @@ -13,23 +24,252 @@ namespace frontend { namespace pytorch { namespace op { +using namespace ov::op; + +namespace { +Output flatten(ov::pass::NodeRegistry& rg, const Output& value, size_t axis) { + // First dimension of output tensor is the product of [d_0, ... d_{axis-1}] dimensions of + // input tensor. The last dimension is the product of the rest of input tensor dimensions: + // [d_{axis}, ..., d_n] + Output output_shape; + if (axis == 0) { + output_shape = v0::Constant::create(element::i32, Shape{2}, {1, -1}); + } else if (axis == 1) { + output_shape = v0::Constant::create(element::i32, Shape{2}, {0, -1}); + } else { + const auto value_shape = rg.make(value, element::i32); + const auto value_rank = rg.make(value_shape, element::i32); + const auto axis_node = v0::Constant::create(element::i32, Shape{1}, {axis}); + auto start = v0::Constant::create(element::i32, Shape{1}, {0}); + auto step = v0::Constant::create(element::i32, Shape{1}, {1}); + const auto first_part_dims = rg.make(value_shape, start, axis_node, step); + auto zero = v0::Constant::create(element::i32, {}, {0}); + auto first_part_dims_length = rg.make(first_part_dims, zero, true); + + auto remaining_part_length = v0::Constant::create(element::i32, {1}, {-1}); + + output_shape = rg.make(OutputVector{first_part_dims_length, remaining_part_length}, 0); + } + return rg.make(value, output_shape, true); +} + +OutputVector index_on_list(ov::pass::NodeRegistry& rg, + const Output& data, + std::deque> ids, + int64_t rank) { + // Multiple tensors as indices. Each tensor could either be + // 1. prim::Constant() + // representing ":" in python indexing. E.g. tensor[:, :] + // 2. prim::Constant[value=...] or tensor output + // representing advanced indexing. E.g. tensor[[0, 1], [2, 0]]. + // For more info on advanced indexing, + // check https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing + + // Consider a general case of + // t: [x_1, y_1, y_2, ..., x_m, ..., y_n] + // where t is a tensor of rank m+n, {x_i} are axes where tensor index is provided, and {y_i} are axes for + // ":". Same results can be achieved through transposing t into + // t: [x_1, x_2, ..., x_m, y_1, y_2, ..., y_n] + // and use gather + // t: [x_1 * x_2 * ... * x_m, y_1 * y_2 * ... * y_n] + // tensor index = \sum_{i=1}^m (ind_i * \prod_{j=i+1}^m (x_j)) + // After gather, reshape and transpose back. + std::vector advanced_ids; + std::vector is_masked_bool; + OutputVector masked_indicies; + // for case when index is bool e.g. x[x>0], replace index with non_zero + for (size_t i = 0; i < ids.size(); i++) { + // skip dimensions where index is None + bool is_none = false; + if (!ids[i].get_node_shared_ptr()) { + is_none = true; + } + if (auto const_input = cast_fw_node(ids[i].get_node_shared_ptr(), "prim::Constant")) { + const auto& attrs = const_input->get_attrs(); + if (attrs.find("none_value") != attrs.end()) { + is_none = true; + } + } + if (is_none) { + masked_indicies.push_back(ids[i]); + is_masked_bool.push_back(false); + continue; + } + auto id_dtype = ids[i].get_element_type(); + if (id_dtype == element::boolean || id_dtype == element::u8) { + auto idx = rg.make(ids[i], element::u8); + auto nonzero = rg.make(idx, element::i32); + auto input_order = v0::Constant::create(element::i32, Shape{2}, {1, 0}); + auto masked_id = rg.make(nonzero, input_order); + masked_indicies.push_back(masked_id); + is_masked_bool.push_back(true); + } else { + masked_indicies.push_back(ids[i]); + is_masked_bool.push_back(false); + } + advanced_ids.push_back(i); + } + + // all indicies prim::Constant(None), return input as is + if (advanced_ids.size() == 0) { + return {data}; + } + // perform gather for single element case + if (advanced_ids.size() == 1) { + auto index = masked_indicies[advanced_ids[0]]; + if (is_masked_bool[advanced_ids[0]]) { + auto gather = rg.make(data, index); + return {gather}; + } + index = rg.make(index, element::i32); + auto dim = v0::Constant::create(element::i32, Shape{}, {advanced_ids[0]}); + auto gather = rg.make(data, index, dim); + return {gather}; + } + auto adv_idx_count = advanced_ids.size(); + auto input_shape = rg.make(data, element::i32); + auto zero = v0::Constant::create(element::i32, Shape{}, {0}); + auto input_dims = rg.make(input_shape, zero, rank); + std::vector non_used_dims; + for (auto i = 0; i < rank; i++) { + if (std::find(advanced_ids.begin(), advanced_ids.end(), i) == advanced_ids.end()) { + non_used_dims.push_back(i); + } + } + std::vector permutation_dims; + permutation_dims.insert(permutation_dims.end(), advanced_ids.begin(), advanced_ids.end()); + permutation_dims.insert(permutation_dims.end(), non_used_dims.begin(), non_used_dims.end()); + auto transpose_dims = v0::Constant::create(element::i32, Shape{permutation_dims.size()}, permutation_dims); + auto transposed_input = rg.make(data, transpose_dims); + auto flatten_input = flatten(rg, transposed_input, adv_idx_count); + auto cum_adv_index = masked_indicies[advanced_ids.back()]; + cum_adv_index = rg.make(cum_adv_index, element::i32); + auto multiplier = input_dims->output(advanced_ids.back()); + for (int i = static_cast(adv_idx_count) - 2; i > -1; i--) { + auto input_id = advanced_ids[i]; + auto m_idx = rg.make(masked_indicies[input_id], element::i32); + auto adv_index = rg.make(m_idx, multiplier); + cum_adv_index = rg.make(cum_adv_index, adv_index); + multiplier = rg.make(multiplier, input_dims->output(input_id)); + } + std::shared_ptr gather = rg.make(flatten_input, cum_adv_index, zero); + OutputVector concat_dims; + // check if all advanced indices are consecutive. + std::vector consequence_dims; + auto cum_adv_index_shape_tensor = rg.make(cum_adv_index, element::i32); + for (size_t i = advanced_ids[0]; i <= advanced_ids[advanced_ids.back()]; i++) { + consequence_dims.push_back(i); + } + // unfold regular index axes + if (advanced_ids == consequence_dims) { + OutputVector folded_adv_idx_shape_vector; + auto minus_one = v0::Constant::create(element::i32, Shape{1}, {-1}); + folded_adv_idx_shape_vector.push_back(minus_one); + for (auto i : non_used_dims) { + folded_adv_idx_shape_vector.push_back(input_dims->output(i)); + } + auto folded_adv_idx_shape = rg.make(folded_adv_idx_shape_vector, 0); + gather = rg.make(gather, folded_adv_idx_shape, false); + std::vector adv_idx_permute; + for (size_t i = 1; i < advanced_ids[0] + 1; i++) { + adv_idx_permute.push_back(i); + } + adv_idx_permute.push_back(0); + for (size_t i = advanced_ids[0] + 1; i < (rank - adv_idx_count + 1); i++) { + adv_idx_permute.push_back(i); + } + // Transpose folded advanced indexed axis to its original location. + auto permute_indicies = v0::Constant::create(element::i32, Shape{adv_idx_permute.size()}, adv_idx_permute); + gather = rg.make(gather, permute_indicies); + // unfold advanced index axes + for (size_t i = 0; i < advanced_ids[0]; i++) { + concat_dims.push_back(input_dims->output(i)); + } + concat_dims.push_back(cum_adv_index_shape_tensor); + for (auto i : non_used_dims) { + if (i < advanced_ids[0]) { + continue; + } + concat_dims.push_back(input_dims->output(i)); + } + + } else { + size_t i = 0; + auto one = v0::Constant::create(element::i32, Shape{1}, {1}); + while (i < non_used_dims.size() && non_used_dims[i] < advanced_ids[0]) { + concat_dims.push_back(one); + i++; + } + concat_dims.push_back(cum_adv_index_shape_tensor); + for (; i < non_used_dims.size(); i++) { + concat_dims.push_back(input_dims->output(non_used_dims[i])); + } + } + auto final_shape = rg.make(concat_dims, 0); + gather = rg.make(gather, final_shape, false); + return {gather}; +} +} // namespace + +OutputVector translate_index(const NodeContext& context) { + num_inputs_check(context, 2, 2); + auto x = context.get_input(0); + if (context.input_is_none(1)) { + return {x}; + } + auto indices = context.get_input(1); + auto index_dtype = context.get_input_type(1); + if (index_dtype.is()) { + auto list_elems = get_list_as_outputs(indices); + ov::pass::NodeRegistry rg; + auto rank = x.get_partial_shape().rank(); + // index transformation supports only tensors with static rank + FRONT_END_OP_CONVERSION_CHECK(rank.is_static(), "Dynamic rank for aten::index input is not supported."); + auto res = index_on_list(rg, x, list_elems, rank.get_length()); + context.mark_nodes(rg.get()); + return res; + } + auto index_ov_type = indices.get_element_type(); + if (index_ov_type.is_dynamic()) { + if (simplified_type_interpret(index_dtype).is()) { + index_ov_type = index_dtype.as(); + } + } + if (index_ov_type == element::boolean || index_ov_type == element::u8) { + auto nonzero = context.mark_node(std::make_shared(indices, element::i32)); + auto input_order = context.mark_node(v0::Constant::create(element::i32, Shape{2}, {1, 0})); + auto masked_id = context.mark_node(std::make_shared(nonzero, input_order)); + auto gather = context.mark_node(std::make_shared(x, masked_id)); + return {gather}; + } + if (index_ov_type != element::i32) { + indices = context.mark_node(std::make_shared(indices, element::i32)); + } + auto dim = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + return {context.mark_node(std::make_shared(x, indices, dim))}; +}; + OutputVector translate_index_fx(const NodeContext& context) { num_inputs_check(context, 2, context.get_input_size()); auto x = context.get_input(0); std::deque> list_elems; for (size_t i = 1; i < context.get_input_size(); i++) { - auto index = context.get_input(static_cast(i)); - if (index.get_element_type() == element::i64) { - auto converted = context.mark_node(std::make_shared(index, element::i32)); - list_elems.push_back(converted); - } else { - list_elems.push_back(index); + Output index; + if (!context.input_is_none(i)) { + index = context.get_input(static_cast(i)); } + list_elems.push_back(index); } - auto concat = - context.mark_node(std::make_shared(OutputVector(list_elems.begin(), list_elems.end()), 0)); - auto gather = std::make_shared(x, concat); - return {gather}; + ov::pass::NodeRegistry rg; + auto rank = x.get_partial_shape().rank(); + if (rank.is_dynamic()) { + rank = context.get_decoder()->get_input_shape(0).rank(); + } + // index transformation supports only tensors with static rank + FRONT_END_OP_CONVERSION_CHECK(rank.is_static(), "Dynamic rank for aten::index input is not supported."); + auto res = index_on_list(rg, x, list_elems, rank.get_length()); + context.mark_nodes(rg.get()); + return res; }; } // namespace op diff --git a/src/frontends/pytorch/src/op/leaky_relu.cpp b/src/frontends/pytorch/src/op/leaky_relu.cpp new file mode 100644 index 00000000000000..202f2c82331ced --- /dev/null +++ b/src/frontends/pytorch/src/op/leaky_relu.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/prelu.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; + +OutputVector translate_leaky_relu_fx(const NodeContext& context) { + num_inputs_check(context, 1, 2); + auto x = context.get_input(0); + float default_negative_slope = 1e-2; + Output negative_slope = ov::op::v0::Constant::create(element::f32, Shape{1}, {default_negative_slope}); + if (context.get_input_size() == 1) { + negative_slope = context.mark_node(std::make_shared(negative_slope, x)); + } else { + negative_slope = context.get_input(1); + } + return {context.mark_node(std::make_shared(x, negative_slope))}; +}; + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/op/mean.cpp b/src/frontends/pytorch/src/op/mean.cpp index 503b7a47f2951f..ef88c2922ac39d 100644 --- a/src/frontends/pytorch/src/op/mean.cpp +++ b/src/frontends/pytorch/src/op/mean.cpp @@ -20,7 +20,7 @@ OutputVector translate_mean(const NodeContext& context) { // aten::mean(Tensor self, *, ScalarType? dtype=None) -> Tensor if (num_inputs == 2) { if (!context.input_is_none(1)) { - x = apply_dtype(context, 3, x); + x = apply_dtype(context, 1, x); } axes = get_axes_range(context, 0); } else { @@ -42,6 +42,30 @@ OutputVector translate_mean(const NodeContext& context) { return {mean}; }; +OutputVector translate_mean_fx(const NodeContext& context) { + num_inputs_check(context, 2, 5); + auto x = context.get_input(0); + auto num_inputs = context.get_input_size(); + bool keep_dims = false; + Output axes; + if (num_inputs == 2) { + axes = context.get_input(1); + } else { + axes = context.get_input(1); + if (!context.input_is_none(2)) { + keep_dims = context.const_input(2); + } + if (!context.input_is_none(3)) { + x = apply_dtype(context, 3, x); + } + } + auto mean = context.mark_node(std::make_shared(x, axes, keep_dims)); + if (num_inputs == 5 && !context.input_is_none(4)) { + context.mutate_input(4, mean); + } + return {mean}; +}; + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/pad.cpp b/src/frontends/pytorch/src/op/pad.cpp index ab853fec5f0e29..390277edcf5796 100644 --- a/src/frontends/pytorch/src/op/pad.cpp +++ b/src/frontends/pytorch/src/op/pad.cpp @@ -22,11 +22,12 @@ namespace op { using namespace ov::op; -OutputVector translate_pad(const NodeContext& context) { - num_inputs_check(context, 2, 4); - auto data = context.get_input(0); - auto paddings = context.const_input>(1); - std::string mode = "constant"; +namespace { +OutputVector translate_pad_common(const NodeContext& context, + const Output& data, + const std::vector& paddings, + const Output& pad_value, + const std::string& mode = "constant") { Output shape; Output rank; std::tie(shape, rank) = get_shape_rank(context, data); @@ -45,9 +46,6 @@ OutputVector translate_pad(const NodeContext& context) { auto pads_remaining = context.mark_node(std::make_shared(zero, pads_diff)); auto pads_begins = context.mark_node(std::make_shared(NodeVector{pads_remaining, pads_begin_short}, 0)); auto pads_ends = context.mark_node(std::make_shared(NodeVector{pads_remaining, pads_end_short}, 0)); - if (!context.input_is_none(2)) { - mode = context.const_input(2); - } if (mode == "circular") { int64_t pad_l; int64_t pad_r; @@ -86,24 +84,46 @@ OutputVector translate_pad(const NodeContext& context) { } return {cur}; } + auto pad_value_ = context.mark_node(std::make_shared(pad_value, data)); const std::map pt_to_ov_pad{ {"constant", PadMode::CONSTANT}, {"reflect", PadMode::REFLECT}, {"replicate", PadMode::EDGE}, }; + auto ov_mode = pt_to_ov_pad.find(mode); + FRONT_END_OP_CONVERSION_CHECK(ov_mode != pt_to_ov_pad.end(), + "aten::pad conversion doesn't support [ ", + mode, + " ] padding mode"); + return {context.mark_node(std::make_shared(data, pads_begins, pads_ends, pad_value_, ov_mode->second))}; +} +} // namespace + +OutputVector translate_pad(const NodeContext& context) { + num_inputs_check(context, 2, 4); + auto data = context.get_input(0); + auto paddings = context.const_input>(1); + std::string mode = "constant"; + + if (!context.input_is_none(2)) { + mode = context.const_input(2); + } + Output pad_value = context.mark_node(v0::Constant::create(element::f32, Shape{}, {0})); if (mode == "constant") { if (!context.input_is_none(3)) { pad_value = context.get_input(3); } - pad_value = context.mark_node(std::make_shared(pad_value, data)); } - auto ov_mode = pt_to_ov_pad.find(mode); - FRONT_END_OP_CONVERSION_CHECK(ov_mode != pt_to_ov_pad.end(), - "aten::pad conversion doesn't support [ ", - mode, - " ] padding mode"); - return {context.mark_node(std::make_shared(data, pads_begins, pads_ends, pad_value, ov_mode->second))}; + return translate_pad_common(context, data, paddings, pad_value, mode); +} + +OutputVector translate_constant_pad_nd_fx(const NodeContext& context) { + num_inputs_check(context, 3, 3); + auto data = context.get_input(0); + auto paddings = context.const_input>(1); + auto pad_value = context.get_input(2); + return translate_pad_common(context, data, paddings, pad_value); } } // namespace op diff --git a/src/frontends/pytorch/src/op/scalar_tensor.cpp b/src/frontends/pytorch/src/op/scalar_tensor.cpp new file mode 100644 index 00000000000000..64428486511adb --- /dev/null +++ b/src/frontends/pytorch/src/op/scalar_tensor.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/convert.hpp" +#include "openvino/op/convert_like.hpp" +#include "pt_framework_node.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; + +OutputVector translate_scalar_tensor_fx(const NodeContext& context) { + // aten.scalar_tensor.default(-100.0, dtype = torch.float32, layout = torch.strided, device = device(type='cpu')) + num_inputs_check(context, 1, 1); + auto data = context.get_input(0); + if (context.has_attribute("dtype")) { + auto dtype = context.get_attribute("dtype"); + data = context.mark_node(std::make_shared(context.get_input(0), dtype)); + } + // layout and device can be ignored + return {data}; +} + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov diff --git a/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp b/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp index 5a9e0d1f95cad7..c1e5fce3abc924 100644 --- a/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp +++ b/src/frontends/pytorch/src/op/scaled_dot_product_attention.cpp @@ -6,6 +6,7 @@ #include "openvino/frontend/pytorch/node_context.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/convert_like.hpp" +#include "openvino/op/unsqueeze.hpp" #include "openvino/op/util/framework_node.hpp" #include "utils.hpp" @@ -45,16 +46,35 @@ OutputVector translate_scaled_dot_product_attention(const NodeContext& context) }; OutputVector translate_scaled_dot_product_attention_fx(const NodeContext& context) { - // aten::scaled_dot_product_attention(Tensor query, Tensor key, Tensor value, Tensor? attn_mask=None, float - // dropout_p=0., bool is_causal=False) TODO: Scale parameter? - num_inputs_check(context, 3, 6); // TODO: Set 7 instead of 6 if `scale` argument supported in FX. - auto output = translate_scaled_dot_product_attention_common(context); - // TODO: scaled_dot_product_flash_attention has 9 outputs but for most cases only - // the first input is used. Rest of the outputs should be returned properly as - // needed. - ov::OutputVector out_vec; - out_vec.push_back(output); - return {context.mark_node(make_list_construct(out_vec))}; + // torch.ops.aten._scaled_dot_product_flash_attention_for_cpu.default(arg1_1, arg2_1, arg3_1, 0.0, True, attn_mask = + // arg0_1, scale = 5.0) + // aten._scaled_dot_product_flash_attention.default(arg0_1, arg1_1, arg2_1, 0.0, True, scale = 5.0) + num_inputs_check(context, 3, 5); + const auto query = context.get_input(0); + const auto key = context.get_input(1); + const auto value = context.get_input(2); + auto zero = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + OutputVector inputs{query, key, value}; + // Index 3 is dropout + auto causal = false; + if (context.has_attribute("is_causal")) { + causal = context.get_attribute("scale"); + } else if (!context.input_is_none(4)) { + causal = context.const_input(4); + } + if (context.has_attribute("attn_mask")) { + const auto attn_mask = context.get_input("attn_mask"); + inputs.push_back(attn_mask); + } else if (context.has_attribute("scale")) { + // if scale exist but attn_mask no, add zero input to fill in gap + inputs.push_back(context.mark_node(std::make_shared(zero, query))); + } + if (context.has_attribute("scale")) { + const auto scale = context.get_input("scale"); + inputs.push_back(context.mark_node(std::make_shared(scale, query))); + } + auto sdpa = context.mark_node(std::make_shared(inputs, causal)); + return {context.mark_node(make_list_construct({sdpa}))}; }; } // namespace op diff --git a/src/frontends/pytorch/src/op/slice_scatter.cpp b/src/frontends/pytorch/src/op/slice_scatter.cpp new file mode 100644 index 00000000000000..05bdc081a3e317 --- /dev/null +++ b/src/frontends/pytorch/src/op/slice_scatter.cpp @@ -0,0 +1,68 @@ +// Copyright (C) 2018-2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include "helper_ops/slice_assign.hpp" +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/constant.hpp" +#include "openvino/op/slice.hpp" +#include "openvino/op/unsqueeze.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; + +OutputVector translate_slice_scatter_fx(const NodeContext& context) { + num_inputs_check(context, 2, 6); + auto input = context.get_input(0); + auto src = context.get_input(1); + auto axis_0 = context.mark_node(v0::Constant::create(element::i32, Shape{}, {0})); + ov::Output dim; + if (!context.input_is_none(2)) { + dim = context.get_input(2); + if (dim.get_partial_shape().rank().is_dynamic() || dim.get_partial_shape().rank().get_length() == 0) { + dim = context.mark_node(std::make_shared(dim, axis_0)); + } + } else { + dim = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); + } + ov::Output start; + if (!context.input_is_none(3)) { + start = context.get_input(3); + if (start.get_partial_shape().rank().is_dynamic() || start.get_partial_shape().rank().get_length() == 0) { + start = context.mark_node(std::make_shared(start, axis_0)); + } + } else { + start = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {0})); + } + ov::Output end; + if (!context.input_is_none(4)) { + end = context.get_input(4); + if (end.get_partial_shape().rank().is_dynamic() || end.get_partial_shape().rank().get_length() == 0) { + end = context.mark_node(std::make_shared(end, axis_0)); + } + } else { + end = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {INT_MAX})); + } + ov::Output step; + if (!context.input_is_none(5)) { + step = context.get_input(5); + if (step.get_partial_shape().rank().is_dynamic() || step.get_partial_shape().rank().get_length() == 0) { + step = context.mark_node(std::make_shared(step, axis_0)); + } + } else { + step = context.mark_node(v0::Constant::create(element::i32, Shape{1}, {1})); + } + return {context.mark_node(std::make_shared(input, src, start, end, step, dim))}; +}; + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov \ No newline at end of file diff --git a/src/frontends/pytorch/src/op/split.cpp b/src/frontends/pytorch/src/op/split.cpp index db7d35075805b8..7b0241192cb667 100644 --- a/src/frontends/pytorch/src/op/split.cpp +++ b/src/frontends/pytorch/src/op/split.cpp @@ -4,10 +4,11 @@ #include "openvino/op/split.hpp" -#include +//#include #include "openvino/frontend/pytorch/node_context.hpp" #include "openvino/op/util/framework_node.hpp" +#include "openvino/op/variadic_split.hpp" #include "utils.hpp" namespace ov { @@ -18,7 +19,7 @@ namespace op { using namespace ov::op; OutputVector translate_chunk_fx(const NodeContext& context) { - num_inputs_check(context, 2, 3); + num_inputs_check(context, 3, 3); auto num_chunks = context.const_input(1); auto dim = context.get_input(2); @@ -35,6 +36,17 @@ OutputVector translate_chunk_fx(const NodeContext& context) { return {context.mark_node(make_list_construct(chunk->outputs()))}; } +OutputVector translate_split_with_sizes_fx(const NodeContext& context) { + num_inputs_check(context, 3, 3); + auto data = context.get_input(0); + auto split_lengths = context.get_input(1); + auto dim = context.get_input(2); + + auto split = std::make_shared(data, dim, split_lengths); + + return {context.mark_node(make_list_construct(split->outputs()))}; +} + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/sub.cpp b/src/frontends/pytorch/src/op/sub.cpp index 62534aee53864b..69148f23329d4d 100644 --- a/src/frontends/pytorch/src/op/sub.cpp +++ b/src/frontends/pytorch/src/op/sub.cpp @@ -21,7 +21,7 @@ OutputVector translate_sub_common(const NodeContext& context, bool inplace) { auto y = context.get_input(1); if (inplace) { if (x.get_element_type().is_dynamic() || x.get_element_type() != y.get_element_type()) - y = context.mark_node(std::make_shared(x, y)); + y = context.mark_node(std::make_shared(y, x)); } else { align_eltwise_input_types(context, x, y); } @@ -45,6 +45,20 @@ OutputVector translate_sub_(const NodeContext& context) { return translate_sub_common(context, true); }; +OutputVector translate_sub_fx(const NodeContext& context) { + num_inputs_check(context, 2, 2); + auto x = context.get_input(0); + auto y = context.get_input(1); + align_eltwise_input_types(context, x, y); + // default alpha is 1 so no need to multiply if alpha is not provided + if (context.has_attribute("alpha")) { + auto alpha = context.get_attribute>("alpha"); + auto casted_alpha = context.mark_node(std::make_shared(alpha, y)); + y = context.mark_node(std::make_shared(casted_alpha, y)); + } + return {context.mark_node(std::make_shared(x, y))}; +}; + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op/to.cpp b/src/frontends/pytorch/src/op/to.cpp index 0267e0ed20c4d4..d902caeb8487bc 100644 --- a/src/frontends/pytorch/src/op/to.cpp +++ b/src/frontends/pytorch/src/op/to.cpp @@ -81,6 +81,16 @@ OutputVector translate_to(const NodeContext& context) { return {cast}; } +OutputVector translate_to_fx(const NodeContext& context) { + num_inputs_check(context, 1, 1); + auto data = context.get_input(0); + if (context.has_attribute("dtype")) { + auto dtype = context.get_attribute("dtype"); + data = context.mark_node(std::make_shared(context.get_input(0), dtype)); + } + return {data}; +} + } // namespace op } // namespace pytorch } // namespace frontend diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index 9bc3083fbfdf0e..c829099c4acee9 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -95,6 +95,7 @@ OP_CONVERTER(translate_gru); OP_CONVERTER(translate_hardtanh); OP_CONVERTER(translate_if); OP_CONVERTER(translate_im2col); +OP_CONVERTER(translate_index); OP_CONVERTER(translate_index_add); OP_CONVERTER(translate_index_put_); OP_CONVERTER(translate_index_select); @@ -230,19 +231,36 @@ OP_CONVERTER(translate_quantized_convnd_relu); OP_CONVERTER(translate_quantized_linear); OP_CONVERTER(translate_xor); // Torch FX Translations +OP_CONVERTER(translate_adaptive_max_pool1d_fx); +OP_CONVERTER(translate_adaptive_max_pool2d_fx); +OP_CONVERTER(translate_adaptive_max_pool3d_fx); +OP_CONVERTER(translate_addcmul_fx); +OP_CONVERTER(translate_addmm_fx); OP_CONVERTER(translate_arange_fx); OP_CONVERTER(translate_batch_norm_legit_fx); OP_CONVERTER(translate_batch_norm_legit_no_training_fx); +OP_CONVERTER(translate_batch_norm_legit_no_stats_fx); OP_CONVERTER(translate_cat_fx); +OP_CONVERTER(translate_constant_pad_nd_fx); OP_CONVERTER(translate_chunk_fx); +OP_CONVERTER(translate_div_fx); OP_CONVERTER(translate_expand_fx); +OP_CONVERTER(translate_full_fx); +OP_CONVERTER(translate_gelu_fx); OP_CONVERTER(translate_group_norm_fx); OP_CONVERTER(translate_index_fx); OP_CONVERTER(translate_layer_norm_fx); +OP_CONVERTER(translate_leaky_relu_fx); OP_CONVERTER(translate_max_poolnd_fx); +OP_CONVERTER(translate_mean_fx); +OP_CONVERTER(translate_split_with_sizes_fx); +OP_CONVERTER(translate_scalar_tensor_fx); OP_CONVERTER(translate_scaled_dot_product_attention_fx); OP_CONVERTER(translate_slice_fx); +OP_CONVERTER(translate_slice_scatter_fx); OP_CONVERTER(translate_softmax_fx); +OP_CONVERTER(translate_sub_fx); +OP_CONVERTER(translate_to_fx); OP_CONVERTER(translate_transpose_fx); } // namespace op @@ -631,81 +649,123 @@ const std::map get_supported_ops_ts() { const std::map get_supported_ops_fx() { return { - {"aten._adaptive_avg_pool2d.default", op::translate_1to1_match_2_inputs}, + {"aten.abs.default", op::translate_1to1_match_1_inputs}, + {"aten._adaptive_avg_pool1d.default", op::translate_adaptive_avg_pool1d}, + {"aten._adaptive_avg_pool2d.default", op::translate_adaptive_avg_pool2d}, + {"aten._adaptive_avg_pool3d.default", op::translate_adaptive_avg_pool3d}, + {"aten.adaptive_max_pool1d.default", op::translate_adaptive_max_pool1d_fx}, + {"aten.adaptive_max_pool2d.default", op::translate_adaptive_max_pool2d_fx}, + {"aten.adaptive_max_pool3d.default", op::translate_adaptive_max_pool3d_fx}, + {"aten._local_scalar_dense.default", op::skip_node}, {"aten._softmax.default", op::translate_softmax_fx}, - {"aten._to_copy.default", op::skip_node}, + {"aten._to_copy.default", op::translate_to_fx}, {"aten._unsafe_view.default", op::translate_reshape}, {"aten.add.Tensor", op::translate_add}, {"aten.add_.Tensor", op::translate_add}, - {"aten.addmm.default", op::translate_addmm}, + {"aten.addcmul.default", op::translate_addcmul_fx}, + {"aten.addmm.default", op::translate_addmm_fx}, + {"aten.alias.default", op::skip_node}, {"aten.arange.start", op::translate_arange_fx}, + {"aten.arange.start_step", op::translate_arange_fx}, {"aten.arange.default", op::translate_arange_fx}, {"aten.argmax.default", op::translate_argmax}, + {"aten.as_strided.default", op::translate_as_strided}, {"aten.avg_pool2d.default", op::translate_avg_poolnd}, - {"aten.baddbmm.default", op::translate_addmm}, + {"aten.avg_pool3d.default", op::translate_avg_poolnd}, + {"aten.baddbmm.default", op::translate_addmm_fx}, {"aten.bitwise_and.Tensor", op::translate_bitwise_and}, {"aten.bmm.default", op::translate_1to1_match_2_inputs_align_types}, {"aten.cat.default", op::translate_cat_fx}, + {"aten.ceil.default", op::translate_1to1_match_1_inputs}, + {"aten.clamp.default", op::translate_clamp}, {"aten.clamp_min.default", op::translate_1to1_match_2_inputs}, + {"aten.constant_pad_nd.default", op::translate_constant_pad_nd_fx}, {"aten.clone.default", op::skip_node}, // ignore clone operators that are inserted by PyTorch autograd {"aten.convolution.default", op::translate_convolution}, - {"aten.copy_.default", op::skip_node}, + {"aten._convolution.default", op::translate_convolution}, + {"aten.copy.default", op::skip_node}, + {"aten.copy_.default", op::translate_copy_}, {"aten.cos.default", op::translate_1to1_match_1_inputs}, {"aten.cumsum.default", op::translate_cumsum}, {"aten.detach.default", op::skip_node}, - {"aten.div.Scalar", op::translate_div}, - {"aten.div.Tensor", op::translate_div}, + {"aten.div.Scalar", op::translate_div_fx}, + {"aten.div.Tensor", op::translate_div_fx}, + {"aten.div.Tensor_mode", op::translate_div_fx}, {"aten.embedding.default", op::translate_embedding}, {"aten.empty.memory_format", op::translate_empty}, {"aten.eq.Scalar", op::translate_1to1_match_2_inputs_align_types}, {"aten.eq.Tensor", op::translate_1to1_match_2_inputs_align_types}, {"aten.exp.default", op::translate_1to1_match_1_inputs}, {"aten.expand.default", op::translate_expand_fx}, - {"aten.full.default", op::translate_full}, + {"aten.floor.default", op::translate_1to1_match_1_inputs}, + {"aten.floor_divide.default", op::translate_floor_divide}, + {"aten.full.default", op::translate_full_fx}, + {"aten.full.names", op::translate_full_fx}, + {"aten.full_like.default", op::translate_full_like}, {"aten.gather.default", op::translate_gather}, - {"aten.gelu.default", op::translate_gelu}, + {"aten.gelu.default", op::translate_gelu_fx}, + {"aten.glu.default", op::translate_glu}, {"aten.gt.Scalar", op::translate_1to1_match_2_inputs_align_types}, {"aten.hardsigmoid.default", op::translate_1to1_match_1_inputs}, + {"aten.hardswish.default", op::translate_1to1_match_1_inputs}, {"aten.hardswish_.default", op::inplace_op>}, + {"aten.hardtanh.default", op::translate_hardtanh}, {"aten.hardtanh_.default", op::inplace_op}, {"aten.index.Tensor", op::translate_index_fx}, - {"aten.leaky_relu_.default", op::inplace_op>}, + {"aten.leaky_relu.default", op::translate_leaky_relu_fx}, + {"aten.leaky_relu_.default", op::inplace_op}, {"aten.lift_fresh_copy.default", op::skip_node}, {"aten.linalg_vector_norm.default", op::translate_linalg_vector_norm}, {"aten.log.default", op::translate_log}, {"aten.logsumexp.default", op::translate_logsumexp}, + {"aten.lt.Scalar", op::translate_1to1_match_2_inputs_align_types}, {"aten.lt.Tensor", op::translate_1to1_match_2_inputs_align_types}, {"aten.masked_fill_.Scalar", op::inplace_op}, {"aten.masked_fill.Tensor", op::translate_masked_fill}, {"aten.max_pool2d_with_indices.default", op::translate_max_poolnd_fx}, - {"aten.mean.dim", op::translate_mean}, + {"aten.max_pool3d_with_indices.default", op::translate_max_poolnd_fx}, + {"aten.mean.dim", op::translate_mean_fx}, {"aten.mm.default", op::translate_1to1_match_2_inputs}, {"aten.mul.Tensor", op::translate_1to1_match_2_inputs_align_types}, {"aten.mul.Scalar", op::translate_1to1_match_2_inputs_align_types}, {"aten.native_batch_norm.default", op::translate_batch_norm_legit_fx}, {"aten._native_batch_norm_legit.default", op::translate_batch_norm_legit_fx}, + {"aten._native_batch_norm_legit.no_stats", op::translate_batch_norm_legit_no_stats_fx}, {"aten._native_batch_norm_legit_no_training.default", op::translate_batch_norm_legit_no_training_fx}, + {"aten._native_batch_norm_legit_functional.default", op::translate_batch_norm_legit_fx}, + {"aten.native_dropout.default", op::skip_node}, {"aten.native_group_norm.default", op::translate_group_norm_fx}, {"aten.native_layer_norm.default", op::translate_layer_norm_fx}, + {"aten.ne.Scalar", op::translate_1to1_match_2_inputs_align_types}, {"aten.neg.default", op::translate_neg}, {"aten.new_ones.default", op::translate_new_ones}, {"aten.permute.default", op::translate_1to1_match_2_inputs}, {"aten.pow.Tensor_Scalar", op::translate_pow}, {"aten.relu.default", op::translate_1to1_match_1_inputs}, {"aten.relu_.default", op::inplace_op>}, + {"aten.repeat.default", op::translate_1to1_match_2_inputs}, {"aten.rsub.Scalar", op::translate_rsub}, + {"aten.roll.default", op::translate_roll}, {"aten._scaled_dot_product_flash_attention.default", op::translate_scaled_dot_product_attention_fx}, + {"aten._scaled_dot_product_flash_attention_for_cpu.default", op::translate_scaled_dot_product_attention_fx}, + {"aten.scalar_tensor.default", op::translate_scalar_tensor_fx}, {"aten.select.int", op::translate_select}, {"aten.sigmoid.default", op::translate_1to1_match_1_inputs}, {"aten.silu.default", op::translate_1to1_match_1_inputs}, {"aten.silu_.default", op::inplace_op>}, {"aten.sin.default", op::translate_1to1_match_1_inputs}, {"aten.slice.Tensor", op::translate_slice_fx}, + {"aten.slice_scatter.default", op::translate_slice_scatter_fx}, {"aten.split.Tensor", op::translate_chunk_fx}, - {"aten.sub.default", op::translate_sub}, - {"aten.sub.Tensor", op::translate_sub}, + {"aten.split_with_sizes.default", op::translate_split_with_sizes_fx}, + {"aten.squeeze.dim", op::translate_squeeze}, + {"aten.squeeze.dims", op::translate_squeeze}, + {"aten.sub.default", op::translate_sub_fx}, + {"aten.sub.Tensor", op::translate_sub_fx}, + {"aten.sum.dim_IntList", op::translate_sum}, {"aten.t.default", op::translate_t}, {"aten.tanh.default", op::translate_1to1_match_1_inputs}, + {"aten.unfold.default", op::translate_unfold}, {"aten.transpose.int", op::translate_transpose}, {"aten.unsqueeze.default", op::translate_1to1_match_2_inputs}, {"aten.upsample_nearest2d.default", op::translate_upsample_nearest2d}, diff --git a/src/frontends/pytorch/src/translate_session.cpp b/src/frontends/pytorch/src/translate_session.cpp index 1beed272f43c48..1791326f41a57b 100644 --- a/src/frontends/pytorch/src/translate_session.cpp +++ b/src/frontends/pytorch/src/translate_session.cpp @@ -74,10 +74,6 @@ std::shared_ptr TranslateSession::convert_pytorch_model( std::shared_ptr pytorch_model, const TensorMap& external_tensor_map, const std::shared_ptr& input_model) { - // FIXME: don't use global variable to count inlined inputs, no we should use global counter because ID should be - // unique for all new inlined inputs - static size_t inlined_nodes_counter = 100000000; // Suppose there are not graph with more than 10M nodes - std::shared_ptr resulting_model; // define here to make a conversion in a nested scope { auto parameters = std::make_shared(); @@ -128,18 +124,6 @@ std::shared_ptr TranslateSession::convert_pytorch_model( // But this value can be found in the outer scope, for this purpose we create new input for the model to // link with external scope on a higher level. - auto inlined_inputs = node->inlined_inputs(inlined_nodes_counter); - for (size_t i = 0; i < inlined_inputs.size(); ++i) { - size_t fw_tensor_id = inlined_nodes_counter; - ++inlined_nodes_counter; // TODO: Make sure that Decoder side use the same increment for producing ids - if (tensor_map->find(fw_tensor_id) != tensor_map->end()) { - throw std::runtime_error("Duplicated producer for PT value with unique ID: " + - std::to_string(fw_tensor_id) + " produced by inlined_inputs"); - } - - (*tensor_map)[fw_tensor_id] = inlined_inputs[i]; - } - auto raw_inputs = node->inputs(); for (size_t i = 0; i < raw_inputs.size(); ++i) { auto input = raw_inputs.at(i); @@ -286,11 +270,13 @@ OutputVector TranslateSession::convert_node(const NodeContext& context) { if (it != m_translator_map.end()) { return it->second(context); } + OPENVINO_DEBUG << "No translator found for: " << context.get_op_type() << "\n"; } catch (std::exception& e) { exception = e.what(); } catch (...) { exception = "Unknown exception type."; } + OPENVINO_DEBUG << exception << "\n"; try { // Create PtFrameworkNode for everything that wasn't able to be converted normally return make_framework_node(context, exception); @@ -299,6 +285,7 @@ OutputVector TranslateSession::convert_node(const NodeContext& context) { } catch (...) { exception += " Unknown exception happened while creating FrameworkNode with subgraphs"; } + OPENVINO_DEBUG << exception << "\n"; return make_framework_node_ignore_bodies(context, exception); } diff --git a/src/frontends/pytorch/src/utils.cpp b/src/frontends/pytorch/src/utils.cpp index 20f56b9d421187..86c6d11e1d65e7 100644 --- a/src/frontends/pytorch/src/utils.cpp +++ b/src/frontends/pytorch/src/utils.cpp @@ -346,7 +346,7 @@ std::shared_ptr cast_fw_node(std::shared_ptr return fw_node; } -std::shared_ptr make_list_construct(const ov::OutputVector& inputs) { +std::shared_ptr make_list_construct(const ov::OutputVector& inputs) { auto list_construct = std::make_shared<::ov::op::util::FrameworkNode>(inputs, inputs.size()); ov::op::util::FrameworkNodeAttrs attrs; attrs.set_type_name("PTFrameworkNode"); diff --git a/src/frontends/pytorch/src/utils.hpp b/src/frontends/pytorch/src/utils.hpp index 93dc956124ae76..3cb5798af9f65c 100644 --- a/src/frontends/pytorch/src/utils.hpp +++ b/src/frontends/pytorch/src/utils.hpp @@ -64,7 +64,7 @@ OutputVector make_framework_node(const NodeContext& context, const std::string& std::shared_ptr cast_fw_node(std::shared_ptr node, const std::string& type); -std::shared_ptr make_list_construct(const ov::OutputVector& inputs); +std::shared_ptr make_list_construct(const ov::OutputVector& inputs); bool is_none_node(const Output& node); @@ -248,8 +248,17 @@ class DummyDecoder : public TorchDecoder { virtual bool may_produce_alias(size_t in_index, size_t out_index) const override { FRONT_END_NOT_IMPLEMENTED(may_produce_alias); } - virtual OutputVector inlined_inputs(size_t start_index) const override { - FRONT_END_NOT_IMPLEMENTED(inlined_inputs); + bool is_input_inlined(size_t index) const override { + FRONT_END_NOT_IMPLEMENTED(is_input_inlined); + } + virtual OutputVector inlined_input(size_t index) const override { + FRONT_END_NOT_IMPLEMENTED(inlined_input); + } + virtual ov::Any get_attribute(const std::string& name) const override { + FRONT_END_NOT_IMPLEMENTED(get_attribute); + } + virtual size_t get_named_input(const std::string& name) const override { + FRONT_END_NOT_IMPLEMENTED(get_named_input); } private: diff --git a/tests/layer_tests/pytest.ini b/tests/layer_tests/pytest.ini index db450888077375..042dbb6d50a1d7 100644 --- a/tests/layer_tests/pytest.ini +++ b/tests/layer_tests/pytest.ini @@ -5,4 +5,5 @@ markers = precommit_tf_fe precommit_ts_backend precommit_fx_backend + precommit_torch_export timeout diff --git a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py index f89af6688ae3b9..3d9064479787fa 100644 --- a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py +++ b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py @@ -9,10 +9,12 @@ import numpy as np from common.constants import test_device, test_precision from openvino.frontend.pytorch.ts_decoder import TorchScriptPythonDecoder +from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder from openvino.frontend import FrontEndManager from openvino.runtime import Core, Type, PartialShape import torch +from packaging import version import openvino.frontend.pytorch.torchdynamo.backend @@ -74,27 +76,59 @@ def use_torch_compile_backend(): return True return False + def use_torch_export(): + torch_compile_env = os.getenv("PYTORCH_TRACING_MODE") + if torch_compile_env is not None: + return torch_compile_env == "EXPORT" + return False + ov_inputs = flattenize_inputs(inputs) if use_torch_compile_backend(): self.torch_compile_backend_test(model, torch_inputs, custom_eps) else: - trace_model = kwargs.get('trace_model', False) - freeze_model = kwargs.get('freeze_model', True) - with torch.no_grad(): - if kwargs.get('use_convert_model', False): - smodel, converted_model = self.convert_via_mo( - model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) - else: - smodel, converted_model = self.convert_directly_via_frontend( - model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) - - if kind is not None and not isinstance(kind, (tuple, list)): - kind = [kind] - if kind is not None: - for op in kind: - assert self._check_kind_exist( - smodel.inlined_graph, op), f"Operation {op} type doesn't exist in provided graph" + if use_torch_export(): + from openvino import convert_model + from torch.export import export + from torch.fx.experimental.proxy_tensor import make_fx + + em = export(model, tuple(torch_inputs)) + if version.parse(torch.__version__) >= version.parse("2.2"): + em = em.run_decompositions() + print(em.graph_module.code) + + try: + gm = make_fx(em)(*torch_inputs) + except: + gm = make_fx(em, tracing_mode='symbolic')(*torch_inputs) + + input_shapes = [] + input_types = [] + for input_data in torch_inputs: + input_types.append(input_data.type()) + input_shapes.append(input_data.size()) + + decoder = TorchFXPythonDecoder(gm, gm, input_shapes=input_shapes, input_types=input_types) + converted_model = convert_model(decoder, example_input=torch_inputs) + self._resolve_input_shape_dtype( + converted_model, ov_inputs, dynamic_shapes) + smodel = model + else: + trace_model = kwargs.get('trace_model', False) + freeze_model = kwargs.get('freeze_model', True) + with torch.no_grad(): + if kwargs.get('use_convert_model', False): + smodel, converted_model = self.convert_via_mo( + model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) + else: + smodel, converted_model = self.convert_directly_via_frontend( + model, torch_inputs, trace_model, dynamic_shapes, ov_inputs, freeze_model) + if kind is not None and not isinstance(kind, (tuple, list)): + kind = [kind] + if kind is not None: + for op in kind: + assert self._check_kind_exist( + smodel.inlined_graph, op), f"Operation {op} type doesn't exist in provided graph" # OV infer: core = Core() compiled = core.compile_model(converted_model, ie_device) diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py index bedd9beb0d4bcf..3b48ef2bfe347c 100644 --- a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py +++ b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py @@ -31,6 +31,7 @@ def forward(self, input_tensor): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend def test_adaptive_avg_pool3d(self, ie_device, precision, ir_version, input_tensor, output_size): @@ -61,6 +62,7 @@ def forward(self, input_tensor): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend def test_adaptive_avg_pool2d(self, ie_device, precision, ir_version, input_shape, output_size): @@ -91,6 +93,7 @@ def forward(self, input_tensor): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend def test_adaptive_avg_pool1d(self, ie_device, precision, ir_version, input_shape, output_size): diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py index b80a82a4a9dee7..5ab0da52ff83e0 100644 --- a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py +++ b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py @@ -47,6 +47,7 @@ def forward(self, input_tensor): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', @@ -92,6 +93,7 @@ def forward(self, input_tensor): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', @@ -139,6 +141,7 @@ def forward(self, input_tensor): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', diff --git a/tests/layer_tests/pytorch_tests/test_addcmul.py b/tests/layer_tests/pytorch_tests/test_addcmul.py index 18acaf7d201ff4..5ac9aa51b5f4a7 100644 --- a/tests/layer_tests/pytorch_tests/test_addcmul.py +++ b/tests/layer_tests/pytorch_tests/test_addcmul.py @@ -46,6 +46,7 @@ def forward(self, x, y, z): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_addcmul(self, input_type, value, ie_device, precision, ir_version): self.input_type = input_type self._test(*self.create_model(value), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_addmm.py b/tests/layer_tests/pytorch_tests/test_addmm.py index f73894766e812f..ac5a78c4fb2eea 100644 --- a/tests/layer_tests/pytorch_tests/test_addmm.py +++ b/tests/layer_tests/pytorch_tests/test_addmm.py @@ -44,6 +44,7 @@ def forward(self, m0, m1, m2): (1, 1)]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_addmm(self, kwargs_to_prepare_input, alpha, beta, ie_device, precision, ir_version): self._test(*self.create_model(alpha, beta), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) @@ -93,6 +94,7 @@ def forward(self, m0, m1, m2): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_baddbmm(self, kwargs_to_prepare_input, alpha, beta, ie_device, precision, ir_version): self._test(*self.create_model(alpha, beta), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) diff --git a/tests/layer_tests/pytorch_tests/test_and.py b/tests/layer_tests/pytorch_tests/test_and.py index 07e9b1d660d6a3..35b3f51ae370fb 100644 --- a/tests/layer_tests/pytorch_tests/test_and.py +++ b/tests/layer_tests/pytorch_tests/test_and.py @@ -50,6 +50,7 @@ def forward(self, int_a: int, int_b: int): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_and_tensor(self, ie_device, precision, ir_version): self.input_data = ( np.array([True, False, False], dtype=np.bool_), @@ -59,18 +60,21 @@ def test_and_tensor(self, ie_device, precision, ir_version): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_and_bool(self, ie_device, precision, ir_version): self.input_data = (np.array(True, dtype=np.bool_), np.array(True, dtype=np.bool_)) self._test(*self.create_model_bool_input(), ie_device, precision, ir_version) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_and_int(self, ie_device, precision, ir_version): self.input_data = (np.array(3, dtype=np.int32), np.array(4, dtype=np.int32)) self._test(*self.create_model_int_input(), ie_device, precision, ir_version) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_and_tensor(self, ie_device, precision, ir_version): self.input_data = (np.array([3, 5, 8], dtype=np.int32), np.array([7, 11, 2], dtype=np.int32)) self._test( diff --git a/tests/layer_tests/pytorch_tests/test_as_strided.py b/tests/layer_tests/pytorch_tests/test_as_strided.py index 9bfaa66d3a7f6b..fbacb1c81adf61 100644 --- a/tests/layer_tests/pytorch_tests/test_as_strided.py +++ b/tests/layer_tests/pytorch_tests/test_as_strided.py @@ -40,6 +40,7 @@ def forward(self, x): @pytest.mark.parametrize("offset", [None, 1, 3, 7]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_as_strided(self, size, stride, offset, ie_device, precision, ir_version): self._test(*self.create_model(size, stride, offset), ie_device, precision, ir_version, trace_model=True) @@ -90,6 +91,7 @@ def forward_size_const(self, x, size_shape_tensor, stride_shape_tensor): @pytest.mark.parametrize("mode", ["no_const", "stride_const", "size_const"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_as_strided_list_construct(self, size, stride, offset, mode, ie_device, precision, ir_version): inp_kwargs = {"size_shape_tensor": size, "stride_shape_tensor": stride} self._test( @@ -121,5 +123,6 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_as_strided_lf(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, freeze_model=False) diff --git a/tests/layer_tests/pytorch_tests/test_batch_norm.py b/tests/layer_tests/pytorch_tests/test_batch_norm.py index 94208c7359a583..2275f53960ae45 100644 --- a/tests/layer_tests/pytorch_tests/test_batch_norm.py +++ b/tests/layer_tests/pytorch_tests/test_batch_norm.py @@ -59,6 +59,7 @@ def forward(self, x): @pytest.mark.precommit @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend + @pytest.mark.precommit_torch_export def test_batch_norm(self, weights, bias, eps, train, running_stats, ie_device, precision, ir_version, kwargs_to_prepare_input): self._test(*self.create_model(weights, bias, eps, train, running_stats), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input, dynamic_shapes=False, use_mo_convert=False) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py index b405f0114b5a4b..2042dde0c460ee 100644 --- a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py +++ b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py @@ -31,6 +31,7 @@ def forward(self, x, y, z): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("x_shape", [[1, ], [2, 1], [2, 2, 1]]) @pytest.mark.parametrize("y_shape", [[2, ], [1, 2], [1, 2, 1]]) @pytest.mark.parametrize("z_shape", [[1, 2], [2, 2], [1, 2, 1, 1]]) diff --git a/tests/layer_tests/pytorch_tests/test_clone.py b/tests/layer_tests/pytorch_tests/test_clone.py index f56aac44e9d575..18e07d0efd01da 100644 --- a/tests/layer_tests/pytorch_tests/test_clone.py +++ b/tests/layer_tests/pytorch_tests/test_clone.py @@ -25,5 +25,6 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_clone(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_conv_transposend.py b/tests/layer_tests/pytorch_tests/test_conv_transposend.py index db0350d649eae8..7b3229188598ec 100644 --- a/tests/layer_tests/pytorch_tests/test_conv_transposend.py +++ b/tests/layer_tests/pytorch_tests/test_conv_transposend.py @@ -62,6 +62,7 @@ def forward(self, x): @pytest.mark.parametrize("bias", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_conv_transpose2d(self, params, bias, ie_device, precision, ir_version): self._test(*self.create_model(**params, bias=bias), ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1) @@ -121,6 +122,7 @@ def forward(self, x): @pytest.mark.parametrize("bias", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_conv_transpose1d(self, params, bias, ie_device, precision, ir_version): self._test(*self.create_model(**params, bias=bias), ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1) @@ -191,6 +193,7 @@ def forward(self, x): @pytest.mark.parametrize("bias", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_conv_transpose3d(self, params, bias, ie_device, precision, ir_version): self._test(*self.create_model(**params, bias=bias), ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1) diff --git a/tests/layer_tests/pytorch_tests/test_convolution.py b/tests/layer_tests/pytorch_tests/test_convolution.py index 5ac994f9d79760..19e4c9b7cee338 100644 --- a/tests/layer_tests/pytorch_tests/test_convolution.py +++ b/tests/layer_tests/pytorch_tests/test_convolution.py @@ -209,6 +209,7 @@ def forward(self, x): @pytest.mark.precommit @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend + @pytest.mark.precommit_torch_export def test_convolution1d(self, params, bias, underscore, ie_device, precision, ir_version): self._test(*self.create_model(**params, bias=bias, underscore=underscore), ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1, @@ -221,6 +222,7 @@ def test_convolution1d(self, params, bias, underscore, ie_device, precision, ir_ @pytest.mark.precommit @pytest.mark.precommit_ts_backend @pytest.mark.precommit_fx_backend + @pytest.mark.precommit_torch_export def test_convolution2d(self, params, bias, underscore, ie_device, precision, ir_version): self._test(*self.create_model(**params, bias=bias, underscore=underscore), ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1) diff --git a/tests/layer_tests/pytorch_tests/test_device.py b/tests/layer_tests/pytorch_tests/test_device.py index 2efdf5c85c50fa..72982f7a6774c3 100644 --- a/tests/layer_tests/pytorch_tests/test_device.py +++ b/tests/layer_tests/pytorch_tests/test_device.py @@ -50,6 +50,7 @@ def forward(self, x): @pytest.mark.parametrize("device_string", ["cpu", "cuda"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_device(self, device_string, ie_device, precision, ir_version): self._test( *self.create_model_device(device_string), @@ -63,6 +64,7 @@ def test_device(self, device_string, ie_device, precision, ir_version): @pytest.mark.parametrize("device_string", ["cpu", "cuda"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_device_type(self, device_string, ie_device, precision, ir_version): self._test( *self.create_model_type(device_string), diff --git a/tests/layer_tests/pytorch_tests/test_div.py b/tests/layer_tests/pytorch_tests/test_div.py index 22243e1a591698..a2809b1fa68899 100644 --- a/tests/layer_tests/pytorch_tests/test_div.py +++ b/tests/layer_tests/pytorch_tests/test_div.py @@ -43,6 +43,7 @@ def forward(self, input_tensor, other_tensor): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_div_pt_spec(self, input_array, other_array, rounding_mode, ie_device, precision, ir_version): self.input_array = input_array self.input_type = np.float32 @@ -118,6 +119,7 @@ def forward3(self, lhs, rhs): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.xfail(condition=platform.system() in ('Darwin', 'Linux') and platform.machine() in ('arm', 'armv7l', 'aarch64', 'arm64', 'ARM64'), diff --git a/tests/layer_tests/pytorch_tests/test_embedding.py b/tests/layer_tests/pytorch_tests/test_embedding.py index a448e21d3ff04e..901f72d4d761fb 100644 --- a/tests/layer_tests/pytorch_tests/test_embedding.py +++ b/tests/layer_tests/pytorch_tests/test_embedding.py @@ -26,6 +26,7 @@ def forward(self, indicies, weight): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("indicies_size", [1, 2, 3, 4]) @pytest.mark.parametrize("indicies_dtype", ["int", "int32"]) def test_embedding(self, ie_device, precision, ir_version, indicies_size, indicies_dtype): diff --git a/tests/layer_tests/pytorch_tests/test_eq.py b/tests/layer_tests/pytorch_tests/test_eq.py index 6fa5f4ecfba5eb..1a73084359bdc1 100644 --- a/tests/layer_tests/pytorch_tests/test_eq.py +++ b/tests/layer_tests/pytorch_tests/test_eq.py @@ -40,6 +40,7 @@ def forward(self, input_tensor, other_tensor): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_eq_pt_spec(self, input_array, other_array, types, ie_device, precision, ir_version): self.input_array = input_array self.input_type = types[0] diff --git a/tests/layer_tests/pytorch_tests/test_expand.py b/tests/layer_tests/pytorch_tests/test_expand.py index 5848aca8fa8028..63453fce9d1ec6 100644 --- a/tests/layer_tests/pytorch_tests/test_expand.py +++ b/tests/layer_tests/pytorch_tests/test_expand.py @@ -35,6 +35,7 @@ def forward_broadcast(self, x): @pytest.mark.parametrize("op_type", ["expand", "broadcast_to"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_expand(self, dims, op_type, ie_device, precision, ir_version): self._test(*self.create_model(dims, op_type), ie_device, precision, ir_version) @@ -68,6 +69,7 @@ def forward_broadcast(self, x, y): @pytest.mark.parametrize("op_type", ["expand", "broadcast_to"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_expand(self, dims, op_type, ie_device, precision, ir_version): self._test(*self.create_model(op_type), ie_device, precision, ir_version, kwargs_to_prepare_input={"broadcast_shape": dims}) @@ -104,6 +106,7 @@ def forward(self, x, y): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_expand(self, ie_device, precision, ir_version, kwargs_to_prepare_input): self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) diff --git a/tests/layer_tests/pytorch_tests/test_flatten.py b/tests/layer_tests/pytorch_tests/test_flatten.py index 285c86d812cecf..c696962332545e 100644 --- a/tests/layer_tests/pytorch_tests/test_flatten.py +++ b/tests/layer_tests/pytorch_tests/test_flatten.py @@ -37,6 +37,7 @@ def forward(self, x): [2, 3]]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_flatten(self, dim0, dim1, ie_device, precision, ir_version): self._test(*self.create_model(dim0, dim1), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_floor_divide.py b/tests/layer_tests/pytorch_tests/test_floor_divide.py index 40d1eb5afa7fed..bd8827b258819d 100644 --- a/tests/layer_tests/pytorch_tests/test_floor_divide.py +++ b/tests/layer_tests/pytorch_tests/test_floor_divide.py @@ -51,6 +51,7 @@ def forward(self, input_tensor, other_tensor): ])) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64', reason='Ticket - 122715') def test_floor_divide(self, input_tensor, other_tensor, ie_device, precision, ir_version): @@ -79,6 +80,7 @@ def test_floor_divide(self, input_tensor, other_tensor, ie_device, precision, ir ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_floor_divide_int(self, input_data, other_data, ie_device, precision, ir_version): input_tensor = input_data["tensor"] if type(input_tensor) is list: diff --git a/tests/layer_tests/pytorch_tests/test_gelu.py b/tests/layer_tests/pytorch_tests/test_gelu.py index 87177c4cde67b7..6a6d5e61a57600 100644 --- a/tests/layer_tests/pytorch_tests/test_gelu.py +++ b/tests/layer_tests/pytorch_tests/test_gelu.py @@ -29,6 +29,7 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("approximate", ["none", "tanh"]) def test_glu(self, approximate, ie_device, precision, ir_version): self._test(*self.create_model(approximate), ie_device, precision, ir_version) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_glu.py b/tests/layer_tests/pytorch_tests/test_glu.py index 718604abc7b31c..aa77fb7d77664c 100644 --- a/tests/layer_tests/pytorch_tests/test_glu.py +++ b/tests/layer_tests/pytorch_tests/test_glu.py @@ -29,6 +29,7 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("dim", [0, 1, 2, 3, -1, -2]) def test_glu(self, dim, ie_device, precision, ir_version): self._test(*self.create_model(dim), ie_device, precision, ir_version) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_group_norm.py b/tests/layer_tests/pytorch_tests/test_group_norm.py index effb8ea90485d3..347d1e013a3c3d 100644 --- a/tests/layer_tests/pytorch_tests/test_group_norm.py +++ b/tests/layer_tests/pytorch_tests/test_group_norm.py @@ -53,6 +53,7 @@ def forward(self, x): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_group_norm(self, params, ie_device, precision, ir_version, kwargs_to_prepare_input): self._test(*self.create_model(**params), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) diff --git a/tests/layer_tests/pytorch_tests/test_index.py b/tests/layer_tests/pytorch_tests/test_index.py index 4b4e53690f927e..d7f3a18469a170 100644 --- a/tests/layer_tests/pytorch_tests/test_index.py +++ b/tests/layer_tests/pytorch_tests/test_index.py @@ -3,6 +3,7 @@ import pytest import numpy as np +import torch from pytorch_layer_test_class import PytorchLayerTest @@ -115,6 +116,7 @@ def forward(self, x, y): def test_index_range(self, input_shape, idx, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={ "input_shape": input_shape, "idx": idx}, trace_model=True, dynamic_shapes=False) + @pytest.mark.nightly @pytest.mark.precommit @pytest.mark.parametrize(("input_shape", "idx"), ( @@ -126,6 +128,7 @@ def test_index_range_free_dims(self, input_shape, idx, ie_device, precision, ir_ self._test(*self.create_model2(), ie_device, precision, ir_version, kwargs_to_prepare_input={ "input_shape": input_shape, "idx": idx}, trace_model=True, dynamic_shapes=False) + class TestIndexMask(PytorchLayerTest): def _prepare_input(self, input_shape): import numpy as np @@ -151,3 +154,27 @@ def forward(self, x): def test_index_mask(self, input_shape, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={ "input_shape": input_shape}, trace_model=True, use_convert_model=True) + + +class TestIndexNone(PytorchLayerTest): + def _prepare_input(self, input_shape): + import numpy as np + return (np.random.randn(*input_shape).astype(np.float32),) + + class aten_index_list(torch.nn.Module): + def __init__(self, idxs): + super(TestIndexNone.aten_index_list, self).__init__() + self.idxs = idxs + + def forward(self, x): + return x[self.idxs] + + @pytest.mark.nightly + @pytest.mark.parametrize(("input_shape,idxs"), [ + ((2, 3, 4, 5), (torch.unsqueeze(torch.randint(0, 2, [14], dtype=torch.int32), 1),)), + ((2, 3, 4, 5), (torch.unsqueeze(torch.randint(0, 2, [14], dtype=torch.int32), 1), torch.randint(0, 3, [14], dtype=torch.int32))), + ((2, 3, 4, 5), (None, None, torch.unsqueeze(torch.randint(0, 2, [14], dtype=torch.int32), 1), torch.randint(0, 3, [14], dtype=torch.int32))), + ]) + def test_index(self, input_shape, idxs, ie_device, precision, ir_version): + self._test(self.aten_index_list(idxs), None, "aten::index", ie_device, precision, + ir_version,kwargs_to_prepare_input={"input_shape": input_shape}, use_convert_model=True, trace_model=True) diff --git a/tests/layer_tests/pytorch_tests/test_mm.py b/tests/layer_tests/pytorch_tests/test_mm.py index b0f920e47f518e..83de1188d11232 100644 --- a/tests/layer_tests/pytorch_tests/test_mm.py +++ b/tests/layer_tests/pytorch_tests/test_mm.py @@ -41,6 +41,7 @@ def forward(self, m1, m2): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_mm(self, kwargs_to_prepare_input, ie_device, precision, ir_version): self._test(*self.create_model('aten::mm'), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) @@ -55,6 +56,7 @@ def test_mm(self, kwargs_to_prepare_input, ie_device, precision, ir_version): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_bmm(self, kwargs_to_prepare_input, ie_device, precision, ir_version): self._test(*self.create_model('aten::bmm'), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) @@ -81,6 +83,7 @@ def test_bmm(self, kwargs_to_prepare_input, ie_device, precision, ir_version): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_matmul(self, kwargs_to_prepare_input, ie_device, precision, ir_version): self._test(*self.create_model('aten::matmul'), ie_device, precision, ir_version, kwargs_to_prepare_input=kwargs_to_prepare_input) diff --git a/tests/layer_tests/pytorch_tests/test_mul.py b/tests/layer_tests/pytorch_tests/test_mul.py index c7aea00ee8ad89..1eca86c6e17498 100644 --- a/tests/layer_tests/pytorch_tests/test_mul.py +++ b/tests/layer_tests/pytorch_tests/test_mul.py @@ -32,6 +32,7 @@ def forward(self, input_tensor, other_tensor): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_mul_pt_spec(self, input_array, other_array, ie_device, precision, ir_version): self.input_array = input_array self.input_type = np.float32 @@ -100,6 +101,7 @@ def forward3(self, lhs, rhs): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_mul_types(self, ie_device, precision, ir_version, lhs_type, lhs_shape, rhs_type, rhs_shape): self.lhs_type = lhs_type self.lhs_shape = lhs_shape diff --git a/tests/layer_tests/pytorch_tests/test_permute.py b/tests/layer_tests/pytorch_tests/test_permute.py index b0efdb72a5d86d..f5a234fc419ccb 100644 --- a/tests/layer_tests/pytorch_tests/test_permute.py +++ b/tests/layer_tests/pytorch_tests/test_permute.py @@ -29,6 +29,7 @@ def forward(self, x): @pytest.mark.parametrize("order", [[0, 2, 3, 1], [0, 3, 1, 2]]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_permute(self, order, ie_device, precision, ir_version): self._test(*self.create_model(order), ie_device, precision, ir_version) @@ -53,5 +54,6 @@ def forward(self, x, y): @pytest.mark.parametrize("order", [[1, 3, 4, 2], [1, 4, 2, 3]]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_permute(self, order, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={"permute_shape": order}) diff --git a/tests/layer_tests/pytorch_tests/test_reshape.py b/tests/layer_tests/pytorch_tests/test_reshape.py index 5b89cab94d03da..f093c8e3bcbed1 100644 --- a/tests/layer_tests/pytorch_tests/test_reshape.py +++ b/tests/layer_tests/pytorch_tests/test_reshape.py @@ -38,5 +38,6 @@ def forward(self, x): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_reshape(self, shape, ie_device, precision, ir_version): self._test(*self.create_model(shape), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_reshape_as.py b/tests/layer_tests/pytorch_tests/test_reshape_as.py index d354a530884a92..1d5c00cc05f283 100644 --- a/tests/layer_tests/pytorch_tests/test_reshape_as.py +++ b/tests/layer_tests/pytorch_tests/test_reshape_as.py @@ -32,6 +32,7 @@ def forward_view(self, input_tensor, shape_tensor): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("op", ["reshape_as", "view_as"]) @pytest.mark.parametrize('input_tensor_shapes',( ((3, 6), (2, 9)), ((2, 2, 3), (6, 2)), ((6, 2), (2, 2, 3)))) def test_reshape_as(self, op, input_tensor_shapes, ie_device, precision, ir_version): diff --git a/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py b/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py index 87097b88af30aa..b26173e94a2741 100644 --- a/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py +++ b/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py @@ -40,6 +40,7 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("op_type", ["resolve_neg", "resolve_conj"]) @pytest.mark.parametrize("dtype", ["float32", "int32"]) def test_reslove(self, op_type, dtype, ie_device, precision, ir_version): @@ -47,6 +48,7 @@ def test_reslove(self, op_type, dtype, ie_device, precision, ir_version): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export @pytest.mark.parametrize("op_type", ["resolve_neg", "resolve_conj"]) @pytest.mark.xfail(reason="complex dtype is not supported yet") def test_resolve_complex(self, op_type, ie_device, precision, ir_version): diff --git a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py index d442b9e86a424e..94e7b43be85eb9 100644 --- a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py +++ b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py @@ -12,13 +12,13 @@ class TestScaledDotProductAttention(PytorchLayerTest): def _prepare_input(self, dtype): return (np.random.randn(1, 2, 8, 4).astype(dtype), np.random.randn(1, 2, 8, 4).astype(dtype), np.random.randn(1, 2, 8, 4).astype(dtype)) - def create_model(self, mask, is_causal, scale, dtype): + def create_model(self, mask, is_causal, dtype): import torch.nn.functional as F import torch class aten_scaled_dot_product_atten(torch.nn.Module): - def __init__(self, mask=False, is_causal=False, scale=False, dtype=np.float32) -> None: + def __init__(self, mask=False, is_causal=False, dtype=np.float32) -> None: super().__init__() self.mask = None if not mask else torch.from_numpy( @@ -28,22 +28,20 @@ def __init__(self, mask=False, is_causal=False, scale=False, dtype=np.float32) - self.mask.to(torch.bool) self.is_causal = False - self.scale = None if not scale else torch.tensor( - 5, dtype=torch.float) - def forward(self, query, key, value): - return F.scaled_dot_product_attention(query, key, value, attn_mask=self.mask, is_causal=self.is_causal, scale=self.scale) - - ref_net = None + # torch export struggles with dynamic scale + a = F.scaled_dot_product_attention(query, key, value, attn_mask=self.mask, is_causal=self.is_causal) + b = F.scaled_dot_product_attention(query, key, value, attn_mask=self.mask, is_causal=self.is_causal, scale=torch.tensor(5, dtype=torch.float)) + return a, b - return aten_scaled_dot_product_atten(mask, is_causal, scale, dtype), ref_net, 'aten::scaled_dot_product_attention' + return aten_scaled_dot_product_atten(mask, is_causal, dtype), None, 'aten::scaled_dot_product_attention' @pytest.mark.nightly @pytest.mark.precommit @pytest.mark.precommit_fx_backend + @pytest.mark.precommit_torch_export @pytest.mark.parametrize(['mask', 'is_causal'], [(False, False), (False, True), (True, True), (True, False)]) - @pytest.mark.parametrize('scale', [False, True]) @pytest.mark.parametrize("dtype", (np.float32, np.float64)) - def test_scaled_dot_product_atten(self, ie_device, precision, ir_version, mask, is_causal, scale, dtype): - self._test(*self.create_model(mask, is_causal, scale, dtype), + def test_scaled_dot_product_atten(self, ie_device, precision, ir_version, mask, is_causal, dtype): + self._test(*self.create_model(mask, is_causal, dtype), ie_device, precision, ir_version, kwargs_to_prepare_input={"dtype": dtype}) diff --git a/tests/layer_tests/pytorch_tests/test_select.py b/tests/layer_tests/pytorch_tests/test_select.py index fd1c325d4a64a6..e11f4a6f102a43 100644 --- a/tests/layer_tests/pytorch_tests/test_select.py +++ b/tests/layer_tests/pytorch_tests/test_select.py @@ -32,6 +32,7 @@ def forward(self, input_tensor): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_select(self, ie_device, precision, ir_version, input_dim, input_index): self._test(*self.create_model(input_dim, input_index), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_silu.py b/tests/layer_tests/pytorch_tests/test_silu.py index 4477184dba7d2a..3c206b073de1ed 100644 --- a/tests/layer_tests/pytorch_tests/test_silu.py +++ b/tests/layer_tests/pytorch_tests/test_silu.py @@ -28,5 +28,6 @@ def forward(self, x): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_silu(self, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_softmax.py b/tests/layer_tests/pytorch_tests/test_softmax.py index eac3f9ba3c6c69..820e99fad178e9 100644 --- a/tests/layer_tests/pytorch_tests/test_softmax.py +++ b/tests/layer_tests/pytorch_tests/test_softmax.py @@ -49,6 +49,7 @@ def forward_prim_dtype(self, x, y): @pytest.mark.parametrize("dim", [-1, 3]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_softmax(self, dim, ie_device, precision, ir_version): self._test(*self.create_model(dim), ie_device, precision, ir_version) @@ -57,6 +58,7 @@ def test_softmax(self, dim, ie_device, precision, ir_version): @pytest.mark.parametrize("use_prim_dtype", [True, False]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_softmax(self, dim, dtype, use_prim_dtype, ie_device, precision, ir_version): input_kwargs = {} if use_prim_dtype: diff --git a/tests/layer_tests/pytorch_tests/test_sub.py b/tests/layer_tests/pytorch_tests/test_sub.py index 5ba3f1a5506053..e24a878239e332 100644 --- a/tests/layer_tests/pytorch_tests/test_sub.py +++ b/tests/layer_tests/pytorch_tests/test_sub.py @@ -110,6 +110,7 @@ def forward3(self, lhs, rhs): ]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_sub_types(self, ie_device, precision, ir_version, lhs_type, lhs_shape, rhs_type, rhs_shape): self.lhs_type = lhs_type self.lhs_shape = lhs_shape diff --git a/tests/layer_tests/pytorch_tests/test_tensor_split.py b/tests/layer_tests/pytorch_tests/test_tensor_split.py index 168cbd6f60f1b1..eeeea7542fb868 100644 --- a/tests/layer_tests/pytorch_tests/test_tensor_split.py +++ b/tests/layer_tests/pytorch_tests/test_tensor_split.py @@ -61,6 +61,7 @@ def forward_4(self, input_tensor): @pytest.mark.parametrize("axis", [0, 1, -1]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_tensor_split(self, input_shape, splits, axis, ie_device, precision, ir_version): self.input_shape = input_shape self._test(*self.create_model(splits, axis), ie_device, precision, ir_version) diff --git a/tests/layer_tests/pytorch_tests/test_type_as.py b/tests/layer_tests/pytorch_tests/test_type_as.py index 35fe0732602097..3f520305794289 100644 --- a/tests/layer_tests/pytorch_tests/test_type_as.py +++ b/tests/layer_tests/pytorch_tests/test_type_as.py @@ -28,6 +28,7 @@ def forward(self, x, y): @pytest.mark.parametrize("cast_dtype", [np.float64, np.float32, np.int64, np.int32, np.int16, np.int8, np.uint8]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_type_as(self, input_dtype, cast_dtype, ie_device, precision, ir_version): self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={"input_dtype": input_dtype, "cast_dtype": cast_dtype}) diff --git a/tests/layer_tests/pytorch_tests/test_unflatten.py b/tests/layer_tests/pytorch_tests/test_unflatten.py index 3f8e9de3a2b9f1..0c9537912bf6eb 100644 --- a/tests/layer_tests/pytorch_tests/test_unflatten.py +++ b/tests/layer_tests/pytorch_tests/test_unflatten.py @@ -31,6 +31,7 @@ def forward(self, x): @pytest.mark.parametrize("dtype", ["float32", "int32"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_unflatten(self, dim, shape, dtype, ie_device, precision, ir_version): self._test(*self.create_model(dim, shape), ie_device, precision, ir_version, kwargs_to_prepare_input={"dtype": dtype}) @@ -65,5 +66,6 @@ def forward(self, x): @pytest.mark.parametrize("dtype", ["float32", "int32"]) @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_unflatten(self, dim, dtype, ie_device, precision, ir_version): self._test(*self.create_model(dim), ie_device, precision, ir_version, kwargs_to_prepare_input={"dtype": dtype}) \ No newline at end of file diff --git a/tests/layer_tests/pytorch_tests/test_unfold.py b/tests/layer_tests/pytorch_tests/test_unfold.py index b4138fa772bb02..37a0e467544e55 100644 --- a/tests/layer_tests/pytorch_tests/test_unfold.py +++ b/tests/layer_tests/pytorch_tests/test_unfold.py @@ -38,6 +38,7 @@ def forward(self, input_tensor): @pytest.mark.nightly @pytest.mark.precommit + @pytest.mark.precommit_torch_export def test_unfold(self, ie_device, precision, ir_version, dimension, size, step, input_shape): self.input_tensor = np.random.randn(*input_shape).astype(np.float32) self._test(*self.create_model(dimension, size, step), diff --git a/tests/model_hub_tests/torch_tests/requirements.txt b/tests/model_hub_tests/torch_tests/requirements.txt index af6f4cf22128af..b734007dafa15c 100644 --- a/tests/model_hub_tests/torch_tests/requirements.txt +++ b/tests/model_hub_tests/torch_tests/requirements.txt @@ -7,6 +7,7 @@ datasets facexlib numpy optimum +packaging pandas protobuf pyctcdecode diff --git a/tests/model_hub_tests/torch_tests/test_aliked.py b/tests/model_hub_tests/torch_tests/test_aliked.py index ad29187de068ce..a2e93c7ce3c0b2 100644 --- a/tests/model_hub_tests/torch_tests/test_aliked.py +++ b/tests/model_hub_tests/torch_tests/test_aliked.py @@ -84,7 +84,7 @@ def setup_class(self): subprocess.check_call(["sh", "build.sh"], cwd=os.path.join( self.repo_dir.name, "custom_ops")) - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): sys.path.append(self.repo_dir.name) from nets.aliked import ALIKED diff --git a/tests/model_hub_tests/torch_tests/test_detectron2.py b/tests/model_hub_tests/torch_tests/test_detectron2.py index 5c2ea9a1d9e153..0c6c9eddb0f8ea 100644 --- a/tests/model_hub_tests/torch_tests/test_detectron2.py +++ b/tests/model_hub_tests/torch_tests/test_detectron2.py @@ -23,7 +23,7 @@ def setup_class(self): subprocess.run([sys.executable, "-m", "pip", "install", "git+https://github.com/facebookresearch/detectron2.git@017abbfa5f2c2a2afa045200c2af9ccf2fc6227f"]) - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): from detectron2 import model_zoo, export from detectron2.modeling import build_model, PanopticFPN from detectron2.checkpoint import DetectionCheckpointer diff --git a/tests/model_hub_tests/torch_tests/test_edsr.py b/tests/model_hub_tests/torch_tests/test_edsr.py index 9d4a9d183e85e6..960af9fd5586cf 100644 --- a/tests/model_hub_tests/torch_tests/test_edsr.py +++ b/tests/model_hub_tests/torch_tests/test_edsr.py @@ -38,7 +38,7 @@ class TestEdsrConvertModel(TestTorchConvertModel): - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): # image link from https://github.com/eugenesiow/super-image url = 'https://paperswithcode.com/media/datasets/Set5-0000002728-07a9793f_zA3bDjj.jpg' image = Image.open(requests.get(url, stream=True).raw) diff --git a/tests/model_hub_tests/torch_tests/test_gfpgan.py b/tests/model_hub_tests/torch_tests/test_gfpgan.py index 90784926183906..ca22789023b648 100644 --- a/tests/model_hub_tests/torch_tests/test_gfpgan.py +++ b/tests/model_hub_tests/torch_tests/test_gfpgan.py @@ -28,7 +28,7 @@ def setup_class(self): subprocess.check_call( ["wget", "-nv", checkpoint_url], cwd=self.repo_dir.name) - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): sys.path.append(self.repo_dir.name) from gfpgan import GFPGANer diff --git a/tests/model_hub_tests/torch_tests/test_hf_transformers.py b/tests/model_hub_tests/torch_tests/test_hf_transformers.py index 1e8c3d76983120..b6360ae6ca0dab 100644 --- a/tests/model_hub_tests/torch_tests/test_hf_transformers.py +++ b/tests/model_hub_tests/torch_tests/test_hf_transformers.py @@ -98,7 +98,7 @@ def setup_class(self): self.image = Image.open(requests.get(url, stream=True).raw) self.cuda_available, self.gptq_postinit = None, None - def load_model(self, name, type): + def load_model_impl(self, name, type): import torch name_suffix = '' from transformers import AutoConfig diff --git a/tests/model_hub_tests/torch_tests/test_speech-transformer.py b/tests/model_hub_tests/torch_tests/test_speech-transformer.py index e08526d7a7b553..a9e7013bdd2cb4 100644 --- a/tests/model_hub_tests/torch_tests/test_speech-transformer.py +++ b/tests/model_hub_tests/torch_tests/test_speech-transformer.py @@ -24,7 +24,7 @@ def setup_class(self): checkpoint_url = "https://github.com/foamliu/Speech-Transformer/releases/download/v1.0/speech-transformer-cn.pt" subprocess.check_call(["wget", "-nv", checkpoint_url], cwd=self.repo_dir.name) - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): sys.path.append(self.repo_dir.name) from transformer.transformer import Transformer diff --git a/tests/model_hub_tests/torch_tests/test_timm.py b/tests/model_hub_tests/torch_tests/test_timm.py index 5805bfb82dd4bf..bfea3c2290205a 100644 --- a/tests/model_hub_tests/torch_tests/test_timm.py +++ b/tests/model_hub_tests/torch_tests/test_timm.py @@ -10,6 +10,9 @@ from models_hub_common.utils import cleanup_dir, get_models_list from torch_utils import TestTorchConvertModel, process_pytest_marks +from openvino import convert_model +from torch.export import export +from packaging import version def filter_timm(timm_list: list) -> list: @@ -47,7 +50,7 @@ def get_all_models() -> list: class TestTimmConvertModel(TestTorchConvertModel): - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): m = timm.create_model(model_name, pretrained=True) cfg = timm.get_pretrained_cfg(model_name) shape = [1] + list(cfg.input_size) @@ -78,11 +81,14 @@ def teardown_method(self): "sequencer2d_l.in1k"]) @pytest.mark.precommit def test_convert_model_precommit(self, name, ie_device): + self.mode = "trace" self.run(name, None, ie_device) @pytest.mark.nightly + @pytest.mark.parametrize("mode", ["trace", "export"]) @pytest.mark.parametrize("name", get_all_models()) - def test_convert_model_all_models(self, name, ie_device): + def test_convert_model_all_models(self, mode, name, ie_device): + self.mode = mode self.run(name, None, ie_device) @pytest.mark.nightly diff --git a/tests/model_hub_tests/torch_tests/test_torchbench.py b/tests/model_hub_tests/torch_tests/test_torchbench.py index 04c2c96de0ae63..c0fba6b605e0b6 100644 --- a/tests/model_hub_tests/torch_tests/test_torchbench.py +++ b/tests/model_hub_tests/torch_tests/test_torchbench.py @@ -30,7 +30,7 @@ def setup_class(self): subprocess.check_call( ["git", "checkout", "850364ac2678b2363f086b7549254b6cb7df2e4d"], cwd=self.repo_dir.name) - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): subprocess.check_call([sys.executable, "install.py"] + [model_name], cwd=self.repo_dir.name) sys.path.append(self.repo_dir.name) from torchbenchmark import load_model_by_name diff --git a/tests/model_hub_tests/torch_tests/test_torchvision_models.py b/tests/model_hub_tests/torch_tests/test_torchvision_models.py index 56ee127c3c701c..eb075baeec0fce 100644 --- a/tests/model_hub_tests/torch_tests/test_torchvision_models.py +++ b/tests/model_hub_tests/torch_tests/test_torchvision_models.py @@ -59,7 +59,7 @@ def setup_class(self): if os.environ.get('USE_SYSTEM_CACHE', 'True') == 'False': torch.hub.set_dir(str(self.cache_dir.name)) - def load_model(self, model_name, model_link): + def load_model_impl(self, model_name, model_link): m = torch.hub.load("pytorch/vision", model_name, weights='DEFAULT', skip_validation=True) m.eval() @@ -105,10 +105,19 @@ def teardown_method(self): @pytest.mark.parametrize("model_name", ["efficientnet_b7", "raft_small", "swin_v2_s"]) @pytest.mark.precommit def test_convert_model_precommit(self, model_name, ie_device): + self.mode = "trace" self.run(model_name, None, ie_device) + @pytest.mark.parametrize("model_name", ["efficientnet_b7"]) + @pytest.mark.precommit + def test_convert_model_precommit_export(self, model_name, ie_device): + self.mode = "export" + self.run(model_name, None, ie_device) + + @pytest.mark.parametrize("mode", ["trace", "export"]) @pytest.mark.parametrize("name", process_pytest_marks(os.path.join(os.path.dirname(__file__), "torchvision_models"))) @pytest.mark.nightly - def test_convert_model_all_models(self, name, ie_device): + def test_convert_model_all_models(self, mode, name, ie_device): + self.mode = mode self.run(name, None, ie_device) diff --git a/tests/model_hub_tests/torch_tests/torch_utils.py b/tests/model_hub_tests/torch_tests/torch_utils.py index 87c9aeb043f596..92bc08ee73e4cf 100644 --- a/tests/model_hub_tests/torch_tests/torch_utils.py +++ b/tests/model_hub_tests/torch_tests/torch_utils.py @@ -45,10 +45,19 @@ def extract_unsupported_ops_from_exception(e: str) -> list: class TestTorchConvertModel(TestConvertModel): + cached_model = None def setup_class(self): torch.set_grad_enabled(False) def load_model(self, model_name, model_link): + if self.cached_model is not None and self.cached_model[0] == model_name and self.cached_model[1] == model_link: + return self.cached_model[2] + else: + res = self.load_model_impl(model_name, model_link) + self.cached_model = (model_name, model_link, res) + return res + + def load_model_impl(self, model_name, model_link): raise "load_model is not implemented" def get_inputs_info(self, model_obj): @@ -61,10 +70,40 @@ def prepare_inputs(self, inputs_info): else: return flattenize_structure(inputs) + def convert_model_impl(self, model_obj): + if hasattr(self, "mode") and self.mode == "export": + from torch.fx.experimental.proxy_tensor import make_fx + from torch.export import export + from packaging import version + from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder + + graph = export(model_obj, self.example) + if version.parse(torch.__version__) >= version.parse("2.2"): + graph = graph.run_decompositions() + + try: + gm = make_fx(graph)(*self.example) + except: + gm = make_fx(graph, tracing_mode='symbolic')(*self.example) + + input_shapes = [] + input_types = [] + for input_data in self.example: + input_types.append(input_data.type()) + input_shapes.append(input_data.size()) + + decoder = TorchFXPythonDecoder(gm, gm, input_shapes=input_shapes, input_types=input_types) + ov_model = convert_model(decoder, example_input=self.example) + else: + ov_model = convert_model(model_obj, + example_input=self.example, + verbose=True + ) + return ov_model + def convert_model(self, model_obj): try: - ov_model = convert_model( - model_obj, example_input=self.example, verbose=True) + ov_model = self.convert_model_impl(model_obj) except Exception as e: report_filename = os.environ.get("OP_REPORT_FILE", None) if report_filename: diff --git a/tools/ovc/openvino/tools/ovc/convert_impl.py b/tools/ovc/openvino/tools/ovc/convert_impl.py index dbfb2c440a6ccc..8a25b73956799b 100644 --- a/tools/ovc/openvino/tools/ovc/convert_impl.py +++ b/tools/ovc/openvino/tools/ovc/convert_impl.py @@ -190,12 +190,13 @@ def check_model_object(argv): return "tf" if 'torch' in sys.modules: import torch - if isinstance(model, (torch.nn.Module, torch.jit.ScriptFunction)): + if isinstance(model, (torch.nn.Module, torch.jit.ScriptFunction, torch.export.ExportedProgram)): return "pytorch" try: from openvino.frontend.pytorch.ts_decoder import TorchScriptPythonDecoder + from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder - if isinstance(model, TorchScriptPythonDecoder): + if isinstance(model, (TorchScriptPythonDecoder, TorchFXPythonDecoder)): return "pytorch" except Exception as e: pass diff --git a/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py b/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py index 3a24e84af1ae9a..138e9a5542074a 100644 --- a/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py +++ b/tools/ovc/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py @@ -13,6 +13,8 @@ def get_pytorch_decoder(model, example_inputs, args): try: from openvino.frontend.pytorch.ts_decoder import TorchScriptPythonDecoder + from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder + import torch except Exception as e: log.error("PyTorch frontend loading failed") raise e @@ -31,8 +33,11 @@ def get_pytorch_decoder(model, example_inputs, args): raise RuntimeError( "NNCF models produced by nncf<2.6 are not supported directly. Please upgrade nncf or export to ONNX first.") inputs = prepare_torch_inputs(example_inputs) - if not isinstance(model, TorchScriptPythonDecoder): - decoder = TorchScriptPythonDecoder(model, example_input=inputs, shared_memory=args.get("share_weights", True)) + if not isinstance(model, (TorchScriptPythonDecoder, TorchFXPythonDecoder)): + if isinstance(model, torch.export.ExportedProgram): + raise RuntimeException("Models recieved from torch.export are not yet supported by convert_model.") + else: + decoder = TorchScriptPythonDecoder(model, example_input=inputs, shared_memory=args.get("share_weights", True)) else: decoder = model args['input_model'] = decoder From 6a4530c23e9776d5bf8101356e5c1a571fe7e5c3 Mon Sep 17 00:00:00 2001 From: Maciej Smyk Date: Tue, 30 Jan 2024 13:07:13 +0100 Subject: [PATCH 24/27] [DOCS] Article directives fix for master (#22535) * directive fixes * Update GPU_RemoteTensor_API.rst --- .../documentation/openvino_extensibility.rst | 36 ++-- .../GPU_Extensibility.rst | 14 +- .../add_openvino_ops.rst | 22 +-- .../step2_markup.rst | 50 +++--- .../ov_transformations.rst | 64 ++++---- .../ov_transformations/graph_rewrite_pass.rst | 10 +- .../ov_transformations/matcher_pass.rst | 32 ++-- .../ov_transformations/model_pass.rst | 12 +- .../GPU/GPU_RemoteTensor_API.rst | 154 +++++++++--------- 9 files changed, 197 insertions(+), 197 deletions(-) diff --git a/docs/articles_en/documentation/openvino_extensibility.rst b/docs/articles_en/documentation/openvino_extensibility.rst index 783c94b6f220cd..64f62c923986da 100644 --- a/docs/articles_en/documentation/openvino_extensibility.rst +++ b/docs/articles_en/documentation/openvino_extensibility.rst @@ -5,8 +5,8 @@ OpenVINO Extensibility Mechanism .. meta:: - :description: Explore OpenVINO™ Extensibility API, which allows adding - support for models with custom operations and their further implementation + :description: Explore OpenVINO™ Extensibility API, which allows adding + support for models with custom operations and their further implementation in applications. .. toctree:: @@ -16,18 +16,18 @@ OpenVINO Extensibility Mechanism openvino_docs_Extensibility_UG_add_openvino_ops openvino_docs_Extensibility_UG_Frontend_Extensions openvino_docs_Extensibility_UG_GPU - + .. toctree:: :maxdepth: 1 :hidden: - + openvino_docs_transformations OpenVINO Plugin Developer Guide The Intel® Distribution of OpenVINO™ toolkit supports neural-network models trained with various frameworks, including -TensorFlow, PyTorch, ONNX, TensorFlow Lite, and PaddlePaddle (OpenVINO support for Apache MXNet, Caffe, and Kaldi is currently -being deprecated and will be removed entirely in the future). The list of supported operations is different for each of the supported frameworks. +TensorFlow, PyTorch, ONNX, TensorFlow Lite, and PaddlePaddle (OpenVINO support for Apache MXNet, Caffe, and Kaldi is currently +being deprecated and will be removed entirely in the future). The list of supported operations is different for each of the supported frameworks. To see the operations supported by your framework, refer to :doc:`Supported Framework Operations `. Custom operations, which are not included in the list, are not recognized by OpenVINO out-of-the-box. The need for custom operation may appear in two cases: @@ -80,32 +80,32 @@ Registering Extensions A custom operation class and a new mapping frontend extension class object should be registered to be usable in OpenVINO runtime. -.. note:: +.. note:: This documentation is derived from the `Template extension `__, which demonstrates the details of extension development. It is based on minimalistic ``Identity`` operation that is a placeholder for your real custom operation. Review the complete, fully compilable code to see how it works. -Use the ``:ref:`ov::Core::add_extension ``` method to load the extensions to the ``:ref:`ov::Core ``` object. This method allows loading library with extensions or extensions from the code. +Use the ``ov::Core::add_extension`` method to load the extensions to the ``ov::Core`` object. This method allows loading library with extensions or extensions from the code. Load Extensions to Core +++++++++++++++++++++++ -Extensions can be loaded from a code with the ``:ref:`ov::Core::add_extension ``` method: +Extensions can be loaded from a code with the ``ov::Core::add_extension`` method: .. tab-set:: .. tab-item:: Python :sync: py - + .. doxygensnippet:: docs/snippets/ov_extensions.py :language: python :fragment: [add_extension] .. tab-item:: C++ :sync: cpp - + .. doxygensnippet:: docs/snippets/ov_extensions.cpp :language: cpp :fragment: [add_extension] - + The ``Identity`` is a custom operation class defined in :doc:`Custom Operation Guide `. This is sufficient to enable reading OpenVINO IR which uses the ``Identity`` extension operation emitted by Model Optimizer. In order to load original model directly to the runtime, add a mapping extension: @@ -130,7 +130,7 @@ When Python API is used, there is no way to implement a custom OpenVINO operatio Python can still be used to map and decompose operations when only operations from the standard OpenVINO operation set are used. .. _create_a_library_with_extensions: - + Create a Library with Extensions ++++++++++++++++++++++++++++++++ @@ -142,7 +142,7 @@ An extension library should be created in the following cases: To create an extension library, for example, to load the extensions into Model Optimizer, perform the following: -1. Create an entry point for extension library. OpenVINO provides the ``:ref:`OPENVINO_CREATE_EXTENSIONS() ``` macro, which allows to define an entry point to a library with OpenVINO Extensions. +1. Create an entry point for extension library. OpenVINO provides the ``OPENVINO_CREATE_EXTENSIONS()`` macro, which allows to define an entry point to a library with OpenVINO Extensions. This macro should have a vector of all OpenVINO Extensions as an argument. Based on that, the declaration of an extension class might look like the following: @@ -162,7 +162,7 @@ This CMake script finds OpenVINO, using the ``find_package`` CMake command. 3. Build the extension library, running the commands below: .. code-block:: sh - + $ cd src/core/template_extension/new $ mkdir build $ cd build @@ -173,16 +173,16 @@ This CMake script finds OpenVINO, using the ``find_package`` CMake command. 4. After the build, you may use the path to your extension library to load your extensions to OpenVINO Runtime: .. tab-set:: - + .. tab-item:: Python :sync: py - + .. doxygensnippet:: docs/snippets/ov_extensions.py :language: python :fragment: [add_extension_lib] .. tab-item:: C++ - :sync: cpp + :sync: cpp .. doxygensnippet:: docs/snippets/ov_extensions.cpp :language: cpp diff --git a/docs/articles_en/documentation/openvino_extensibility/GPU_Extensibility.rst b/docs/articles_en/documentation/openvino_extensibility/GPU_Extensibility.rst index 082823330684f1..e9ff4af6a319cf 100644 --- a/docs/articles_en/documentation/openvino_extensibility/GPU_Extensibility.rst +++ b/docs/articles_en/documentation/openvino_extensibility/GPU_Extensibility.rst @@ -5,7 +5,7 @@ How to Implement Custom GPU Operations .. meta:: - :description: Learn the details of custom kernel support for the GPU device to + :description: Learn the details of custom kernel support for the GPU device to enable operations not supported by OpenVINO. @@ -16,20 +16,20 @@ The GPU codepath abstracts many details about OpenCL. You need to provide the ke There are two options for using the custom operation configuration file: * Include a section with your kernels into the automatically-loaded ``/cldnn_global_custom_kernels/cldnn_global_custom_kernels.xml`` file. -* Call the ``:ref:`ov::Core::set_property() ``` method from your application with the ``"CONFIG_FILE"`` key and the configuration file name as a value before loading the network that uses custom operations to the plugin: +* Call the ``ov::Core::set_property()`` method from your application with the ``"CONFIG_FILE"`` key and the configuration file name as a value before loading the network that uses custom operations to the plugin: .. tab-set:: .. tab-item:: Python :sync: py - + .. doxygensnippet:: docs/snippets/gpu/custom_kernels_api.py :language: python :fragment: [part0] .. tab-item:: C++ :sync: cpp - + .. doxygensnippet:: docs/snippets/gpu/custom_kernels_api.cpp :language: cpp :fragment: [part0] @@ -43,10 +43,10 @@ feature a dedicated command-line option ``-c`` to load custom kernels. For examp $ ./classification_sample -m /bvlc_alexnet_fp16.xml -i ./validation_set/daily/227x227/apron.bmp -d GPU -c /custom_layer_example.xml -.. _config-file-format: +.. _config-file-format: Configuration File Format -######################### +######################### The configuration file is expected to follow the ``.xml`` file structure with a node of the type ``CustomLayer`` for every custom operation you provide. @@ -344,7 +344,7 @@ Example Kernel .. _debugging-tips: -.. note:: +.. note:: As described in the previous section, all items such as the ``INPUT0_TYPE`` are actually defined as OpenCL (pre-)compiler inputs by OpenVINO for efficiency reasons. See the `Debugging Tips <#debugging-tips>`__ below for information on debugging the results. Debugging Tips diff --git a/docs/articles_en/documentation/openvino_extensibility/add_openvino_ops.rst b/docs/articles_en/documentation/openvino_extensibility/add_openvino_ops.rst index 9df891732643ff..dafa52da350731 100644 --- a/docs/articles_en/documentation/openvino_extensibility/add_openvino_ops.rst +++ b/docs/articles_en/documentation/openvino_extensibility/add_openvino_ops.rst @@ -5,8 +5,8 @@ Custom OpenVINO™ Operations .. meta:: - :description: Explore OpenVINO™ Extension API which enables registering - custom operations to support models with operations + :description: Explore OpenVINO™ Extension API which enables registering + custom operations to support models with operations not supported by OpenVINO. OpenVINO™ Extension API allows you to register custom operations to support models with operations which OpenVINO™ does not support out-of-the-box. This capability requires writing code in C++, so if you are using Python to develop your application you need to build a separate shared library implemented in C++ first and load it in Python using ``add_extension`` API. Please refer to :ref:`Create library with extensions ` for more details on library creation and usage. The remining part of this document describes how to implement an operation class. @@ -14,7 +14,7 @@ OpenVINO™ Extension API allows you to register custom operations to support mo Operation Class ############### -To add your custom operation, create a new class that extends ``ov::Op``, which is in turn derived from ``:ref:`ov::Node ```, the base class for all graph operations in OpenVINO™. To add ``ov::Op``, include the next file: +To add your custom operation, create a new class that extends ``ov::Op``, which is in turn derived from ``ov::Node``, the base class for all graph operations in OpenVINO™. To add ``ov::Op``, include the next file: .. doxygensnippet:: ./src/core/template_extension/new/identity.hpp :language: cpp @@ -24,9 +24,9 @@ Follow the steps below to add a custom operation: 1. Add the ``OPENVINO_OP`` macro which defines a ``NodeTypeInfo`` object that identifies the type of the operation to the graph users and helps with dynamic type resolution. The type info of an operation currently consists of a string operation identifier and a string for operation version. -2. Implement default constructor and constructors that optionally take the operation inputs and attributes as parameters. +2. Implement default constructor and constructors that optionally take the operation inputs and attributes as parameters. -3. Override the shape inference method ``validate_and_infer_types``. This method is called multiple times during graph manipulations to determine the shapes and element types of the operations outputs. To access the input shapes and input element types, use the ``get_input_partial_shape()`` and ``get_input_element_type()`` methods of ``:ref:`ov::Node ```. Set the inferred shape and element type of the output using ``set_output_type``. +3. Override the shape inference method ``validate_and_infer_types``. This method is called multiple times during graph manipulations to determine the shapes and element types of the operations outputs. To access the input shapes and input element types, use the ``get_input_partial_shape()`` and ``get_input_element_type()`` methods of ``ov::Node``. Set the inferred shape and element type of the output using ``set_output_type``. 4. Override the ``clone_with_new_inputs`` method, which enables graph manipulation routines to create copies of this operation and connect it to different nodes during optimization. @@ -40,9 +40,9 @@ Based on that, declaration of an operation class can look as follows: Operation Constructors ++++++++++++++++++++++ -OpenVINO™ operation contains two constructors: +OpenVINO™ operation contains two constructors: -* Default constructor, which enables you to create an operation without attributes +* Default constructor, which enables you to create an operation without attributes * Constructor that creates and validates an operation with specified inputs and attributes .. doxygensnippet:: ./src/core/template_extension/new/identity.cpp @@ -52,7 +52,7 @@ OpenVINO™ operation contains two constructors: ``validate_and_infer_types()`` ++++++++++++++++++++++++++++++ -``:ref:`ov::Node::validate_and_infer_types ``` method validates operation attributes and calculates output shapes using attributes of the operation. +``ov::Node::validate_and_infer_types`` method validates operation attributes and calculates output shapes using attributes of the operation. .. doxygensnippet:: ./src/core/template_extension/new/identity.cpp :language: cpp @@ -61,7 +61,7 @@ OpenVINO™ operation contains two constructors: ``clone_with_new_inputs()`` +++++++++++++++++++++++++++ -``:ref:`ov::Node::clone_with_new_inputs ``` method creates a copy of the operation with new inputs. +``ov::Node::clone_with_new_inputs`` method creates a copy of the operation with new inputs. .. doxygensnippet:: ./src/core/template_extension/new/identity.cpp :language: cpp @@ -70,7 +70,7 @@ OpenVINO™ operation contains two constructors: ``visit_attributes()`` ++++++++++++++++++++++ -``:ref:`ov::Node::visit_attributes ``` method enables you to visit all operation attributes. +``ov::Node::visit_attributes`` method enables you to visit all operation attributes. .. doxygensnippet:: ./src/core/template_extension/new/identity.cpp :language: cpp @@ -79,7 +79,7 @@ OpenVINO™ operation contains two constructors: ``evaluate() and has_evaluate()`` +++++++++++++++++++++++++++++++++ -``:ref:`ov::Node::evaluate ``` method enables you to apply constant folding to an operation. +``ov::Node::evaluate`` method enables you to apply constant folding to an operation. .. doxygensnippet:: ./src/core/template_extension/new/identity.cpp :language: cpp diff --git a/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step2_markup.rst b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step2_markup.rst index 467f4451f141b7..7c0383492ffef8 100644 --- a/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step2_markup.rst +++ b/docs/articles_en/documentation/openvino_extensibility/openvino_plugin_library/detailed_guides/low_precision_transformations/step2_markup.rst @@ -5,7 +5,7 @@ Step 2. Markup Transformations .. meta:: - :description: Learn about markup transformations, which are used to create + :description: Learn about markup transformations, which are used to create attributes for input and output ports and operations during runtime. .. toctree:: @@ -21,7 +21,7 @@ Step 2. Markup Transformations PropagatePrecisions AlignQuantizationIntervals AlignQuantizationParameters - + CreateAttribute CreatePrecisionsDependentAttribute PropagateThroughPrecisionPreserved @@ -31,13 +31,13 @@ Step 2. Markup Transformations This step defines the optimal ``FakeQuantize`` decomposition precisions for the best inference performance via operations markup with runtime attribute instances. Attributes are created for input and output ports and operations. Transformations do not change the operation output port precisions. A model markup low precision logic is decomposed and implemented into the following common markup transformations. The order of transformations is important: 1. :doc:`MarkupBias ` -2. :doc:`MarkupCanBeQuantized ` -3. :doc:`MarkupPrecisions ` -4. :doc:`MarkupPerTensorQuantization ` -5. :doc:`MarkupAvgPoolPrecisionPreserved ` -6. :doc:`PropagatePrecisions ` -7. :doc:`AlignQuantizationIntervals ` -8. :doc:`AlignQuantizationParameters ` +2. :doc:`MarkupCanBeQuantized ` +3. :doc:`MarkupPrecisions ` +4. :doc:`MarkupPerTensorQuantization ` +5. :doc:`MarkupAvgPoolPrecisionPreserved ` +6. :doc:`PropagatePrecisions ` +7. :doc:`AlignQuantizationIntervals ` +8. :doc:`AlignQuantizationParameters ` .. list-table:: :header-rows: 1 @@ -47,16 +47,16 @@ This step defines the optimal ``FakeQuantize`` decomposition precisions for the - Use attributes * - MarkupBias - Bias - - + - * - MarkupCanBeQuantized - Precisions - - + - * - MarkupPrecisions - Precisions,PrecisionPreserved - - + - * - MarkupPerTensorQuantization - PerTensorQuantization - - + - * - MarkupAvgPoolPrecisionPreserved - AvgPoolPrecisionPreserved - Precisions, PrecisionPreserved @@ -70,16 +70,16 @@ This step defines the optimal ``FakeQuantize`` decomposition precisions for the - QuantizationAlignment - PrecisionPreserved, PerTensorQuantization -.. note:: +.. note:: The same type of attribute instances can be created in different transformations. This approach is the result of the transformation single-responsibility principle. For example, ``Precision`` attribute instances are created in ``MarkupCanBeQuantized`` and ``MarkupPrecisions`` transformations, but the reasons for their creation are different Common markup transformations can be decomposed into simpler utility markup transformations. The order of Markup utility transformations is not important: -* :doc:`CreateAttribute ` -* :doc:`CreatePrecisionsDependentAttribute ` -* :doc:`PropagateThroughPrecisionPreserved ` -* :doc:`PropagateToInput ` -* :doc:`UpdateSharedPrecisionPreserved ` +* :doc:`CreateAttribute ` +* :doc:`CreatePrecisionsDependentAttribute ` +* :doc:`PropagateThroughPrecisionPreserved ` +* :doc:`PropagateToInput ` +* :doc:`UpdateSharedPrecisionPreserved ` Let's explore all transformations and their relations in detail, using one and the same model: @@ -90,12 +90,12 @@ The original model key features: * The first ``concat1`` concatenation operation has not quantized ``convolution1`` consumer. -* The second ``concat2`` concatenation operation has quantized ``convolution2`` consumer with requirements: - +* The second ``concat2`` concatenation operation has quantized ``convolution2`` consumer with requirements: + * support ``unsigned int8`` on activations, * per-tensor quantization. -* Between the ``concat2`` concatenation operation and ``Convolution`` there is an ``AvgPool`` operation, which mathematically should return an ``f32`` tensor. But the ``MarkupAvgPoolPrecisionPreserved`` transformation is active. This allows the low precision transformation, that goes after the ``AvgPool``, to propagate low precision tensor to the next consumer. +* Between the ``concat2`` concatenation operation and ``Convolution`` there is an ``AvgPool`` operation, which mathematically should return an ``f32`` tensor. But the ``MarkupAvgPoolPrecisionPreserved`` transformation is active. This allows the low precision transformation, that goes after the ``AvgPool``, to propagate low precision tensor to the next consumer. Transformations are run with the following parameters: @@ -127,8 +127,8 @@ Model display features (here and below): The transformation is required and includes two tasks: -1. Mark operation input ports (create ``Precision`` attribute instance) by provided restrictions: input port index and required precisions. Restrictions are provided as input argument in ``:ref:`ov::pass::low_precision::LowPrecision ``` constructor. -2. Mark precision preserved operations. +1. Mark operation input ports (create ``Precision`` attribute instance) by provided restrictions: input port index and required precisions. Restrictions are provided as input argument in ``ov::pass::low_precision::LowPrecision`` constructor. +2. Mark precision preserved operations. No attributes are required before the transformation. Changes in the example model after ``MarkupPrecisions`` transformation: @@ -191,7 +191,7 @@ Result model: .. image:: _static/images/step2_markup5.svg :alt: PropagatePrecisions -.. note:: +.. note:: ``AlignQuantizationIntervals`` and ``AlignQuantizationParameters`` transformations are required if the model has quantized concatenation operations. 6. AlignQuantizationIntervals diff --git a/docs/articles_en/documentation/openvino_extensibility/ov_transformations.rst b/docs/articles_en/documentation/openvino_extensibility/ov_transformations.rst index c138ac5ba930e4..9bcb1f778f0b53 100644 --- a/docs/articles_en/documentation/openvino_extensibility/ov_transformations.rst +++ b/docs/articles_en/documentation/openvino_extensibility/ov_transformations.rst @@ -5,7 +5,7 @@ Overview of Transformations API .. meta:: - :description: Learn how to apply additional model optimizations or transform + :description: Learn how to apply additional model optimizations or transform unsupported subgraphs and operations, using OpenVINO™ Transformations API. @@ -17,19 +17,19 @@ Overview of Transformations API openvino_docs_Extensibility_UG_matcher_pass openvino_docs_Extensibility_UG_graph_rewrite_pass -OpenVINO Transformation mechanism allows to develop transformation passes to modify ``:ref:`ov::Model ```. You can use this mechanism to apply additional optimizations to the original Model or transform unsupported subgraphs and operations to new operations which are supported by the plugin. +OpenVINO Transformation mechanism allows to develop transformation passes to modify ``ov::Model``. You can use this mechanism to apply additional optimizations to the original Model or transform unsupported subgraphs and operations to new operations which are supported by the plugin. This guide contains all necessary information that you need to start implementing OpenVINO™ transformations. Working with Model ################## -Before the moving to transformation part it is needed to say several words about functions which allow to modify ``:ref:`ov::Model ```. -This chapter extends the :doc:`model representation guide ` and shows an API that allows us to manipulate with ``:ref:`ov::Model ```. +Before the moving to transformation part it is needed to say several words about functions which allow to modify ``ov::Model``. +This chapter extends the :doc:`model representation guide ` and shows an API that allows us to manipulate with ``ov::Model``. Working with node input and output ports ++++++++++++++++++++++++++++++++++++++++ -First of all let's talk about ``:ref:`ov::Node ``` input/output ports. Each OpenVINO™ operation has input and output ports except cases when operation has ``Parameter`` or ``Constant`` type. +First of all let's talk about ``ov::Node`` input/output ports. Each OpenVINO™ operation has input and output ports except cases when operation has ``Parameter`` or ``Constant`` type. Every port belongs to its node, so using a port we can access parent node, get shape and type for particular input/output, get all consumers in case of output port, and get producer node in case of input port. With output port we can set inputs for newly created operations. @@ -49,13 +49,13 @@ Let's start with OpenVINO™ helper functions. The most popular function is ``ov We will review real replacement case where Negative operation is replaced with Multiply. -.. image:: ./_static/images/ngraph_replace_node.png +.. image:: ./_static/images/ngraph_replace_node.png .. doxygensnippet:: docs/snippets/ov_model_snippets.cpp :language: cpp :fragment: [ov:replace_node] -``:ref:`ov::replace_node ``` has a constraint that number of output ports for both of ops must be the same; otherwise, it raises an exception. +``ov::replace_node`` has a constraint that number of output ports for both of ops must be the same; otherwise, it raises an exception. The alternative way to do the same replacement is the following: @@ -71,7 +71,7 @@ Another transformation example is insertion. :language: cpp :fragment: [ov:insert_node] -The alternative way to the insert operation is to make a node copy and use ``:ref:`ov::replace_node() ```: +The alternative way to the insert operation is to make a node copy and use ``ov::replace_node()``: .. doxygensnippet:: docs/snippets/ov_model_snippets.cpp :language: cpp @@ -88,16 +88,16 @@ To eliminate operation, OpenVINO™ has special method that considers all limita :language: cpp :fragment: [ov:eliminate_node] -``:ref:`ov::replace_output_update_name() ``` in case of successful replacement it automatically preserves friendly name and runtime info. +``ov::replace_output_update_name()`` in case of successful replacement it automatically preserves friendly name and runtime info. .. _transformations_types: -Transformations types +Transformations types ##################### OpenVINO™ Runtime has three main transformation types: -* :doc:`Model pass ` - straightforward way to work with ``:ref:`ov::Model ``` directly +* :doc:`Model pass ` - straightforward way to work with ``ov::Model`` directly * :doc:`Matcher pass ` - pattern-based transformation approach * :doc:`Graph rewrite pass ` - container for matcher passes needed for efficient execution @@ -108,12 +108,12 @@ Transformation conditional compilation Transformation library has two internal macros to support conditional compilation feature. -* ``:ref:`MATCHER_SCOPE(region) ``` - allows to disable the MatcherPass if matcher isn't used. The region name should be unique. This macro creates a local variable ``matcher_name`` which you should use as a matcher name. -* ``:ref:`RUN_ON_MODEL_SCOPE(region) ``` - allows to disable run_on_model pass if it isn't used. The region name should be unique. +* ``MATCHER_SCOPE(region)`` - allows to disable the MatcherPass if matcher isn't used. The region name should be unique. This macro creates a local variable ``matcher_name`` which you should use as a matcher name. +* ``RUN_ON_MODEL_SCOPE(region)`` - allows to disable run_on_model pass if it isn't used. The region name should be unique. .. _transformation_writing_essentials: -Transformation writing essentials +Transformation writing essentials ################################# When developing a transformation, you need to follow these transformation rules: @@ -121,7 +121,7 @@ When developing a transformation, you need to follow these transformation rules: 1. Friendly Names +++++++++++++++++ -Each ``:ref:`ov::Node ``` has an unique name and a friendly name. In transformations we care only about friendly name because it represents the name from the model. +Each ``ov::Node`` has an unique name and a friendly name. In transformations we care only about friendly name because it represents the name from the model. To avoid losing friendly name when replacing node with other node or subgraph, set the original friendly name to the latest node in replacing subgraph. See the example below. .. doxygensnippet:: docs/snippets/ov_model_snippets.cpp @@ -133,8 +133,8 @@ In more advanced cases, when replaced operation has several outputs and we add a 2. Runtime Info +++++++++++++++ -Runtime info is a map ``std::map`>`` located inside ``:ref:`ov::Node ``` class. It represents additional attributes in ``:ref:`ov::Node ```. -These attributes can be set by users or by plugins and when executing transformation that changes ``:ref:`ov::Model ``` we need to preserve these attributes as they will not be automatically propagated. +Runtime info is a map ``std::map`` located inside ``ov::Node`` class. It represents additional attributes in ``ov::Node``. +These attributes can be set by users or by plugins and when executing transformation that changes ``ov::Model`` we need to preserve these attributes as they will not be automatically propagated. In most cases, transformations have the following types: 1:1 (replace node with another node), 1:N (replace node with a sub-graph), N:1 (fuse sub-graph into a single node), N:M (any other transformation). Currently, there is no mechanism that automatically detects transformation types, so we need to propagate this runtime information manually. See the examples below. @@ -143,21 +143,21 @@ Currently, there is no mechanism that automatically detects transformation types :language: cpp :fragment: [ov:copy_runtime_info] -When transformation has multiple fusions or decompositions, ``:ref:`ov::copy_runtime_info ``` must be called multiple times for each case. +When transformation has multiple fusions or decompositions, ``ov::copy_runtime_info`` must be called multiple times for each case. .. note:: ``copy_runtime_info`` removes ``rt_info`` from destination nodes. If you want to keep it, you need to specify them in source nodes like this: ``copy_runtime_info({a, b, c}, {a, b})`` 3. Constant Folding +++++++++++++++++++ -If your transformation inserts constant sub-graphs that need to be folded, do not forget to use ``:ref:`ov::pass::ConstantFolding() ``` after your transformation or call constant folding directly for operation. +If your transformation inserts constant sub-graphs that need to be folded, do not forget to use ``ov::pass::ConstantFolding()`` after your transformation or call constant folding directly for operation. The example below shows how constant subgraph can be constructed. .. doxygensnippet:: docs/snippets/ov_model_snippets.cpp :language: cpp :fragment: [ov:constant_subgraph] -Manual constant folding is more preferable than ``:ref:`ov::pass::ConstantFolding() ``` because it is much faster. +Manual constant folding is more preferable than ``ov::pass::ConstantFolding()`` because it is much faster. Below you can find an example of manual constant folding: @@ -167,28 +167,28 @@ Below you can find an example of manual constant folding: .. _common_mistakes: -Common mistakes in transformations +Common mistakes in transformations ################################## In transformation development process: * Do not use deprecated OpenVINO™ API. Deprecated methods has the ``OPENVINO_DEPRECATED`` macros in its definition. * Do not pass ``shared_ptr`` as an input for other node if type of node is unknown or it has multiple outputs. Use explicit output port. -* If you replace node with another node that produces different shape, remember that new shape will not be propagated until the first ``validate_nodes_and_infer_types`` call for ``:ref:`ov::Model ```. If you are using ``:ref:`ov::pass::Manager ```, it will automatically call this method after each transformation execution. -* Do not forget to call the ``:ref:`ov::pass::ConstantFolding ``` pass if your transformation creates constant subgraphs. +* If you replace node with another node that produces different shape, remember that new shape will not be propagated until the first ``validate_nodes_and_infer_types`` call for ``ov::Model``. If you are using ``ov::pass::Manager``, it will automatically call this method after each transformation execution. +* Do not forget to call the ``ov::pass::ConstantFolding`` pass if your transformation creates constant subgraphs. * Use latest OpSet if you are not developing downgrade transformation pass. -* When developing a callback for ``:ref:`ov::pass::MatcherPass ```, do not change nodes that come after the root node in topological order. +* When developing a callback for ``ov::pass::MatcherPass``, do not change nodes that come after the root node in topological order. .. _using_pass_manager: Using pass manager ################## -``:ref:`ov::pass::Manager ``` is a container class that can store the list of transformations and execute them. The main idea of this class is to have high-level representation for grouped list of transformations. +``ov::pass::Manager`` is a container class that can store the list of transformations and execute them. The main idea of this class is to have high-level representation for grouped list of transformations. It can register and apply any `transformation pass <#transformations_types>`__ on model. -In addition, ``:ref:`ov::pass::Manager ``` has extended debug capabilities (find more information in the `how to debug transformations <#how_to_debug_transformations>`__ section). +In addition, ``ov::pass::Manager`` has extended debug capabilities (find more information in the `how to debug transformations <#how_to_debug_transformations>`__ section). -The example below shows basic usage of ``:ref:`ov::pass::Manager ``` +The example below shows basic usage of ``ov::pass::Manager`` .. doxygensnippet:: docs/snippets/template_pattern_transformation.cpp :language: cpp @@ -199,16 +199,16 @@ Another example shows how multiple matcher passes can be united into single Grap .. doxygensnippet:: docs/snippets/template_pattern_transformation.cpp :language: cpp :fragment: [matcher_pass:manager2] - -.. _how_to_debug_transformations: -How to debug transformations +.. _how_to_debug_transformations: + +How to debug transformations ############################ If you are using ``ov::pass::Manager`` to run sequence of transformations, you can get additional debug capabilities by using the following environment variables: .. code-block:: cpp - + OV_PROFILE_PASS_ENABLE=1 - enables performance measurement for each transformation and prints execution status OV_ENABLE_VISUALIZE_TRACING=1 - enables visualization after each transformation. By default, it saves dot and svg files. @@ -218,6 +218,6 @@ If you are using ``ov::pass::Manager`` to run sequence of transformations, you c See Also ######## -* :doc:`OpenVINO™ Model Representation ` +* :doc:`OpenVINO™ Model Representation ` * :doc:`OpenVINO™ Extensions ` diff --git a/docs/articles_en/documentation/openvino_extensibility/ov_transformations/graph_rewrite_pass.rst b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/graph_rewrite_pass.rst index 621d0d23e319ac..d3f84abadbfef1 100644 --- a/docs/articles_en/documentation/openvino_extensibility/ov_transformations/graph_rewrite_pass.rst +++ b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/graph_rewrite_pass.rst @@ -5,11 +5,11 @@ OpenVINO Graph Rewrite Pass .. meta:: - :description: Get to know how Graph Rewrite handles running multiple matcher passes on + :description: Get to know how Graph Rewrite handles running multiple matcher passes on ov::Model in a single graph traversal. -``:ref:`ov::pass::GraphRewrite ``` serves for running multiple matcher passes on ``:ref:`ov::Model ``` in a single graph traversal. +``ov::pass::GraphRewrite`` serves for running multiple matcher passes on ``ov::Model`` in a single graph traversal. Example: .. doxygensnippet:: docs/snippets/template_pattern_transformation.cpp @@ -18,13 +18,13 @@ Example: In addition, GraphRewrite handles nodes that were registered by MatcherPasses during their execution. This nodes will be added to the beginning of the sequence with nodes for pattern matching. -.. note:: +.. note:: - When using ``:ref:`ov::pass::Manager ``` temporary GraphRewrite is used to execute single MatcherPass. + When using ``ov::pass::Manager`` temporary GraphRewrite is used to execute single MatcherPass. GraphRewrite has two algorithms for MatcherPasses execution. First algorithm is straightforward. It applies each MatcherPass in registration order to current node. -.. image:: ./_static/images/graph_rewrite_execution.png +.. image:: ./_static/images/graph_rewrite_execution.png But it is not really efficient when you have a lot of registered passes. So first of all GraphRewrite checks that all MatcherPass patterns has type-based root node (it means that type of this node is not hidden into predicate). And then creates map from registered MatcherPasses. That helps to avoid additional cost of applying each MatcherPass for each node. diff --git a/docs/articles_en/documentation/openvino_extensibility/ov_transformations/matcher_pass.rst b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/matcher_pass.rst index 3f9a31331c45ac..1943a5e5635480 100644 --- a/docs/articles_en/documentation/openvino_extensibility/ov_transformations/matcher_pass.rst +++ b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/matcher_pass.rst @@ -5,11 +5,11 @@ OpenVINO Matcher Pass .. meta:: - :description: Learn how to create a pattern, implement a callback, register - the pattern and Matcher to execute MatcherPass transformation + :description: Learn how to create a pattern, implement a callback, register + the pattern and Matcher to execute MatcherPass transformation on a model. -``:ref:`ov::pass::MatcherPass ``` is used for pattern-based transformations. +``ov::pass::MatcherPass`` is used for pattern-based transformations. Template for MatcherPass transformation class @@ -22,7 +22,7 @@ Template for MatcherPass transformation class :fragment: [graph_rewrite:template_transformation_cpp] -To use ``:ref:`ov::pass::MatcherPass ```, you need to complete these steps: +To use ``ov::pass::MatcherPass``, you need to complete these steps: 1. Create a pattern 2. Implement a callback @@ -34,10 +34,10 @@ So let's go through each of these steps. Create a pattern ################ -Pattern is a single root ``:ref:`ov::Model ```. But the only difference is that you do not need to create a model object, you just need to create and connect opset or special pattern operations. +Pattern is a single root ``ov::Model``. But the only difference is that you do not need to create a model object, you just need to create and connect opset or special pattern operations. Then you need to take the last created operation and put it as a root of the pattern. This root node will be used as a root node in pattern matching. -.. note:: +.. note:: Any nodes in a pattern that have no consumers and are not registered as root will not be used in pattern matching. .. doxygensnippet:: docs/snippets/ov_model_snippets.cpp @@ -60,13 +60,13 @@ Callback is an action applied to every pattern entrance. In general, callback is The example above shows the callback structure and how Matcher can be used for accessing nodes detected by pattern. Callback return value is ``true`` if root node was replaced and another pattern cannot be applied to the same root node; otherwise, it is ``false``. -.. note:: +.. note:: It is not recommended to manipulate with nodes that are under root node. This may affect GraphRewrite execution as it is expected that all nodes that come after root node in topological order are valid and can be used in pattern matching. MatcherPass also provides functionality that allows reporting of the newly created nodes that can be used in additional pattern matching. -If MatcherPass was registered in ``:ref:`ov::pass::Manager ``` or ``:ref:`ov::pass::GraphRewrite ```, these registered nodes will be added for additional pattern matching. -That means that matcher passes registered in ``:ref:`ov::pass::GraphRewrite ``` will be applied to these nodes. +If MatcherPass was registered in ``ov::pass::Manager`` or ``ov::pass::GraphRewrite``, these registered nodes will be added for additional pattern matching. +That means that matcher passes registered in ``ov::pass::GraphRewrite`` will be applied to these nodes. The example below shows how single MatcherPass can fuse sequence of operations using the ``register_new_node`` method. @@ -74,7 +74,7 @@ The example below shows how single MatcherPass can fuse sequence of operations u :language: cpp :fragment: [matcher_pass:relu_fusion] -.. note:: +.. note:: If you register multiple nodes, please add them in topological order. We do not topologically sort these nodes as it is a time-consuming operation. Register pattern and Matcher @@ -82,12 +82,12 @@ Register pattern and Matcher The last step is to register Matcher and callback inside the MatcherPass pass. To do this, call the ``register_matcher`` method. -.. note:: +.. note:: Only one matcher can be registered for a single MatcherPass class. .. code-block:: cpp - + // Register matcher and callback register_matcher(m, callback); @@ -103,13 +103,13 @@ MatcherPass has multiple ways to be executed: :language: cpp :fragment: [matcher_pass:run_on_node] -* Run on ``:ref:`ov::Model ``` using GraphRewrite - this approach gives ability to run MatcherPass on whole ``:ref:`ov::Model ```. Moreover, multiple MatcherPass transformation can be registered in a single GraphRewite to be executed in a single graph traversal. +* Run on ``ov::Model`` using GraphRewrite - this approach gives ability to run MatcherPass on whole ``ov::Model``. Moreover, multiple MatcherPass transformation can be registered in a single GraphRewite to be executed in a single graph traversal. .. doxygensnippet:: docs/snippets/template_pattern_transformation.cpp :language: cpp :fragment: [matcher_pass:graph_rewrite] -* Run on ``:ref:`ov::Model ``` using ``:ref:`ov::pass::Manager ``` - this approach helps you to register MatcherPass for execution on ``:ref:`ov::Model ``` as another transformation types. +* Run on ``ov::Model`` using ``ov::pass::Manager`` - this approach helps you to register MatcherPass for execution on ``ov::Model`` as another transformation types. .. doxygensnippet:: docs/snippets/template_pattern_transformation.cpp :language: cpp @@ -125,8 +125,8 @@ And for these cases OpenVINO™ provides additional helpers to construct pattern There are two main helpers: -1. ``:ref:`ov::pass::pattern::any_input ``` - helps to express inputs if their types are undefined. -2. ``:ref:`ov::pass::pattern::wrap_type ``` - helps to express nodes of pattern without specifying node attributes. +1. ``ov::pass::pattern::any_input`` - helps to express inputs if their types are undefined. +2. ``ov::pass::pattern::wrap_type `` - helps to express nodes of pattern without specifying node attributes. Let's go through the example to have better understanding of how it works: diff --git a/docs/articles_en/documentation/openvino_extensibility/ov_transformations/model_pass.rst b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/model_pass.rst index f79dc9dcf69ee0..eb09d2986939e0 100644 --- a/docs/articles_en/documentation/openvino_extensibility/ov_transformations/model_pass.rst +++ b/docs/articles_en/documentation/openvino_extensibility/ov_transformations/model_pass.rst @@ -5,25 +5,25 @@ OpenVINO Model Pass .. meta:: - :description: Learn how to use Model Pass transformation class to take entire + :description: Learn how to use Model Pass transformation class to take entire ov::Model as input and process it. -``:ref:`ov::pass::ModelPass ``` is used for transformations that take entire ``:ref:`ov::Model ``` as an input and process it. +``ov::pass::ModelPass`` is used for transformations that take entire ``ov::Model`` as an input and process it. Template for ModelPass transformation class -.. doxygensnippet:: docs/snippets/template_model_transformation.hpp - :language: cpp +.. doxygensnippet:: docs/snippets/template_model_transformation.hpp + :language: cpp :fragment: [model_pass:template_transformation_hpp] .. doxygensnippet:: docs/snippets/template_model_transformation.cpp :language: cpp :fragment: [model_pass:template_transformation_cpp] -Using ``:ref:`ov::pass::ModelPass ```, you need to override the ``run_on_model`` method where you will write the transformation code. +Using ``ov::pass::ModelPass``, you need to override the ``run_on_model`` method where you will write the transformation code. Return value is ``true`` if the original model has changed during transformation (new operation was added, or operations replacement was made, or node attributes were changed); otherwise, it is ``false``. -Also ``:ref:`ov::pass::ModelPass ``` based transformations can be executed via ``:ref:`ov::pass::Manager ```. +Also ``ov::pass::ModelPass`` based transformations can be executed via ``ov::pass::Manager``. See Also ######## diff --git a/docs/articles_en/openvino_workflow/running_inference_with_openvino/Device_Plugins/GPU/GPU_RemoteTensor_API.rst b/docs/articles_en/openvino_workflow/running_inference_with_openvino/Device_Plugins/GPU/GPU_RemoteTensor_API.rst index 1475d62ac65bd5..60baddcfa8fd1a 100644 --- a/docs/articles_en/openvino_workflow/running_inference_with_openvino/Device_Plugins/GPU/GPU_RemoteTensor_API.rst +++ b/docs/articles_en/openvino_workflow/running_inference_with_openvino/Device_Plugins/GPU/GPU_RemoteTensor_API.rst @@ -5,13 +5,13 @@ Remote Tensor API of GPU Plugin .. meta:: - :description: The Remote Tensor API of GPU plugin in OpenVINO™ supports - interoperability with existing native APIs, such as OpenCL, + :description: The Remote Tensor API of GPU plugin in OpenVINO™ supports + interoperability with existing native APIs, such as OpenCL, Microsoft DirectX, or VAAPI. The GPU plugin implementation of the ``ov::RemoteContext`` and ``ov::RemoteTensor`` interfaces supports GPU -pipeline developers who need video memory sharing and interoperability with existing native APIs, +pipeline developers who need video memory sharing and interoperability with existing native APIs, such as OpenCL, Microsoft DirectX, or VAAPI. The ``ov::RemoteContext`` and ``ov::RemoteTensor`` interface implementation targets the need for memory sharing and @@ -57,24 +57,24 @@ of ``ov::RemoteContext`` derived classes. :sync: windows-cpp .. tab-set:: - + .. tab-item:: Create from cl_context :sync: create-from-cl-context - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [context_from_cl_context] - + .. tab-item:: Create from cl_queue :sync: create-from-cl-queue - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [context_from_cl_queue] - + .. tab-item:: Create from ID3D11Device :sync: create-from-id3d11device - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [context_from_d3d_device] @@ -83,24 +83,24 @@ of ``ov::RemoteContext`` derived classes. :sync: windows-c .. tab-set:: - + .. tab-item:: Create from cl_context :sync: create-from-cl-context - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [context_from_cl_context] - + .. tab-item:: Create from cl_queue :sync: create-from-cl-queue - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [context_from_cl_queue] - + .. tab-item:: Create from ID3D11Device :sync: create-from-id3d11device - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [context_from_d3d_device] @@ -109,54 +109,54 @@ of ``ov::RemoteContext`` derived classes. :sync: linux-cpp .. tab-set:: - + .. tab-item:: Create from cl_context :sync: create-from-cl-context - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [context_from_cl_context] - + .. tab-item:: Create from cl_queue :sync: create-from-cl-queue - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [context_from_cl_queue] - + .. tab-item:: Create from VADisplay :sync: create-from-vadisplay - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [context_from_va_display] - + .. tab-item:: Linux/C :sync: linux-c .. tab-set:: - + .. tab-item:: Create from cl_context :sync: create-from-cl-context - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [context_from_cl_context] - + .. tab-item:: Create from cl_queue :sync: create-from-cl-queue - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [context_from_cl_queue] - + .. tab-item:: Create from VADisplay :sync: create-from-vadisplay - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [context_from_va_display] - + Getting RemoteContext from the Plugin +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -173,40 +173,40 @@ To request the current default context of the plugin, use one of the following m :sync: cpp .. tab-set:: - + .. tab-item:: Get context from Core :sync: get-context-core - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [default_context_from_core] - + .. tab-item:: Get context from compiled model :sync: get-context-compiled-model - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation.cpp :language: cpp :fragment: [default_context_from_model] - + .. tab-item:: C :sync: c .. tab-set:: - + .. tab-item:: Get context from Core :sync: get-context-core - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [default_context_from_core] - + .. tab-item:: Get context from compiled model :sync: get-context-compiled-model - + .. doxygensnippet:: docs/snippets/gpu/remote_objects_creation_c.cpp :language: c :fragment: [default_context_from_model] - + Memory Sharing Between Application and GPU Plugin ########################################################### @@ -359,11 +359,11 @@ Direct NV12 Video Surface Input To support the direct consumption of a hardware video decoder output, the GPU plugin accepts: -* Two-plane NV12 video surface input - calling the ``create_tensor_nv12()`` function creates - a pair of ``ov::RemoteTensor`` objects, representing the Y and UV planes. -* Single-plane NV12 video surface input - calling the ``create_tensor()`` function creates one +* Two-plane NV12 video surface input - calling the ``create_tensor_nv12()`` function creates + a pair of ``ov::RemoteTensor`` objects, representing the Y and UV planes. +* Single-plane NV12 video surface input - calling the ``create_tensor()`` function creates one ``ov::RemoteTensor`` object, representing the Y and UV planes at once (Y elements before UV elements). -* NV12 to Grey video surface input conversion - calling the ``create_tensor()`` function creates one +* NV12 to Grey video surface input conversion - calling the ``create_tensor()`` function creates one ``ov::RemoteTensor`` object, representing only the Y plane. To ensure that the plugin generates a correct execution graph, static preprocessing @@ -375,102 +375,102 @@ should be added before model compilation: :sync: two-plane .. tab-set:: - + .. tab-item:: C++ :sync: cpp - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_two_planes.cpp :language: cpp :fragment: [init_preproc] - + .. tab-item:: C :sync: c - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_two_planes_c.cpp :language: c :fragment: [init_preproc] - + .. tab-item:: single-plane :sync: single-plane - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_single_plane.cpp :language: cpp :fragment: [init_preproc] - + .. tab-item:: NV12 to Grey :sync: nv12-grey - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_to_gray.cpp :language: cpp :fragment: [init_preproc] -Since the ``ov::intel_gpu::ocl::ClImage2DTensor`` and its derived classes do not support batched surfaces, -if batching and surface sharing are required at the same time, +Since the ``ov::intel_gpu::ocl::ClImage2DTensor`` and its derived classes do not support batched surfaces, +if batching and surface sharing are required at the same time, inputs need to be set via the ``ov::InferRequest::set_tensors`` method with vector of shared surfaces for each plane: .. tab-set:: .. tab-item:: Single Batch :sync: single-batch - + .. tab-set:: .. tab-item:: two-plane :sync: two-plane .. tab-set:: - + .. tab-item:: C++ :sync: cpp - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_two_planes.cpp :language: cpp :fragment: [single_batch] - + .. tab-item:: C :sync: cpp - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_two_planes_c.cpp :language: c :fragment: [single_batch] - + .. tab-item:: single-plane :sync: single-plane - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_single_plane.cpp :language: cpp :fragment: [single_batch] - + .. tab-item:: NV12 to Grey :sync: nv12-grey - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_to_gray.cpp :language: cpp :fragment: [single_batch] - + .. tab-item:: Multiple Batches :sync: multiple-batches .. tab-set:: - + .. tab-item:: two-plane :sync: two-plane - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_two_planes.cpp :language: cpp :fragment: [batched_case] - + .. tab-item:: single-plane :sync: single-plane - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_single_plane.cpp :language: cpp :fragment: [batched_case] - + .. tab-item:: NV12 to Grey :sync: nv12-grey - + .. doxygensnippet:: docs/snippets/gpu/preprocessing_nv12_to_gray.cpp :language: cpp :fragment: [batched_case] @@ -524,7 +524,7 @@ To see pseudo-code of usage examples, refer to the sections below. .. NOTE:: - + For low-level parameter usage examples, see the source code of user-side wrappers from the include files mentioned above. @@ -543,19 +543,19 @@ To see pseudo-code of usage examples, refer to the sections below. :fragment: [context_sharing_user_handle] .. dropdown:: Direct Consuming of the NV12 VAAPI Video Decoder Surface on Linux - + .. tab-set:: - + .. tab-item:: C++ :sync: cpp - + .. doxygensnippet:: docs/snippets/gpu/context_sharing_va.cpp :language: cpp :fragment: [context_sharing_va] - + .. tab-item:: C :sync: c - + .. doxygensnippet:: docs/snippets/gpu/context_sharing_va_c.cpp :language: c :fragment: [context_sharing_va] @@ -563,6 +563,6 @@ To see pseudo-code of usage examples, refer to the sections below. See Also ####################################### -* ``:ref:`ov::Core ``` -* ``:ref:`ov::RemoteTensor ``` +* ``ov::Core`` +* ``ov::RemoteTensor`` From 53672ec0bc5b5174421e86f8492415a0c304123d Mon Sep 17 00:00:00 2001 From: Karol Blaszczak Date: Tue, 30 Jan 2024 14:21:27 +0100 Subject: [PATCH 25/27] [DOCS] Fix nightly link (#22431) (#22533) * fix nightly link * change link Co-authored-by: Tatiana Savina --- .../installing-openvino-from-archive-linux.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/articles_en/get_started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-from-archive-linux.rst b/docs/articles_en/get_started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-from-archive-linux.rst index 0453db1b403e20..351ca99aeb0f61 100644 --- a/docs/articles_en/get_started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-from-archive-linux.rst +++ b/docs/articles_en/get_started/installing-openvino-overview/installing-openvino-linux-header/installing-openvino-from-archive-linux.rst @@ -187,7 +187,7 @@ Step 1: Download and Install the OpenVINO Core Components .. code-block:: sh - curl -L https://storage.openvinotoolkit.org/repositories/openvino/packages/nightly/2024.0.0-13770-9b52171d290/l_openvino_toolkit_ubuntu18_2023.3.0.13775.ceeafaf64f3_arm64.tgz -O openvino_2023.3.0.tgz + curl -L https://storage.openvinotoolkit.org/repositories/openvino/packages/2023.3/linux/l_openvino_toolkit_ubuntu18_2023.3.0.13775.ceeafaf64f3_arm64.tgz -O openvino_2023.3.0.tgz tar -xf openvino_2023.3.0.tgz sudo mv l_openvino_toolkit_ubuntu18_2023.3.0.13775.ceeafaf64f3_arm64 /opt/intel/openvino_2023.3.0 From dab68a88bbc8c3debb29b346be215545124e35af Mon Sep 17 00:00:00 2001 From: Andrei Kashchikhin Date: Tue, 30 Jan 2024 14:03:40 +0000 Subject: [PATCH 26/27] [CI] [GHA] Add retries for APT, update deadsnakes action (#22515) * update setup_python version, add retries for apt in Linux workflows * account for sudo * use sudo via sh --- .github/actions/setup_python/action.yml | 2 +- .github/workflows/job_cpu_functional_tests.yml | 3 +++ .github/workflows/job_cxx_unit_tests.yml | 3 +++ .github/workflows/job_debian_packages.yml | 2 ++ .github/workflows/job_onnx_models_tests.yml | 3 +++ .github/workflows/job_onnx_runtime.yml | 3 +++ .github/workflows/job_python_unit_tests.yml | 3 +++ .github/workflows/job_pytorch_models_tests.yml | 9 ++++++++- .github/workflows/job_samples_tests.yml | 3 +++ .github/workflows/job_tensorflow_hub_models_tests.yml | 9 ++++++++- .github/workflows/linux.yml | 6 ++++++ .github/workflows/linux_arm64.yml | 3 +++ .github/workflows/linux_conditional_compilation.yml | 6 ++++++ .github/workflows/linux_riscv.yml | 3 +++ 14 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.github/actions/setup_python/action.yml b/.github/actions/setup_python/action.yml index 2ca7668dc2d25d..fc376047e9b37c 100644 --- a/.github/actions/setup_python/action.yml +++ b/.github/actions/setup_python/action.yml @@ -35,7 +35,7 @@ runs: - if: ${{ runner.os == 'Linux' && runner.arch == 'ARM64' }} name: Setup Python ${{ inputs.version }} - uses: akashchi/deadsnakes-action@f01521a69eee61eaca3a34440bea3ce838317846 + uses: akashchi/deadsnakes-action@92417281055a5878a0450f240a5b95883eb2d7e2 with: python-version: ${{ inputs.version }} diff --git a/.github/workflows/job_cpu_functional_tests.yml b/.github/workflows/job_cpu_functional_tests.yml index 26a805c210d3b3..fa45d642813b05 100644 --- a/.github/workflows/job_cpu_functional_tests.yml +++ b/.github/workflows/job_cpu_functional_tests.yml @@ -31,6 +31,9 @@ jobs: PARALLEL_TEST_CACHE: ${{ github.workspace }}/install/tests/test_cache.lst if: ${{ github.event_name != 'merge_group' }} steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_cxx_unit_tests.yml b/.github/workflows/job_cxx_unit_tests.yml index 519ff962b6793f..a2e42d1a0aed30 100644 --- a/.github/workflows/job_cxx_unit_tests.yml +++ b/.github/workflows/job_cxx_unit_tests.yml @@ -33,6 +33,9 @@ jobs: INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests if: ${{ github.event_name != 'merge_group' }} steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_debian_packages.yml b/.github/workflows/job_debian_packages.yml index f063a7734b8aec..3e4d78d3f3f50f 100644 --- a/.github/workflows/job_debian_packages.yml +++ b/.github/workflows/job_debian_packages.yml @@ -26,6 +26,8 @@ jobs: DEBIAN_FRONTEND: noninteractive # to prevent apt-get from waiting user input DEBIAN_PACKAGES_DIR: ${{ github.workspace }}/packages steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries - name: Download OpenVINO debian packages uses: actions/download-artifact@v3 diff --git a/.github/workflows/job_onnx_models_tests.yml b/.github/workflows/job_onnx_models_tests.yml index 25fce51699cd10..f98f9e0d723111 100644 --- a/.github/workflows/job_onnx_models_tests.yml +++ b/.github/workflows/job_onnx_models_tests.yml @@ -32,6 +32,9 @@ jobs: ONNX_MODEL_ZOO_SHA: "d58213534f2a4d1c4b19ba62b3bb5f544353256e" if: ${{ github.event_name != 'merge_group' }} steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_onnx_runtime.yml b/.github/workflows/job_onnx_runtime.yml index 986c1a108fa4ad..2aa28ef4f7233f 100644 --- a/.github/workflows/job_onnx_runtime.yml +++ b/.github/workflows/job_onnx_runtime.yml @@ -40,6 +40,9 @@ jobs: ONNX_RUNTIME_UTILS: ${{ github.workspace }}/install/onnxruntime ONNX_RUNTIME_BUILD_DIR: ${{ github.workspace }}/onnxruntime/build steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_python_unit_tests.yml b/.github/workflows/job_python_unit_tests.yml index e20a055eb5b4ba..a2129b7267293e 100644 --- a/.github/workflows/job_python_unit_tests.yml +++ b/.github/workflows/job_python_unit_tests.yml @@ -37,6 +37,9 @@ jobs: INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests LAYER_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/layer_tests steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_pytorch_models_tests.yml b/.github/workflows/job_pytorch_models_tests.yml index 8904b2212e9e33..f2a651e6727533 100644 --- a/.github/workflows/job_pytorch_models_tests.yml +++ b/.github/workflows/job_pytorch_models_tests.yml @@ -33,11 +33,18 @@ jobs: INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests steps: - - name: Check sudo if: ${{ runner.os == 'Linux' }} run: if [ "$(id -u)" -eq 0 ]; then apt update && apt --assume-yes install sudo; fi + - name: Set apt retries + run: | + if [ "$(id -u)" -eq 0 ]; then + echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + else + sudo sh -c "echo 'Acquire::Retries \"10\";' >> /etc/apt/apt.conf.d/80-retries" + fi + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_samples_tests.yml b/.github/workflows/job_samples_tests.yml index 8c1401a819d845..cb939af4cfe7f3 100644 --- a/.github/workflows/job_samples_tests.yml +++ b/.github/workflows/job_samples_tests.yml @@ -31,6 +31,9 @@ jobs: INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests BUILD_DIR: ${{ github.workspace }}/build steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/job_tensorflow_hub_models_tests.yml b/.github/workflows/job_tensorflow_hub_models_tests.yml index 6dcecaa267e8c4..54302b7cfbef58 100644 --- a/.github/workflows/job_tensorflow_hub_models_tests.yml +++ b/.github/workflows/job_tensorflow_hub_models_tests.yml @@ -33,11 +33,18 @@ jobs: INSTALL_TEST_DIR: ${{ github.workspace }}/install/tests MODEL_HUB_TESTS_INSTALL_DIR: ${{ github.workspace }}/install/tests/model_hub_tests steps: - - name: Check sudo if: ${{ runner.os == 'Linux' }} run: if [ "$(id -u)" -eq 0 ]; then apt update && apt --assume-yes install sudo; fi + - name: Set apt retries + run: | + if [ "$(id -u)" -eq 0 ]; then + echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + else + sudo sh -c "echo 'Acquire::Retries \"10\";' >> /etc/apt/apt.conf.d/80-retries" + fi + - name: Download OpenVINO package uses: actions/download-artifact@v3 with: diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 6b4c3be5d43288..58db216bb2344f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -80,6 +80,9 @@ jobs: if: "!needs.smart_ci.outputs.skip_workflow" steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Install git run: | apt-get update @@ -529,6 +532,9 @@ jobs: if: fromJSON(needs.smart_ci.outputs.affected_components).NVIDIA steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Fetch install_build_dependencies.sh uses: actions/checkout@v4 with: diff --git a/.github/workflows/linux_arm64.yml b/.github/workflows/linux_arm64.yml index d4e55ef5724394..5dbc82f4d484f4 100644 --- a/.github/workflows/linux_arm64.yml +++ b/.github/workflows/linux_arm64.yml @@ -82,6 +82,9 @@ jobs: if: "!needs.smart_ci.outputs.skip_workflow" steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Install git run: apt-get update && apt-get install --assume-yes --no-install-recommends git ca-certificates diff --git a/.github/workflows/linux_conditional_compilation.yml b/.github/workflows/linux_conditional_compilation.yml index df6ed63521f0d6..4fd27f4f790248 100644 --- a/.github/workflows/linux_conditional_compilation.yml +++ b/.github/workflows/linux_conditional_compilation.yml @@ -75,6 +75,9 @@ jobs: if: ${{ !needs.smart_ci.outputs.skip_workflow && github.event_name != 'merge_group' }} steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Install git run: | apt-get update @@ -273,6 +276,9 @@ jobs: SCCACHE_AZURE_KEY_PREFIX: ubuntu22_x86_64_cc_Release steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Install git run: apt-get update && apt-get install --assume-yes --no-install-recommends git ca-certificates git-lfs diff --git a/.github/workflows/linux_riscv.yml b/.github/workflows/linux_riscv.yml index 5ec550150675ba..179020a218f0c6 100644 --- a/.github/workflows/linux_riscv.yml +++ b/.github/workflows/linux_riscv.yml @@ -66,6 +66,9 @@ jobs: CCACHE_MAXSIZE: 50G if: ${{ !needs.smart_ci.outputs.skip_workflow && github.event_name != 'merge_group' }} steps: + - name: Set apt retries + run: echo 'Acquire::Retries "10";' > /etc/apt/apt.conf.d/80-retries + - name: Install git run: apt-get update && apt-get install --assume-yes --no-install-recommends git ca-certificates From d2fd6b950388f3ecb9e7ca546e8ee4e25ceb1af5 Mon Sep 17 00:00:00 2001 From: Haiqi Pan Date: Tue, 30 Jan 2024 22:09:15 +0800 Subject: [PATCH 27/27] [Core] remove file_utils.h (#22148) * remove file_utils.h * Revert "remove file_utils.h" This reverts commit 8e03de55931fd1a717bfb013bb165603100034e2. * remove file_utils.h * remove file_utils.h in ov_shared_object_test.cpp * remove file_utils.h in core.cpp * remove file_utils.h in ie_extension_test.cpp * remove file_utils.h in ie_network_reader.cpp * remove file_utils.h in compilation_context.cpp * fix conflits * fix conflits * fix conflits * remove file_utils.h in src/frontends/ir/tests/meta_data_tests.cpp * remove file_utils.h in src/frontends/tests/frontend/shared/include/utils.hpp * remove file_utils.h in src/tests/functional/plugin/shared/include/behavior/plugin/core_threading.hpp * Revert "remove file_utils.h in src/tests/functional/plugin/shared/include/behavior/plugin/core_threading.hpp" This reverts commit 445af3656ee27068cf9a00af732cce2ee342d063. * remove file_utils.h in src/tests/functional/plugin/shared/include/behavior/plugin/core_threading.hpp * Revert "remove file_utils.h in src/tests/functional/plugin/shared/include/behavior/plugin/core_threading.hpp" This reverts commit 6d7e6aecf2eabce008eb769c1a6faec1e37cc5d7. * fix conflicts in src/inference/src/compilation_context.cpp * fix code style in src/inference/src/ie_core.cpp * fix code style in src/inference/src/ie_network_reader.cpp * fix code style in src/inference/tests/functional/ov_shared_object_test.cpp * fix code style in src/inference/tests/functional/ov_shared_object_test.cpp * add make_path * remove file_utils.h in src/plugins/intel_cpu/tests/functional/extension/extension.cpp * remove file_util.h in src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp * remove file_util.h in src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp * remove file_utils.h in src/frontends/paddle/tests/read_paddle_model_test.cpp * remove file_utils.cpp in cmake * fix code style * remove file_utils.h in src/frontends/onnx/tests/onnx_reader_external_data.cpp * remove OV_STATIC_DEPENDENT_FILES in cmake --- .../util/include/openvino/util/file_util.hpp | 11 ++ src/frontends/ir/tests/meta_data_tests.cpp | 1 - .../onnx/tests/onnx_reader_external_data.cpp | 1 - .../paddle/tests/read_paddle_model_test.cpp | 2 +- .../tests/frontend/shared/include/utils.hpp | 1 - src/inference/CMakeLists.txt | 6 +- src/inference/dev_api/file_utils.h | 182 ------------------ src/inference/src/compilation_context.cpp | 6 +- src/inference/src/dev/core_impl.cpp | 2 +- src/inference/src/dev/core_impl.hpp | 2 +- src/inference/src/file_utils.cpp | 146 -------------- src/inference/src/ie_cache_manager.hpp | 8 +- src/inference/src/ie_core.cpp | 1 - src/inference/src/ie_network_reader.cpp | 2 +- .../functional/ov_shared_object_test.cpp | 7 +- src/inference/tests/unit/core.cpp | 18 +- .../tests/functional/extension/extension.cpp | 13 +- .../src/onnx/quantized_models_tests.cpp | 10 +- .../common_test_utils/unicode_utils.hpp | 6 +- 19 files changed, 52 insertions(+), 373 deletions(-) delete mode 100644 src/inference/dev_api/file_utils.h delete mode 100644 src/inference/src/file_utils.cpp diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index 05538638c9d7fc..94678df085db05 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -355,5 +355,16 @@ void save_binary(const std::string& path, const char* binary, size_t bin_size); */ const char* trim_file_name(const char* const fname); +template +using enableIfSupportedChar = + typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; + +template > +inline std::basic_string make_path(const std::basic_string& folder, const std::basic_string& file) { + if (folder.empty()) + return file; + return folder + ov::util::FileTraits::file_separator + file; +} + } // namespace util } // namespace ov diff --git a/src/frontends/ir/tests/meta_data_tests.cpp b/src/frontends/ir/tests/meta_data_tests.cpp index 8dd75fd65e33e7..eba4f38af67913 100644 --- a/src/frontends/ir/tests/meta_data_tests.cpp +++ b/src/frontends/ir/tests/meta_data_tests.cpp @@ -7,7 +7,6 @@ #include #include "common_test_utils/common_utils.hpp" -#include "file_utils.h" #include "openvino/core/any.hpp" #include "openvino/openvino.hpp" #include "openvino/util/file_util.hpp" diff --git a/src/frontends/onnx/tests/onnx_reader_external_data.cpp b/src/frontends/onnx/tests/onnx_reader_external_data.cpp index 6a501a38a93d88..128dc1a86ba1f7 100644 --- a/src/frontends/onnx/tests/onnx_reader_external_data.cpp +++ b/src/frontends/onnx/tests/onnx_reader_external_data.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include diff --git a/src/frontends/paddle/tests/read_paddle_model_test.cpp b/src/frontends/paddle/tests/read_paddle_model_test.cpp index 08beac86b67f24..521e14b79e7408 100644 --- a/src/frontends/paddle/tests/read_paddle_model_test.cpp +++ b/src/frontends/paddle/tests/read_paddle_model_test.cpp @@ -2,12 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include #include #include #include +#include #include #include diff --git a/src/frontends/tests/frontend/shared/include/utils.hpp b/src/frontends/tests/frontend/shared/include/utils.hpp index 8d4cce4e5196f1..6a771c98f0e7e9 100644 --- a/src/frontends/tests/frontend/shared/include/utils.hpp +++ b/src/frontends/tests/frontend/shared/include/utils.hpp @@ -9,7 +9,6 @@ #include #include "common_test_utils/file_utils.hpp" -#include "file_utils.h" #include "openvino/util/env_util.hpp" #include "openvino/util/file_util.hpp" diff --git a/src/inference/CMakeLists.txt b/src/inference/CMakeLists.txt index cc7422a456101f..abdf8f57e979c7 100644 --- a/src/inference/CMakeLists.txt +++ b/src/inference/CMakeLists.txt @@ -20,9 +20,6 @@ file (GLOB LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp_interfaces/interface/*.cpp ) -set(OV_STATIC_DEPENDENT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/file_utils.cpp) -list(REMOVE_ITEM LIBRARY_SRC ${OV_STATIC_DEPENDENT_FILES}) - file (GLOB LIBRARY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp @@ -83,7 +80,6 @@ source_group("include" FILES ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) # Create object library add_library(${TARGET_NAME}_obj OBJECT - ${OV_STATIC_DEPENDENT_FILES} ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) @@ -132,7 +128,7 @@ target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime) target_include_directories(${TARGET_NAME} INTERFACE $ $) -ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${OV_STATIC_DEPENDENT_FILES} ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) +ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS}) ov_ncc_naming_style(FOR_TARGET ${TARGET_NAME}_obj SOURCE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/include/openvino" diff --git a/src/inference/dev_api/file_utils.h b/src/inference/dev_api/file_utils.h deleted file mode 100644 index 870cc91a1fdff3..00000000000000 --- a/src/inference/dev_api/file_utils.h +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -/** - * @brief Basic function to work with file system and UNICODE symbols - * @file file_utils.h - */ - -#pragma once - -// clang-format off -#include -#include - -#include "ie_api.h" -#include "openvino/util/file_util.hpp" - -/// @ingroup ie_dev_api_file_utils -namespace FileUtils { - -/** - * @brief Enables only `char` or `wchar_t` template specializations - * @tparam C A char type - */ -template -using enableIfSupportedChar = - typename std::enable_if<(std::is_same::value || std::is_same::value)>::type; - -/** - * @brief Interface function to get absolute path of file - * @ingroup ie_dev_api_file_utils - * @param filePath - path to file, can be relative to current working directory - * @return Absolute path of file - * @throw InferenceEngine::Exception if any error occurred - */ -INFERENCE_ENGINE_API_CPP(std::string) absoluteFilePath(const std::string& filePath); - -/** - * @brief Interface function to create directorty recursively by given path - * @ingroup ie_dev_api_file_utils - * @param dirPath - path to file, can be relative to current working directory - * @throw InferenceEngine::Exception if any error occurred - */ -INFERENCE_ENGINE_API_CPP(void) createDirectoryRecursive(const std::string& dirPath); - -/** - * @brief Interface function to check if directory exists for given path - * @ingroup ie_dev_api_file_utils - * @param path - path to directory - * @return true if directory exists, false otherwise - */ -INFERENCE_ENGINE_API_CPP(bool) directoryExists(const std::string& path); - -/** - * @brief Interface function to get the size of a file. The function supports UNICODE path - * @ingroup ie_dev_api_file_utils - * @param fileName - name of the file - * @return size of the file - */ -INFERENCE_ENGINE_API(long long) fileSize(const char *fileName); - -#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -/** - * @brief Returns file size for file with UNICODE path name - * @ingroup ie_dev_api_file_utils - * - * @param[in] fileName The file name - * - * @return { description_of_the_return_value } - */ -inline long long fileSize(const wchar_t* fileName) { - return fileSize(::ov::util::wstring_to_string(fileName).c_str()); -} - -#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -/** - * @brief Function to get the size of a file. The function supports UNICODE path - * @ingroup ie_dev_api_file_utils - * @param f - string name of the file - * @return size of the file - */ -template > -inline long long fileSize(const std::basic_string &f) { - return fileSize(f.c_str()); -} - -/** - * @brief check if file with a given filename exists. The function supports UNICODE path - * @ingroup ie_dev_api_file_utils - * @param fileName - given filename - * @return true is exists - */ -template > -inline bool fileExist(const C * fileName) { - return fileSize(fileName) >= 0; -} - -/** - * @brief check if file with a given filename exists. The function supports UNICODE path - * @ingroup ie_dev_api_file_utils - * @param fileName - string with a given filename - * @return true is exists - */ -template > -inline bool fileExist(const std::basic_string &fileName) { - return fileExist(fileName.c_str()); -} - -/** - * @brief CPP Interface function to combint path with filename. The function supports UNICODE path - * @ingroup ie_dev_api_file_utils - * @param folder - path to add filename to - * @param file - filename to add to path - * @return string with combination of the path and the filename divided by file separator - */ - -template > -inline std::basic_string makePath(const std::basic_string &folder, const std::basic_string &file) { - if (folder.empty()) - return file; - return folder + ov::util::FileTraits::file_separator + file; -} - -/** - * @brief CPP Interface function to extract extension from filename - * @ingroup ie_dev_api_file_utils - * @param filename - string with the name of the file which extension should be extracted - * @return string with extracted file extension - */ -template > -inline std::basic_string fileExt(const std::basic_string &filename) { - auto pos = filename.rfind(ov::util::FileTraits::dot_symbol); - if (pos == std::string::npos) - return {}; - return filename.substr(pos + 1); -} - -template > -inline std::basic_string makePluginLibraryName(const std::basic_string &path, const std::basic_string &input) { - std::basic_string separator(1, ov::util::FileTraits::file_separator); - if (path.empty()) - separator = {}; - return path + separator + ov::util::FileTraits::library_prefix() + input + ov::util::FileTraits::dot_symbol + ov::util::FileTraits::library_ext(); -} - -} // namespace FileUtils -// clang-format on - -namespace InferenceEngine { - -/** - * @brief Returns a path to Inference Engine library - * @ingroup ie_dev_api_file_utils - * @return A `std::string` path to Inference Engine library - */ -INFERENCE_ENGINE_API_CPP(std::string) getIELibraryPath(); - -#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -/** - * @brief Returns a unicode path to Inference Engine library - * @ingroup ie_dev_api_file_utils - * @return A `std::wstring` path to Inference Engine library - */ -INFERENCE_ENGINE_API_CPP(std::wstring) getIELibraryPathW(); - -inline ::ov::util::FilePath getInferenceEngineLibraryPath() { - return getIELibraryPathW(); -} - -#else - -inline ::ov::util::FilePath getInferenceEngineLibraryPath() { - return getIELibraryPath(); -} - -#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -} // namespace InferenceEngine diff --git a/src/inference/src/compilation_context.cpp b/src/inference/src/compilation_context.cpp index 9d9df1754eab08..4b7b0b1e477b36 100644 --- a/src/inference/src/compilation_context.cpp +++ b/src/inference/src/compilation_context.cpp @@ -13,9 +13,9 @@ #include "cpp/ie_cnn_network.h" #include "details/ie_exception.hpp" -#include "file_utils.h" #include "itt.hpp" #include "openvino/pass/manager.hpp" +#include "openvino/util/file_util.hpp" #include "openvino/util/xml_parse_utils.hpp" #include "transformations/hash.hpp" #include "transformations/rt_info/fused_names_attribute.hpp" @@ -59,7 +59,7 @@ std::string ModelCache::calculate_file_info(const std::string& filePath) { auto absPath = filePath; if (filePath.size() > 0) { try { - absPath = FileUtils::absoluteFilePath(filePath); + absPath = ov::util::get_absolute_file_path(filePath); } catch (std::runtime_error&) { // can't get absolute path, will use filePath for hash } @@ -127,7 +127,7 @@ std::string ModelCache::compute_hash(const std::string& modelName, const ov::Any OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::ReadTime, "ModelCache::compute_hash - ModelName"); uint64_t seed = 0; try { - seed = hash_combine(seed, FileUtils::absoluteFilePath(modelName)); + seed = hash_combine(seed, ov::util::get_absolute_file_path(modelName)); } catch (...) { // can't get absolute path, use modelName for hash calculation seed = hash_combine(seed, modelName); diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp index 6ab1a69f0f8d92..83d7077d5d071c 100644 --- a/src/inference/src/dev/core_impl.cpp +++ b/src/inference/src/dev/core_impl.cpp @@ -1616,7 +1616,7 @@ ov::CoreImpl::CoreConfig::CacheConfig ov::CoreImpl::CoreConfig::CacheConfig::cre std::shared_ptr cache_manager = nullptr; if (!dir.empty()) { - FileUtils::createDirectoryRecursive(dir); + ov::util::create_directory_recursive(dir); cache_manager = std::make_shared(dir); } diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hpp index e7fa69178e282a..b62d8f05a127a2 100644 --- a/src/inference/src/dev/core_impl.hpp +++ b/src/inference/src/dev/core_impl.hpp @@ -183,7 +183,7 @@ class CoreImpl : public InferenceEngine::ICore, public std::enable_shared_from_t bool is_hidden_device(const std::string& device_name) const; void register_plugin_in_registry_unsafe(const std::string& device_name, PluginDescriptor& desc); - template > + template > void try_to_register_plugin_extensions(const std::basic_string& path) const { try { auto plugin_extensions = ov::detail::load_extensions(path); diff --git a/src/inference/src/file_utils.cpp b/src/inference/src/file_utils.cpp deleted file mode 100644 index b4602873988ccd..00000000000000 --- a/src/inference/src/file_utils.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (C) 2018-2023 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#ifndef FILE_UTILS_CPP -#define FILE_UTILS_CPP - -#include -#include -#include - -#ifdef __MACH__ -# include -# include -#endif - -#include -#include -#include - -#include "ie_common.h" -#include "openvino/core/except.hpp" -#include "openvino/util/file_util.hpp" - -#ifndef _WIN32 -# include -# include -# include -#else -# if defined(WINAPI_FAMILY) && !WINAPI_PARTITION_DESKTOP -# error "Only WINAPI_PARTITION_DESKTOP is supported, because of GetModuleHandleEx[A|W]" -# endif -# ifndef NOMINMAX -# define NOMINMAX -# endif -# include -#endif - -long long FileUtils::fileSize(const char* charfilepath) { - return ov::util::file_size(charfilepath); -} - -std::string FileUtils::absoluteFilePath(const std::string& filePath) { - return ov::util::get_absolute_file_path(filePath); -} - -bool FileUtils::directoryExists(const std::string& path) { - return ov::util::directory_exists(path); -} - -void FileUtils::createDirectoryRecursive(const std::string& dirPath) { - ov::util::create_directory_recursive(dirPath); -} - -namespace InferenceEngine { - -namespace { - -template > -std::basic_string getPathName(const std::basic_string& s) { - size_t i = s.rfind(ov::util::FileTraits::file_separator, s.length()); - if (i != std::string::npos) { - return (s.substr(0, i)); - } - - return {}; -} - -#if defined __GNUC__ || defined __clang__ -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-function" -#endif - -std::string getIELibraryPathA() { -#ifdef _WIN32 - CHAR ie_library_path[MAX_PATH]; - HMODULE hm = NULL; - if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(getIELibraryPath), - &hm)) { - OPENVINO_THROW("GetModuleHandle returned ", GetLastError()); - } - GetModuleFileNameA(hm, (LPSTR)ie_library_path, sizeof(ie_library_path)); - return getPathName(std::string(ie_library_path)); -#elif defined(__APPLE__) || defined(__linux__) || defined(__EMSCRIPTEN__) -# ifdef USE_STATIC_IE -# ifdef __APPLE__ - Dl_info info; - dladdr(reinterpret_cast(getIELibraryPath), &info); - std::string path = getPathName(std::string(info.dli_fname)); -# else - char result[PATH_MAX]; - ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); - std::string path = getPathName(std::string(result, (count > 0) ? count : 0)); -# endif // __APPLE__ - return FileUtils::makePath(path, std::string("lib")); -# else - Dl_info info; - dladdr(reinterpret_cast(getIELibraryPath), &info); - std::string path = FileUtils::absoluteFilePath(info.dli_fname); - return getPathName(path); -# endif // USE_STATIC_IE -#else -# error "Unsupported OS" -#endif // _WIN32 -} - -#if defined __GNUC__ || defined __clang__ -# pragma GCC diagnostic pop -#endif - -} // namespace - -#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -std::wstring getIELibraryPathW() { -# ifdef _WIN32 - WCHAR ie_library_path[MAX_PATH]; - HMODULE hm = NULL; - if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast(getIELibraryPath), - &hm)) { - OPENVINO_THROW("GetModuleHandle returned ", GetLastError()); - } - GetModuleFileNameW(hm, (LPWSTR)ie_library_path, sizeof(ie_library_path) / sizeof(ie_library_path[0])); - return getPathName(std::wstring(ie_library_path)); -# elif defined(__linux__) || defined(__APPLE__) || defined(__EMSCRIPTEN__) - return ::ov::util::string_to_wstring(getIELibraryPathA().c_str()); -# else -# error "Unsupported OS" -# endif -} - -#endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - -std::string getIELibraryPath() { -#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT - return ov::util::wstring_to_string(getIELibraryPathW()); -#else - return getIELibraryPathA(); -#endif -} - -} // namespace InferenceEngine - -#endif diff --git a/src/inference/src/ie_cache_manager.hpp b/src/inference/src/ie_cache_manager.hpp index 09a0f57e5f1309..01f6cc943d68ab 100644 --- a/src/inference/src/ie_cache_manager.hpp +++ b/src/inference/src/ie_cache_manager.hpp @@ -14,8 +14,8 @@ #include #include -#include "file_utils.h" #include "ie_api.h" +#include "openvino/util/file_util.hpp" namespace ov { @@ -82,7 +82,7 @@ class FileStorageCacheManager final : public ICacheManager { std::string m_cachePath; std::string getBlobFile(const std::string& blobHash) const { - return FileUtils::makePath(m_cachePath, blobHash + ".blob"); + return ov::util::make_path(m_cachePath, blobHash + ".blob"); } public: @@ -106,7 +106,7 @@ class FileStorageCacheManager final : public ICacheManager { void read_cache_entry(const std::string& id, StreamReader reader) override { auto blobFileName = getBlobFile(id); - if (FileUtils::fileExist(blobFileName)) { + if (ov::util::file_exists(blobFileName)) { std::ifstream stream(blobFileName, std::ios_base::binary); reader(stream); } @@ -114,7 +114,7 @@ class FileStorageCacheManager final : public ICacheManager { void remove_cache_entry(const std::string& id) override { auto blobFileName = getBlobFile(id); - if (FileUtils::fileExist(blobFileName)) + if (ov::util::file_exists(blobFileName)) std::remove(blobFileName.c_str()); } }; diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 83bde0a46bd099..85684bdc869bfe 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -22,7 +22,6 @@ #include "cpp_interfaces/interface/ie_internal_plugin_config.hpp" #include "dev/converter_utils.hpp" #include "dev/core_impl.hpp" -#include "file_utils.h" #include "ie_cache_manager.hpp" #include "ie_icore.hpp" #include "ie_network_reader.hpp" diff --git a/src/inference/src/ie_network_reader.cpp b/src/inference/src/ie_network_reader.cpp index dc64c6831ce6a3..4732f4c69bf30e 100644 --- a/src/inference/src/ie_network_reader.cpp +++ b/src/inference/src/ie_network_reader.cpp @@ -14,7 +14,6 @@ #include "cnn_network_ngraph_impl.hpp" #include "cpp/ie_cnn_network.h" #include "dev/converter_utils.hpp" -#include "file_utils.h" #include "ie_api.h" #include "ie_common.h" #include "ie_icnn_network.hpp" @@ -28,6 +27,7 @@ #include "openvino/frontend/manager.hpp" #include "openvino/runtime/shared_buffer.hpp" #include "openvino/runtime/so_ptr.hpp" +#include "openvino/util/file_util.hpp" #include "openvino/util/shared_object.hpp" #include "transformations/rt_info/old_api_map_order_attribute.hpp" #include "transformations/utils/utils.hpp" diff --git a/src/inference/tests/functional/ov_shared_object_test.cpp b/src/inference/tests/functional/ov_shared_object_test.cpp index 3c268ea94fa610..424adb88cddcbc 100644 --- a/src/inference/tests/functional/ov_shared_object_test.cpp +++ b/src/inference/tests/functional/ov_shared_object_test.cpp @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 // -#include #include +#include + #include "common_test_utils/file_utils.hpp" #include "cpp_interfaces/interface/ie_iplugin_internal.hpp" #include "openvino/util/shared_object.hpp" @@ -15,8 +16,8 @@ using namespace std; class SharedObjectOVTests : public ::testing::Test { protected: std::string get_mock_engine_name() { - return FileUtils::makePluginLibraryName(ov::test::utils::getExecutableDirectory(), - std::string("mock_engine") + OV_BUILD_POSTFIX); + return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), + std::string("mock_engine") + OV_BUILD_POSTFIX); } void loadDll(const string& libraryName) { diff --git a/src/inference/tests/unit/core.cpp b/src/inference/tests/unit/core.cpp index 8cb1cfc8f74ca7..c654787bd9d056 100644 --- a/src/inference/tests/unit/core.cpp +++ b/src/inference/tests/unit/core.cpp @@ -12,7 +12,6 @@ #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_assertions.hpp" #include "dev/core_impl.hpp" -#include "file_utils.h" #include "openvino/op/relu.hpp" #include "openvino/util/file_util.hpp" @@ -57,7 +56,7 @@ TEST(CoreTests_get_plugin_path_from_xml, Use_abs_path_as_is) { TEST(CoreTests_get_plugin_path_from_xml, Convert_relative_path_as_relative_to_xmldir) { auto xml_path = "path_to_plugins.xml"; - auto lib_path = FileUtils::makePath(std::string("."), std::string("test_name.ext")); // ./test_name.ext + auto lib_path = ov::util::make_path(std::string("."), std::string("test_name.ext")); // ./test_name.ext for (auto as_abs_only : std::vector{true, false}) { auto abs_path = from_file_path(get_plugin_path(lib_path, xml_path, as_abs_only)); // XMLDIR/test_name.ext EXPECT_TRUE(is_absolute_file_path(abs_path)); @@ -73,7 +72,7 @@ TEST(CoreTests_get_plugin_path_from_xml, Convert_filename_to_abs_path_if_as_abs_ auto abs_path = from_file_path(get_plugin_path(name, xml_path, true)); // XMLDIR/libtest_name.ext.so EXPECT_TRUE(is_absolute_file_path(abs_path)); - auto lib_name = FileUtils::makePluginLibraryName({}, std::string(name)); + auto lib_name = ov::util::make_plugin_library_name({}, std::string(name)); auto ref_path = ov::util::get_absolute_file_path(lib_name); EXPECT_STREQ(abs_path.c_str(), ref_path.c_str()); // XMLDIR/libtest_name.ext.so == CWD/libtest_name.ext.so } @@ -82,12 +81,12 @@ TEST(CoreTests_get_plugin_path_from_xml, Use_filename_if_not_as_abs_only) { auto xml_path = "path_to_plugins.xml"; auto name = "test_name.ext"; // test_name.ext auto lib_name = from_file_path(get_plugin_path(name, xml_path)); // libtest_name.ext.so - auto ref_name = FileUtils::makePluginLibraryName({}, std::string(name)); + auto ref_name = ov::util::make_plugin_library_name({}, std::string(name)); EXPECT_STREQ(lib_name.c_str(), ref_name.c_str()); } TEST(CoreTests_get_plugin_path, Use_abs_path_as_is) { - auto lib_name = FileUtils::makePluginLibraryName({}, std::string("test_name")); // libtest_name.so + auto lib_name = ov::util::make_plugin_library_name({}, std::string("test_name")); // libtest_name.so auto lib_path = ov::util::get_absolute_file_path(lib_name); auto abs_path = from_file_path(get_plugin_path(lib_path)); EXPECT_TRUE(is_absolute_file_path(abs_path)); @@ -95,7 +94,8 @@ TEST(CoreTests_get_plugin_path, Use_abs_path_as_is) { } TEST(CoreTests_get_plugin_path, Relative_path_is_from_workdir) { - auto lib_name = FileUtils::makePluginLibraryName(std::string("."), std::string("test_name")); // ./libtest_name.so + auto lib_name = + ov::util::make_plugin_library_name(std::string("."), std::string("test_name")); // ./libtest_name.so auto abs_path = from_file_path(get_plugin_path(lib_name)); EXPECT_TRUE(is_absolute_file_path(abs_path)); EXPECT_STREQ(abs_path.c_str(), get_absolute_file_path(lib_name).c_str()); @@ -114,8 +114,8 @@ class CoreTests_get_plugin_path_Class : public ::testing::Test { std::remove(lib_path.c_str()); } - std::string lib_name = FileUtils::makePluginLibraryName({}, std::string("test_name")); // libtest_name.so - std::string lib_path = ov::util::get_absolute_file_path(lib_name); // CWD/libtest_name.so + std::string lib_name = ov::util::make_plugin_library_name({}, std::string("test_name")); // libtest_name.so + std::string lib_path = ov::util::get_absolute_file_path(lib_name); // CWD/libtest_name.so }; TEST_F(CoreTests_get_plugin_path_Class, Filename_is_from_workdir_if_exists) { @@ -129,7 +129,7 @@ TEST(CoreTests_get_plugin_path, Use_filename_as_is_if_not_exist_in_workdir) { auto abs_path = from_file_path(get_plugin_path(lib_name)); // libtest_name.ext.so -> libtest_name.ext.so EXPECT_FALSE(is_absolute_file_path(abs_path)); - auto ref_path = FileUtils::makePluginLibraryName({}, std::string(lib_name)); + auto ref_path = ov::util::make_plugin_library_name({}, std::string(lib_name)); EXPECT_STREQ(abs_path.c_str(), ref_path.c_str()); } diff --git a/src/plugins/intel_cpu/tests/functional/extension/extension.cpp b/src/plugins/intel_cpu/tests/functional/extension/extension.cpp index 46b62c605e5065..7357b9be723d55 100644 --- a/src/plugins/intel_cpu/tests/functional/extension/extension.cpp +++ b/src/plugins/intel_cpu/tests/functional/extension/extension.cpp @@ -2,13 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "openvino/frontend/extension.hpp" + #include #include "common_test_utils/file_utils.hpp" #include "common_test_utils/test_assertions.hpp" -#include "file_utils.h" -#include "openvino/frontend/extension.hpp" #include "openvino/runtime/core.hpp" +#include "openvino/util/file_util.hpp" using testing::ElementsAreArray; @@ -65,8 +66,8 @@ static void infer_model(ov::Core& core, } static std::string model_full_path(const char* path) { - return FileUtils::makePath( - FileUtils::makePath(ov::test::utils::getExecutableDirectory(), TEST_MODELS), path); + return ov::util::make_path(ov::util::make_path(ov::test::utils::getExecutableDirectory(), TEST_MODELS), + path); } TEST(Extension, XmlModelWithCustomAbs) { @@ -122,8 +123,8 @@ TEST(Extension, XmlModelWithCustomAbs) { static std::string get_extension_path() { - return FileUtils::makePluginLibraryName(ov::test::utils::getExecutableDirectory(), - std::string("openvino_template_extension") + OV_BUILD_POSTFIX); + return ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(), + std::string("openvino_template_extension") + OV_BUILD_POSTFIX); } TEST(Extension, smoke_XmlModelWithExtensionFromDSO) { diff --git a/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp b/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp index bc4c02679070df..28b2c2b1843a06 100644 --- a/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp +++ b/src/tests/functional/plugin/shared/src/onnx/quantized_models_tests.cpp @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include -#include "common_test_utils/file_utils.hpp" #include "onnx/quantized_models_tests.hpp" +#include + +#include "common_test_utils/file_utils.hpp" + namespace ONNXTestsDefinitions { std::string QuantizedModelsTests::getTestCaseName(const testing::TestParamInfo& obj) { @@ -20,8 +22,8 @@ void QuantizedModelsTests::SetUp() { } static std::string getModelFullPath(const char* path) { - return FileUtils::makePath( - FileUtils::makePath(ov::test::utils::getExecutableDirectory(), TEST_MODELS), path); + return ov::util::make_path(ov::util::make_path(ov::test::utils::getExecutableDirectory(), TEST_MODELS), + path); } void QuantizedModelsTests::run_model(const char* model, const LayerInputTypes& expected_layer_input_types, float thr) { diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp index 9b72fa448ee8b3..df0260400f27d9 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/unicode_utils.hpp @@ -11,8 +11,8 @@ #include "common_test_utils/common_utils.hpp" #include "common_test_utils/w_dirent.h" -#include "file_utils.h" #include "gtest/gtest.h" +#include "openvino/util/file_util.hpp" #ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT @@ -95,7 +95,7 @@ inline int removeFilesWithExt(std::wstring path, std::wstring ext) { _WDIR* dir = _wopendir(path.c_str()); if (dir != nullptr) { while ((ent = _wreaddir(dir)) != NULL) { - auto file = ::FileUtils::makePath(path, std::wstring(ent->wd_name)); + auto file = ov::util::make_path(path, std::wstring(ent->wd_name)); struct _stat64i32 stat_path; _wstat(file.c_str(), &stat_path); if (!S_ISDIR(stat_path.st_mode) && endsWith(file, L"." + ext)) { @@ -116,7 +116,7 @@ inline int removeFilesWithExt(std::wstring path, std::wstring ext) { DIR* dir = opendir(path_mb.c_str()); if (dir != nullptr) { while ((ent = readdir(dir)) != NULL) { - std::string file = ::FileUtils::makePath(path_mb, std::string(ent->d_name)); + std::string file = ov::util::make_path(path_mb, std::string(ent->d_name)); struct stat stat_path; stat(file.c_str(), &stat_path); if (!S_ISDIR(stat_path.st_mode) && endsWith(file, "." + ext_mb)) {