diff --git a/src/core/include/ngraph/validation_util.hpp b/src/core/include/ngraph/validation_util.hpp index 78e604d7bcded4..500a258747dc43 100644 --- a/src/core/include/ngraph/validation_util.hpp +++ b/src/core/include/ngraph/validation_util.hpp @@ -105,15 +105,6 @@ ov::PartialShape infer_slice_shape(const Node* node, const ov::AxisSet& shrink_axis_mask, const ov::AxisSet& ellipsis_mask); -/// \brief Try to compute the maximum value of value -/// \return (true, max_value) if can be determined, or (false, numeric_limits::max()) -/// if not. -/// \deprecated Use evaluate_upper_bound instead -OPENVINO_DEPRECATED("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") -OPENVINO_API std::pair maximum_value(const ov::Output& value); - /// \brief Returns a Constant storing scalar value equal to std::numeric_limits::max() OPENVINO_DEPRECATED("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 " diff --git a/src/core/include/ngraph/evaluator.hpp b/src/core/src/evaluator.hpp similarity index 72% rename from src/core/include/ngraph/evaluator.hpp rename to src/core/src/evaluator.hpp index a2a17432effccf..8705b44c3eb5f5 100644 --- a/src/core/include/ngraph/evaluator.hpp +++ b/src/core/src/evaluator.hpp @@ -4,46 +4,31 @@ #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 "ngraph/shape.hpp" -#include "openvino/core/deprecated.hpp" #include "openvino/core/node.hpp" #include "openvino/core/type/element_type_traits.hpp" -namespace ngraph { +namespace ov { /// \brief Execute handlers on a subgraph to compute values /// /// template -class OPENVINO_DEPRECATED("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") Evaluator { - OPENVINO_SUPPRESS_DEPRECATED_START +class Evaluator { 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(ov::Node* op, std::vector& inputs)>; + using op_handler = std::function(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. /// @@ -80,7 +65,7 @@ class OPENVINO_DEPRECATED("The nGraph API is deprecated and will be removed in t } protected: - op_handler get_handler(ov::Node* node) { + op_handler get_handler(Node* node) { op_handler handler = m_universal_handler; if (!handler) { auto it = m_handlers.find(node->get_type_info()); @@ -100,27 +85,27 @@ class OPENVINO_DEPRECATED("The nGraph API is deprecated and will be removed in t /// \brief Intstructions for evaluations state machine class Inst { protected: - Inst(ov::Node* node) : m_node(node) {} + Inst(Node* node) : m_node(node) {} public: virtual ~Inst() {} - virtual void handle(Evaluator& evaluator, InstStack& inst_stack, ov::Node* node) = 0; - ov::Node* get_node() { + virtual void handle(Evaluator& evaluator, InstStack& inst_stack, Node* node) = 0; + Node* get_node() { return m_node; } protected: - ov::Node* m_node; + 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 Output& value) : Inst(value.get_node()), m_index(value.get_index()) {} - ValueInst(const ov::RawNodeOutput& value) : Inst(value.node), m_index(value.index) {} + ValueInst(const RawNodeOutput& value) : Inst(value.node), m_index(value.index) {} - void handle(Evaluator& evaluator, InstStack& inst_stack, ov::Node* node) override { + void handle(Evaluator& evaluator, InstStack& inst_stack, 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 @@ -143,9 +128,9 @@ class OPENVINO_DEPRECATED("The nGraph API is deprecated and will be removed in t /// \brief All arguments have been handled; execute the node handler class ExecuteInst : public Inst { public: - ExecuteInst(ov::Node* node, op_handler& handler) : Inst(node), m_handler(handler) {} + ExecuteInst(Node* node, op_handler& handler) : Inst(node), m_handler(handler) {} - void handle(Evaluator& evaluator, InstStack& inst_stack, ov::Node* node) override { + void handle(Evaluator& evaluator, InstStack& inst_stack, 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; @@ -164,7 +149,7 @@ class OPENVINO_DEPRECATED("The nGraph API is deprecated and will be removed in t public: /// \brief Determine information about value - V evaluate(const ov::Output& value) { + V evaluate(const Output& value) { InstStack inst_stack; inst_stack.push(InstPtr(new ValueInst(value))); while (!inst_stack.empty()) { @@ -186,6 +171,5 @@ class OPENVINO_DEPRECATED("The nGraph API is deprecated and will be removed in t op_handler_map m_handlers; op_handler m_default_handler; value_map& m_value_map; - OPENVINO_SUPPRESS_DEPRECATED_END }; -} // namespace ngraph +} // namespace ov diff --git a/src/core/src/model.cpp b/src/core/src/model.cpp index 16138ae3765931..b0d1ad56f93ea5 100644 --- a/src/core/src/model.cpp +++ b/src/core/src/model.cpp @@ -8,9 +8,9 @@ #include #include +#include "evaluator.hpp" #include "itt.hpp" #include "layout_utils.hpp" -#include "ngraph/evaluator.hpp" #include "openvino/core/attribute_visitor.hpp" #include "openvino/core/except.hpp" #include "openvino/core/meta_data.hpp" @@ -521,8 +521,7 @@ bool ov::Model::evaluate(ov::TensorVector& output_tensors, outputs.push_back(m_sink); } // evaluate nodes - OPENVINO_SUPPRESS_DEPRECATED_START - ngraph::Evaluator evaluator({}, value_map); + Evaluator evaluator({}, value_map); evaluator.set_universal_handler( [&output_tensor_map, &evaluation_context](Node* node, const ov::TensorVector& input_tensors) -> ov::TensorVector { @@ -551,7 +550,6 @@ bool ov::Model::evaluate(ov::TensorVector& output_tensors, for (const auto& value : outputs) { evaluator.evaluate(value); } - OPENVINO_SUPPRESS_DEPRECATED_END for (size_t i = 0; i < m_results.size(); ++i) { auto result = m_results.at(i)->output(0); output_tensors.at(i) = output_tensor_map[result]; diff --git a/src/core/src/validation_util.cpp b/src/core/src/validation_util.cpp index cccc848729015e..8b59a6941ff004 100644 --- a/src/core/src/validation_util.cpp +++ b/src/core/src/validation_util.cpp @@ -9,7 +9,6 @@ #include "bound_evaluate.hpp" #include "compare.hpp" -#include "ngraph/evaluator.hpp" #include "openvino/core/dimension_tracker.hpp" #include "openvino/op/concat.hpp" #include "openvino/op/gather.hpp" @@ -526,155 +525,8 @@ struct MaxValue { std::vector m_slices; int64_t m_slice_axis{-1}; }; - -std::vector exec_constant(Node* node, std::vector& inputs) { - auto result = MaxValue(); - auto op = ov::as_type(node); - auto element_type = op->get_output_element_type(0); - if (element_type.is_integral()) { - uint64_t max_val = 0; - if (element_type.is_signed()) { - for (auto elt : op->cast_vector()) { - if (max_val < static_cast(elt)) { - max_val = elt; - } - } - } else { - for (auto elt : op->cast_vector()) { - if (max_val < elt) { - max_val = elt; - } - } - } - result = MaxValue(max_val); - } - return {result}; -} - -std::vector exec_minimum(Node* node, std::vector& inputs) { - uint64_t min_value = std::numeric_limits::max(); - switch (node->get_output_element_type(0)) { - case element::Type_t::i8: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::i16: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::i32: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::i64: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::u8: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::u16: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::u32: - min_value = std::numeric_limits::max(); - break; - case element::Type_t::u64: - min_value = std::numeric_limits::max(); - break; - default: - break; - } - min_value = std::min(min_value, inputs.at(0).m_value); - min_value = std::min(min_value, inputs.at(1).m_value); - return {MaxValue(min_value)}; -} - -std::vector exec_concat(Node* node, std::vector& inputs) { - auto op = ov::as_type(node); - std::vector slice_maxen; - for (const auto& input : inputs) { - slice_maxen.push_back(input.m_value); - } - auto axis = op->get_concatenation_axis(); - return {MaxValue(slice_maxen, axis)}; -} - -std::vector exec_reduce_min(Node* node, std::vector& inputs) { - auto data = inputs.at(0); - if (data.m_slice_axis >= 0 && data.m_slices.size() > 1) { - if (auto indices_const = ov::as_type(node->get_input_node_ptr(1))) { - if (indices_const->get_output_element_type(0).is_integral()) { - const auto& indices_shape = indices_const->get_output_shape(0); - if (indices_shape == Shape{1}) { - auto indices = indices_const->cast_vector(); - auto axis = indices.at(0); - if (axis == data.m_slice_axis) { - return {MaxValue(*min_element(data.m_slices.begin(), data.m_slices.end()))}; - } - } - } - } - } - // Noting we can do - return {MaxValue(data.m_value)}; -} - -std::vector exec_shape_of(Node* node, std::vector& inputs) { - const auto& inputPS = node->get_input_partial_shape(0); - std::vector shapeDims; - for (int64_t i = 0; i < inputPS.rank().get_length(); i++) { - if (inputPS[i].is_static()) { - shapeDims.push_back(inputPS[i].get_length()); - } else { - shapeDims.push_back(std::numeric_limits::max()); - } - } - - return {MaxValue(shapeDims, 0)}; -} - -std::vector exec_gather(Node* node, std::vector& inputs) { - auto gather = ov::as_type(node); - - const auto& indices = ov::as_type_ptr(node->input_value(1).get_node_shared_ptr()); - const auto& axis = ov::as_type_ptr(node->input_value(2).get_node_shared_ptr()); - - if (!indices || !axis) { - return {MaxValue()}; - } - - if (gather->get_axis() != 0) { - return {MaxValue()}; - } - - const auto& indicesVec = indices->cast_vector(); - if (indicesVec.size() != 1 || indicesVec[0] >= static_cast(inputs[0].m_slices.size())) { - return {MaxValue()}; - } - - return {MaxValue(inputs[0].m_slices[indicesVec[0]])}; -} - -std::vector exec_nop(Node* node, std::vector& inputs) { - return {inputs.at(0)}; -} } // namespace -std::pair maximum_value(const ov::Output& value) { - static ngraph::Evaluator::op_handler_map handlers = { - {ov::op::v0::Concat::get_type_info_static(), exec_concat}, - {ov::op::v0::Constant::get_type_info_static(), exec_constant}, - {ov::op::v0::Convert::get_type_info_static(), exec_nop}, - {ov::op::v1::Gather::get_type_info_static(), exec_gather}, - {ov::op::v1::Minimum::get_type_info_static(), exec_minimum}, - {ov::op::v1::ReduceMin::get_type_info_static(), exec_reduce_min}, - {ov::op::v1::Reshape::get_type_info_static(), exec_nop}, - {ov::op::v3::ShapeOf::get_type_info_static(), exec_shape_of}, - {ov::op::v0::Squeeze::get_type_info_static(), exec_nop}, - {ov::op::v0::Unsqueeze::get_type_info_static(), exec_nop}}; - Evaluator::value_map value_map; - Evaluator evaluator(handlers, value_map); - auto val = evaluator.evaluate(value); - return std::pair(val.m_value < std::numeric_limits::max(), val.m_value); -} - std::shared_ptr get_constant_max_of_type(element::Type_t t) { auto tensor = ov::util::make_tensor_of_max_value(t); return tensor ? std::make_shared(tensor) : nullptr;