Skip to content

Commit

Permalink
Remove legacy API from op/util (openvinotoolkit#18951)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyachur authored Aug 3, 2023
1 parent fb45deb commit e64f84d
Show file tree
Hide file tree
Showing 32 changed files with 232 additions and 330 deletions.
8 changes: 3 additions & 5 deletions src/core/src/axis_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/axis_vector.hpp"
#include "openvino/core/axis_vector.hpp"

#include "ngraph/util.hpp"
#include "openvino/util/common_util.hpp"

std::ostream& ov::operator<<(std::ostream& s, const AxisVector& axis_vector) {
s << "AxisVector{";
OPENVINO_SUPPRESS_DEPRECATED_START
s << ngraph::join(axis_vector);
OPENVINO_SUPPRESS_DEPRECATED_END
s << ov::util::join(axis_vector);
s << "}";
return s;
}
Expand Down
40 changes: 19 additions & 21 deletions src/core/src/op/util/activation_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,36 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/util/activation_functions.hpp"
#include "openvino/op/util/activation_functions.hpp"

#include <cmath>
#include <functional>
#include <memory>
#include <unordered_map>

#include "ngraph/op/constant.hpp"
#include "ngraph/op/hard_sigmoid.hpp"
#include "ngraph/op/relu.hpp"
#include "ngraph/op/sigmoid.hpp"
#include "ngraph/op/tanh.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/hard_sigmoid.hpp"
#include "openvino/op/relu.hpp"
#include "openvino/op/sigmoid.hpp"
#include "openvino/op/tanh.hpp"

using namespace std;

static shared_ptr<ov::Node> sigmoid(const shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<ngraph::op::Sigmoid>(arg);
static std::shared_ptr<ov::Node> sigmoid(const std::shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return std::make_shared<ov::op::v0::Sigmoid>(arg);
}

static shared_ptr<ov::Node> tanh(const shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<ngraph::op::Tanh>(arg);
static std::shared_ptr<ov::Node> tanh(const std::shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return std::make_shared<ov::op::v0::Tanh>(arg);
}

static shared_ptr<ov::Node> relu(const shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<ngraph::op::Relu>(arg);
static std::shared_ptr<ov::Node> relu(const std::shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return std::make_shared<ov::op::v0::Relu>(arg);
}

static shared_ptr<ov::Node> hardsigmoid(const shared_ptr<ov::Node>& arg, float alpha, float beta) {
const auto alpha_node = ngraph::op::Constant::create<float>(arg->get_element_type(), ngraph::Shape{}, {alpha});
const auto beta_node = ngraph::op::Constant::create<float>(arg->get_element_type(), ngraph::Shape{}, {beta});
static std::shared_ptr<ov::Node> hardsigmoid(const std::shared_ptr<ov::Node>& arg, float alpha, float beta) {
const auto alpha_node = ov::op::v0::Constant::create<float>(arg->get_element_type(), ov::Shape{}, {alpha});
const auto beta_node = ov::op::v0::Constant::create<float>(arg->get_element_type(), ov::Shape{}, {beta});

return make_shared<ngraph::op::HardSigmoid>(arg, alpha_node, beta_node);
return std::make_shared<ov::op::v0::HardSigmoid>(arg, alpha_node, beta_node);
}

ov::op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f, float alpha, float beta)
Expand All @@ -47,12 +45,12 @@ ov::op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f, f
ov::op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f)
: ActivationFunction(f, nanf(""), nanf("")) {}

shared_ptr<ov::Node> ov::op::util::ActivationFunction::operator()(const shared_ptr<Node>& arg) const {
std::shared_ptr<ov::Node> ov::op::util::ActivationFunction::operator()(const std::shared_ptr<Node>& arg) const {
return m_function(arg, m_alpha, m_beta);
}

ov::op::util::ActivationFunction ov::op::util::get_activation_func_by_name(const string& func_name) {
using ActivationFunctionMap = unordered_map<string, op::util::ActivationFunction>;
ov::op::util::ActivationFunction ov::op::util::get_activation_func_by_name(const std::string& func_name) {
using ActivationFunctionMap = std::unordered_map<std::string, op::util::ActivationFunction>;

static ActivationFunctionMap func_map{
{"sigmoid", op::util::ActivationFunction{sigmoid}},
Expand Down
5 changes: 1 addition & 4 deletions src/core/src/op/util/arithmetic_reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/util/arithmetic_reduction.hpp"
#include "openvino/op/util/arithmetic_reduction.hpp"

#include "itt.hpp"
#include "ngraph/validation_util.hpp"

using namespace std;

ov::op::util::ArithmeticReduction::ArithmeticReduction() = default;

Expand Down
14 changes: 4 additions & 10 deletions src/core/src/op/util/arithmetic_reductions_keep_dims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/util/arithmetic_reductions_keep_dims.hpp"
#include "openvino/op/util/arithmetic_reductions_keep_dims.hpp"

#include "itt.hpp"
#include "ngraph/attribute_visitor.hpp"
#include "ngraph/op/constant.hpp"
#include "ngraph/validation_util.hpp"

using namespace std;

ov::op::util::ArithmeticReductionKeepDims::ArithmeticReductionKeepDims(
const ngraph::Output<ngraph::Node>& arg,
const ngraph::Output<ngraph::Node>& reduction_axes,
bool keep_dims)
ov::op::util::ArithmeticReductionKeepDims::ArithmeticReductionKeepDims(const ov::Output<ov::Node>& arg,
const ov::Output<ov::Node>& reduction_axes,
bool keep_dims)
: ArithmeticReduction(arg, reduction_axes),
m_keep_dims{keep_dims} {}

Expand Down
126 changes: 61 additions & 65 deletions src/core/src/op/util/attr_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,109 +2,105 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/util/attr_types.hpp"
#include "openvino/op/util/attr_types.hpp"

#include <cctype>
#include <map>

#include "ngraph/attribute_visitor.hpp"
#include "ngraph/check.hpp"
#include "ngraph/enum_names.hpp"
#include "openvino/core/except.hpp"

namespace ov {

template <>
NGRAPH_API EnumNames<ngraph::op::PadMode>& EnumNames<ngraph::op::PadMode>::get() {
static auto enum_names = EnumNames<ngraph::op::PadMode>("ngraph::op::PadMode",
{{"constant", ngraph::op::PadMode::CONSTANT},
{"edge", ngraph::op::PadMode::EDGE},
{"reflect", ngraph::op::PadMode::REFLECT},
{"symmetric", ngraph::op::PadMode::SYMMETRIC}});
OPENVINO_API EnumNames<ov::op::PadMode>& EnumNames<ov::op::PadMode>::get() {
static auto enum_names = EnumNames<ov::op::PadMode>("ov::op::PadMode",
{{"constant", ov::op::PadMode::CONSTANT},
{"edge", ov::op::PadMode::EDGE},
{"reflect", ov::op::PadMode::REFLECT},
{"symmetric", ov::op::PadMode::SYMMETRIC}});
return enum_names;
}

template <>
NGRAPH_API EnumNames<ngraph::op::PadType>& EnumNames<ngraph::op::PadType>::get() {
static auto enum_names = EnumNames<ngraph::op::PadType>("ngraph::op::PadType",
{{"explicit", ngraph::op::PadType::EXPLICIT},
{"same_lower", ngraph::op::PadType::SAME_LOWER},
{"same_upper", ngraph::op::PadType::SAME_UPPER},
{"valid", ngraph::op::PadType::VALID}});
OPENVINO_API EnumNames<ov::op::PadType>& EnumNames<ov::op::PadType>::get() {
static auto enum_names = EnumNames<ov::op::PadType>("ov::op::PadType",
{{"explicit", ov::op::PadType::EXPLICIT},
{"same_lower", ov::op::PadType::SAME_LOWER},
{"same_upper", ov::op::PadType::SAME_UPPER},
{"valid", ov::op::PadType::VALID}});
return enum_names;
}

template <>
NGRAPH_API EnumNames<ngraph::op::RoundingType>& EnumNames<ngraph::op::RoundingType>::get() {
static auto enum_names = EnumNames<ngraph::op::RoundingType>(
"ngraph::op::RoundingType",
{{"floor", ngraph::op::RoundingType::FLOOR}, {"ceil", ngraph::op::RoundingType::CEIL}});
OPENVINO_API EnumNames<ov::op::RoundingType>& EnumNames<ov::op::RoundingType>::get() {
static auto enum_names =
EnumNames<ov::op::RoundingType>("ov::op::RoundingType",
{{"floor", ov::op::RoundingType::FLOOR}, {"ceil", ov::op::RoundingType::CEIL}});
return enum_names;
}

template <>
NGRAPH_API EnumNames<ngraph::op::AutoBroadcastType>& EnumNames<ngraph::op::AutoBroadcastType>::get() {
static auto enum_names =
EnumNames<ngraph::op::AutoBroadcastType>("ngraph::op::AutoBroadcastType",
{{"none", ngraph::op::AutoBroadcastType::NONE},
{"explicit", ngraph::op::AutoBroadcastType::EXPLICIT},
{"numpy", ngraph::op::AutoBroadcastType::NUMPY},
{"pdpd", ngraph::op::AutoBroadcastType::PDPD}});
OPENVINO_API EnumNames<ov::op::AutoBroadcastType>& EnumNames<ov::op::AutoBroadcastType>::get() {
static auto enum_names = EnumNames<ov::op::AutoBroadcastType>("ov::op::AutoBroadcastType",
{{"none", ov::op::AutoBroadcastType::NONE},
{"explicit", ov::op::AutoBroadcastType::EXPLICIT},
{"numpy", ov::op::AutoBroadcastType::NUMPY},
{"pdpd", ov::op::AutoBroadcastType::PDPD}});
return enum_names;
}

template <>
NGRAPH_API EnumNames<ngraph::op::BroadcastType>& EnumNames<ngraph::op::BroadcastType>::get() {
OPENVINO_API EnumNames<ov::op::BroadcastType>& EnumNames<ov::op::BroadcastType>::get() {
static auto enum_names =
EnumNames<ngraph::op::BroadcastType>("ngraph::op::BroadcastType",
{{"explicit", ngraph::op::BroadcastType::EXPLICIT},
{"none", ngraph::op::BroadcastType::NONE},
{"numpy", ngraph::op::BroadcastType::NUMPY},
{"pdpd", ngraph::op::BroadcastType::PDPD},
{"bidirectional", ngraph::op::BroadcastType::BIDIRECTIONAL}});
EnumNames<ov::op::BroadcastType>("ov::op::BroadcastType",
{{"explicit", ov::op::BroadcastType::EXPLICIT},
{"none", ov::op::BroadcastType::NONE},
{"numpy", ov::op::BroadcastType::NUMPY},
{"pdpd", ov::op::BroadcastType::PDPD},
{"bidirectional", ov::op::BroadcastType::BIDIRECTIONAL}});
return enum_names;
}

template <>
NGRAPH_API EnumNames<ngraph::op::EpsMode>& EnumNames<ngraph::op::EpsMode>::get() {
OPENVINO_API EnumNames<ov::op::EpsMode>& EnumNames<ov::op::EpsMode>::get() {
static auto enum_names =
EnumNames<ngraph::op::EpsMode>("ngraph::op::EpsMode",
{{"add", ngraph::op::EpsMode::ADD}, {"max", ngraph::op::EpsMode::MAX}});
EnumNames<ov::op::EpsMode>("ov::op::EpsMode", {{"add", ov::op::EpsMode::ADD}, {"max", ov::op::EpsMode::MAX}});
return enum_names;
}

template <>
NGRAPH_API EnumNames<ngraph::op::TopKSortType>& EnumNames<ngraph::op::TopKSortType>::get() {
static auto enum_names = EnumNames<ngraph::op::TopKSortType>("ngraph::op::TopKSortType",
{{"none", ngraph::op::TopKSortType::NONE},
{"index", ngraph::op::TopKSortType::SORT_INDICES},
{"value", ngraph::op::TopKSortType::SORT_VALUES}});
OPENVINO_API EnumNames<ov::op::TopKSortType>& EnumNames<ov::op::TopKSortType>::get() {
static auto enum_names = EnumNames<ov::op::TopKSortType>("ov::op::TopKSortType",
{{"none", ov::op::TopKSortType::NONE},
{"index", ov::op::TopKSortType::SORT_INDICES},
{"value", ov::op::TopKSortType::SORT_VALUES}});
return enum_names;
}
template <>
NGRAPH_API EnumNames<ngraph::op::TopKMode>& EnumNames<ngraph::op::TopKMode>::get() {
OPENVINO_API EnumNames<ov::op::TopKMode>& EnumNames<ov::op::TopKMode>::get() {
static auto enum_names =
EnumNames<ngraph::op::TopKMode>("ngraph::op::TopKMode",
{{"min", ngraph::op::TopKMode::MIN}, {"max", ngraph::op::TopKMode::MAX}});
EnumNames<ov::op::TopKMode>("ov::op::TopKMode",
{{"min", ov::op::TopKMode::MIN}, {"max", ov::op::TopKMode::MAX}});
return enum_names;
}

bool AttributeAdapter<ngraph::op::AutoBroadcastSpec>::visit_attributes(AttributeVisitor& visitor) {
bool AttributeAdapter<ov::op::AutoBroadcastSpec>::visit_attributes(AttributeVisitor& visitor) {
// Maintain back-compatibility
std::string name = visitor.finish_structure();
visitor.on_attribute(name, m_ref.m_type);
visitor.start_structure(name);
if (m_ref.m_type == ngraph::op::AutoBroadcastType::PDPD) {
if (m_ref.m_type == ov::op::AutoBroadcastType::PDPD) {
visitor.on_attribute("auto_broadcast_axis", m_ref.m_axis);
}
return true;
}

bool AttributeAdapter<ngraph::op::BroadcastModeSpec>::visit_attributes(AttributeVisitor& visitor) {
bool AttributeAdapter<ov::op::BroadcastModeSpec>::visit_attributes(AttributeVisitor& visitor) {
// Maintain back-compatibility
std::string name = visitor.finish_structure();
visitor.on_attribute(name, m_ref.m_type);
visitor.start_structure(name);
if (m_ref.m_type == ngraph::op::BroadcastType::PDPD) {
if (m_ref.m_type == ov::op::BroadcastType::PDPD) {
visitor.start_structure(name);
visitor.on_attribute("axis", m_ref.m_axis);
visitor.finish_structure();
Expand All @@ -113,44 +109,44 @@ bool AttributeAdapter<ngraph::op::BroadcastModeSpec>::visit_attributes(Attribute
}

template <>
NGRAPH_API EnumNames<ngraph::op::RecurrentSequenceDirection>& EnumNames<ngraph::op::RecurrentSequenceDirection>::get() {
static auto enum_names = EnumNames<ngraph::op::RecurrentSequenceDirection>(
"ngraph::op::RecurrentSequenceDirection",
{{"forward", ngraph::op::RecurrentSequenceDirection::FORWARD},
{"reverse", ngraph::op::RecurrentSequenceDirection::REVERSE},
{"bidirectional", ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL}});
OPENVINO_API EnumNames<ov::op::RecurrentSequenceDirection>& EnumNames<ov::op::RecurrentSequenceDirection>::get() {
static auto enum_names = EnumNames<ov::op::RecurrentSequenceDirection>(
"ov::op::RecurrentSequenceDirection",
{{"forward", ov::op::RecurrentSequenceDirection::FORWARD},
{"reverse", ov::op::RecurrentSequenceDirection::REVERSE},
{"bidirectional", ov::op::RecurrentSequenceDirection::BIDIRECTIONAL}});
return enum_names;
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::PadMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::PadMode& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::PadType& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::PadType& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::RoundingType& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::RoundingType& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::BroadcastType& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::BroadcastType& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::AutoBroadcastType& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::AutoBroadcastType& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::EpsMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::EpsMode& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::TopKSortType& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::TopKSortType& type) {
return s << as_string(type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::TopKMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::TopKMode& type) {
return s << as_string(type);
}

Expand All @@ -165,12 +161,12 @@ op::AutoBroadcastType op::AutoBroadcastSpec::type_from_string(const std::string&
{"pdpd", AutoBroadcastType::PDPD},
{"explicit", AutoBroadcastType::EXPLICIT}};

NGRAPH_CHECK(allowed_values.count(lowercase_type) > 0, "Invalid 'type' value passed in.");
OPENVINO_ASSERT(allowed_values.count(lowercase_type) > 0, "Invalid 'type' value passed in.");

return allowed_values.at(lowercase_type);
}

std::ostream& op::operator<<(std::ostream& s, const ngraph::op::RecurrentSequenceDirection& direction) {
std::ostream& op::operator<<(std::ostream& s, const ov::op::RecurrentSequenceDirection& direction) {
return s << as_string(direction);
}
} // namespace ov
7 changes: 2 additions & 5 deletions src/core/src/op/util/binary_elementwise_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/util/binary_elementwise_arithmetic.hpp"
#include "openvino/op/util/binary_elementwise_arithmetic.hpp"

#include "bound_evaluate.hpp"
#include "itt.hpp"
#include "ngraph/attribute_visitor.hpp"
#include "ngraph/op/util/elementwise_args.hpp"

using namespace std;
#include "openvino/op/util/elementwise_args.hpp"

ov::op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic(const AutoBroadcastSpec& autob)
: m_autob(autob) {}
Expand Down
7 changes: 2 additions & 5 deletions src/core/src/op/util/binary_elementwise_comparison.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "ngraph/op/util/binary_elementwise_comparison.hpp"
#include "openvino/op/util/binary_elementwise_comparison.hpp"

#include "itt.hpp"
#include "ngraph/attribute_visitor.hpp"
#include "ngraph/op/util/elementwise_args.hpp"

using namespace std;
#include "openvino/op/util/elementwise_args.hpp"

ov::op::util::BinaryElementwiseComparison::BinaryElementwiseComparison(const AutoBroadcastSpec& autob)
: m_autob(autob) {}
Expand Down
Loading

0 comments on commit e64f84d

Please sign in to comment.