Move new util functions from public api to dev api (#16683)
This commit is contained in:
1 parent
186a1ccdcd
commit
e978db3132
7 files changed
+65
-53
No files matched your search
+4
-4
@@ -4,10 +4,10 @@
|
||||
|
||||
#include "transformations/common_optimizations/push_constant_to_subgraph.hpp"
|
||||
|
||||
#include <openvino/core/validation_util.hpp>
|
||||
#include <openvino/op/util/multi_subgraph_base.hpp>
|
||||
|
||||
#include "itt.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/util/multi_subgraph_base.hpp"
|
||||
#include "validation_util.hpp"
|
||||
|
||||
using MultiSubGraphOp = ov::op::util::MultiSubGraphOp;
|
||||
|
||||
@@ -21,7 +21,7 @@ static std::shared_ptr<ov::op::v0::Constant> try_constantfold_input(
|
||||
const auto input_index = input_desc->m_input_index;
|
||||
auto it = cache.find(input_index);
|
||||
if (it == cache.end()) {
|
||||
auto constant = constantfold_subgraph(op->input_value(input_index));
|
||||
auto constant = ov::util::constantfold_subgraph(op->input_value(input_index));
|
||||
if (constant) {
|
||||
cache.insert({input_index, constant});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openvino/core/node.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace util {
|
||||
/// \brief Normalize value to the max if value is negative.
|
||||
///
|
||||
/// \param value Input value to normalize.
|
||||
/// \param max Value used for normalization
|
||||
///
|
||||
/// \return Value if positive otherwise return value + max
|
||||
OPENVINO_API int64_t normalize(const int64_t& value, const int64_t& max);
|
||||
|
||||
/// \brief Check if values in vector are unique.
|
||||
///
|
||||
/// \param data Input data to check.
|
||||
///
|
||||
/// \return True if unique otherwise false.
|
||||
OPENVINO_API bool are_unique(const std::vector<int64_t>& data);
|
||||
|
||||
/// \brief Clip value to minimum if below min, or to maximum of above max.
|
||||
///
|
||||
/// \param value Value to be clipped.
|
||||
/// \param min Minimum value bound.
|
||||
/// \param max Maximum value boiund
|
||||
///
|
||||
/// \return Value if between min, max otherwise min or max.
|
||||
OPENVINO_API int64_t clip(const int64_t& value, const int64_t& min, const int64_t& max);
|
||||
|
||||
/// \brief Constant folds a subgraph to a constant node
|
||||
///
|
||||
/// \param subgraph sink
|
||||
///
|
||||
/// \return Constant node or nullptr if unable to constantfold the subgraph
|
||||
OPENVINO_API std::shared_ptr<op::v0::Constant> constantfold_subgraph(const Output<Node>& subgraph_sink);
|
||||
} // namespace util
|
||||
} // namespace ov
|
||||
@@ -30,15 +30,6 @@ void infer_auto_padding(const Shape& image_shape,
|
||||
CoordinateDiff& padding_above,
|
||||
CoordinateDiff& padding_below);
|
||||
|
||||
/// \brief Normalize value to the max if value is negative.
|
||||
///
|
||||
/// \param value Input value to normalize.
|
||||
/// \param max Value used for normalization
|
||||
///
|
||||
/// \return Value if positive otherwise return value + max
|
||||
OPENVINO_API
|
||||
int64_t normalize(const int64_t& value, const int64_t& max);
|
||||
|
||||
/// \brief Handle out of range axis.
|
||||
///
|
||||
/// \param[in] node The node with requested axis.
|
||||
@@ -182,26 +173,4 @@ OPENVINO_API std::vector<PartialShape> get_node_input_partial_shapes(const ov::N
|
||||
/// \return True if rank compatible to any from ranks, otherwise false.
|
||||
OPENVINO_API bool is_rank_compatible_any_of(const ov::Rank& rank, const std::vector<ov::Rank>& ranks);
|
||||
|
||||
/// \brief Check if values in vector are unique.
|
||||
///
|
||||
/// \param data Input data to check.
|
||||
///
|
||||
/// \return True if unique otherwise false.
|
||||
OPENVINO_API bool are_unique(const std::vector<int64_t>& data);
|
||||
|
||||
/// \brief Clip value to minimum if below min, or to maximum of above max.
|
||||
///
|
||||
/// \param value Value to be clipped.
|
||||
/// \param min Minimum value bound.
|
||||
/// \param max Maximum value boiund
|
||||
///
|
||||
/// \return Value if between min, max otherwise min or max.
|
||||
OPENVINO_API int64_t clip(const int64_t& value, const int64_t& min, const int64_t& max);
|
||||
|
||||
/// \brief Constant folds a subgraph to a constant node
|
||||
///
|
||||
/// \param subgraph sink
|
||||
///
|
||||
/// \return Constant node or nullptr if unable to constantfold the subgraph
|
||||
OPENVINO_API std::shared_ptr<op::v0::Constant> constantfold_subgraph(const Output<Node>& subgraph_sink);
|
||||
} // namespace ov
|
||||
@@ -4,11 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ngraph/validation_util.hpp>
|
||||
#include <openvino/op/constant.hpp>
|
||||
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "sequnce_generator.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "validation_util.hpp"
|
||||
|
||||
namespace ov {
|
||||
namespace internal {
|
||||
@@ -161,8 +160,8 @@ inline int64_t get_sliced_value(const int64_t& dim, const int64_t& start, const
|
||||
}
|
||||
lb = min_bound;
|
||||
} else {
|
||||
lb = clip(normalize(start, norm_dim), min_bound, lower_max);
|
||||
ub = clip(normalize(stop, norm_dim), upper_min, norm_dim);
|
||||
lb = ov::util::clip(ov::util::normalize(start, norm_dim), min_bound, lower_max);
|
||||
ub = ov::util::clip(ov::util::normalize(stop, norm_dim), upper_min, norm_dim);
|
||||
}
|
||||
|
||||
// Calculate sliced value from bounds and step.
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "itt.hpp"
|
||||
#include "ngraph/attribute_visitor.hpp"
|
||||
#include "ngraph/runtime/reference/concat.hpp"
|
||||
#include "ngraph/validation_util.hpp"
|
||||
#include "validation_util.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
@@ -115,7 +115,7 @@ bool op::Concat::evaluate(ov::TensorVector& outputs, const ov::TensorVector& inp
|
||||
OPENVINO_ASSERT(!inputs.empty());
|
||||
OPENVINO_ASSERT(outputs.size() == 1);
|
||||
|
||||
auto concat_axis = ov::normalize(get_axis(), inputs.front().get_shape().size());
|
||||
auto concat_axis = ov::util::normalize(get_axis(), inputs.front().get_shape().size());
|
||||
|
||||
std::vector<const char*> arg_bufs;
|
||||
std::vector<ov::Shape> arg_shapes;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "ngraph/util.hpp"
|
||||
#include "openvino/op/ops.hpp"
|
||||
#include "sequnce_generator.hpp"
|
||||
#include "validation_util.hpp"
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
using namespace std;
|
||||
@@ -872,7 +873,7 @@ std::string normalize_axis_error_msg(const int64_t& axis, const int64_t& lower,
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int64_t ov::normalize(const int64_t& value, const int64_t& max) {
|
||||
int64_t ov::util::normalize(const int64_t& value, const int64_t& max) {
|
||||
return (value < 0) ? value + max : value;
|
||||
};
|
||||
|
||||
@@ -937,7 +938,7 @@ int64_t ov::normalize_axis(const std::string& node_description,
|
||||
OPENVINO_ASSERT((axis_range_min <= axis) && (axis <= axis_range_max),
|
||||
node_description,
|
||||
normalize_axis_error_msg(axis, axis_range_min, axis_range_max));
|
||||
return normalize(axis, tensor_rank);
|
||||
return util::normalize(axis, tensor_rank);
|
||||
}
|
||||
|
||||
void ngraph::opset1::infer_conv_backprop_auto_padding(const Shape& input_data_shape,
|
||||
@@ -1312,7 +1313,7 @@ void ov::generate_transpose_default_order(std::vector<int64_t>& axes_order, cons
|
||||
}
|
||||
|
||||
bool ov::is_valid_axes_order(const std::vector<int64_t>& axes_order, const size_t size) {
|
||||
return are_unique(axes_order) &&
|
||||
return util::are_unique(axes_order) &&
|
||||
std::all_of(axes_order.cbegin(), axes_order.cend(), ov::cmp::Between<int64_t, ov::cmp::LOWER>(0, size));
|
||||
}
|
||||
|
||||
@@ -1331,16 +1332,16 @@ bool ov::is_rank_compatible_any_of(const ov::Rank& rank, const std::vector<Rank>
|
||||
});
|
||||
}
|
||||
|
||||
bool ov::are_unique(const std::vector<int64_t>& data) {
|
||||
bool ov::util::are_unique(const std::vector<int64_t>& data) {
|
||||
return std::unordered_set<int64_t>(data.begin(), data.cend()).size() == data.size();
|
||||
}
|
||||
|
||||
// clip value to min, max
|
||||
int64_t ov::clip(const int64_t& value, const int64_t& min, const int64_t& max) {
|
||||
int64_t ov::util::clip(const int64_t& value, const int64_t& min, const int64_t& max) {
|
||||
return std::min(std::max(value, min), max);
|
||||
};
|
||||
|
||||
std::shared_ptr<op::v0::Constant> ov::constantfold_subgraph(const Output<Node>& subgraph_sink) {
|
||||
std::shared_ptr<op::v0::Constant> ov::util::constantfold_subgraph(const Output<Node>& subgraph_sink) {
|
||||
if (const auto& c = ov::as_type_ptr<op::v0::Constant>(subgraph_sink.get_node_shared_ptr()))
|
||||
return c;
|
||||
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <openvino/core/type.hpp>
|
||||
#include <openvino/core/validation_util.hpp>
|
||||
#include <openvino/opsets/opset8.hpp>
|
||||
#include <openvino/util/common_util.hpp>
|
||||
#include "openvino/core/type.hpp"
|
||||
#include "openvino/core/validation_util.hpp"
|
||||
#include "openvino/opsets/opset8.hpp"
|
||||
#include "openvino/util/common_util.hpp"
|
||||
#include "validation_util.hpp"
|
||||
|
||||
TEST(get_constant_from_source, invalidation_check) {
|
||||
auto a = ov::opset8::Constant::create(ov::element::i64, {100}, {123});
|
||||
@@ -61,7 +62,7 @@ TEST(constantfold_subgraph, split) {
|
||||
auto axis = ov::opset8::Constant::create(ov::element::i64, ov::Shape{}, {0});
|
||||
auto split = std::make_shared<ov::opset8::VariadicSplit>(mul, axis, lenghts);
|
||||
std::vector<float> expected(std::next(input.begin(), input.size() / 2), input.end());
|
||||
auto ret = ov::constantfold_subgraph(split->output(1));
|
||||
auto ret = ov::util::constantfold_subgraph(split->output(1));
|
||||
ASSERT_NE(ret, nullptr);
|
||||
auto actual = ret->cast_vector<float>();
|
||||
ASSERT_EQ(expected, actual);
|
||||
|
||||
Reference in new issue
Block a user