Moved op utils to ov namespace (#7274)

* Moved ngraph::Node to ov namespace

* Fixed code style

* Fixed VPU

* Fixed GNA

* Fixed tests

* Added aliases for backward compatibility

* Fix clDNN

* Try to fix build

* Fixed comment

* Renamed RTTI macros

* Moved op utils to ov namespace

* Fixed ngraph library build

* Fixed unit-tests

* Changed src folder

* Fixed recurrent_sequence

* Changed low latency

* Fixed serialize

* Fixed ieFuncTests

* Try to fix windows

* Remove custom operator<< from tests

* Fixed build
This commit is contained in:
Ilya Churaev authored and GitHub committed 2021-09-03 00:58:26 +03:00
1 parent 46646059f8
commit b78f228fa5
121 files changed
+3499 -2938

No files matched your search

@@ -95,8 +95,8 @@ void op::FrameworkNode::validate_and_infer_types() {
}
}
constexpr ov::DiscreteTypeInfo ov::AttributeAdapter<op::FrameworkNodeAttrs>::type_info;
constexpr ov::DiscreteTypeInfo ov::AttributeAdapter<ngraph::op::FrameworkNodeAttrs>::type_info;
ov::AttributeAdapter<op::FrameworkNodeAttrs>::AttributeAdapter(
op::FrameworkNodeAttrs& value)
: DirectValueAccessor<op::FrameworkNodeAttrs>(value) {}
ov::AttributeAdapter<ngraph::op::FrameworkNodeAttrs>::AttributeAdapter(
ngraph::op::FrameworkNodeAttrs& value)
: DirectValueAccessor<ngraph::op::FrameworkNodeAttrs>(value) {}
@@ -325,7 +325,7 @@ public:
m_xml_node.append_attribute("offset").set_value(offset);
m_xml_node.append_attribute("size").set_value(size);
}
} else if (const auto& a = ngraph::as_type<ngraph::AttributeAdapter<op::FrameworkNodeAttrs>>(&adapter)) {
} else if (const auto& a = ngraph::as_type<ngraph::AttributeAdapter<ngraph::op::FrameworkNodeAttrs>>(&adapter)) {
const auto & attrs = a->get();
// Update type and version attributes
@@ -623,7 +623,7 @@ bool resolve_dynamic_shapes(const ngraph::Function& f) {
auto & op = f_ops[id];
auto & clone_op = f_clone_ops[id];
if (auto op_subgraph = std::dynamic_pointer_cast<op::util::SubGraphOp>(op)) {
if (auto op_subgraph = std::dynamic_pointer_cast<ngraph::op::util::SubGraphOp>(op)) {
resolve_dynamic_shapes(*op_subgraph->get_function());
}
@@ -5,11 +5,6 @@
#include "common_test_utils/common_utils.hpp"
#include <legacy/details/ie_cnn_network_iterator.hpp>
::std::ostream& ngraph::operator << (::std::ostream & os, const Function&) {
throw std::runtime_error("should not be called");
return os;
}
namespace CommonTestUtils {
IE_SUPPRESS_DEPRECATED_START
@@ -17,10 +17,6 @@
#include <cpp/ie_cnn_network.h>
#include <ngraph/function.hpp>
namespace ngraph {
::std::ostream& operator << (::std::ostream &, const Function&);
}
namespace InferenceEngine {
class CNNLayer;
}
+2 -6
View File
@@ -7,14 +7,10 @@
#include <string>
#include "ngraph/node.hpp"
#include "openvino/op/op.hpp"
namespace ngraph {
namespace op {
/// Root of all actual ops
class NGRAPH_API Op : public Node {
protected:
Op() : Node() {}
Op(const OutputVector& arguments);
};
using ov::op::Op;
} // namespace op
} // namespace ngraph
@@ -9,98 +9,25 @@
#include "ngraph/except.hpp"
#include "ngraph/node.hpp"
#ifdef _WIN32
# pragma warning(push)
# pragma warning(disable : 4100)
#endif
// Prevents the compiler from complaining about or optimizing away variables
// that appear unused on Linux
#if (defined(__GNUC__) && !defined(__clang__))
# undef NG_ATTRIBUTE_UNUSED
# define NG_ATTRIBUTE_UNUSED __attribute__((__unused__))
#else
# define NG_ATTRIBUTE_UNUSED
#endif
#define UNUSED_PARAMETER NG_ATTRIBUTE_UNUSED = 0
#include "openvino/op/util/activation_functions.hpp"
namespace ngraph {
namespace op {
namespace util {
namespace error {
struct UnknownActivationFunction : ngraph_error {
UnknownActivationFunction(const std::string& func_name)
: ngraph_error{"Unknown activation function: " + func_name} {}
};
using ov::op::util::error::UnknownActivationFunction;
} // namespace error
namespace detail {
std::shared_ptr<Node> sigmoid(const std::shared_ptr<Node>& arg,
float alpha UNUSED_PARAMETER,
float beta UNUSED_PARAMETER);
std::shared_ptr<Node> tanh(const std::shared_ptr<Node>& arg, float alpha UNUSED_PARAMETER, float beta UNUSED_PARAMETER);
std::shared_ptr<Node> relu(const std::shared_ptr<Node>& arg, float alpha UNUSED_PARAMETER, float beta UNUSED_PARAMETER);
std::shared_ptr<Node> hardsigmoid(const std::shared_ptr<Node>& arg, float alpha, float beta);
using ov::op::util::detail::hardsigmoid;
using ov::op::util::detail::relu;
using ov::op::util::detail::sigmoid;
using ov::op::util::detail::tanh;
} // namespace detail
using ActivationFunctionType = std::shared_ptr<Node> (*)(const std::shared_ptr<Node>&, float, float);
///
/// \brief Class representing activation function used in RNN cells.
///
class NGRAPH_API ActivationFunction {
public:
ActivationFunction(ActivationFunctionType f, float alpha, float beta);
ActivationFunction(ActivationFunctionType f, float alpha);
ActivationFunction(ActivationFunctionType f);
ActivationFunction() = default;
///
/// \brief Calls stored activation function with provided node argument.
///
std::shared_ptr<Node> operator()(const std::shared_ptr<Node>& arg) const;
void set_alpha(float alpha) {
m_alpha = alpha;
}
void set_beta(float beta) {
m_beta = beta;
}
private:
/// \brief Activation function wrapper.
ActivationFunctionType m_function;
/// \brief Activation function alpha parameter (may be unused).
float m_alpha;
/// \brief Activation function beta parameter (may be unused).
float m_beta;
};
/// \brief Gets the activation function by name.
///
/// \param[in] func_name The function name
///
/// \throws UnknownActivationFunction When provided func_name is unknown.
///
/// \return The activation function object.
///
ActivationFunction get_activation_func_by_name(const std::string& func_name);
using ov::op::util::ActivationFunction;
using ov::op::util::ActivationFunctionType;
using ov::op::util::get_activation_func_by_name;
} // namespace util
} // namespace op
} // namespace ngraph
#ifdef _WIN32
# pragma warning(pop)
#endif
#ifdef UNUSED_PARAMETER
# undef UNUSED_PARAMETER
#endif
#ifdef NG_ATTRIBUTE_UNUSED
# undef NG_ATTRIBUTE_UNUSED
#endif
@@ -6,39 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/reduction_base.hpp"
#include "openvino/op/util/arithmetic_reduction.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Abstract base class for arithmetic reduction operations, i.e., operations
/// where chosen axes of the input tensors are eliminated (reduced out) by
/// repeated application of a particular binary arithmetic operation.
class NGRAPH_API ArithmeticReduction : public ReductionBase {
protected:
/// \brief Constructs an arithmetic reduction operation.
ArithmeticReduction();
/// \brief Constructs an arithmetic reduction operation.
///
/// \param arg Output that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
ArithmeticReduction(const Output<Node>& arg, const Output<Node>& reduction_axes);
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return true if reduction axes are constant else false.
bool reduction_axes_constant() const;
/// \return The axis positions (0-based) to be eliminated through reduction.
/// \throws CheckFailure if the reduction axes are not constant. (Use
/// reduction_axes_constant to check.)
const AxisSet get_reduction_axes() const;
/// \brief Change the reduction axes
void set_reduction_axes(const AxisSet& reduction_axes);
};
using ov::op::util::ArithmeticReduction;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -6,37 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/arithmetic_reduction.hpp"
#include "openvino/op/util/arithmetic_reductions_keep_dims.hpp"
namespace ngraph {
namespace op {
namespace util {
class NGRAPH_API ArithmeticReductionKeepDims : public util::ArithmeticReduction {
protected:
ArithmeticReductionKeepDims() = default;
/// \param arg The tensor to be summed.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
/// \param keep_dims If set to 1 it holds axes that are used for reduction.
ArithmeticReductionKeepDims(const Output<Node>& arg, const Output<Node>& reduction_axes, bool keep_dims = false);
bool visit_attributes(AttributeVisitor& visitor) override;
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return If set to 1 it holds axes that are used for reduction.
/// For each such axis, output dimension is equal to 1.
bool get_keep_dims() const {
return m_keep_dims;
}
void set_keep_dims(bool keep_dims) {
m_keep_dims = keep_dims;
}
private:
bool m_keep_dims = false;
};
using ov::op::util::ArithmeticReductionKeepDims;
} // namespace util
} // namespace op
} // namespace ngraph
+12 -324
View File
@@ -10,332 +10,20 @@
#include "ngraph/attribute_adapter.hpp"
#include "ngraph/ngraph_visibility.hpp"
#include "ngraph/type.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ngraph {
namespace op {
/// \brief Modes for the `Pad` operator.
enum class PadMode { CONSTANT = 0, EDGE, REFLECT, SYMMETRIC };
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const PadMode& type);
/// \brief Padding Type used for `Convolution` and `Pooling`
///
/// Follows ONNX padding type definitions
/// EXPLICIT - Pad dimensions are explicity specified
/// SAME_LOWER - Pad dimensions computed to match input shape
/// Ceil(num_dims/2) at the beginning and
/// Floor(num_dims/2) at the end
/// SAME_UPPER - Pad dimensions computed to match input shape
/// Floor(num_dims/2) at the beginning and
/// Ceil(num_dims/2) at the end
/// VALID - No padding
/// AUTO - Deprecated. User should not use it in the future
/// NOTSET - Deprecated. User should not use it in the future
enum class PadType {
EXPLICIT = 0,
SAME_LOWER,
SAME_UPPER,
VALID,
AUTO = SAME_UPPER,
NOTSET = EXPLICIT,
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const PadType& type);
/// \brief Rounding Type used for `Pooling` operators.
enum class RoundingType {
FLOOR = 0,
CEIL = 1,
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const RoundingType& type);
/// \brief Specifies the algorithm to use for implicit broadcasting of a tensor
/// to align with another tensor
///
/// NONE - No implicit broadcasting of tensor
/// NUMPY - Numpy-style implicit broadcasting
/// (https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
/// Right-align dimensions of the two tensors, with missing dimensions
/// treated as size 1 dimensions. After alignment, for each dimension,
/// their sizes should either match or one of them should be of size 1.
/// Size 1 dimension will be implicitly broadcast to match the other
/// size.
///
/// E.g.,
/// A: Shape(2, 1, 6)
/// B: Shape( 3, 1)
/// Result: Shape(2, 3, 6)
///
/// A: Shape(2, 1, 6)
/// B: Shape( 3, 1)
/// Result: Shape(2, 3, 6)
/// PDPD - PaddlePaddle-style implicit broadcasting
/// (https://github.com/PaddlePaddle/Paddle/blob/release/1.5/paddle/
/// fluid/operators/elementwise/elementwise_op.h#L126)
/// Broadcast B to match the shape of A, where axis is the start
/// dimension index to align B with A. If axis is -1 (default), i
/// axis = rank(A) - rank(B). The trailing dimensions of size 1 for B
/// will be ignored.
///
/// E.g.,
/// A: Shape(2, 3, 4, 5)
/// B: Shape( 3, 4 ) with axis =1
/// Result: Shape(2, 3, 4, 5)
///
/// A: Shape(2, 3, 4, 5)
/// B: Shape( 3, 1 ) with axis = 1
/// Result: Shape(2, 3, 4, 5)
///
/// TODO: Add more implicit broadcast modes used by frameworks
enum class AutoBroadcastType {
NONE = 0,
EXPLICIT = NONE,
NUMPY,
PDPD,
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const AutoBroadcastType& type);
/// \brief BroadcastType specifies rules used for mapping of input tensor axes to output
/// shape axes.
///
/// \note Broadcasting rules are different for Broadcast op and for element-wise ops.
/// AutoBroadcastType::NUMPY is equivalent of BroadcastType::BIDIRECTIONAL
/// according to spec.
///
/// EXPLICIT - Mapping of the input data shape to output shape
/// based on axes_mapping input.
/// NUMPY - Numpy broadcasting rules, aligned with ONNX Broadcasting.
/// (https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md)
/// PDPD - PaddlePaddle-style implicit broadcasting.
/// For more informaction see AutoBroadcastType documentation.
/// BIDIRECTIONAL - The broadcast rule is similar to
/// numpy.array(input) * numpy.ones(target_shape).
/// Dimensions are right alignment.
enum class BroadcastType { NONE, EXPLICIT = NONE, NUMPY, PDPD, BIDIRECTIONAL };
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const BroadcastType& type);
/// \brief Specifies how eps is combined with L2 value
enum class EpsMode {
// Add bias to norm
ADD,
// Calculate max of norm and bias
MAX
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const EpsMode& type);
enum class TopKSortType {
// Returned values are not sorte
NONE,
// Sort result based on element indices
SORT_INDICES,
// Sort result based on element values
SORT_VALUES,
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const TopKSortType& type);
enum class TopKMode {
MAX,
MIN,
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const TopKMode& type);
/// \brief Implicit broadcast specification
struct NGRAPH_API AutoBroadcastSpec {
AutoBroadcastSpec() : m_type(AutoBroadcastType::NONE), m_axis(0) {}
AutoBroadcastSpec(AutoBroadcastType type) : m_type(type), m_axis(0) {}
AutoBroadcastSpec(const char* type) : AutoBroadcastSpec(type_from_string(type)) {}
AutoBroadcastSpec(AutoBroadcastType type, int64_t axis) : m_type(type), m_axis(axis) {}
AutoBroadcastType m_type; // Implicit broadcasting algorithm
int64_t m_axis; // Axis to start alignment on
bool operator==(const AutoBroadcastSpec& a) const {
return a.m_type == m_type && a.m_axis == m_axis;
}
bool operator!=(const AutoBroadcastSpec& a) const {
return !(*this == a);
}
static const AutoBroadcastSpec NUMPY;
static const AutoBroadcastSpec NONE;
private:
AutoBroadcastType type_from_string(const std::string& type) const;
};
/// \brief Implicit broadcast specification
struct NGRAPH_API BroadcastModeSpec {
BroadcastModeSpec() : m_type(BroadcastType::NUMPY), m_axis(0) {}
BroadcastModeSpec(BroadcastType type) : m_type(type), m_axis(0) {}
BroadcastModeSpec(const char* type) : BroadcastModeSpec(as_enum<BroadcastType>(type)) {}
BroadcastModeSpec(BroadcastType type, int64_t axis) : m_type(type), m_axis(axis) {}
BroadcastType m_type; // Implicit broadcasting algorithm
int64_t m_axis; // Axis to start alignment on
bool operator==(const BroadcastModeSpec& a) const {
return a.m_type == m_type && a.m_axis == m_axis;
}
};
///
/// \brief This class defines possible recurrent sequence directions.
///
enum class RecurrentSequenceDirection { FORWARD, REVERSE, BIDIRECTIONAL };
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const RecurrentSequenceDirection& direction);
using ov::op::AutoBroadcastSpec;
using ov::op::AutoBroadcastType;
using ov::op::BroadcastModeSpec;
using ov::op::BroadcastType;
using ov::op::EpsMode;
using ov::op::PadMode;
using ov::op::PadType;
using ov::op::RecurrentSequenceDirection;
using ov::op::RoundingType;
using ov::op::TopKMode;
using ov::op::TopKSortType;
} // namespace op
} // namespace ngraph
namespace ov {
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::PadMode> : public EnumAttributeAdapterBase<ngraph::op::PadMode> {
public:
AttributeAdapter(ngraph::op::PadMode& value) : EnumAttributeAdapterBase<ngraph::op::PadMode>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::PadMode>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::PadType> : public EnumAttributeAdapterBase<ngraph::op::PadType> {
public:
AttributeAdapter(ngraph::op::PadType& value) : EnumAttributeAdapterBase<ngraph::op::PadType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::PadType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::RoundingType>
: public EnumAttributeAdapterBase<ngraph::op::RoundingType> {
public:
AttributeAdapter(ngraph::op::RoundingType& value) : EnumAttributeAdapterBase<ngraph::op::RoundingType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::RoundingType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::AutoBroadcastType>
: public EnumAttributeAdapterBase<ngraph::op::AutoBroadcastType> {
public:
AttributeAdapter(ngraph::op::AutoBroadcastType& value)
: EnumAttributeAdapterBase<ngraph::op::AutoBroadcastType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::AutoBroadcastType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::BroadcastType>
: public EnumAttributeAdapterBase<ngraph::op::BroadcastType> {
public:
AttributeAdapter(ngraph::op::BroadcastType& value) : EnumAttributeAdapterBase<ngraph::op::BroadcastType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::BroadcastType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::EpsMode> : public EnumAttributeAdapterBase<ngraph::op::EpsMode> {
public:
AttributeAdapter(ngraph::op::EpsMode& value) : EnumAttributeAdapterBase<ngraph::op::EpsMode>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::EpsMode>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::TopKSortType>
: public EnumAttributeAdapterBase<ngraph::op::TopKSortType> {
public:
AttributeAdapter(ngraph::op::TopKSortType& value) : EnumAttributeAdapterBase<ngraph::op::TopKSortType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::TopKSortType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::TopKMode> : public EnumAttributeAdapterBase<ngraph::op::TopKMode> {
public:
AttributeAdapter(ngraph::op::TopKMode& value) : EnumAttributeAdapterBase<ngraph::op::TopKMode>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::TopKMode>", 1};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class AttributeAdapter<ngraph::op::AutoBroadcastSpec> : public VisitorAdapter {
public:
AttributeAdapter(ngraph::op::AutoBroadcastSpec& value) : m_ref(value) {}
bool visit_attributes(AttributeVisitor& visitor) override;
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::AutoBroadcastSpec>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
protected:
ngraph::op::AutoBroadcastSpec& m_ref;
};
template <>
class AttributeAdapter<ngraph::op::BroadcastModeSpec> : public VisitorAdapter {
public:
AttributeAdapter(ngraph::op::BroadcastModeSpec& value) : m_ref(value) {}
bool visit_attributes(AttributeVisitor& visitor) override;
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::BroadcastModeSpec>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
protected:
ngraph::op::BroadcastModeSpec& m_ref;
};
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::RecurrentSequenceDirection>
: public EnumAttributeAdapterBase<ngraph::op::RecurrentSequenceDirection> {
public:
AttributeAdapter(ngraph::op::RecurrentSequenceDirection& value)
: EnumAttributeAdapterBase<ngraph::op::RecurrentSequenceDirection>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::RecurrentSequenceDirection>", 1};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
@@ -6,65 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "openvino/op/util/binary_elementwise_arithmetic.hpp"
namespace ngraph {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise binary arithmetic operations, i.e.,
/// operations where the same scalar binary arithmetic operation is applied to
/// each corresponding pair of elements in the two input tensors. Implicit
/// broadcast of input tensors is supported through one of the AutoBroadcast
/// modes.
///
/// For example, if the underlying arithmetic operation (determined by the subclass) is
/// \f$\mathit{op}(x,y)\f$, the input tensors
/// \f$[[x_0,y_0],[z_0,w_0]]\f$ and \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
/// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ------ | --------------------------------- | ------------------------------------------------------------------------ |
/// | `arg0` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape. The element type \f$N\f$ may be any numeric type. |
/// | `arg1` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same element type as `arg0`. |
/// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
/// | \f$N[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape and element type as the input tensors (after auto broadcasting). |
// clang-format on
class NGRAPH_API BinaryElementwiseArithmetic : public Op {
protected:
BinaryElementwiseArithmetic(const AutoBroadcastSpec& autob);
/// \brief Constructs a binary elementwise arithmetic operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
BinaryElementwiseArithmetic(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& autob);
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
const AutoBroadcastSpec& get_autob() const override {
return m_autob;
}
void set_autob(const AutoBroadcastSpec& autob) {
m_autob = autob;
}
bool visit_attributes(AttributeVisitor& visitor) override;
bool evaluate_lower(const HostTensorVector& outputs) const override;
bool evaluate_upper(const HostTensorVector& outputs) const override;
private:
AutoBroadcastSpec m_autob;
void validate_and_infer_elementwise_arithmetic(const op::AutoBroadcastSpec& autob);
};
using ov::op::util::BinaryElementwiseArithmetic;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -6,66 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "openvino/op/util/binary_elementwise_comparison.hpp"
namespace ngraph {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise binary comparison operations, i.e.,
/// operations where the same scalar binary comparison operation is applied to
/// each corresponding pair of elements in two input tensors. Implicit
/// broadcast of input tensors is supported through one of the AutoBroadcast
/// modes.
///
/// For example, if the underlying comparison operation (determined by the subclass) is
/// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
/// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
/// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ------ | --------------------------------- | ------------------------------------------------------ |
/// | `arg0` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape and element type. |
/// | `arg1` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
/// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
/// | \f$\texttt{bool}[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape as the input tensors, and the element type `bool`. |
// clang-format on
class NGRAPH_API BinaryElementwiseComparison : public Op {
protected:
/// \brief Constructs a binary elementwise comparison operation.
BinaryElementwiseComparison(const AutoBroadcastSpec& autob);
/// \brief Constructs a binary elementwise comparison operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
/// \param autob AutoBroadcast mode.
BinaryElementwiseComparison(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob = AutoBroadcastSpec());
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
const AutoBroadcastSpec& get_autob() const override {
return m_autob;
}
void set_autob(const AutoBroadcastSpec& autob) {
m_autob = autob;
}
bool visit_attributes(AttributeVisitor& visitor) override;
private:
AutoBroadcastSpec m_autob;
};
using ov::op::util::BinaryElementwiseComparison;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -5,64 +5,12 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/binary_elementwise_logical.hpp"
namespace ngraph {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise binary logical operations, i.e.,
/// operations where the same scalar binary logical operation is applied to
/// each corresponding pair of elements in two boolean input tensors. Implicit
/// broadcast of input tensors is supported through one of the AutoBroadcast
/// modes.
///
/// For example, if the underlying operation (determined by the subclass) is
/// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
/// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
/// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ------ | --------------------------------------------- | ------------------------------------------------------ |
/// | `arg0` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape, with element type `bool`. |
/// | `arg1` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
/// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
/// | \f$\texttt{bool}[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape as the input tensors, and the element type `bool`. |
// clang-format on
class NGRAPH_API BinaryElementwiseLogical : public Op {
protected:
NGRAPH_RTTI_DECLARATION;
BinaryElementwiseLogical();
/// \brief Constructs a binary elementwise logical operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
BinaryElementwiseLogical(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob = AutoBroadcastSpec());
public:
void validate_and_infer_types() override;
const AutoBroadcastSpec& get_autob() const override {
return m_autob;
}
void set_autob(const AutoBroadcastSpec& autob) {
m_autob = autob;
}
bool visit_attributes(AttributeVisitor& visitor) override;
private:
AutoBroadcastSpec m_autob = AutoBroadcastSpec::NUMPY;
};
using ov::op::util::BinaryElementwiseLogical;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -2,84 +2,18 @@
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/axis_set.hpp"
#include "ngraph/axis_vector.hpp"
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#pragma once
#include "openvino/op/util/broadcast_base.hpp"
namespace ngraph {
namespace op {
namespace util {
class NGRAPH_API BroadcastBase : public Op {
protected:
BroadcastBase() = default;
/// \brief Constructs a broadcast operation.
///
/// \param arg The input tensor to be broadcast.
/// \param target_shape The shape of the output tensor.
/// \param axes_mapping The axis positions (0-based) in the result that correspond
/// to input axes.
/// \param broadcast_mode Broadcast specification to use for determining broadcast
/// axes. 'axes_mapping' should not be provided if mode other
///
BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const Output<Node>& axes_mapping,
const BroadcastModeSpec& broadcast_mode = BroadcastType::EXPLICIT);
/// \brief Constructs a broadcast operation.
///
/// \param arg The input tensor to be broadcast.
/// \param target_shape The shape of the output tensor.
/// \param broadcast_mode Broadcast specification to use for determining broadcast
/// axes
BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const BroadcastModeSpec& broadcast_mode = BroadcastType::NUMPY);
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return true and the AxisSet if broadcast axes can be fully determined.
virtual std::pair<bool, AxisSet> get_broadcast_axes() const;
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
protected:
BroadcastModeSpec m_mode;
bool evaluate_broadcast(const HostTensorPtr& arg0,
const HostTensorPtr& out,
const std::pair<bool, AxisSet> pair_broadcast_axes,
const Shape output_shape) const;
bool evaluate_broadcast(const HostTensorPtr& arg0, const HostTensorPtr& out, const AxisSet& broadcast_axes) const;
bool evaluate_lower(const HostTensorVector& outputs) const override;
bool evaluate_upper(const HostTensorVector& outputs) const override;
PartialShape get_result_shape_pdpd(const PartialShape& arg0_shape,
const PartialShape& target_shape,
const op::BroadcastModeSpec& broadcast_spec) const;
void validate_target_shape_numpy(const PartialShape& arg_shape, const PartialShape& target_shape) const;
static std::pair<bool, AxisSet> get_broadcast_axes_numpy_pdpd(const Shape& arg_shape,
const Shape& result_shape,
const op::BroadcastModeSpec& broadcast_spec);
static std::pair<bool, AxisSet> get_broadcast_axes_none(const AxisVector axes_mapping_val,
const size_t target_shape);
void validate_target_shape_none(const PartialShape& arg_shape,
const AxisVector& axes_mapping_val,
const PartialShape& target_shape) const;
Shape get_target_shape(const HostTensorPtr& input1) const;
};
using ov::op::util::BroadcastBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -7,99 +7,12 @@
#include "ngraph/coordinate_diff.hpp"
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "openvino/op/util/deformable_convolution_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Base class for operations DeformableConvolution v1 and DeformableConvolution
/// v8.
class NGRAPH_API DeformableConvolutionBase : public Op {
public:
NGRAPH_RTTI_DECLARATION;
/// \brief Constructs a conversion operation.
DeformableConvolutionBase() = default;
/// \brief Constructs a conversion operation.
/// \param strides Convolution strides.
/// \param pads_begin Amount of padding to be added to the beginning along
/// each axis. For example in case of a 2D input the value
/// of (1, 2) means that 1 element will be added to the
/// top and 2 elements to the left.
/// \param pads_end Amount of padding to be added to the end along each
/// axis.
/// \param dilations The distance in width and height between the weights
/// in the filters tensor.
/// \param auto_pad Specifies how the automatic calculation of padding
/// should be done.
/// \param group The number of groups which both output and input
/// should be split into.
/// \param deformable_group The number of groups which deformable values and
/// output should be split into along the channel axis.
DeformableConvolutionBase(const OutputVector& arguments,
const Strides& strides,
const CoordinateDiff& pads_begin,
const CoordinateDiff& pads_end,
const Strides& dilations,
const PadType& auto_pad = PadType::EXPLICIT,
int64_t group = 1,
int64_t deformable_group = 1);
bool visit_attributes(AttributeVisitor& visitor) override;
void validate_and_infer_types() override;
const Strides& get_strides() const {
return m_strides;
}
void set_strides(const Strides& strides) {
m_strides = strides;
}
const Strides& get_dilations() const {
return m_dilations;
}
void set_dilations(const Strides& dilations) {
m_dilations = dilations;
}
const CoordinateDiff& get_pads_begin() const {
return m_pads_begin;
}
void set_pads_begin(const CoordinateDiff& pads_begin) {
m_pads_begin = pads_begin;
}
const CoordinateDiff& get_pads_end() const {
return m_pads_end;
}
void set_pads_end(const CoordinateDiff& pads_end) {
m_pads_end = pads_end;
}
const PadType& get_auto_pad() const {
return m_auto_pad;
}
void set_auto_pad(const PadType& auto_pad) {
m_auto_pad = auto_pad;
}
int64_t get_group() const {
return m_group;
}
void set_group(const int64_t group) {
m_group = group;
}
int64_t get_deformable_group() const {
return m_deformable_group;
}
void set_deformable_group(const int64_t deformable_group) {
m_deformable_group = deformable_group;
}
protected:
Strides m_strides;
Strides m_dilations;
CoordinateDiff m_pads_begin;
CoordinateDiff m_pads_end;
PadType m_auto_pad;
int64_t m_group;
int64_t m_deformable_group;
};
using ov::op::util::DeformableConvolutionBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -5,13 +5,12 @@
#pragma once
#include "ngraph/node.hpp"
#include "openvino/op/util/elementwise_args.hpp"
namespace ngraph {
namespace op {
namespace util {
std::tuple<element::Type, PartialShape> validate_and_infer_elementwise_args(
Node* node,
const op::AutoBroadcastSpec& autob = op::AutoBroadcastSpec());
using ov::op::util::validate_and_infer_elementwise_args;
}
} // namespace op
} // namespace ngraph
@@ -6,61 +6,12 @@
#include "ngraph/axis_set.hpp"
#include "ngraph/op/util/index_reduction.hpp"
#include "openvino/op/util/embeddingbag_offsets_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Returns embeddings for given indices
class NGRAPH_API EmbeddingBagOffsetsBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"EmbeddingBagOffsetsBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
/// \brief Constructs a EmbeddingBagOffsetsBase operation.
EmbeddingBagOffsetsBase() = default;
/// \brief Constructs a EmbeddingBagOffsetsBase operation.
///
/// EmbeddingBagOffsetsBase constructs an output tensor by replacing every index in
/// a
/// given
/// input tensor with a row (from the weights matrix) at that index
///
/// \param emb_table tensor containing the embedding lookup table of the module of
/// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
/// \param tensor of shape [num_indices] and of type T_IND. Required
/// \param offsets tensor of shape [batch] and of type T_IND containing the starting
/// index positions of each "bag" in indices. Required.
/// \param per_sample_weigths tensor of the same shape as indices and of type T.
/// Each value in this tensor are multiplied with each
/// value pooled from embedding table for each index. Optional.
/// \param default_index scalar of type T_IND containing default index in embedding
/// table to fill empty "bags". If not provided empty "bags"
/// are filled with zeros. Optional.
EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index,
const Output<Node>& per_sample_weights);
EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index);
EmbeddingBagOffsetsBase(const Output<Node>& emb_table, const Output<Node>& indices, const Output<Node>& offsets);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
private:
static constexpr int EMB_TABLE = 0;
static constexpr int INDICES = 1;
static constexpr int OFFSETS = 2;
static constexpr int DEFAULT_INDEX = 3;
static constexpr int PER_SAMPLE_WEIGHTS = 4;
};
using ov::op::util::EmbeddingBagOffsetsBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -6,47 +6,12 @@
#include "ngraph/axis_set.hpp"
#include "ngraph/op/util/index_reduction.hpp"
#include "openvino/op/util/embeddingbag_packed_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Returns embeddings for given indices
class NGRAPH_API EmbeddingBagPackedBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"EmbeddingBagPackedBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
/// \brief Constructs a EmbeddingBagPackedBase operation.
EmbeddingBagPackedBase() = default;
/// \brief Constructs a EmbeddingBagPackedBase operation.
///
/// EmbeddingBagPackedBase constructs an output tensor by replacing every index in a
/// given
/// input tensor with a row (from the weights matrix) at that index
///
/// \param emb_table Tensor containing the embedding lookup table of the module of
/// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
/// \param indices Tensor of shape `[batch, indices_per_bag]` and of type *T_IND*.
/// Required.
/// \param per_sample_weigths tensor of the same shape as indices and of type T.
/// Each value in this tensor are multiplied with each
/// value pooled from embedding table for each index. Optional.
EmbeddingBagPackedBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& per_sample_weights);
EmbeddingBagPackedBase(const Output<Node>& emb_table, const Output<Node>& indices);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
private:
static constexpr int EMB_TABLE = 0;
static constexpr int INDICES = 1;
static constexpr int PER_SAMPLE_WEIGHTS = 2;
};
using ov::op::util::EmbeddingBagPackedBase;
} // namespace util
using util::EmbeddingBagPackedBase;
} // namespace op
@@ -6,35 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "openvino/op/util/fft_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Base class for operations DFT and DFT.
class NGRAPH_API FFTBase : public Op {
public:
NGRAPH_RTTI_DECLARATION;
FFTBase() = default;
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
/// \brief Constructs an FFT operation. FFT is performed for full size axes.
///
/// \param data Input data
/// \param axes Axes to perform FFT
FFTBase(const Output<Node>& data, const Output<Node>& axes);
/// \brief Constructs a FFT operation.
///
/// \param data Input data
/// \param axes Axes to perform FFT
/// \param signal_size Signal sizes for 'axes'
FFTBase(const Output<Node>& data, const Output<Node>& axes, const Output<Node>& signal_size);
void validate();
};
using ov::op::util::FFTBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -5,38 +5,12 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/gather_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief GatherBase basic class for Gather v1 and v7
class NGRAPH_API GatherBase : public Op {
public:
NGRAPH_RTTI_DECLARATION;
GatherBase() = default;
/// \param data The tensor from which slices are gathered
/// \param indices Tensor with indexes to gather
/// \param axis The tensor is a dimension index to gather data from
/// \param batch_dims The number of batch dimension in data and indices tensors
GatherBase(const Output<Node>& data,
const Output<Node>& indices,
const Output<Node>& axis,
const int64_t batch_dims = 0);
void validate_and_infer_types() override;
virtual int64_t get_axis() const;
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
bool evaluate_lower(const HostTensorVector& outputs) const override;
bool evaluate_upper(const HostTensorVector& outputs) const override;
bool constant_fold(OutputVector& output_values, const OutputVector& inputs_values) override;
protected:
int64_t m_batch_dims = 0;
};
using ov::op::util::GatherBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -10,28 +10,12 @@
#include <utility>
#include "ngraph/op/op.hpp"
#include "openvino/op/util/index_reduction.hpp"
namespace ngraph {
namespace op {
namespace util {
class NGRAPH_API IndexReduction : public Op {
protected:
IndexReduction();
IndexReduction(const Output<Node>& arg, uint64_t axis, const element::Type& index_element_type);
public:
uint64_t get_reduction_axis() const;
void set_reduction_axis(uint64_t value);
element::Type get_index_element_type() const;
void set_index_element_type(const element::Type& index_element_type);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
uint64_t m_axis{0};
element::Type m_index_element_type;
};
using ov::op::util::IndexReduction;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -6,41 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/reduction_base.hpp"
#include "openvino/op/util/logical_reduction.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Abstract base class for logical reduction operations, i.e., operations where
/// chosen axes of the input tensors are eliminated (reduced out) by repeated
/// application of a particular binary logical operation.
class NGRAPH_API LogicalReduction : public ReductionBase {
protected:
/// \brief Constructs a logical reduction operation.
LogicalReduction();
/// \brief Constructs a logical reduction operation.
///
/// \param arg Output that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
LogicalReduction(const Output<Node>& arg, const AxisSet& reduction_axes);
/// \brief Constructs a 'dynamic' logical reduction operation.
///
/// \param arg Node that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
LogicalReduction(const Output<Node>& arg, const Output<Node>& reduction_axes);
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return true if reduction axes are constant else false.
bool reduction_axes_constant() const;
/// \return The axis positions (0-based) to be eliminated through reduction.
/// \throws CheckFailure if the reduction axes are not constant. (Use
/// reduction_axes_constant to check.)
const AxisSet get_reduction_axes() const;
void set_reduction_axes(const AxisSet& reduction_axes);
};
using ov::op::util::LogicalReduction;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -6,37 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/logical_reduction.hpp"
#include "openvino/op/util/logical_reduction_keep_dims.hpp"
namespace ngraph {
namespace op {
namespace util {
class NGRAPH_API LogicalReductionKeepDims : public util::LogicalReduction {
protected:
LogicalReductionKeepDims() = default;
/// \param arg The tensor to be reduced.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
/// \param keep_dims If set to 1 it holds axes that are used for reduction.
LogicalReductionKeepDims(const Output<Node>& arg, const Output<Node>& reduction_axes, const bool keep_dims = false);
bool visit_attributes(AttributeVisitor& visitor) override;
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return If set to 1 it holds axes that are used for reduction.
/// For each such axis, output dimension is equal to 1.
bool get_keep_dims() const {
return m_keep_dims;
}
void set_keep_dims(bool keep_dims) {
m_keep_dims = keep_dims;
}
private:
bool m_keep_dims = false;
};
using ov::op::util::LogicalReductionKeepDims;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -6,91 +6,12 @@
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "openvino/op/util/max_pool_base.hpp"
namespace ngraph {
namespace op {
namespace util {
class NGRAPH_API MaxPoolBase : public Op {
public:
NGRAPH_RTTI_DECLARATION;
MaxPoolBase() = default;
/// \param arg The node producing the input data batch tensor.
/// \param strides The strides.
/// \param pads_begin The beginning of padding shape.
/// \param pads_end The end of padding shape.
/// \param kernel The kernel shape.
/// \param rounding_mode Whether to use ceiling or floor rounding type while
/// computing output shape.
/// \param auto_pad The pad type for automatically computing padding sizes.
MaxPoolBase(const Output<Node>& arg,
const Strides& strides,
const Shape& pads_begin,
const Shape& pads_end,
const Shape& kernel,
const op::RoundingType rounding_mode = op::RoundingType::FLOOR,
const PadType auto_pad = op::PadType::EXPLICIT);
void validate_and_infer_types() override;
/// \return The kernel shape.
const Shape& get_kernel() const {
return m_kernel;
}
void set_kernel(const Shape& kernel) {
m_kernel = kernel;
}
/// \return The strides.
const Strides& get_strides() const {
return m_strides;
}
void set_strides(const Strides& strides) {
m_strides = strides;
}
/// \return The beginning of padding shape.
const Shape& get_pads_begin() const {
return m_pads_begin;
}
void set_pads_begin(const Shape& pads_begin) {
m_pads_begin = pads_begin;
}
/// \return The end of padding shape.
const Shape& get_pads_end() const {
return m_pads_end;
}
void set_adding_above(const Shape& pads_end) {
m_pads_end = pads_end;
}
/// \return The pad type for pooling.
PadType get_auto_pad() const {
return m_auto_pad;
}
void set_auto_pad(const PadType auto_pad) {
m_auto_pad = auto_pad;
}
/// \return The ceiling mode being used for output shape computations
op::RoundingType get_rounding_type() const {
return m_rounding_type;
}
void set_rounding_type(op::RoundingType rounding_type) {
m_rounding_type = rounding_type;
}
protected:
bool update_auto_padding(const PartialShape& in_shape,
const Strides& filter_dilations,
Shape& new_pads_end,
Shape& new_pads_begin) const;
PartialShape infer_output_shape(const Strides& dilations);
Shape m_kernel;
Strides m_strides;
Shape m_pads_begin;
Shape m_pads_end;
PadType m_auto_pad;
op::RoundingType m_rounding_type;
};
using ov::op::util::MaxPoolBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -8,317 +8,16 @@
#include <ngraph/op/parameter.hpp>
#include "ngraph/op/op.hpp"
#include "openvino/op/util/multi_subgraph_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Abstract base class for sub-graph based ops, i.e ops that have some
/// sub-graphs
///
class NGRAPH_API MultiSubGraphOp : public Op {
public:
NGRAPH_RTTI_DECLARATION;
/// \brief Abstract class describes a connection between a MultiSubGraphOp input and
/// the body.
class InputDescription {
protected:
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// \param body_parameter_index Body parameter to receive input
///
InputDescription(uint64_t input_index, uint64_t body_parameter_index);
InputDescription() = default;
public:
using type_info_t = DiscreteTypeInfo;
virtual ~InputDescription() = default;
virtual std::shared_ptr<InputDescription> copy() const = 0;
virtual const type_info_t& get_type_info() const = 0;
uint64_t m_input_index{0};
uint64_t m_body_parameter_index{0};
};
/// \brief Abstract class describes how a MultiSubGraphOp output is produced from
/// the body.
class OutputDescription {
protected:
///
/// \brief Constructs a new instance.
///
/// \param body_value_index A body value that produces the output
/// \param output_index The MultiSubGraphOp output index
///
OutputDescription(uint64_t body_value_index, uint64_t output_index);
OutputDescription() = default;
public:
using type_info_t = DiscreteTypeInfo;
virtual ~OutputDescription() = default;
virtual std::shared_ptr<OutputDescription> copy() const = 0;
virtual const type_info_t& get_type_info() const = 0;
uint64_t m_body_value_index{0};
uint64_t m_output_index{0};
};
///
/// \brief Describes a body input formed from slices of an input to
/// MultiSubGraphOp.
///
class NGRAPH_API SliceInputDescription : public InputDescription {
public:
NGRAPH_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// \param body_parameter_index Body parameter position to receive input
/// \param start First index for slices
/// \param stride Step amount for slices
/// \param part_size Width of slices
/// \param end Last index for slices
/// \param axis Axis being sliced
///
SliceInputDescription(uint64_t input_index,
uint64_t body_parameter_index,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
SliceInputDescription() = default;
std::shared_ptr<InputDescription> copy() const override;
int64_t m_start{0};
int64_t m_stride{0};
int64_t m_part_size{0};
int64_t m_end{0};
int64_t m_axis{0};
};
///
/// \brief Describes a body input initialized from a MultiSubGraphOp input
/// on the first iteration, and then a body output thereafter.
///
class NGRAPH_API MergedInputDescription : public InputDescription {
public:
NGRAPH_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// supplying a value to body_parameter for
/// the initial iteration.
/// \param body_parameter_index Body parameter position to receive input.
/// \param body_value_index Body value to supply body_parameter for
/// successive
/// iterations.
///
MergedInputDescription(uint64_t input_index, uint64_t body_parameter_index, uint64_t body_value_index);
MergedInputDescription() = default;
std::shared_ptr<InputDescription> copy() const override;
uint64_t m_body_value_index{0};
};
/// \brief Produces an output by concatenating an output from each iteration
class NGRAPH_API ConcatOutputDescription : public OutputDescription {
public:
NGRAPH_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param body_value_index A body value that produces the output
/// \param output_index The MultiSubGraphOp output index
/// \param start First index for slices
/// \param stride Step amount for slices
/// \param part_size Width of slices
/// \param end Last index for slices
/// \param axis Axis being sliced
///
ConcatOutputDescription(uint64_t body_value_index,
uint64_t output_index,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
ConcatOutputDescription() = default;
std::shared_ptr<OutputDescription> copy() const override;
int64_t m_start{0};
int64_t m_stride{0};
int64_t m_part_size{0};
int64_t m_end{0};
int64_t m_axis{0};
};
/// \brief Produces an input
class NGRAPH_API InvariantInputDescription : public InputDescription {
public:
NGRAPH_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// \param body_parameter_index Body parameter to receive input
///
InvariantInputDescription(uint64_t input_index, uint64_t body_parameter_index);
InvariantInputDescription() = default;
std::shared_ptr<InputDescription> copy() const override;
};
/// \brief Produces an output from a specific iteration
class NGRAPH_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription {
public:
NGRAPH_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param body_value_index A body value that produces the output
/// \param output_index The SubGraphOp output index
/// \param iteration which iteration (typically -1, final) will
/// supply the value
///
BodyOutputDescription(uint64_t body_value_index, uint64_t output_index, int64_t iteration = -1);
BodyOutputDescription() = default;
std::shared_ptr<MultiSubGraphOp::OutputDescription> copy() const override;
int64_t m_iteration{0};
};
using MultiSubgraphInputDescriptionPtr = std::shared_ptr<MultiSubGraphOp::InputDescription>;
using MultiSubgraphOutputDescriptionPtr = std::shared_ptr<MultiSubGraphOp::OutputDescription>;
using MultiSubgraphInputDescriptionVector = std::vector<MultiSubgraphInputDescriptionPtr>;
using MultiSubgraphOutputDescriptionVector = std::vector<MultiSubgraphOutputDescriptionPtr>;
/// \brief Gets internal sub-graph by index in MultiSubGraphOp
///
/// \param index sub-graph's index in op
/// \return pointer to ngraph::Function with sub-graph
virtual const std::shared_ptr<Function>& get_function(int index) const {
return m_bodies[index];
};
/// \brief Adds sub-graph to MultiSubGraphOp
///
/// \param index index of new sub-graph
/// \param func func new sub_graph as ngraph::Function
virtual void set_function(int index, const std::shared_ptr<Function>& func) {
m_bodies[index] = func;
}
/// \brief Gets vector with connections beewtwen operation inputs
/// and internal sub-graph parameters
///
/// \param index index of internal sub-graph
/// \return vector of input descriptions
const MultiSubgraphInputDescriptionVector& get_input_descriptions(int index) const {
return m_input_descriptions[index];
}
/// \brief Gets vector with connections beewtwen operation inputs
/// and internal sub-graph parameters
///
/// \param index index of internal sub-graph
/// \return vector of input descriptions
MultiSubgraphInputDescriptionVector& get_input_descriptions(int index) {
return m_input_descriptions[index];
}
/// \brief Gets vector with connections beewtwen operation outputs
/// and internal sub-graph results
///
/// \param index index of internal sub-graph
/// \return vector of output descriptions
const MultiSubgraphOutputDescriptionVector& get_output_descriptions(int index) const {
return m_output_descriptions[index];
}
/// \brief Gets vector with connections beewtwen operation outputs
/// and internal sub-graph results
///
/// \param index index of internal sub-graph
/// \return vector of output descriptions
MultiSubgraphOutputDescriptionVector& get_output_descriptions(int index) {
return m_output_descriptions[index];
}
/// \brief Sets vector with connections beewtwen operation inputs
/// and internal sub-graph parameters
///
/// \param index index of internal sub-graph
/// \param inputs vector of input descriptions
void set_input_descriptions(int index, const MultiSubgraphInputDescriptionVector& inputs) {
m_input_descriptions[index] = inputs;
}
/// \brief Sets vector with connections beewtwen operation outputs
/// and internal sub-graph results
///
/// \param index index of internal sub-graph
/// \param outputs vector of input descriptions
void set_output_descriptions(int index, const MultiSubgraphOutputDescriptionVector& outputs) {
m_output_descriptions[index] = outputs;
}
///
/// \brief Set input decriptions for MultiSubGraphOp input.
///
/// \param value The value supplied as an input to the block.
/// \param bodies_parameters vector of bodies parameters.
virtual void set_invariant_inputs(const Output<Node>& value, const ParameterVector& bodies_parameters);
///
/// \brief Set output decriptions for MultiSubGraphOp output.
///
/// \param bodies_results vector of bodies results for one output.
/// \return value Output node for bodies_results.
virtual Output<Node> set_body_outputs(const ResultVector& bodies_results);
MultiSubGraphOp(const MultiSubGraphOp&) = delete;
MultiSubGraphOp(MultiSubGraphOp&&) = default;
MultiSubGraphOp& operator=(const MultiSubGraphOp&) = delete;
MultiSubGraphOp& operator=(MultiSubGraphOp&&) = default;
protected:
// Find an input corresponding to value, adding one if necessary.
Input<Node> input_for_value(const Output<Node>& value);
MultiSubGraphOp(size_t number_of_bodies);
MultiSubGraphOp() = default;
MultiSubGraphOp(const OutputVector& args, size_t number_of_bodies);
explicit MultiSubGraphOp(const OutputVector& args);
std::vector<std::shared_ptr<Function>> m_bodies;
std::vector<MultiSubgraphInputDescriptionVector> m_input_descriptions;
std::vector<MultiSubgraphOutputDescriptionVector> m_output_descriptions;
};
using MultiSubgraphInputDescriptionPtr = util::MultiSubGraphOp::MultiSubgraphInputDescriptionPtr;
using MultiSubgraphOutputDescriptionPtr = util::MultiSubGraphOp::MultiSubgraphOutputDescriptionPtr;
using ov::op::util::MultiSubGraphOp;
using MultiSubgraphInputDescriptionPtr = ov::op::util::MultiSubGraphOp::InputDescription::Ptr;
using MultiSubgraphOutputDescriptionPtr = ov::op::util::MultiSubGraphOp::OutputDescription::Ptr;
using MultiSubgraphInputDescriptionVector = util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector;
using MultiSubgraphOutputDescriptionVector = util::MultiSubGraphOp::MultiSubgraphOutputDescriptionVector;
} // namespace util
} // namespace op
} // namespace ngraph
namespace ov {
template <>
class NGRAPH_API AttributeAdapter<std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::InputDescription>>>
: public DirectValueAccessor<std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::InputDescription>>> {
public:
AttributeAdapter(std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::InputDescription>>& value)
: DirectValueAccessor<std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::InputDescription>>>(
value) {}
NGRAPH_RTTI_DECLARATION;
};
template <>
class NGRAPH_API AttributeAdapter<std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::OutputDescription>>>
: public DirectValueAccessor<std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::OutputDescription>>> {
public:
AttributeAdapter(std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::OutputDescription>>& value)
: DirectValueAccessor<std::vector<std::shared_ptr<ngraph::op::util::MultiSubGraphOp::OutputDescription>>>(
value) {}
NGRAPH_RTTI_DECLARATION;
};
} // namespace ov
@@ -5,91 +5,13 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/nms_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Base class for operations NmsBase and MatrixNms
///
class NGRAPH_API NmsBase : public Op {
public:
NGRAPH_RTTI_DECLARATION;
enum class SortResultType {
CLASSID, // sort selected boxes by class id (ascending) in each batch element
SCORE, // sort selected boxes by score (descending) in each batch element
NONE // do not guarantee the order in each batch element
};
NmsBase() = delete;
/// \brief Constructs a NmsBase operation
///
/// \param output_type Specifies the output tensor type
/// \param nms_top_k Specifies maximum number of boxes to be selected per
/// class, -1 meaning to keep all boxes
/// \param keep_top_k Specifies maximum number of boxes to be selected per
/// batch element, -1 meaning to keep all boxes
NmsBase(ngraph::element::Type& output_type, int& nms_top_k, int& keep_top_k);
/// \brief Constructs a NmsBase operation
///
/// \param boxes Node producing the box coordinates
/// \param scores Node producing the box scores
/// \param output_type Specifies the output tensor type
/// \param nms_top_k Specifies maximum number of boxes to be selected per
/// class, -1 meaning to keep all boxes
/// \param keep_top_k Specifies maximum number of boxes to be selected per
/// batch element, -1 meaning to keep all boxes
NmsBase(const Output<Node>& boxes,
const Output<Node>& scores,
ngraph::element::Type& output_type,
int& nms_top_k,
int& keep_top_k);
void validate_and_infer_types() override;
const element::Type& get_output_type() const {
return m_output_type;
}
void set_output_type(const element::Type& output_type) {
m_output_type = output_type;
}
using Node::set_output_type;
int get_nms_top_k() const {
return m_nms_top_k;
}
int get_keep_top_k() const {
return m_keep_top_k;
}
protected:
ngraph::element::Type& m_output_type;
int& m_nms_top_k;
int& m_keep_top_k;
virtual void validate();
};
using ov::op::util::NmsBase;
} // namespace util
} // namespace op
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const op::util::NmsBase::SortResultType& type);
using ov::operator<<;
} // namespace ngraph
namespace ov {
template <>
class NGRAPH_API AttributeAdapter<ngraph::op::util::NmsBase::SortResultType>
: public EnumAttributeAdapterBase<ngraph::op::util::NmsBase::SortResultType> {
public:
AttributeAdapter(ngraph::op::util::NmsBase::SortResultType& value)
: EnumAttributeAdapterBase<ngraph::op::util::NmsBase::SortResultType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::util::NmsBase::SortResultType>", 1};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
+12 -49
View File
@@ -8,57 +8,20 @@
#include "ngraph/ngraph_visibility.hpp"
#include "ngraph/node.hpp"
#include "openvino/op/util/op_types.hpp"
namespace ngraph {
namespace op {
NGRAPH_API
bool is_unary_elementwise_arithmetic(const ngraph::Node* node);
NGRAPH_API
bool is_binary_elementwise_arithmetic(const ngraph::Node* node);
NGRAPH_API
bool is_binary_elementwise_comparison(const ngraph::Node* node);
NGRAPH_API
bool is_binary_elementwise_logical(const ngraph::Node* node);
NGRAPH_API
bool supports_auto_broadcast(const ngraph::Node* node);
NGRAPH_API
bool is_op(const ngraph::Node* node);
NGRAPH_API
bool is_parameter(const ngraph::Node* node);
NGRAPH_API
bool is_output(const ngraph::Node* node);
NGRAPH_API
bool is_sink(const ngraph::Node* node);
NGRAPH_API
bool is_constant(const ngraph::Node* node);
NGRAPH_API
bool is_commutative(const ngraph::Node* node);
NGRAPH_API
bool is_unary_elementwise_arithmetic(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_binary_elementwise_arithmetic(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_binary_elementwise_comparison(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_binary_elementwise_logical(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool supports_auto_broadcast(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_op(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_parameter(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_output(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_sink(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_constant(const std::shared_ptr<ngraph::Node>& node);
NGRAPH_API
bool is_commutative(const std::shared_ptr<ngraph::Node>& node);
using ov::op::util::is_binary_elementwise_arithmetic;
using ov::op::util::is_binary_elementwise_comparison;
using ov::op::util::is_binary_elementwise_logical;
using ov::op::util::is_commutative;
using ov::op::util::is_constant;
using ov::op::util::is_op;
using ov::op::util::is_output;
using ov::op::util::is_parameter;
using ov::op::util::is_sink;
using ov::op::util::is_unary_elementwise_arithmetic;
using ov::op::util::supports_auto_broadcast;
} // namespace op
} // namespace ngraph
@@ -5,31 +5,12 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/reduction_base.hpp"
namespace ngraph {
namespace op {
namespace util {
class NGRAPH_API ReductionBase : public Op {
protected:
/// \brief Constructs a reduction operation.
ReductionBase();
/// \brief Constructs a reduction operation.
///
/// \param arg Output that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
ReductionBase(const Output<Node>& arg, const Output<Node>& reduction_axes);
/// \brief Infers reduction operations output shape.
///
/// \param[in] keep_dims Reduction operation keeps dimensions.
///
/// \return Partial shape of the output.
PartialShape infer_reduction_output_shape(const bool keep_dims);
public:
NGRAPH_RTTI_DECLARATION;
};
using ov::op::util::ReductionBase;
} // namespace util
} // namespace op
} // namespace ngraph
} // namespace ngraph
@@ -12,151 +12,14 @@
#include "ngraph/node.hpp"
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/activation_functions.hpp"
#include "openvino/op/util/rnn_cell_base.hpp"
namespace ngraph {
namespace op {
namespace util {
enum class LSTMWeightsFormat {
FICO, // IE
ICOF, // PyTorch
IFCO, // DNNL, TF, MxNet
IFOC, // Caffe
IOFC, // ONNX
};
///
/// \brief Change data format of provided node.
///
/// \param[in] node The input node to be permuted.
///
///
/// \param[in] from_format Original node weights format.
///
///
/// \param[in] to_format Weights format to convert to.
///
/// \return Node representing reshaped tensor according to `to_format` weights
/// format.
///
std::shared_ptr<Node> NGRAPH_API convert_lstm_node_format(const Output<Node>& node,
LSTMWeightsFormat from_format,
LSTMWeightsFormat to_format = LSTMWeightsFormat::FICO,
int64_t axis = 0);
/// \brief Base class for all recurrent network cells.
///
/// \note It holds all common attributes.
///
class NGRAPH_API RNNCellBase : public Op {
public:
NGRAPH_RTTI_DECLARATION;
///
/// \brief Constructs a RNNCellBase class.
///
/// \param[in] hidden_size The number of hidden units for recurrent cell.
/// \param[in] clip The value defining clipping range [-clip, clip]
/// on input of activation functions.
/// \param[in] activations The vector of activation functions used inside
/// recurrent cell.
/// \param[in] activations_alpha The vector of alpha parameters for activation
/// functions in order respective to activation list.
/// \param[in] activations_beta The vector of beta parameters for activation
/// functions in order respective to activation list.
///
RNNCellBase(const OutputVector& args,
std::size_t hidden_size,
float clip,
const std::vector<std::string>& activations,
const std::vector<float>& activations_alpha,
const std::vector<float>& activations_beta);
RNNCellBase();
virtual ~RNNCellBase() = default;
///
/// \brief Validates static rank and dimension for provided input parameters.
/// Additionally input_size dimension is checked for X and W inputs.
///
///
/// \param[in] input Vector with RNN-Cell op inputs in following order:
/// X, initial_hidden_state, W, R and B.
///
void validate_input_rank_dimension(const std::vector<ngraph::PartialShape>& input);
bool visit_attributes(AttributeVisitor& visitor) override;
std::size_t get_hidden_size() const {
return m_hidden_size;
}
float get_clip() const {
return m_clip;
}
const std::vector<std::string>& get_activations() const {
return m_activations;
}
const std::vector<float>& get_activations_alpha() const {
return m_activations_alpha;
}
const std::vector<float>& get_activations_beta() const {
return m_activations_beta;
}
protected:
///
/// \brief Constructs activation function object.
///
/// \param[in] idx The index of the activation function name.
///
/// \return The object representing activation function.
///
ActivationFunction get_activation_function(std::size_t idx) const;
///
/// \brief Creates node with element-wise add operation with numpy
/// broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise add operation.
///
static std::shared_ptr<Node> add(const Output<Node>& lhs, const Output<Node>& rhs);
///
/// \brief Creates node with element-wise subtract operation with numpy
/// broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise subtract operation.
///
static std::shared_ptr<Node> sub(const Output<Node>& lhs, const Output<Node>& rhs);
///
/// \brief Creates node with element-wise multiply operation with numpy
/// broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise multiply operation.
///
static std::shared_ptr<Node> mul(const Output<Node>& lhs, const Output<Node>& rhs);
///
/// \brief Creates node with element-wise clip operation with numpy
/// broadcasting.
///
/// \param[in] data The input tensor for clipping.
///
/// \return Node with element-wise clip operation.
///
std::shared_ptr<Node> clip(const Output<Node>& data) const;
protected:
std::size_t m_hidden_size;
float m_clip;
std::vector<std::string> m_activations;
std::vector<float> m_activations_alpha;
std::vector<float> m_activations_beta;
};
using ov::op::util::convert_lstm_node_format;
using ov::op::util::LSTMWeightsFormat;
using ov::op::util::RNNCellBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -5,45 +5,12 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/scatter_base.hpp"
namespace ngraph {
namespace op {
namespace util {
///
/// \brief Base class for ScatterXXX operators.
///
class NGRAPH_API ScatterBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"ScatterBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
virtual void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
ScatterBase() = default;
///
/// \brief Constructs ScatterBase object.
///
/// \param inputs The input tensor to be updated.
/// \param indices The tensor with indexes which will be updated.
/// \param updates The tensor with update values.
/// \param[in] axis The axis at which elements will be updated.
///
ScatterBase(const Output<Node>& inputs,
const Output<Node>& indices,
const Output<Node>& updates,
const Output<Node>& axis);
private:
// Respective input ordinal number.
static constexpr int DATA = 0;
static constexpr int INDICES = 1;
static constexpr int UPDATES = 2;
static constexpr int AXIS = 3;
};
using ov::op::util::ScatterBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -5,38 +5,12 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/scatter_nd_base.hpp"
namespace ngraph {
namespace op {
namespace util {
///
/// \brief Base class for ScatterNDXXX operators.
///
class NGRAPH_API ScatterNDBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"ScatterNDBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
// Respective input ordinal number.
static constexpr int INPUTS = 0;
static constexpr int INDICES = 1;
static constexpr int UPDATES = 2;
virtual void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
ScatterNDBase() = default;
///
/// \brief Constructs ScatterNDBase object.
///
/// \param inputs The input tensor to be updated.
/// \param indices The tensor with indexes which will be updated.
/// \param updates The tensor with update values.
///
ScatterNDBase(const Output<Node>& inputs, const Output<Node>& indices, const Output<Node>& updates);
};
using ov::op::util::ScatterNDBase;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -7,142 +7,14 @@
#include <ngraph/op/parameter.hpp>
#include "ngraph/op/util/multi_subgraph_base.hpp"
#include "openvino/op/util/sub_graph_base.hpp"
namespace ngraph {
namespace op {
namespace util {
/// \brief Abstract base class for sub-graph based ops, i.e ops that have only one
/// sub-graph
///
class NGRAPH_API SubGraphOp : public MultiSubGraphOp {
public:
NGRAPH_RTTI_DECLARATION;
virtual const std::shared_ptr<Function>& get_function() const {
return m_bodies[0];
};
virtual void set_function(const std::shared_ptr<Function>& func) {
m_bodies[0] = func;
};
/// \return a reference to the input descriptions.
const std::vector<std::shared_ptr<InputDescription>>& get_input_descriptions() const {
return m_input_descriptions[0];
}
/// \return a reference to the input descriptions. Can add input descriptions
/// before
/// validation.
std::vector<std::shared_ptr<InputDescription>>& get_input_descriptions() {
return m_input_descriptions[0];
}
/// \return a reference to the output descriptions.
const std::vector<std::shared_ptr<OutputDescription>>& get_output_descriptions() const {
return m_output_descriptions[0];
}
/// \return a reference to the output descriptions. Can add output descriptions
/// before
/// validation.
std::vector<std::shared_ptr<OutputDescription>>& get_output_descriptions() {
return m_output_descriptions[0];
}
///
/// \brief Indicate that a body parameter comes from slices of a value
///
/// \param parameter The parameter to receive the slices
/// \param value The value to be sliced. This will be added as an input to
/// SubGraphOp.
/// \param start First index on axis of the slicing
/// \param stride Stepping of the slice
/// \param part_size Size of the slice on axis
/// \param end The last index on axis of the slicing
/// \param axis The axis to slice along
///
virtual void set_sliced_input(const std::shared_ptr<Parameter>& parameter,
const Output<Node>& value,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
///
/// \brief Indicates that a body parameter has an initial value in the first
/// iteration and computed value thereafter
///
/// \param[in] body_parameter The body parameter
/// \param initial_value Value for the parameter in first iteration. This
/// will be added as an input to Loop.
/// \param successive_value Value for the parameter in successive iterations.
/// The value is what is active in the most recent
/// completed iteration.
///
virtual void set_merged_input(const std::shared_ptr<Parameter>& body_parameter,
const Output<Node>& initial_value,
const Output<Node>& successive_value);
///
/// \brief Indicates that a body parameter has an invariant value during
/// iteration that may depend on values computed outside of the
/// iteration.
///
/// \param body_parameter The body parameter
/// \param value The value supplied as an input to the block
///
virtual void set_invariant_input(const std::shared_ptr<Parameter>& body_parameter, const Output<Node>& value);
///
/// \brief Gets a value for a particular iteration point
///
/// \param body_value The value
/// \param iteration The iteration that supplies the value. Negative values
/// are from the last iteration.
/// Default value -1 (the last iteration).
///
/// \return The iterator value.
///
virtual Output<Node> get_iter_value(const Output<Node>& body_value, int64_t iteration = -1);
///
/// \brief Concatenates slices from all iterations
///
/// \param value The value supplying slice values from each iteration.
/// \param start First index on axis of the slicing
/// \param stride Stepping of the slice
/// \param part_size Size of the slice on axis
/// \param end The last index on axis of the slicing
/// \param axis The axis to slice along
///
/// \return The concatenated slices.
///
virtual Output<Node> get_concatenated_slices(const Output<Node>& value,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
SubGraphOp(const SubGraphOp&) = delete;
SubGraphOp(SubGraphOp&&) = default;
SubGraphOp& operator=(const SubGraphOp&) = delete;
SubGraphOp& operator=(SubGraphOp&&) = default;
int64_t get_num_iterations() const {
return m_num_iterations;
}
protected:
int64_t m_num_iterations = -1; // -1 means infinity for Loop op, inconsistent for TensorIterator
// Find an input corresponding to value, adding one if necessary.
Input<Node> input_for_value(const Output<Node>& value);
SubGraphOp();
explicit SubGraphOp(const OutputVector& args);
private:
using MultiSubGraphOp::get_function;
using MultiSubGraphOp::set_function;
};
using InputDescriptionPtr = std::shared_ptr<util::SubGraphOp::InputDescription>;
using OutputDescriptionPtr = std::shared_ptr<util::SubGraphOp::OutputDescription>;
using ov::op::util::SubGraphOp;
using InputDescriptionPtr = util::SubGraphOp::InputDescription::Ptr;
using OutputDescriptionPtr = util::SubGraphOp::OutputDescription::Ptr;
using InputDescriptionVector = std::vector<InputDescriptionPtr>;
using OutputDescriptionVector = std::vector<OutputDescriptionPtr>;
} // namespace util
@@ -5,49 +5,12 @@
#pragma once
#include "ngraph/op/op.hpp"
#include "openvino/op/util/unary_elementwise_arithmetic.hpp"
namespace ngraph {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise unary arithmetic operations, i.e.,
/// operations where the same scalar arithmetic operation is applied to each
/// element.
///
/// For example, if the underlying operation (determined by the subclass) is
/// \f$\mathit{op}(x)\f$, the input tensor \f$[[x,y],[z,w]]\f$ will be mapped to
/// \f$[[\mathit{op}(x),\mathit{op}(y)],[\mathit{op}(z),\mathit{op}(w)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ----- | --------------------------------- | ------------------------------------------------------------------------ |
/// | `arg` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape. The element type \f$N\f$ may be any numeric type. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
/// | \f$N[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg}[i_1,\dots,i_n])\f$. This will always have the same shape and element type as the input tensor. |
// clang-format on
class NGRAPH_API UnaryElementwiseArithmetic : public Op {
protected:
/// \brief Constructs a unary elementwise arithmetic operation.
UnaryElementwiseArithmetic();
/// \brief Constructs a unary elementwise arithmetic operation.
///
/// \param arg Output that produces the input tensor.
UnaryElementwiseArithmetic(const Output<Node>& arg);
public:
NGRAPH_RTTI_DECLARATION;
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
private:
void validate_and_infer_elementwise_arithmetic();
};
using ov::op::util::UnaryElementwiseArithmetic;
} // namespace util
} // namespace op
} // namespace ngraph
@@ -10,51 +10,11 @@
#include "ngraph/partial_shape.hpp"
#include "ngraph/type.hpp"
#include "ngraph/type/element_type.hpp"
#include "openvino/op/util/variable.hpp"
namespace ngraph {
struct VariableInfo {
PartialShape data_shape;
element::Type data_type;
std::string variable_id;
inline bool operator==(const VariableInfo& other) const {
return data_shape == other.data_shape && data_type == other.data_type && variable_id == other.variable_id;
}
};
class NGRAPH_API Variable {
public:
Variable() = default;
explicit Variable(const VariableInfo& variable_info) : m_info(variable_info) {}
VariableInfo get_info() const {
return m_info;
}
void update(const VariableInfo& variable_info) {
m_info = variable_info;
}
private:
VariableInfo m_info;
};
using ov::op::util::Variable;
using ov::op::util::VariableInfo;
using VariablePtr = std::shared_ptr<Variable>;
using VariableVector = std::vector<VariablePtr>;
} // namespace ngraph
namespace ov {
template <>
class NGRAPH_API AttributeAdapter<std::shared_ptr<ngraph::Variable>>
: public DirectValueAccessor<std::shared_ptr<ngraph::Variable>> {
public:
explicit AttributeAdapter(std::shared_ptr<ngraph::Variable>& value)
: DirectValueAccessor<std::shared_ptr<ngraph::Variable>>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<std::shared_ptr<Variable>>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
@@ -11,81 +11,9 @@
#include "ngraph/op/util/variable_value.hpp"
#include "ngraph/output_vector.hpp"
#include "ngraph/variant.hpp"
#include "openvino/op/util/variable_context.hpp"
namespace ngraph {
using VariableValuePtr = std::shared_ptr<VariableValue>;
using VariableMap = std::unordered_map<VariablePtr, VariableValuePtr>;
/// VariableContext stores and manages a evaluation context for Variables.
class NGRAPH_API VariableContext {
public:
/// \brief Constructs an uninitialized VariableContext.
VariableContext() = default;
/// \brief Constructor for VariableContext.
/// \param variable_values The values associated with a particular Variables.
explicit VariableContext(const VariableMap& variable_values) : m_variable_values(variable_values) {}
/// \brief Sets the reset flags for all stored Variables to true.
void reset_variable_context() const {
for (const auto& el : m_variable_values) {
el.second->set_reset(true);
}
}
/// \brief Sets the new values for Variables.
/// \param variable_values The new values associated with a particular Variable.
void set_variable_values(const VariableMap& variable_values) {
m_variable_values = variable_values;
}
/// \brief Changes/sets the values for Variable.
/// \param variable New or stored Variable.
/// \param variable_value The values associated with the variable.
void set_variable_value(const VariablePtr& variable, const VariableValuePtr& variable_value) {
m_variable_values[variable] = variable_value;
}
/// \brief Removes context for a particular Variable.
/// \param variable The variable for which the context will be cleared.
void remove_variable_value(const VariablePtr& variable) {
m_variable_values.erase(variable);
}
/// \brief Returns the current values for Variables.
const VariableMap& get_variable_values() const {
return m_variable_values;
}
/// \brief Returns the value for specified Variable.
VariableValuePtr get_variable_value(const VariablePtr& variable) const {
auto var_value = m_variable_values.find(variable);
if (var_value != m_variable_values.end()) {
return (*var_value).second;
}
return VariableValuePtr();
}
private:
/// The values associated with a particular Variable.
VariableMap m_variable_values;
};
using ov::op::util::VariableContext;
} // namespace ngraph
namespace ov {
template <>
class NGRAPH_API VariantWrapper<ngraph::VariableContext> : public VariantImpl<ngraph::VariableContext> {
public:
static constexpr VariantTypeInfo type_info{"Variant::EvaluationContext::VariableContext", 0};
const VariantTypeInfo& get_type_info() const override {
return type_info;
}
explicit VariantWrapper(const value_type& value) : VariantImpl<value_type>(value) {}
private:
using Variant::init;
using Variant::merge;
};
} // namespace ov
@@ -4,37 +4,11 @@
#pragma once
#include <ngraph/runtime/host_tensor.hpp>
#include <utility>
#include "ngraph/runtime/host_tensor.hpp"
#include "openvino/op/util/variable_extension.hpp"
namespace ngraph {
class NGRAPH_API VariableExtension {
public:
VariableExtension() = default;
/// \brief Returns variable connected to this node.
virtual std::shared_ptr<ngraph::Variable> get_variable() const {
return m_variable;
}
/// \brief Sets a new variable to be connected to this node.
///
/// \param variable New variable to be connected to this node.
virtual void set_variable(const std::shared_ptr<ngraph::Variable>& variable) {
m_variable = variable;
}
/// \brief Sets the identifier to a variable
///
/// \param variable_id New identifier of the variable.
virtual void set_variable_id(const std::string& variable_id) {
m_variable->get_info().variable_id = variable_id;
};
/// \brief Returns the identifier of corresponding variable.
virtual std::string get_variable_id() const = 0;
protected:
std::shared_ptr<ngraph::Variable> m_variable;
};
using ov::op::util::VariableExtension;
} // namespace ngraph
@@ -4,51 +4,12 @@
#pragma once
#include <ngraph/runtime/host_tensor.hpp>
#include <utility>
#include "ngraph/runtime/host_tensor.hpp"
#include "openvino/op/util/variable_value.hpp"
namespace ngraph {
/// VariableValue stores data and state (reset flag) for a Variable,
/// and provides an interface for changing them.
class NGRAPH_API VariableValue {
public:
/// \brief Constructs an uninitialized VariableValue.
VariableValue() = default;
/// \brief Constructor for VariableValue.
/// \param value The data for Variable.
explicit VariableValue(HostTensorPtr value) : m_value(std::move(value)) {}
/// \brief Constructor for VariableValue.
/// \param value Data for Variable.
/// \param reset The current state of the reset flag.
VariableValue(HostTensorPtr value, bool reset) : m_reset(reset), m_value(std::move(value)) {}
/// \brief Sets the reset flag to a new state.
/// \param reset The new state of the reset flag.
void set_reset(bool reset) {
m_reset = reset;
}
/// \brief Returns the current reset flag state.
bool get_reset() const {
return m_reset;
}
/// \brief Returns the current stored data.
const HostTensorPtr& get_value() const {
return m_value;
}
/// \brief Sets new values for Variable.
/// \param value New data for Variable.
void set_value(const HostTensorPtr& value) {
m_value = value;
}
private:
bool m_reset = true;
HostTensorPtr m_value;
};
using ov::op::util::VariableValue;
using VariableValuePtr = std::shared_ptr<VariableValue>;
} // namespace ngraph
+2 -41
View File
@@ -10,47 +10,8 @@
#include "ngraph/attribute_adapter.hpp"
#include "ngraph/ngraph_visibility.hpp"
#include "openvino/core/strides.hpp"
namespace ngraph {
/// \brief Strides for a tensor.
class Strides : public std::vector<size_t> {
public:
NGRAPH_API Strides();
NGRAPH_API Strides(const std::initializer_list<size_t>& axis_strides);
NGRAPH_API Strides(const std::vector<size_t>& axis_strides);
NGRAPH_API Strides(const Strides& axis_strides);
NGRAPH_API explicit Strides(size_t n, size_t initial_value = 0);
template <class InputIterator>
Strides(InputIterator first, InputIterator last) : std::vector<size_t>(first, last) {}
NGRAPH_API Strides& operator=(const Strides& v);
NGRAPH_API Strides& operator=(Strides&& v) noexcept;
};
NGRAPH_API
std::ostream& operator<<(std::ostream& s, const Strides& strides);
using ov::Strides;
} // namespace ngraph
namespace ov {
template <>
class NGRAPH_API AttributeAdapter<ngraph::Strides>
: public IndirectVectorValueAccessor<ngraph::Strides, std::vector<int64_t>>
{
public:
AttributeAdapter(ngraph::Strides& value)
: IndirectVectorValueAccessor<ngraph::Strides, std::vector<int64_t>>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<Strides>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
+8 -6
View File
@@ -20,11 +20,7 @@
#include "ngraph/check.hpp"
#include "ngraph/deprecated.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/op/util/op_annotations.hpp"
#include "ngraph/op/util/variable.hpp"
#include "ngraph/op/util/variable_value.hpp"
#include "ngraph/strides.hpp"
#include "openvino/core/attribute_visitor.hpp"
#include "openvino/core/core_visibility.hpp"
#include "openvino/core/descriptor/input.hpp"
@@ -33,8 +29,12 @@
#include "openvino/core/node_input.hpp"
#include "openvino/core/node_output.hpp"
#include "openvino/core/node_vector.hpp"
#include "openvino/core/strides.hpp"
#include "openvino/core/type.hpp"
#include "openvino/core/variant.hpp"
#include "openvino/op/util/attr_types.hpp"
#include "openvino/op/util/variable.hpp"
#include "openvino/op/util/variable_value.hpp"
namespace ngraph {
@@ -43,7 +43,6 @@ class HostTensor;
} // namespace runtime
namespace op {
struct AutoBroadcastSpec;
namespace v0 {
class Result;
@@ -53,6 +52,9 @@ class Result;
} // namespace ngraph
namespace ov {
namespace op {
struct AutoBroadcastSpec;
}
namespace pass {
namespace pattern {
class Matcher;
@@ -196,7 +198,7 @@ public:
return false;
}
/// \returns the autobroadcasr spec
virtual const ngraph::op::AutoBroadcastSpec& get_autob() const;
virtual const ov::op::AutoBroadcastSpec& get_autob() const;
/// \brief Allows to get information about availability of evaluate method for the current
/// operation
@@ -12,15 +12,11 @@
#include "openvino/core/dimension.hpp"
#include "openvino/core/rank.hpp"
namespace ngraph {
namespace ov {
namespace op {
struct AutoBroadcastSpec;
}
} // namespace ngraph
namespace ov {
/// \brief Class representing a shape that may be partially or totally dynamic.
///
///
@@ -0,0 +1,49 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cstddef>
#include <ostream>
#include <vector>
#include "openvino/core/attribute_adapter.hpp"
#include "openvino/core/core_visibility.hpp"
namespace ov {
/// \brief Strides for a tensor.
class Strides : public std::vector<size_t> {
public:
OPENVINO_API Strides();
OPENVINO_API Strides(const std::initializer_list<size_t>& axis_strides);
OPENVINO_API Strides(const std::vector<size_t>& axis_strides);
OPENVINO_API Strides(const Strides& axis_strides);
OPENVINO_API explicit Strides(size_t n, size_t initial_value = 0);
template <class InputIterator>
Strides(InputIterator first, InputIterator last) : std::vector<size_t>(first, last) {}
OPENVINO_API Strides& operator=(const Strides& v);
OPENVINO_API Strides& operator=(Strides&& v) noexcept;
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const Strides& strides);
template <>
class OPENVINO_API AttributeAdapter<Strides> : public IndirectVectorValueAccessor<Strides, std::vector<int64_t>> {
public:
AttributeAdapter(Strides& value) : IndirectVectorValueAccessor<Strides, std::vector<int64_t>>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<Strides>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
+20
View File
@@ -0,0 +1,20 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <string>
#include "openvino/core/node.hpp"
namespace ov {
namespace op {
/// Root of all actual ops
class OPENVINO_API Op : public Node {
protected:
Op() : Node() {}
Op(const OutputVector& arguments);
};
} // namespace op
} // namespace ov
@@ -0,0 +1,86 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <string>
#include "openvino/core/core_visibility.hpp"
#include "openvino/core/except.hpp"
#include "openvino/core/node.hpp"
#ifdef _WIN32
# pragma warning(push)
# pragma warning(disable : 4100)
#endif
namespace ov {
namespace op {
namespace util {
namespace error {
struct UnknownActivationFunction : Exception {
UnknownActivationFunction(const std::string& func_name) : Exception{"Unknown activation function: " + func_name} {}
};
} // namespace error
namespace detail {
std::shared_ptr<Node> sigmoid(const std::shared_ptr<Node>& arg, float alpha, float beta);
std::shared_ptr<Node> tanh(const std::shared_ptr<Node>& arg, float alpha, float beta);
std::shared_ptr<Node> relu(const std::shared_ptr<Node>& arg, float alpha, float beta);
std::shared_ptr<Node> hardsigmoid(const std::shared_ptr<Node>& arg, float alpha, float beta);
} // namespace detail
using ActivationFunctionType = std::shared_ptr<Node> (*)(const std::shared_ptr<Node>&, float, float);
///
/// \brief Class representing activation function used in RNN cells.
///
class OPENVINO_API ActivationFunction {
public:
ActivationFunction(ActivationFunctionType f, float alpha, float beta);
ActivationFunction(ActivationFunctionType f, float alpha);
ActivationFunction(ActivationFunctionType f);
ActivationFunction() = default;
///
/// \brief Calls stored activation function with provided node argument.
///
std::shared_ptr<Node> operator()(const std::shared_ptr<Node>& arg) const;
void set_alpha(float alpha) {
m_alpha = alpha;
}
void set_beta(float beta) {
m_beta = beta;
}
private:
/// \brief Activation function wrapper.
ActivationFunctionType m_function;
/// \brief Activation function alpha parameter (may be unused).
float m_alpha;
/// \brief Activation function beta parameter (may be unused).
float m_beta;
};
/// \brief Gets the activation function by name.
///
/// \param[in] func_name The function name
///
/// \throws UnknownActivationFunction When provided func_name is unknown.
///
/// \return The activation function object.
///
ActivationFunction get_activation_func_by_name(const std::string& func_name);
} // namespace util
} // namespace op
} // namespace ov
#ifdef _WIN32
# pragma warning(pop)
#endif
@@ -0,0 +1,44 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/core_visibility.hpp"
#include "openvino/op/util/reduction_base.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Abstract base class for arithmetic reduction operations, i.e., operations
/// where chosen axes of the input tensors are eliminated (reduced out) by
/// repeated application of a particular binary arithmetic operation.
class OPENVINO_API ArithmeticReduction : public ReductionBase {
protected:
/// \brief Constructs an arithmetic reduction operation.
ArithmeticReduction();
/// \brief Constructs an arithmetic reduction operation.
///
/// \param arg Output that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
ArithmeticReduction(const Output<Node>& arg, const Output<Node>& reduction_axes);
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return true if reduction axes are constant else false.
bool reduction_axes_constant() const;
/// \return The axis positions (0-based) to be eliminated through reduction.
/// \throws CheckFailure if the reduction axes are not constant. (Use
/// reduction_axes_constant to check.)
const AxisSet get_reduction_axes() const;
/// \brief Change the reduction axes
void set_reduction_axes(const AxisSet& reduction_axes);
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,41 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/util/arithmetic_reduction.hpp"
namespace ov {
namespace op {
namespace util {
class OPENVINO_API ArithmeticReductionKeepDims : public util::ArithmeticReduction {
protected:
ArithmeticReductionKeepDims() = default;
/// \param arg The tensor to be summed.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
/// \param keep_dims If set to 1 it holds axes that are used for reduction.
ArithmeticReductionKeepDims(const Output<Node>& arg, const Output<Node>& reduction_axes, bool keep_dims = false);
bool visit_attributes(AttributeVisitor& visitor) override;
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return If set to 1 it holds axes that are used for reduction.
/// For each such axis, output dimension is equal to 1.
bool get_keep_dims() const {
return m_keep_dims;
}
void set_keep_dims(bool keep_dims) {
m_keep_dims = keep_dims;
}
private:
bool m_keep_dims = false;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,333 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cstddef>
#include <ostream>
#include "openvino/core/attribute_adapter.hpp"
#include "openvino/core/core_visibility.hpp"
#include "openvino/core/type.hpp"
namespace ov {
namespace op {
/// \brief Modes for the `Pad` operator.
enum class PadMode { CONSTANT = 0, EDGE, REFLECT, SYMMETRIC };
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const PadMode& type);
/// \brief Padding Type used for `Convolution` and `Pooling`
///
/// Follows ONNX padding type definitions
/// EXPLICIT - Pad dimensions are explicity specified
/// SAME_LOWER - Pad dimensions computed to match input shape
/// Ceil(num_dims/2) at the beginning and
/// Floor(num_dims/2) at the end
/// SAME_UPPER - Pad dimensions computed to match input shape
/// Floor(num_dims/2) at the beginning and
/// Ceil(num_dims/2) at the end
/// VALID - No padding
/// AUTO - Deprecated. User should not use it in the future
/// NOTSET - Deprecated. User should not use it in the future
enum class PadType {
EXPLICIT = 0,
SAME_LOWER,
SAME_UPPER,
VALID,
AUTO = SAME_UPPER,
NOTSET = EXPLICIT,
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const PadType& type);
/// \brief Rounding Type used for `Pooling` operators.
enum class RoundingType {
FLOOR = 0,
CEIL = 1,
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const RoundingType& type);
/// \brief Specifies the algorithm to use for implicit broadcasting of a tensor
/// to align with another tensor
///
/// NONE - No implicit broadcasting of tensor
/// NUMPY - Numpy-style implicit broadcasting
/// (https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html)
/// Right-align dimensions of the two tensors, with missing dimensions
/// treated as size 1 dimensions. After alignment, for each dimension,
/// their sizes should either match or one of them should be of size 1.
/// Size 1 dimension will be implicitly broadcast to match the other
/// size.
///
/// E.g.,
/// A: Shape(2, 1, 6)
/// B: Shape( 3, 1)
/// Result: Shape(2, 3, 6)
///
/// A: Shape(2, 1, 6)
/// B: Shape( 3, 1)
/// Result: Shape(2, 3, 6)
/// PDPD - PaddlePaddle-style implicit broadcasting
/// (https://github.com/PaddlePaddle/Paddle/blob/release/1.5/paddle/
/// fluid/operators/elementwise/elementwise_op.h#L126)
/// Broadcast B to match the shape of A, where axis is the start
/// dimension index to align B with A. If axis is -1 (default), i
/// axis = rank(A) - rank(B). The trailing dimensions of size 1 for B
/// will be ignored.
///
/// E.g.,
/// A: Shape(2, 3, 4, 5)
/// B: Shape( 3, 4 ) with axis =1
/// Result: Shape(2, 3, 4, 5)
///
/// A: Shape(2, 3, 4, 5)
/// B: Shape( 3, 1 ) with axis = 1
/// Result: Shape(2, 3, 4, 5)
///
enum class AutoBroadcastType {
NONE = 0,
EXPLICIT = NONE,
NUMPY,
PDPD,
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const AutoBroadcastType& type);
/// \brief BroadcastType specifies rules used for mapping of input tensor axes to output
/// shape axes.
///
/// \note Broadcasting rules are different for Broadcast op and for element-wise ops.
/// AutoBroadcastType::NUMPY is equivalent of BroadcastType::BIDIRECTIONAL
/// according to spec.
///
/// EXPLICIT - Mapping of the input data shape to output shape
/// based on axes_mapping input.
/// NUMPY - Numpy broadcasting rules, aligned with ONNX Broadcasting.
/// (https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md)
/// PDPD - PaddlePaddle-style implicit broadcasting.
/// For more informaction see AutoBroadcastType documentation.
/// BIDIRECTIONAL - The broadcast rule is similar to
/// numpy.array(input) * numpy.ones(target_shape).
/// Dimensions are right alignment.
enum class BroadcastType { NONE, EXPLICIT = NONE, NUMPY, PDPD, BIDIRECTIONAL };
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const BroadcastType& type);
/// \brief Specifies how eps is combined with L2 value
enum class EpsMode {
// Add bias to norm
ADD,
// Calculate max of norm and bias
MAX
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const EpsMode& type);
enum class TopKSortType {
// Returned values are not sorte
NONE,
// Sort result based on element indices
SORT_INDICES,
// Sort result based on element values
SORT_VALUES,
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const TopKSortType& type);
enum class TopKMode {
MAX,
MIN,
};
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const TopKMode& type);
/// \brief Implicit broadcast specification
struct OPENVINO_API AutoBroadcastSpec {
AutoBroadcastSpec() : m_type(AutoBroadcastType::NONE), m_axis(0) {}
AutoBroadcastSpec(AutoBroadcastType type) : m_type(type), m_axis(0) {}
AutoBroadcastSpec(const char* type) : AutoBroadcastSpec(type_from_string(type)) {}
AutoBroadcastSpec(AutoBroadcastType type, int64_t axis) : m_type(type), m_axis(axis) {}
AutoBroadcastType m_type; // Implicit broadcasting algorithm
int64_t m_axis; // Axis to start alignment on
bool operator==(const AutoBroadcastSpec& a) const {
return a.m_type == m_type && a.m_axis == m_axis;
}
bool operator!=(const AutoBroadcastSpec& a) const {
return !(*this == a);
}
static const AutoBroadcastSpec NUMPY;
static const AutoBroadcastSpec NONE;
private:
AutoBroadcastType type_from_string(const std::string& type) const;
};
/// \brief Implicit broadcast specification
struct OPENVINO_API BroadcastModeSpec {
BroadcastModeSpec() : m_type(BroadcastType::NUMPY), m_axis(0) {}
BroadcastModeSpec(BroadcastType type) : m_type(type), m_axis(0) {}
BroadcastModeSpec(const char* type) : BroadcastModeSpec(as_enum<BroadcastType>(type)) {}
BroadcastModeSpec(BroadcastType type, int64_t axis) : m_type(type), m_axis(axis) {}
BroadcastType m_type; // Implicit broadcasting algorithm
int64_t m_axis; // Axis to start alignment on
bool operator==(const BroadcastModeSpec& a) const {
return a.m_type == m_type && a.m_axis == m_axis;
}
};
///
/// \brief This class defines possible recurrent sequence directions.
///
enum class RecurrentSequenceDirection { FORWARD, REVERSE, BIDIRECTIONAL };
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const RecurrentSequenceDirection& direction);
} // namespace op
template <>
class OPENVINO_API AttributeAdapter<op::PadMode> : public EnumAttributeAdapterBase<op::PadMode> {
public:
AttributeAdapter(op::PadMode& value) : EnumAttributeAdapterBase<op::PadMode>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::PadMode>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::PadType> : public EnumAttributeAdapterBase<op::PadType> {
public:
AttributeAdapter(op::PadType& value) : EnumAttributeAdapterBase<op::PadType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::PadType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::RoundingType> : public EnumAttributeAdapterBase<op::RoundingType> {
public:
AttributeAdapter(op::RoundingType& value) : EnumAttributeAdapterBase<op::RoundingType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::RoundingType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::AutoBroadcastType> : public EnumAttributeAdapterBase<op::AutoBroadcastType> {
public:
AttributeAdapter(op::AutoBroadcastType& value) : EnumAttributeAdapterBase<op::AutoBroadcastType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::AutoBroadcastType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::BroadcastType> : public EnumAttributeAdapterBase<op::BroadcastType> {
public:
AttributeAdapter(op::BroadcastType& value) : EnumAttributeAdapterBase<op::BroadcastType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::BroadcastType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::EpsMode> : public EnumAttributeAdapterBase<op::EpsMode> {
public:
AttributeAdapter(op::EpsMode& value) : EnumAttributeAdapterBase<op::EpsMode>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::EpsMode>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::TopKSortType> : public EnumAttributeAdapterBase<op::TopKSortType> {
public:
AttributeAdapter(op::TopKSortType& value) : EnumAttributeAdapterBase<op::TopKSortType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::TopKSortType>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class OPENVINO_API AttributeAdapter<op::TopKMode> : public EnumAttributeAdapterBase<op::TopKMode> {
public:
AttributeAdapter(op::TopKMode& value) : EnumAttributeAdapterBase<op::TopKMode>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::TopKMode>", 1};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
template <>
class AttributeAdapter<op::AutoBroadcastSpec> : public VisitorAdapter {
public:
AttributeAdapter(op::AutoBroadcastSpec& value) : m_ref(value) {}
bool visit_attributes(AttributeVisitor& visitor) override;
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::AutoBroadcastSpec>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
protected:
op::AutoBroadcastSpec& m_ref;
};
template <>
class AttributeAdapter<op::BroadcastModeSpec> : public VisitorAdapter {
public:
AttributeAdapter(op::BroadcastModeSpec& value) : m_ref(value) {}
bool visit_attributes(AttributeVisitor& visitor) override;
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::BroadcastModeSpec>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
protected:
op::BroadcastModeSpec& m_ref;
};
template <>
class OPENVINO_API AttributeAdapter<op::RecurrentSequenceDirection>
: public EnumAttributeAdapterBase<op::RecurrentSequenceDirection> {
public:
AttributeAdapter(op::RecurrentSequenceDirection& value)
: EnumAttributeAdapterBase<op::RecurrentSequenceDirection>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::RecurrentSequenceDirection>", 1};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
@@ -0,0 +1,70 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ov {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise binary arithmetic operations, i.e.,
/// operations where the same scalar binary arithmetic operation is applied to
/// each corresponding pair of elements in the two input tensors. Implicit
/// broadcast of input tensors is supported through one of the AutoBroadcast
/// modes.
///
/// For example, if the underlying arithmetic operation (determined by the subclass) is
/// \f$\mathit{op}(x,y)\f$, the input tensors
/// \f$[[x_0,y_0],[z_0,w_0]]\f$ and \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
/// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ------ | --------------------------------- | ------------------------------------------------------------------------ |
/// | `arg0` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape. The element type \f$N\f$ may be any numeric type. |
/// | `arg1` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same element type as `arg0`. |
/// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
/// | \f$N[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape and element type as the input tensors (after auto broadcasting). |
// clang-format on
class OPENVINO_API BinaryElementwiseArithmetic : public Op {
protected:
BinaryElementwiseArithmetic(const AutoBroadcastSpec& autob);
/// \brief Constructs a binary elementwise arithmetic operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
BinaryElementwiseArithmetic(const Output<Node>& arg0, const Output<Node>& arg1, const AutoBroadcastSpec& autob);
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
const AutoBroadcastSpec& get_autob() const override {
return m_autob;
}
void set_autob(const AutoBroadcastSpec& autob) {
m_autob = autob;
}
bool visit_attributes(AttributeVisitor& visitor) override;
bool evaluate_lower(const HostTensorVector& outputs) const override;
bool evaluate_upper(const HostTensorVector& outputs) const override;
private:
AutoBroadcastSpec m_autob;
void validate_and_infer_elementwise_arithmetic(const op::AutoBroadcastSpec& autob);
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,71 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ov {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise binary comparison operations, i.e.,
/// operations where the same scalar binary comparison operation is applied to
/// each corresponding pair of elements in two input tensors. Implicit
/// broadcast of input tensors is supported through one of the AutoBroadcast
/// modes.
///
/// For example, if the underlying comparison operation (determined by the subclass) is
/// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
/// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
/// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ------ | --------------------------------- | ------------------------------------------------------ |
/// | `arg0` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape and element type. |
/// | `arg1` | \f$E[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
/// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
/// | \f$\texttt{bool}[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape as the input tensors, and the element type `bool`. |
// clang-format on
class OPENVINO_API BinaryElementwiseComparison : public Op {
protected:
/// \brief Constructs a binary elementwise comparison operation.
BinaryElementwiseComparison(const AutoBroadcastSpec& autob);
/// \brief Constructs a binary elementwise comparison operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
/// \param autob AutoBroadcast mode.
BinaryElementwiseComparison(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob = AutoBroadcastSpec());
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
const AutoBroadcastSpec& get_autob() const override {
return m_autob;
}
void set_autob(const AutoBroadcastSpec& autob) {
m_autob = autob;
}
bool visit_attributes(AttributeVisitor& visitor) override;
private:
AutoBroadcastSpec m_autob;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,68 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise binary logical operations, i.e.,
/// operations where the same scalar binary logical operation is applied to
/// each corresponding pair of elements in two boolean input tensors. Implicit
/// broadcast of input tensors is supported through one of the AutoBroadcast
/// modes.
///
/// For example, if the underlying operation (determined by the subclass) is
/// \f$\mathit{op}(x,y)\f$, the input tensors \f$[[x_0,y_0],[z_0,w_0]]\f$ and
/// \f$[[x_1,y_1],[z_1,w_1]]\f$ will be mapped to
/// \f$[[\mathit{op}(x_0,x_1),\mathit{op}(y_0,y_1)],[\mathit{op}(z_0,z_1),\mathit{op}(w_0,w_1)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ------ | --------------------------------------------- | ------------------------------------------------------ |
/// | `arg0` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape, with element type `bool`. |
/// | `arg1` | \f$\texttt{bool}[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of the same shape and element type as `arg0`. |
/// | `autob`| AutoBroadcastSpec | Auto broadcast specification. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
/// | \f$\texttt{bool}[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg0}[i_1,\dots,i_n],\texttt{arg1}[i_1,\dots,i_n])\f$. This will always have the same shape as the input tensors, and the element type `bool`. |
// clang-format on
class OPENVINO_API BinaryElementwiseLogical : public Op {
protected:
OPENVINO_RTTI_DECLARATION;
BinaryElementwiseLogical();
/// \brief Constructs a binary elementwise logical operation.
///
/// \param arg0 Output that produces the first input tensor.
/// \param arg1 Output that produces the second input tensor.
BinaryElementwiseLogical(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob = AutoBroadcastSpec());
public:
void validate_and_infer_types() override;
const AutoBroadcastSpec& get_autob() const override {
return m_autob;
}
void set_autob(const AutoBroadcastSpec& autob) {
m_autob = autob;
}
bool visit_attributes(AttributeVisitor& visitor) override;
private:
AutoBroadcastSpec m_autob = AutoBroadcastSpec::NUMPY;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,84 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/axis_set.hpp"
#include "openvino/core/axis_vector.hpp"
#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ov {
namespace op {
namespace util {
class OPENVINO_API BroadcastBase : public Op {
protected:
BroadcastBase() = default;
/// \brief Constructs a broadcast operation.
///
/// \param arg The input tensor to be broadcast.
/// \param target_shape The shape of the output tensor.
/// \param axes_mapping The axis positions (0-based) in the result that correspond
/// to input axes.
/// \param broadcast_mode Broadcast specification to use for determining broadcast
/// axes. 'axes_mapping' should not be provided if mode other
///
BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const Output<Node>& axes_mapping,
const BroadcastModeSpec& broadcast_mode = BroadcastType::EXPLICIT);
/// \brief Constructs a broadcast operation.
///
/// \param arg The input tensor to be broadcast.
/// \param target_shape The shape of the output tensor.
/// \param broadcast_mode Broadcast specification to use for determining broadcast
/// axes
BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const BroadcastModeSpec& broadcast_mode = BroadcastType::NUMPY);
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return true and the AxisSet if broadcast axes can be fully determined.
virtual std::pair<bool, AxisSet> get_broadcast_axes() const;
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
protected:
BroadcastModeSpec m_mode;
bool evaluate_broadcast(const HostTensorPtr& arg0,
const HostTensorPtr& out,
const std::pair<bool, AxisSet>& pair_broadcast_axes,
const ngraph::Shape& output_shape) const;
bool evaluate_broadcast(const HostTensorPtr& arg0, const HostTensorPtr& out, const AxisSet& broadcast_axes) const;
bool evaluate_lower(const HostTensorVector& outputs) const override;
bool evaluate_upper(const HostTensorVector& outputs) const override;
PartialShape get_result_shape_pdpd(const PartialShape& arg0_shape,
const PartialShape& target_shape,
const op::BroadcastModeSpec& broadcast_spec) const;
void validate_target_shape_numpy(const PartialShape& arg_shape, const PartialShape& target_shape) const;
static std::pair<bool, AxisSet> get_broadcast_axes_numpy_pdpd(const ngraph::Shape& arg_shape,
const ngraph::Shape& result_shape,
const op::BroadcastModeSpec& broadcast_spec);
static std::pair<bool, AxisSet> get_broadcast_axes_none(const AxisVector& axes_mapping_val,
const size_t target_shape);
void validate_target_shape_none(const PartialShape& arg_shape,
const AxisVector& axes_mapping_val,
const PartialShape& target_shape) const;
ngraph::Shape get_target_shape(const HostTensorPtr& input1) const;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,105 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/coordinate_diff.hpp"
#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Base class for operations DeformableConvolution v1 and DeformableConvolution
/// v8.
class OPENVINO_API DeformableConvolutionBase : public Op {
public:
OPENVINO_RTTI_DECLARATION;
/// \brief Constructs a conversion operation.
DeformableConvolutionBase() = default;
/// \brief Constructs a conversion operation.
/// \param strides Convolution strides.
/// \param pads_begin Amount of padding to be added to the beginning along
/// each axis. For example in case of a 2D input the value
/// of (1, 2) means that 1 element will be added to the
/// top and 2 elements to the left.
/// \param pads_end Amount of padding to be added to the end along each
/// axis.
/// \param dilations The distance in width and height between the weights
/// in the filters tensor.
/// \param auto_pad Specifies how the automatic calculation of padding
/// should be done.
/// \param group The number of groups which both output and input
/// should be split into.
/// \param deformable_group The number of groups which deformable values and
/// output should be split into along the channel axis.
DeformableConvolutionBase(const OutputVector& arguments,
const Strides& strides,
const CoordinateDiff& pads_begin,
const CoordinateDiff& pads_end,
const Strides& dilations,
const PadType& auto_pad = PadType::EXPLICIT,
int64_t group = 1,
int64_t deformable_group = 1);
bool visit_attributes(AttributeVisitor& visitor) override;
void validate_and_infer_types() override;
const Strides& get_strides() const {
return m_strides;
}
void set_strides(const Strides& strides) {
m_strides = strides;
}
const Strides& get_dilations() const {
return m_dilations;
}
void set_dilations(const Strides& dilations) {
m_dilations = dilations;
}
const CoordinateDiff& get_pads_begin() const {
return m_pads_begin;
}
void set_pads_begin(const CoordinateDiff& pads_begin) {
m_pads_begin = pads_begin;
}
const CoordinateDiff& get_pads_end() const {
return m_pads_end;
}
void set_pads_end(const CoordinateDiff& pads_end) {
m_pads_end = pads_end;
}
const PadType& get_auto_pad() const {
return m_auto_pad;
}
void set_auto_pad(const PadType& auto_pad) {
m_auto_pad = auto_pad;
}
int64_t get_group() const {
return m_group;
}
void set_group(const int64_t group) {
m_group = group;
}
int64_t get_deformable_group() const {
return m_deformable_group;
}
void set_deformable_group(const int64_t deformable_group) {
m_deformable_group = deformable_group;
}
protected:
Strides m_strides;
Strides m_dilations;
CoordinateDiff m_pads_begin;
CoordinateDiff m_pads_end;
PadType m_auto_pad;
int64_t m_group;
int64_t m_deformable_group;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,17 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/node.hpp"
namespace ov {
namespace op {
namespace util {
std::tuple<element::Type, PartialShape> validate_and_infer_elementwise_args(
Node* node,
const op::AutoBroadcastSpec& autob = op::AutoBroadcastSpec());
}
} // namespace op
} // namespace ov
@@ -0,0 +1,66 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/axis_set.hpp"
#include "openvino/op/util/index_reduction.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Returns embeddings for given indices
class OPENVINO_API EmbeddingBagOffsetsBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"EmbeddingBagOffsetsBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
/// \brief Constructs a EmbeddingBagOffsetsBase operation.
EmbeddingBagOffsetsBase() = default;
/// \brief Constructs a EmbeddingBagOffsetsBase operation.
///
/// EmbeddingBagOffsetsBase constructs an output tensor by replacing every index in
/// a
/// given
/// input tensor with a row (from the weights matrix) at that index
///
/// \param emb_table tensor containing the embedding lookup table of the module of
/// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
/// \param tensor of shape [num_indices] and of type T_IND. Required
/// \param offsets tensor of shape [batch] and of type T_IND containing the starting
/// index positions of each "bag" in indices. Required.
/// \param per_sample_weigths tensor of the same shape as indices and of type T.
/// Each value in this tensor are multiplied with each
/// value pooled from embedding table for each index. Optional.
/// \param default_index scalar of type T_IND containing default index in embedding
/// table to fill empty "bags". If not provided empty "bags"
/// are filled with zeros. Optional.
EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index,
const Output<Node>& per_sample_weights);
EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index);
EmbeddingBagOffsetsBase(const Output<Node>& emb_table, const Output<Node>& indices, const Output<Node>& offsets);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
private:
static constexpr int EMB_TABLE = 0;
static constexpr int INDICES = 1;
static constexpr int OFFSETS = 2;
static constexpr int DEFAULT_INDEX = 3;
static constexpr int PER_SAMPLE_WEIGHTS = 4;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,52 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/axis_set.hpp"
#include "openvino/op/util/index_reduction.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Returns embeddings for given indices
class OPENVINO_API EmbeddingBagPackedBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"EmbeddingBagPackedBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
/// \brief Constructs a EmbeddingBagPackedBase operation.
EmbeddingBagPackedBase() = default;
/// \brief Constructs a EmbeddingBagPackedBase operation.
///
/// EmbeddingBagPackedBase constructs an output tensor by replacing every index in a
/// given
/// input tensor with a row (from the weights matrix) at that index
///
/// \param emb_table Tensor containing the embedding lookup table of the module of
/// shape [num_emb, emb_dim1, emb_dim2, ...] and of type T
/// \param indices Tensor of shape `[batch, indices_per_bag]` and of type *T_IND*.
/// Required.
/// \param per_sample_weigths tensor of the same shape as indices and of type T.
/// Each value in this tensor are multiplied with each
/// value pooled from embedding table for each index. Optional.
EmbeddingBagPackedBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& per_sample_weights);
EmbeddingBagPackedBase(const Output<Node>& emb_table, const Output<Node>& indices);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
private:
static constexpr int EMB_TABLE = 0;
static constexpr int INDICES = 1;
static constexpr int PER_SAMPLE_WEIGHTS = 2;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,40 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Base class for operations DFT and DFT.
class OPENVINO_API FFTBase : public Op {
public:
OPENVINO_RTTI_DECLARATION;
FFTBase() = default;
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
/// \brief Constructs an FFT operation. FFT is performed for full size axes.
///
/// \param data Input data
/// \param axes Axes to perform FFT
FFTBase(const Output<Node>& data, const Output<Node>& axes);
/// \brief Constructs a FFT operation.
///
/// \param data Input data
/// \param axes Axes to perform FFT
/// \param signal_size Signal sizes for 'axes'
FFTBase(const Output<Node>& data, const Output<Node>& axes, const Output<Node>& signal_size);
void validate();
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,42 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief GatherBase basic class for Gather v1 and v7
class OPENVINO_API GatherBase : public Op {
public:
OPENVINO_RTTI_DECLARATION;
GatherBase() = default;
/// \param data The tensor from which slices are gathered
/// \param indices Tensor with indexes to gather
/// \param axis The tensor is a dimension index to gather data from
/// \param batch_dims The number of batch dimension in data and indices tensors
GatherBase(const Output<Node>& data,
const Output<Node>& indices,
const Output<Node>& axis,
const int64_t batch_dims = 0);
void validate_and_infer_types() override;
virtual int64_t get_axis() const;
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
bool evaluate_lower(const HostTensorVector& outputs) const override;
bool evaluate_upper(const HostTensorVector& outputs) const override;
bool constant_fold(OutputVector& output_values, const OutputVector& inputs_values) override;
protected:
int64_t m_batch_dims = 0;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,37 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
class NGRAPH_API IndexReduction : public Op {
protected:
IndexReduction();
IndexReduction(const Output<Node>& arg, uint64_t axis, const element::Type& index_element_type);
public:
uint64_t get_reduction_axis() const;
void set_reduction_axis(uint64_t value);
element::Type get_index_element_type() const;
void set_index_element_type(const element::Type& index_element_type);
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
uint64_t m_axis{0};
element::Type m_index_element_type;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,46 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
#include "openvino/op/util/reduction_base.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Abstract base class for logical reduction operations, i.e., operations where
/// chosen axes of the input tensors are eliminated (reduced out) by repeated
/// application of a particular binary logical operation.
class OPENVINO_API LogicalReduction : public ReductionBase {
protected:
/// \brief Constructs a logical reduction operation.
LogicalReduction();
/// \brief Constructs a logical reduction operation.
///
/// \param arg Output that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
LogicalReduction(const Output<Node>& arg, const AxisSet& reduction_axes);
/// \brief Constructs a 'dynamic' logical reduction operation.
///
/// \param arg Node that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
LogicalReduction(const Output<Node>& arg, const Output<Node>& reduction_axes);
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return true if reduction axes are constant else false.
bool reduction_axes_constant() const;
/// \return The axis positions (0-based) to be eliminated through reduction.
/// \throws CheckFailure if the reduction axes are not constant. (Use
/// reduction_axes_constant to check.)
const AxisSet get_reduction_axes() const;
void set_reduction_axes(const AxisSet& reduction_axes);
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,42 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
#include "openvino/op/util/logical_reduction.hpp"
namespace ov {
namespace op {
namespace util {
class OPENVINO_API LogicalReductionKeepDims : public util::LogicalReduction {
protected:
LogicalReductionKeepDims() = default;
/// \param arg The tensor to be reduced.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
/// \param keep_dims If set to 1 it holds axes that are used for reduction.
LogicalReductionKeepDims(const Output<Node>& arg, const Output<Node>& reduction_axes, const bool keep_dims = false);
bool visit_attributes(AttributeVisitor& visitor) override;
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
/// \return If set to 1 it holds axes that are used for reduction.
/// For each such axis, output dimension is equal to 1.
bool get_keep_dims() const {
return m_keep_dims;
}
void set_keep_dims(bool keep_dims) {
m_keep_dims = keep_dims;
}
private:
bool m_keep_dims = false;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,96 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
#include "openvino/op/util/attr_types.hpp"
namespace ov {
namespace op {
namespace util {
class OPENVINO_API MaxPoolBase : public Op {
public:
OPENVINO_RTTI_DECLARATION;
MaxPoolBase() = default;
/// \param arg The node producing the input data batch tensor.
/// \param strides The strides.
/// \param pads_begin The beginning of padding shape.
/// \param pads_end The end of padding shape.
/// \param kernel The kernel shape.
/// \param rounding_mode Whether to use ceiling or floor rounding type while
/// computing output shape.
/// \param auto_pad The pad type for automatically computing padding sizes.
MaxPoolBase(const Output<Node>& arg,
const Strides& strides,
const ngraph::Shape& pads_begin,
const ngraph::Shape& pads_end,
const ngraph::Shape& kernel,
const op::RoundingType rounding_mode = op::RoundingType::FLOOR,
const PadType auto_pad = op::PadType::EXPLICIT);
void validate_and_infer_types() override;
/// \return The kernel shape.
const ngraph::Shape& get_kernel() const {
return m_kernel;
}
void set_kernel(const ngraph::Shape& kernel) {
m_kernel = kernel;
}
/// \return The strides.
const Strides& get_strides() const {
return m_strides;
}
void set_strides(const Strides& strides) {
m_strides = strides;
}
/// \return The beginning of padding shape.
const ngraph::Shape& get_pads_begin() const {
return m_pads_begin;
}
void set_pads_begin(const ngraph::Shape& pads_begin) {
m_pads_begin = pads_begin;
}
/// \return The end of padding shape.
const ngraph::Shape& get_pads_end() const {
return m_pads_end;
}
void set_adding_above(const ngraph::Shape& pads_end) {
m_pads_end = pads_end;
}
/// \return The pad type for pooling.
PadType get_auto_pad() const {
return m_auto_pad;
}
void set_auto_pad(const PadType auto_pad) {
m_auto_pad = auto_pad;
}
/// \return The ceiling mode being used for output shape computations
op::RoundingType get_rounding_type() const {
return m_rounding_type;
}
void set_rounding_type(op::RoundingType rounding_type) {
m_rounding_type = rounding_type;
}
protected:
bool update_auto_padding(const PartialShape& in_shape,
const Strides& filter_dilations,
ngraph::Shape& new_pads_end,
ngraph::Shape& new_pads_begin) const;
PartialShape infer_output_shape(const Strides& dilations);
ngraph::Shape m_kernel;
Strides m_strides;
ngraph::Shape m_pads_begin;
ngraph::Shape m_pads_end;
PadType m_auto_pad;
op::RoundingType m_rounding_type;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,313 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/op/parameter.hpp"
#include "openvino/core/function.hpp"
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Abstract base class for sub-graph based ops, i.e ops that have some
/// sub-graphs
///
class OPENVINO_API MultiSubGraphOp : public Op {
public:
OPENVINO_RTTI_DECLARATION;
/// \brief Abstract class describes a connection between a MultiSubGraphOp input and
/// the body.
class InputDescription {
protected:
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// \param body_parameter_index Body parameter to receive input
///
InputDescription(uint64_t input_index, uint64_t body_parameter_index);
InputDescription() = default;
public:
using Ptr = std::shared_ptr<InputDescription>;
using type_info_t = DiscreteTypeInfo;
virtual ~InputDescription() = default;
virtual std::shared_ptr<InputDescription> copy() const = 0;
virtual const type_info_t& get_type_info() const = 0;
uint64_t m_input_index{0};
uint64_t m_body_parameter_index{0};
};
/// \brief Abstract class describes how a MultiSubGraphOp output is produced from
/// the body.
class OutputDescription {
protected:
///
/// \brief Constructs a new instance.
///
/// \param body_value_index A body value that produces the output
/// \param output_index The MultiSubGraphOp output index
///
OutputDescription(uint64_t body_value_index, uint64_t output_index);
OutputDescription() = default;
public:
using Ptr = std::shared_ptr<OutputDescription>;
using type_info_t = DiscreteTypeInfo;
virtual ~OutputDescription() = default;
virtual std::shared_ptr<OutputDescription> copy() const = 0;
virtual const type_info_t& get_type_info() const = 0;
uint64_t m_body_value_index{0};
uint64_t m_output_index{0};
};
///
/// \brief Describes a body input formed from slices of an input to
/// MultiSubGraphOp.
///
class OPENVINO_API SliceInputDescription : public InputDescription {
public:
OPENVINO_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// \param body_parameter_index Body parameter position to receive input
/// \param start First index for slices
/// \param stride Step amount for slices
/// \param part_size Width of slices
/// \param end Last index for slices
/// \param axis Axis being sliced
///
SliceInputDescription(uint64_t input_index,
uint64_t body_parameter_index,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
SliceInputDescription() = default;
std::shared_ptr<InputDescription> copy() const override;
int64_t m_start{0};
int64_t m_stride{0};
int64_t m_part_size{0};
int64_t m_end{0};
int64_t m_axis{0};
};
///
/// \brief Describes a body input initialized from a MultiSubGraphOp input
/// on the first iteration, and then a body output thereafter.
///
class OPENVINO_API MergedInputDescription : public InputDescription {
public:
OPENVINO_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// supplying a value to body_parameter for
/// the initial iteration.
/// \param body_parameter_index Body parameter position to receive input.
/// \param body_value_index Body value to supply body_parameter for
/// successive
/// iterations.
///
MergedInputDescription(uint64_t input_index, uint64_t body_parameter_index, uint64_t body_value_index);
MergedInputDescription() = default;
std::shared_ptr<InputDescription> copy() const override;
uint64_t m_body_value_index{0};
};
/// \brief Produces an output by concatenating an output from each iteration
class OPENVINO_API ConcatOutputDescription : public OutputDescription {
public:
OPENVINO_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param body_value_index A body value that produces the output
/// \param output_index The MultiSubGraphOp output index
/// \param start First index for slices
/// \param stride Step amount for slices
/// \param part_size Width of slices
/// \param end Last index for slices
/// \param axis Axis being sliced
///
ConcatOutputDescription(uint64_t body_value_index,
uint64_t output_index,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
ConcatOutputDescription() = default;
std::shared_ptr<OutputDescription> copy() const override;
int64_t m_start{0};
int64_t m_stride{0};
int64_t m_part_size{0};
int64_t m_end{0};
int64_t m_axis{0};
};
/// \brief Produces an input
class OPENVINO_API InvariantInputDescription : public InputDescription {
public:
OPENVINO_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param input_index Position of the MultiSubGraphOp input
/// \param body_parameter_index Body parameter to receive input
///
InvariantInputDescription(uint64_t input_index, uint64_t body_parameter_index);
InvariantInputDescription() = default;
std::shared_ptr<InputDescription> copy() const override;
};
/// \brief Produces an output from a specific iteration
class OPENVINO_API BodyOutputDescription : public MultiSubGraphOp::OutputDescription {
public:
OPENVINO_RTTI_DECLARATION;
///
/// \brief Constructs a new instance.
///
/// \param body_value_index A body value that produces the output
/// \param output_index The SubGraphOp output index
/// \param iteration which iteration (typically -1, final) will
/// supply the value
///
BodyOutputDescription(uint64_t body_value_index, uint64_t output_index, int64_t iteration = -1);
BodyOutputDescription() = default;
std::shared_ptr<MultiSubGraphOp::OutputDescription> copy() const override;
int64_t m_iteration{0};
};
using MultiSubgraphInputDescriptionVector = std::vector<MultiSubGraphOp::InputDescription::Ptr>;
using MultiSubgraphOutputDescriptionVector = std::vector<MultiSubGraphOp::OutputDescription::Ptr>;
/// \brief Gets internal sub-graph by index in MultiSubGraphOp
///
/// \param index sub-graph's index in op
/// \return pointer to Function with sub-graph
virtual const std::shared_ptr<Function>& get_function(int index) const {
return m_bodies[index];
};
/// \brief Adds sub-graph to MultiSubGraphOp
///
/// \param index index of new sub-graph
/// \param func func new sub_graph as Function
virtual void set_function(int index, const std::shared_ptr<Function>& func) {
m_bodies[index] = func;
}
/// \brief Gets vector with connections beewtwen operation inputs
/// and internal sub-graph parameters
///
/// \param index index of internal sub-graph
/// \return vector of input descriptions
const MultiSubgraphInputDescriptionVector& get_input_descriptions(int index) const {
return m_input_descriptions[index];
}
/// \brief Gets vector with connections beewtwen operation inputs
/// and internal sub-graph parameters
///
/// \param index index of internal sub-graph
/// \return vector of input descriptions
MultiSubgraphInputDescriptionVector& get_input_descriptions(int index) {
return m_input_descriptions[index];
}
/// \brief Gets vector with connections beewtwen operation outputs
/// and internal sub-graph results
///
/// \param index index of internal sub-graph
/// \return vector of output descriptions
const MultiSubgraphOutputDescriptionVector& get_output_descriptions(int index) const {
return m_output_descriptions[index];
}
/// \brief Gets vector with connections beewtwen operation outputs
/// and internal sub-graph results
///
/// \param index index of internal sub-graph
/// \return vector of output descriptions
MultiSubgraphOutputDescriptionVector& get_output_descriptions(int index) {
return m_output_descriptions[index];
}
/// \brief Sets vector with connections beewtwen operation inputs
/// and internal sub-graph parameters
///
/// \param index index of internal sub-graph
/// \param inputs vector of input descriptions
void set_input_descriptions(int index, const MultiSubgraphInputDescriptionVector& inputs) {
m_input_descriptions[index] = inputs;
}
/// \brief Sets vector with connections beewtwen operation outputs
/// and internal sub-graph results
///
/// \param index index of internal sub-graph
/// \param outputs vector of input descriptions
void set_output_descriptions(int index, const MultiSubgraphOutputDescriptionVector& outputs) {
m_output_descriptions[index] = outputs;
}
///
/// \brief Set input decriptions for MultiSubGraphOp input.
///
/// \param value The value supplied as an input to the block.
/// \param bodies_parameters vector of bodies parameters.
virtual void set_invariant_inputs(const Output<Node>& value, const ngraph::ParameterVector& bodies_parameters);
///
/// \brief Set output decriptions for MultiSubGraphOp output.
///
/// \param bodies_results vector of bodies results for one output.
/// \return value Output node for bodies_results.
virtual Output<Node> set_body_outputs(const ResultVector& bodies_results);
MultiSubGraphOp(const MultiSubGraphOp&) = delete;
MultiSubGraphOp(MultiSubGraphOp&&) = default;
MultiSubGraphOp& operator=(const MultiSubGraphOp&) = delete;
MultiSubGraphOp& operator=(MultiSubGraphOp&&) = default;
protected:
// Find an input corresponding to value, adding one if necessary.
Input<Node> input_for_value(const Output<Node>& value);
MultiSubGraphOp(size_t number_of_bodies);
MultiSubGraphOp() = default;
MultiSubGraphOp(const OutputVector& args, size_t number_of_bodies);
explicit MultiSubGraphOp(const OutputVector& args);
std::vector<std::shared_ptr<Function>> m_bodies;
std::vector<MultiSubgraphInputDescriptionVector> m_input_descriptions;
std::vector<MultiSubgraphOutputDescriptionVector> m_output_descriptions;
};
} // namespace util
} // namespace op
template <>
class OPENVINO_API AttributeAdapter<std::vector<std::shared_ptr<op::util::MultiSubGraphOp::InputDescription>>>
: public DirectValueAccessor<std::vector<std::shared_ptr<op::util::MultiSubGraphOp::InputDescription>>> {
public:
AttributeAdapter(std::vector<std::shared_ptr<op::util::MultiSubGraphOp::InputDescription>>& value)
: DirectValueAccessor<std::vector<std::shared_ptr<op::util::MultiSubGraphOp::InputDescription>>>(value) {}
OPENVINO_RTTI_DECLARATION;
};
template <>
class OPENVINO_API AttributeAdapter<std::vector<std::shared_ptr<op::util::MultiSubGraphOp::OutputDescription>>>
: public DirectValueAccessor<std::vector<std::shared_ptr<op::util::MultiSubGraphOp::OutputDescription>>> {
public:
AttributeAdapter(std::vector<std::shared_ptr<op::util::MultiSubGraphOp::OutputDescription>>& value)
: DirectValueAccessor<std::vector<std::shared_ptr<op::util::MultiSubGraphOp::OutputDescription>>>(value) {}
OPENVINO_RTTI_DECLARATION;
};
} // namespace ov
@@ -0,0 +1,92 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/op/op.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Base class for operations NmsBase and MatrixNms
///
class OPENVINO_API NmsBase : public Op {
public:
OPENVINO_RTTI_DECLARATION;
enum class SortResultType {
CLASSID, // sort selected boxes by class id (ascending) in each batch element
SCORE, // sort selected boxes by score (descending) in each batch element
NONE // do not guarantee the order in each batch element
};
NmsBase() = delete;
/// \brief Constructs a NmsBase operation
///
/// \param output_type Specifies the output tensor type
/// \param nms_top_k Specifies maximum number of boxes to be selected per
/// class, -1 meaning to keep all boxes
/// \param keep_top_k Specifies maximum number of boxes to be selected per
/// batch element, -1 meaning to keep all boxes
NmsBase(element::Type& output_type, int& nms_top_k, int& keep_top_k);
/// \brief Constructs a NmsBase operation
///
/// \param boxes Node producing the box coordinates
/// \param scores Node producing the box scores
/// \param output_type Specifies the output tensor type
/// \param nms_top_k Specifies maximum number of boxes to be selected per
/// class, -1 meaning to keep all boxes
/// \param keep_top_k Specifies maximum number of boxes to be selected per
/// batch element, -1 meaning to keep all boxes
NmsBase(const Output<Node>& boxes,
const Output<Node>& scores,
element::Type& output_type,
int& nms_top_k,
int& keep_top_k);
void validate_and_infer_types() override;
const element::Type& get_output_type() const {
return m_output_type;
}
void set_output_type(const element::Type& output_type) {
m_output_type = output_type;
}
using Node::set_output_type;
int get_nms_top_k() const {
return m_nms_top_k;
}
int get_keep_top_k() const {
return m_keep_top_k;
}
protected:
element::Type& m_output_type;
int& m_nms_top_k;
int& m_keep_top_k;
virtual void validate();
};
} // namespace util
} // namespace op
OPENVINO_API
std::ostream& operator<<(std::ostream& s, const op::util::NmsBase::SortResultType& type);
template <>
class OPENVINO_API AttributeAdapter<op::util::NmsBase::SortResultType>
: public EnumAttributeAdapterBase<op::util::NmsBase::SortResultType> {
public:
AttributeAdapter(op::util::NmsBase::SortResultType& value)
: EnumAttributeAdapterBase<op::util::NmsBase::SortResultType>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<op::util::NmsBase::SortResultType>", 1};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
@@ -0,0 +1,66 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include "openvino/core/core_visibility.hpp"
#include "openvino/core/node.hpp"
namespace ov {
namespace op {
namespace util {
OPENVINO_API
bool is_unary_elementwise_arithmetic(const Node* node);
OPENVINO_API
bool is_binary_elementwise_arithmetic(const Node* node);
OPENVINO_API
bool is_binary_elementwise_comparison(const Node* node);
OPENVINO_API
bool is_binary_elementwise_logical(const Node* node);
OPENVINO_API
bool supports_auto_broadcast(const Node* node);
OPENVINO_API
bool is_op(const Node* node);
OPENVINO_API
bool is_parameter(const Node* node);
OPENVINO_API
bool is_output(const Node* node);
OPENVINO_API
bool is_sink(const Node* node);
OPENVINO_API
bool is_constant(const Node* node);
OPENVINO_API
bool is_commutative(const Node* node);
OPENVINO_API
bool is_unary_elementwise_arithmetic(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_binary_elementwise_arithmetic(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_binary_elementwise_comparison(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_binary_elementwise_logical(const std::shared_ptr<Node>& node);
OPENVINO_API
bool supports_auto_broadcast(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_op(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_parameter(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_output(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_sink(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_constant(const std::shared_ptr<Node>& node);
OPENVINO_API
bool is_commutative(const std::shared_ptr<Node>& node);
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,36 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/core/core_visibility.hpp"
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
class OPENVINO_API ReductionBase : public Op {
protected:
/// \brief Constructs a reduction operation.
ReductionBase();
/// \brief Constructs a reduction operation.
///
/// \param arg Output that produces the first input tensor.
/// \param reduction_axes The axis positions (0-based) to be eliminated.
ReductionBase(const Output<Node>& arg, const Output<Node>& reduction_axes);
/// \brief Infers reduction operations output shape.
///
/// \param[in] keep_dims Reduction operation keeps dimensions.
///
/// \return Partial shape of the output.
PartialShape infer_reduction_output_shape(const bool keep_dims);
public:
OPENVINO_RTTI_DECLARATION;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,162 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
#include "openvino/core/node.hpp"
#include "openvino/op/op.hpp"
#include "openvino/op/util/activation_functions.hpp"
namespace ov {
namespace op {
namespace util {
enum class LSTMWeightsFormat {
FICO, // IE
ICOF, // PyTorch
IFCO, // DNNL, TF, MxNet
IFOC, // Caffe
IOFC, // ONNX
};
///
/// \brief Change data format of provided node.
///
/// \param[in] node The input node to be permuted.
///
///
/// \param[in] from_format Original node weights format.
///
///
/// \param[in] to_format Weights format to convert to.
///
/// \return Node representing reshaped tensor according to `to_format` weights
/// format.
///
std::shared_ptr<Node> OPENVINO_API convert_lstm_node_format(const Output<Node>& node,
LSTMWeightsFormat from_format,
LSTMWeightsFormat to_format = LSTMWeightsFormat::FICO,
int64_t axis = 0);
/// \brief Base class for all recurrent network cells.
///
/// \note It holds all common attributes.
///
class OPENVINO_API RNNCellBase : public Op {
public:
OPENVINO_RTTI_DECLARATION;
///
/// \brief Constructs a RNNCellBase class.
///
/// \param[in] hidden_size The number of hidden units for recurrent cell.
/// \param[in] clip The value defining clipping range [-clip, clip]
/// on input of activation functions.
/// \param[in] activations The vector of activation functions used inside
/// recurrent cell.
/// \param[in] activations_alpha The vector of alpha parameters for activation
/// functions in order respective to activation list.
/// \param[in] activations_beta The vector of beta parameters for activation
/// functions in order respective to activation list.
///
RNNCellBase(const OutputVector& args,
std::size_t hidden_size,
float clip,
const std::vector<std::string>& activations,
const std::vector<float>& activations_alpha,
const std::vector<float>& activations_beta);
RNNCellBase();
~RNNCellBase() override = default;
///
/// \brief Validates static rank and dimension for provided input parameters.
/// Additionally input_size dimension is checked for X and W inputs.
///
///
/// \param[in] input Vector with RNN-Cell op inputs in following order:
/// X, initial_hidden_state, W, R and B.
///
void validate_input_rank_dimension(const std::vector<ngraph::PartialShape>& input);
bool visit_attributes(AttributeVisitor& visitor) override;
std::size_t get_hidden_size() const {
return m_hidden_size;
}
float get_clip() const {
return m_clip;
}
const std::vector<std::string>& get_activations() const {
return m_activations;
}
const std::vector<float>& get_activations_alpha() const {
return m_activations_alpha;
}
const std::vector<float>& get_activations_beta() const {
return m_activations_beta;
}
protected:
///
/// \brief Constructs activation function object.
///
/// \param[in] idx The index of the activation function name.
///
/// \return The object representing activation function.
///
ActivationFunction get_activation_function(std::size_t idx) const;
///
/// \brief Creates node with element-wise add operation with numpy
/// broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise add operation.
///
static std::shared_ptr<Node> add(const Output<Node>& lhs, const Output<Node>& rhs);
///
/// \brief Creates node with element-wise subtract operation with numpy
/// broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise subtract operation.
///
static std::shared_ptr<Node> sub(const Output<Node>& lhs, const Output<Node>& rhs);
///
/// \brief Creates node with element-wise multiply operation with numpy
/// broadcasting.
///
/// \param[in] lhs The left hand side argument node.
/// \param[in] rhs The right hand side argument node.
///
/// \return Node with element-wise multiply operation.
///
static std::shared_ptr<Node> mul(const Output<Node>& lhs, const Output<Node>& rhs);
///
/// \brief Creates node with element-wise clip operation with numpy
/// broadcasting.
///
/// \param[in] data The input tensor for clipping.
///
/// \return Node with element-wise clip operation.
///
std::shared_ptr<Node> clip(const Output<Node>& data) const;
protected:
std::size_t m_hidden_size;
float m_clip;
std::vector<std::string> m_activations;
std::vector<float> m_activations_alpha;
std::vector<float> m_activations_beta;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,49 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
///
/// \brief Base class for ScatterXXX operators.
///
class OPENVINO_API ScatterBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"ScatterBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
ScatterBase() = default;
///
/// \brief Constructs ScatterBase object.
///
/// \param inputs The input tensor to be updated.
/// \param indices The tensor with indexes which will be updated.
/// \param updates The tensor with update values.
/// \param[in] axis The axis at which elements will be updated.
///
ScatterBase(const Output<Node>& inputs,
const Output<Node>& indices,
const Output<Node>& updates,
const Output<Node>& axis);
private:
// Respective input ordinal number.
static constexpr int DATA = 0;
static constexpr int INDICES = 1;
static constexpr int UPDATES = 2;
static constexpr int AXIS = 3;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,42 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/op/op.hpp"
namespace ov {
namespace op {
namespace util {
///
/// \brief Base class for ScatterNDXXX operators.
///
class OPENVINO_API ScatterNDBase : public Op {
public:
static constexpr NodeTypeInfo type_info{"ScatterNDBase", 3};
const NodeTypeInfo& get_type_info() const override {
return type_info;
}
// Respective input ordinal number.
static constexpr int INPUTS = 0;
static constexpr int INDICES = 1;
static constexpr int UPDATES = 2;
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
protected:
ScatterNDBase() = default;
///
/// \brief Constructs ScatterNDBase object.
///
/// \param inputs The input tensor to be updated.
/// \param indices The tensor with indexes which will be updated.
/// \param updates The tensor with update values.
///
ScatterNDBase(const Output<Node>& inputs, const Output<Node>& indices, const Output<Node>& updates);
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,149 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "ngraph/op/parameter.hpp"
#include "ngraph/op/util/multi_subgraph_base.hpp"
namespace ov {
namespace op {
namespace util {
/// \brief Abstract base class for sub-graph based ops, i.e ops that have only one
/// sub-graph
///
class OPENVINO_API SubGraphOp : public MultiSubGraphOp {
public:
OPENVINO_RTTI_DECLARATION;
virtual const std::shared_ptr<Function>& get_function() const {
return m_bodies[0];
};
virtual void set_function(const std::shared_ptr<Function>& func) {
m_bodies[0] = func;
};
/// \return a reference to the input descriptions.
const std::vector<std::shared_ptr<InputDescription>>& get_input_descriptions() const {
return m_input_descriptions[0];
}
/// \return a reference to the input descriptions. Can add input descriptions
/// before
/// validation.
std::vector<std::shared_ptr<InputDescription>>& get_input_descriptions() {
return m_input_descriptions[0];
}
/// \return a reference to the output descriptions.
const std::vector<std::shared_ptr<OutputDescription>>& get_output_descriptions() const {
return m_output_descriptions[0];
}
/// \return a reference to the output descriptions. Can add output descriptions
/// before
/// validation.
std::vector<std::shared_ptr<OutputDescription>>& get_output_descriptions() {
return m_output_descriptions[0];
}
///
/// \brief Indicate that a body parameter comes from slices of a value
///
/// \param parameter The parameter to receive the slices
/// \param value The value to be sliced. This will be added as an input to
/// SubGraphOp.
/// \param start First index on axis of the slicing
/// \param stride Stepping of the slice
/// \param part_size Size of the slice on axis
/// \param end The last index on axis of the slicing
/// \param axis The axis to slice along
///
virtual void set_sliced_input(const std::shared_ptr<ngraph::op::Parameter>& parameter,
const Output<Node>& value,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
///
/// \brief Indicates that a body parameter has an initial value in the first
/// iteration and computed value thereafter
///
/// \param[in] body_parameter The body parameter
/// \param initial_value Value for the parameter in first iteration. This
/// will be added as an input to Loop.
/// \param successive_value Value for the parameter in successive iterations.
/// The value is what is active in the most recent
/// completed iteration.
///
virtual void set_merged_input(const std::shared_ptr<ngraph::op::Parameter>& body_parameter,
const Output<Node>& initial_value,
const Output<Node>& successive_value);
///
/// \brief Indicates that a body parameter has an invariant value during
/// iteration that may depend on values computed outside of the
/// iteration.
///
/// \param body_parameter The body parameter
/// \param value The value supplied as an input to the block
///
virtual void set_invariant_input(const std::shared_ptr<ngraph::op::Parameter>& body_parameter,
const Output<Node>& value);
///
/// \brief Gets a value for a particular iteration point
///
/// \param body_value The value
/// \param iteration The iteration that supplies the value. Negative values
/// are from the last iteration.
/// Default value -1 (the last iteration).
///
/// \return The iterator value.
///
virtual Output<Node> get_iter_value(const Output<Node>& body_value, int64_t iteration = -1);
///
/// \brief Concatenates slices from all iterations
///
/// \param value The value supplying slice values from each iteration.
/// \param start First index on axis of the slicing
/// \param stride Stepping of the slice
/// \param part_size Size of the slice on axis
/// \param end The last index on axis of the slicing
/// \param axis The axis to slice along
///
/// \return The concatenated slices.
///
virtual Output<Node> get_concatenated_slices(const Output<Node>& value,
int64_t start,
int64_t stride,
int64_t part_size,
int64_t end,
int64_t axis);
SubGraphOp(const SubGraphOp&) = delete;
SubGraphOp(SubGraphOp&&) = default;
SubGraphOp& operator=(const SubGraphOp&) = delete;
SubGraphOp& operator=(SubGraphOp&&) = default;
int64_t get_num_iterations() const {
return m_num_iterations;
}
protected:
int64_t m_num_iterations = -1; // -1 means infinity for Loop op, inconsistent for TensorIterator
// Find an input corresponding to value, adding one if necessary.
Input<Node> input_for_value(const Output<Node>& value);
SubGraphOp();
explicit SubGraphOp(const OutputVector& args);
private:
using MultiSubGraphOp::get_function;
using MultiSubGraphOp::set_function;
};
using InputDescriptionVector = std::vector<util::SubGraphOp::InputDescription::Ptr>;
using OutputDescriptionVector = std::vector<util::SubGraphOp::OutputDescription::Ptr>;
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,53 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "openvino/op/op.hpp"
namespace ov {
namespace op {
namespace util {
// clang-format off
/// \brief Abstract base class for elementwise unary arithmetic operations, i.e.,
/// operations where the same scalar arithmetic operation is applied to each
/// element.
///
/// For example, if the underlying operation (determined by the subclass) is
/// \f$\mathit{op}(x)\f$, the input tensor \f$[[x,y],[z,w]]\f$ will be mapped to
/// \f$[[\mathit{op}(x),\mathit{op}(y)],[\mathit{op}(z),\mathit{op}(w)]]\f$.
///
/// ## Inputs
///
/// | | Type | Description |
/// | ----- | --------------------------------- | ------------------------------------------------------------------------ |
/// | `arg` | \f$N[d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape. The element type \f$N\f$ may be any numeric type. |
///
/// ## Output
///
/// | Type | Description |
/// | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
/// | \f$N[d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[i_1,\dots,i_n] = \mathit{op}(\texttt{arg}[i_1,\dots,i_n])\f$. This will always have the same shape and element type as the input tensor. |
// clang-format on
class OPENVINO_API UnaryElementwiseArithmetic : public Op {
protected:
/// \brief Constructs a unary elementwise arithmetic operation.
UnaryElementwiseArithmetic();
/// \brief Constructs a unary elementwise arithmetic operation.
///
/// \param arg Output that produces the input tensor.
UnaryElementwiseArithmetic(const Output<Node>& arg);
public:
OPENVINO_RTTI_DECLARATION;
void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;
private:
void validate_and_infer_elementwise_arithmetic();
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,60 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <string>
#include <utility>
#include "openvino/core/partial_shape.hpp"
#include "openvino/core/type.hpp"
#include "openvino/core/type/element_type.hpp"
namespace ov {
namespace op {
namespace util {
struct VariableInfo {
PartialShape data_shape;
element::Type data_type;
std::string variable_id;
inline bool operator==(const VariableInfo& other) const {
return data_shape == other.data_shape && data_type == other.data_type && variable_id == other.variable_id;
}
};
class OPENVINO_API Variable {
public:
using Ptr = std::shared_ptr<Variable>;
Variable() = default;
explicit Variable(const VariableInfo& variable_info) : m_info(variable_info) {}
VariableInfo get_info() const {
return m_info;
}
void update(const VariableInfo& variable_info) {
m_info = variable_info;
}
private:
VariableInfo m_info;
};
using VariableVector = std::vector<Variable::Ptr>;
} // namespace util
} // namespace op
template <>
class OPENVINO_API AttributeAdapter<std::shared_ptr<op::util::Variable>>
: public DirectValueAccessor<std::shared_ptr<op::util::Variable>> {
public:
explicit AttributeAdapter(std::shared_ptr<op::util::Variable>& value)
: DirectValueAccessor<std::shared_ptr<op::util::Variable>>(value) {}
static constexpr DiscreteTypeInfo type_info{"AttributeAdapter<std::shared_ptr<Variable>>", 0};
const DiscreteTypeInfo& get_type_info() const override {
return type_info;
}
};
} // namespace ov
@@ -0,0 +1,91 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <unordered_map>
#include "openvino/core/node_vector.hpp"
#include "openvino/core/variant.hpp"
#include "openvino/op/util/variable.hpp"
#include "openvino/op/util/variable_value.hpp"
namespace ov {
namespace op {
namespace util {
using VariableMap = std::unordered_map<Variable::Ptr, VariableValue::Ptr>;
/// VariableContext stores and manages a evaluation context for Variables.
class NGRAPH_API VariableContext {
public:
/// \brief Constructs an uninitialized VariableContext.
VariableContext() = default;
/// \brief Constructor for VariableContext.
/// \param variable_values The values associated with a particular Variables.
explicit VariableContext(const VariableMap& variable_values) : m_variable_values(variable_values) {}
/// \brief Sets the reset flags for all stored Variables to true.
void reset_variable_context() const {
for (const auto& el : m_variable_values) {
el.second->set_reset(true);
}
}
/// \brief Sets the new values for Variables.
/// \param variable_values The new values associated with a particular Variable.
void set_variable_values(const VariableMap& variable_values) {
m_variable_values = variable_values;
}
/// \brief Changes/sets the values for Variable.
/// \param variable New or stored Variable.
/// \param variable_value The values associated with the variable.
void set_variable_value(const Variable::Ptr& variable, const VariableValue::Ptr& variable_value) {
m_variable_values[variable] = variable_value;
}
/// \brief Removes context for a particular Variable.
/// \param variable The variable for which the context will be cleared.
void remove_variable_value(const Variable::Ptr& variable) {
m_variable_values.erase(variable);
}
/// \brief Returns the current values for Variables.
const VariableMap& get_variable_values() const {
return m_variable_values;
}
/// \brief Returns the value for specified Variable.
VariableValue::Ptr get_variable_value(const Variable::Ptr& variable) const {
auto var_value = m_variable_values.find(variable);
if (var_value != m_variable_values.end()) {
return (*var_value).second;
}
return VariableValue::Ptr();
}
private:
/// The values associated with a particular Variable.
VariableMap m_variable_values;
};
} // namespace util
} // namespace op
template <>
class NGRAPH_API VariantWrapper<op::util::VariableContext> : public VariantImpl<op::util::VariableContext> {
public:
static constexpr VariantTypeInfo type_info{"Variant::EvaluationContext::VariableContext", 0};
const VariantTypeInfo& get_type_info() const override {
return type_info;
}
explicit VariantWrapper(const value_type& value) : VariantImpl<value_type>(value) {}
private:
using Variant::init;
using Variant::merge;
};
} // namespace ov
@@ -0,0 +1,47 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <utility>
#include "ngraph/runtime/host_tensor.hpp"
#include "openvino/core/core_visibility.hpp"
#include "openvino/op/util/variable.hpp"
namespace ov {
namespace op {
namespace util {
class OPENVINO_API VariableExtension {
public:
VariableExtension() = default;
/// \brief Returns variable connected to this node.
virtual std::shared_ptr<Variable> get_variable() const {
return m_variable;
}
/// \brief Sets a new variable to be connected to this node.
///
/// \param variable New variable to be connected to this node.
virtual void set_variable(const std::shared_ptr<Variable>& variable) {
m_variable = variable;
}
/// \brief Sets the identifier to a variable
///
/// \param variable_id New identifier of the variable.
virtual void set_variable_id(const std::string& variable_id) {
m_variable->get_info().variable_id = variable_id;
};
/// \brief Returns the identifier of corresponding variable.
virtual std::string get_variable_id() const = 0;
protected:
std::shared_ptr<Variable> m_variable;
};
} // namespace util
} // namespace op
} // namespace ov
@@ -0,0 +1,60 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <utility>
#include "ngraph/runtime/host_tensor.hpp"
#include "openvino/core/core_visibility.hpp"
namespace ov {
namespace op {
namespace util {
/// VariableValue stores data and state (reset flag) for a Variable,
/// and provides an interface for changing them.
class OPENVINO_API VariableValue {
public:
using Ptr = std::shared_ptr<VariableValue>;
/// \brief Constructs an uninitialized VariableValue.
VariableValue() = default;
/// \brief Constructor for VariableValue.
/// \param value The data for Variable.
explicit VariableValue(ngraph::HostTensorPtr value) : m_value(std::move(value)) {}
/// \brief Constructor for VariableValue.
/// \param value Data for Variable.
/// \param reset The current state of the reset flag.
VariableValue(ngraph::HostTensorPtr value, bool reset) : m_reset(reset), m_value(std::move(value)) {}
/// \brief Sets the reset flag to a new state.
/// \param reset The new state of the reset flag.
void set_reset(bool reset) {
m_reset = reset;
}
/// \brief Returns the current reset flag state.
bool get_reset() const {
return m_reset;
}
/// \brief Returns the current stored data.
const ngraph::HostTensorPtr& get_value() const {
return m_value;
}
/// \brief Sets new values for Variable.
/// \param value New data for Variable.
void set_value(const ngraph::HostTensorPtr& value) {
m_value = value;
}
private:
bool m_reset = true;
ngraph::HostTensorPtr m_value;
};
} // namespace util
} // namespace op
} // namespace ov
+129 -124
View File
@@ -7,129 +7,133 @@
#include <algorithm>
#include <list>
#include <memory>
#include <ngraph/ops.hpp>
#include "itt.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/op/util/op_types.hpp"
#include "ngraph/op/util/variable_context.hpp"
#include "ngraph/op/util/variable_extension.hpp"
#include "ngraph/ops.hpp"
#include "ngraph/opsets/opset7.hpp"
#include "ngraph/validation_util.hpp"
#include "openvino/core/except.hpp"
#include "openvino/op/util/op_types.hpp"
#include "openvino/op/util/variable_context.hpp"
#include "openvino/op/util/variable_extension.hpp"
using namespace std;
using namespace ngraph;
constexpr DiscreteTypeInfo Function::type_info;
constexpr ov::DiscreteTypeInfo ov::Function::type_info;
atomic<size_t> Function::m_next_instance_id(0);
atomic<size_t> ov::Function::m_next_instance_id(0);
void check_all_variables_registered(const std::vector<shared_ptr<Node>>& ordered_ops, const VariableVector& variables) {
void check_all_variables_registered(const std::vector<shared_ptr<ov::Node>>& ordered_ops,
const ov::op::util::VariableVector& variables) {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraphPass_LT, "Function::check_all_variables_registered");
std::stringstream unregistered_variables;
for (auto& node : ordered_ops) {
const auto& variable_op = dynamic_pointer_cast<VariableExtension>(node);
const auto& variable_op = dynamic_pointer_cast<ov::op::util::VariableExtension>(node);
if (variable_op &&
std::find(variables.begin(), variables.end(), variable_op->get_variable()) == variables.end())
unregistered_variables << variable_op->get_variable_id() << std::endl;
}
if (!unregistered_variables.str().empty())
throw ngraph_error("Function references undeclared variables: " + unregistered_variables.str());
throw ov::Exception("Function references undeclared variables: " + unregistered_variables.str());
}
void check_all_parameters_registered(const std::vector<shared_ptr<Node>>& ordered_ops,
const ParameterVector& parameters) {
void check_all_parameters_registered(const std::vector<shared_ptr<ov::Node>>& ordered_ops,
const ngraph::ParameterVector& parameters) {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::check_all_parameters_registered");
std::stringstream unregistered_parameters;
for (auto& node : ordered_ops) {
if (op::is_parameter(node) && std::find(parameters.begin(), parameters.end(), node) == parameters.end())
if (ov::op::util::is_parameter(node) &&
std::find(parameters.begin(), parameters.end(), node) == parameters.end())
unregistered_parameters << node << std::endl;
}
if (!unregistered_parameters.str().empty())
throw ngraph_error("Function references undeclared parameters: " + unregistered_parameters.str());
throw ov::Exception("Function references undeclared parameters: " + unregistered_parameters.str());
}
VariableVector auto_detect_variables(const std::vector<std::shared_ptr<Node>>& ordered_ops) {
ov::op::util::VariableVector auto_detect_variables(const std::vector<std::shared_ptr<ov::Node>>& ordered_ops) {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::auto_detect_variables");
unordered_set<VariablePtr> variables;
unordered_set<ov::op::util::Variable::Ptr> variables;
for (const auto& op : ordered_ops) {
if (const auto& variable_op = dynamic_pointer_cast<VariableExtension>(op)) {
if (const auto& variable_op = dynamic_pointer_cast<ov::op::util::VariableExtension>(op)) {
variables.insert(variable_op->get_variable());
}
}
return VariableVector(variables.begin(), variables.end());
return ov::op::util::VariableVector(variables.begin(), variables.end());
}
ParameterVector auto_detect_parameters(const std::vector<std::shared_ptr<Node>>& ordered_ops) {
ngraph::ParameterVector auto_detect_parameters(const std::vector<std::shared_ptr<ov::Node>>& ordered_ops) {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::auto_detect_parameters");
ParameterVector parameter_vector;
ngraph::ParameterVector parameter_vector;
for (const auto& op : ordered_ops) {
if (const auto& param = dynamic_pointer_cast<opset7::Parameter>(op)) {
if (const auto& param = dynamic_pointer_cast<ngraph::opset7::Parameter>(op)) {
parameter_vector.push_back(param);
}
}
return parameter_vector;
}
Function::Function(const ResultVector& results, const ParameterVector& parameters, const std::string& name)
ov::Function::Function(const ResultVector& results, const ngraph::ParameterVector& parameters, const std::string& name)
: m_name(name),
m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))),
m_topological_sorter(topological_sort<std::vector<std::shared_ptr<Node>>>),
m_topological_sorter(ngraph::topological_sort<std::vector<std::shared_ptr<ov::Node>>>),
m_results(results),
m_parameters(parameters) {
prerequirements(true, false);
}
Function::Function(const OutputVector& results, const ParameterVector& parameters, const std::string& name)
ov::Function::Function(const OutputVector& results, const ngraph::ParameterVector& parameters, const std::string& name)
: m_name(name),
m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))),
m_topological_sorter(topological_sort<std::vector<std::shared_ptr<Node>>>),
m_topological_sorter(ngraph::topological_sort<std::vector<std::shared_ptr<ov::Node>>>),
m_results(as_result_vector(results)),
m_parameters(parameters) {
prerequirements(true, false);
}
Function::Function(const NodeVector& results, const ParameterVector& parameters, const std::string& name)
ov::Function::Function(const NodeVector& results, const ngraph::ParameterVector& parameters, const std::string& name)
: m_name(name),
m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))),
m_topological_sorter(topological_sort<std::vector<std::shared_ptr<Node>>>),
m_topological_sorter(ngraph::topological_sort<std::vector<std::shared_ptr<ov::Node>>>),
m_results(as_result_vector(as_output_vector(results))),
m_parameters(parameters) {
prerequirements(true, false);
}
Function::Function(const std::shared_ptr<Node>& result, const ParameterVector& parameters, const std::string& name)
ov::Function::Function(const std::shared_ptr<Node>& result,
const ngraph::ParameterVector& parameters,
const std::string& name)
: Function(result->outputs(), parameters, name) {}
Function::Function(const ResultVector& results,
const SinkVector& sinks,
const ParameterVector& parameters,
const std::string& name)
ov::Function::Function(const ngraph::ResultVector& results,
const ngraph::SinkVector& sinks,
const ngraph::ParameterVector& parameters,
const std::string& name)
: m_name(name),
m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))),
m_topological_sorter(topological_sort<std::vector<std::shared_ptr<Node>>>),
m_topological_sorter(ngraph::topological_sort<std::vector<std::shared_ptr<Node>>>),
m_results(results),
m_sinks(sinks),
m_parameters(parameters) {
prerequirements(true, false);
}
Function::Function(const OutputVector& results,
const SinkVector& sinks,
const ParameterVector& parameters,
const std::string& name)
ov::Function::Function(const OutputVector& results,
const ngraph::SinkVector& sinks,
const ngraph::ParameterVector& parameters,
const std::string& name)
: Function(as_result_vector(results), sinks, parameters, name) {}
Function::Function(const ResultVector& results,
const SinkVector& sinks,
const ParameterVector& parameters,
const VariableVector& variables,
const std::string& name)
ov::Function::Function(const ngraph::ResultVector& results,
const ngraph::SinkVector& sinks,
const ngraph::ParameterVector& parameters,
const ngraph::VariableVector& variables,
const std::string& name)
: m_name(name),
m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))),
m_topological_sorter(topological_sort<std::vector<std::shared_ptr<Node>>>),
m_topological_sorter(ngraph::topological_sort<std::vector<std::shared_ptr<Node>>>),
m_results(results),
m_sinks(sinks),
m_parameters(parameters),
@@ -137,37 +141,38 @@ Function::Function(const ResultVector& results,
prerequirements(false, false);
}
Function::Function(const OutputVector& results,
const SinkVector& sinks,
const ParameterVector& parameters,
const VariableVector& variables,
const std::string& name)
ov::Function::Function(const OutputVector& results,
const ngraph::SinkVector& sinks,
const ngraph::ParameterVector& parameters,
const ngraph::VariableVector& variables,
const std::string& name)
: Function(as_result_vector(results), sinks, parameters, variables, name) {}
Function::Function(const OutputVector& results,
const ParameterVector& parameters,
const VariableVector& variables,
const std::string& name)
ov::Function::Function(const ngraph::OutputVector& results,
const ngraph::ParameterVector& parameters,
const ngraph::VariableVector& variables,
const std::string& name)
: Function(as_result_vector(results), {}, parameters, variables, name) {}
Function::Function(const ResultVector& results,
const ParameterVector& parameters,
const VariableVector& variables,
const std::string& name)
ov::Function::Function(const ngraph::ResultVector& results,
const ngraph::ParameterVector& parameters,
const ngraph::VariableVector& variables,
const std::string& name)
: Function(results, {}, parameters, variables, name) {}
Function::Function(const OutputVector& results, const SinkVector& sinks, const string& name)
ov::Function::Function(const ngraph::OutputVector& results, const ngraph::SinkVector& sinks, const string& name)
: m_name(name),
m_unique_name("Function_" + to_string(m_next_instance_id.fetch_add(1))),
m_topological_sorter(topological_sort<std::vector<std::shared_ptr<Node>>>),
m_topological_sorter(ngraph::topological_sort<std::vector<std::shared_ptr<Node>>>),
m_results(as_result_vector(results)),
m_sinks(sinks) {
prerequirements(true, true);
}
Function::Function(const OutputVector& results, const string& name) : Function(results, SinkVector{}, name) {}
ov::Function::Function(const OutputVector& results, const string& name)
: Function(results, ngraph::SinkVector{}, name) {}
void Function::prerequirements(bool detect_variables, bool detect_parameters) {
void ov::Function::prerequirements(bool detect_variables, bool detect_parameters) {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::prerequirements");
const auto& ordered_ops = get_ordered_ops();
@@ -182,47 +187,48 @@ void Function::prerequirements(bool detect_variables, bool detect_parameters) {
check_all_variables_registered(ordered_ops, m_variables);
}
void Function::validate_nodes_and_infer_types() const {
void ov::Function::validate_nodes_and_infer_types() const {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::validate_nodes_and_infer_types");
struct Counter {
int cnt_assign = 0;
int cnt_read_val = 0;
};
std::map<Variable*, Counter> pair_checker;
std::map<ov::op::util::Variable*, Counter> pair_checker;
std::stringstream unregistered_parameters;
std::stringstream unregistered_variables;
for (auto& node : get_ordered_ops()) {
node->revalidate_and_infer_types();
if (op::is_parameter(node) && std::find(m_parameters.begin(), m_parameters.end(), node) == m_parameters.end())
if (op::util::is_parameter(node) &&
std::find(m_parameters.begin(), m_parameters.end(), node) == m_parameters.end())
unregistered_parameters << node << std::endl;
const auto& variable_op = dynamic_pointer_cast<VariableExtension>(node);
const auto& variable_op = dynamic_pointer_cast<op::util::VariableExtension>(node);
if (variable_op &&
std::find(m_variables.begin(), m_variables.end(), variable_op->get_variable()) == m_variables.end())
unregistered_variables << variable_op->get_variable_id() << std::endl;
if (const auto& assign = std::dynamic_pointer_cast<op::AssignBase>(node)) {
if (const auto& assign = std::dynamic_pointer_cast<ngraph::op::AssignBase>(node)) {
pair_checker[assign->get_variable().get()].cnt_assign++;
} else if (const auto& read_value = std::dynamic_pointer_cast<op::ReadValueBase>(node)) {
} else if (const auto& read_value = std::dynamic_pointer_cast<ngraph::op::ReadValueBase>(node)) {
pair_checker[read_value->get_variable().get()].cnt_read_val++;
}
}
if (!unregistered_parameters.str().empty())
throw ngraph_error("Function references undeclared parameters: " + unregistered_parameters.str());
throw ov::Exception("Function references undeclared parameters: " + unregistered_parameters.str());
if (!unregistered_variables.str().empty())
throw ngraph_error("Function references undeclared Variables: " + unregistered_variables.str());
throw ov::Exception("Function references undeclared Variables: " + unregistered_variables.str());
bool only_pairs =
std::all_of(pair_checker.begin(), pair_checker.end(), [](const std::pair<Variable*, Counter>& val) {
std::all_of(pair_checker.begin(), pair_checker.end(), [](const std::pair<op::util::Variable*, Counter>& val) {
return val.second.cnt_assign == 1 && val.second.cnt_read_val == 1;
});
if (!only_pairs)
throw ngraph_error("Function is incorrect. Assign and ReadValue operations must be in pairs on the "
"network.");
throw ov::Exception("Function is incorrect. Assign and ReadValue operations must be in pairs on the "
"network.");
}
std::vector<shared_ptr<Node>> Function::get_ordered_ops() const {
std::vector<shared_ptr<ov::Node>> ov::Function::get_ordered_ops() const {
OV_ITT_SCOPED_TASK(ov::itt::domains::nGraph, "Function::get_ordered_ops");
vector<shared_ptr<Node>> nodes;
@@ -239,7 +245,7 @@ std::vector<shared_ptr<Node>> Function::get_ordered_ops() const {
return m_topological_sorter(nodes);
}
void Function::map_unordered_ops(std::function<void(Node*)> f) const {
void ov::Function::map_unordered_ops(std::function<void(Node*)> f) const {
std::unordered_set<Node*> unordered_ops;
std::stack<Node*, std::vector<Node*>> remaining_ops;
for (auto& r : get_results()) {
@@ -267,75 +273,75 @@ void Function::map_unordered_ops(std::function<void(Node*)> f) const {
}
}
const std::string& Function::get_friendly_name() const {
const std::string& ov::Function::get_friendly_name() const {
if (m_name.empty()) {
return m_unique_name;
}
return m_name;
}
const std::string& Function::get_name() const {
const std::string& ov::Function::get_name() const {
return m_unique_name;
}
void Function::set_friendly_name(const string& name) {
void ov::Function::set_friendly_name(const string& name) {
m_name = name;
}
std::ostream& operator<<(std::ostream& out, const Function& f) {
std::ostream& operator<<(std::ostream& out, const ov::Function& f) {
out << "Function(" << f.get_name() << ")";
return out;
}
size_t Function::get_output_size() const {
size_t ov::Function::get_output_size() const {
return m_results.size();
}
const element::Type& Function::get_output_element_type(size_t i) const {
const ov::element::Type& ov::Function::get_output_element_type(size_t i) const {
return m_results.at(i)->get_element_type();
}
const Shape& Function::get_output_shape(size_t i) const {
const ngraph::Shape& ov::Function::get_output_shape(size_t i) const {
return m_results.at(i)->get_shape();
}
const PartialShape& Function::get_output_partial_shape(size_t i) const {
const ov::PartialShape& ov::Function::get_output_partial_shape(size_t i) const {
return m_results.at(i)->get_output_partial_shape(0);
}
shared_ptr<Node> Function::get_output_op(size_t i) const {
shared_ptr<ov::Node> ov::Function::get_output_op(size_t i) const {
return m_results.at(i);
}
Output<Node> Function::output(size_t i) const {
ov::Output<ov::Node> ov::Function::output(size_t i) const {
return m_results.at(i);
}
shared_ptr<Node> Function::get_result() const {
shared_ptr<ov::Node> ov::Function::get_result() const {
if (m_results.size() != 1) {
throw ngraph_error("get_result() must be called on a function with exactly one result.");
throw ov::Exception("get_result() must be called on a function with exactly one result.");
}
return m_results.at(0);
}
std::vector<shared_ptr<Node>> Function::get_ops() const {
std::vector<shared_ptr<ov::Node>> ov::Function::get_ops() const {
std::vector<std::shared_ptr<Node>> ops;
traverse_nodes(this, [&](shared_ptr<Node> node) {
ngraph::traverse_nodes(this, [&](shared_ptr<Node> node) {
ops.push_back(node);
});
return ops;
}
void Function::replace_node(std::shared_ptr<Node> old, std::shared_ptr<Node> repl) {
void ov::Function::replace_node(std::shared_ptr<Node> old, std::shared_ptr<Node> repl) {
ngraph::replace_node(old, repl);
}
size_t Function::get_graph_size() const {
size_t ov::Function::get_graph_size() const {
size_t total_size = 0;
for (auto node : get_ops()) {
total_size += sizeof(*node);
if (node->description() == "Constant") {
const Shape& shape = node->get_output_shape(0);
const ngraph::Shape& shape = node->get_output_shape(0);
size_t const_size = node->get_output_element_type(0).size();
if (shape.size() == 0) {
total_size += const_size;
@@ -347,10 +353,7 @@ size_t Function::get_graph_size() const {
return total_size;
}
// TODO(pthoreho) this will be expensive, since we will be traversing all the nodes in
// the graph, figure out if their is a way to cache the result and invalidate/update
// the result if the function is modified
bool Function::is_dynamic() const {
bool ov::Function::is_dynamic() const {
auto list_of_nodes = this->get_ops();
for (auto& node : list_of_nodes) {
if (node->get_output_partial_shape(0).is_dynamic()) {
@@ -360,7 +363,7 @@ bool Function::is_dynamic() const {
return false;
}
void Function::replace_parameter(size_t parameter_index, const shared_ptr<op::Parameter>& parameter) {
void ov::Function::replace_parameter(size_t parameter_index, const shared_ptr<ngraph::op::Parameter>& parameter) {
NGRAPH_CHECK(parameter_index < m_parameters.size(),
"replace_parameter(): Tried to replace parameter at index ",
parameter_index,
@@ -371,11 +374,11 @@ void Function::replace_parameter(size_t parameter_index, const shared_ptr<op::Pa
m_parameters[parameter_index] = parameter;
}
void Function::set_topological_sort(topological_sort_t sorter) {
void ov::Function::set_topological_sort(topological_sort_t sorter) {
m_topological_sorter = sorter;
}
int64_t Function::get_parameter_index(const std::shared_ptr<op::Parameter>& parameter) const {
int64_t ov::Function::get_parameter_index(const std::shared_ptr<ngraph::op::Parameter>& parameter) const {
int64_t pos = 0;
for (auto p : get_parameters()) {
if (p == parameter) {
@@ -386,9 +389,9 @@ int64_t Function::get_parameter_index(const std::shared_ptr<op::Parameter>& para
return -1;
}
int64_t Function::get_result_index(const Output<Node>& value) const {
int64_t ov::Function::get_result_index(const Output<Node>& value) const {
int64_t pos = 0;
if (ov::is_type<op::Result>(value.get_node_shared_ptr())) {
if (is_type<ngraph::op::Result>(value.get_node_shared_ptr())) {
auto result = value.get_node_shared_ptr();
for (auto r : get_results()) {
if (r == result) {
@@ -407,11 +410,12 @@ int64_t Function::get_result_index(const Output<Node>& value) const {
return -1;
}
bool Function::evaluate(const HostTensorVector& output_tensors,
const HostTensorVector& input_tensors,
EvaluationContext evaluation_context) const {
bool ov::Function::evaluate(const HostTensorVector& output_tensors,
const HostTensorVector& input_tensors,
EvaluationContext evaluation_context) const {
if (evaluation_context.find("VariableContext") == evaluation_context.end())
evaluation_context["VariableContext"] = std::make_shared<VariantWrapper<VariableContext>>(VariableContext());
evaluation_context["VariableContext"] =
std::make_shared<VariantWrapper<ov::op::util::VariableContext>>(ov::op::util::VariableContext());
std::map<RawNodeOutput, HostTensorPtr> value_map;
for (size_t i = 0; i < m_parameters.size(); ++i) {
value_map[m_parameters.at(i)->output(0)] = input_tensors.at(i);
@@ -426,20 +430,20 @@ bool Function::evaluate(const HostTensorVector& output_tensors,
for (const auto& m_sink : m_sinks) {
outputs.push_back(m_sink);
}
evaluate_nodes(value_map, output_tensor_map, outputs, evaluation_context);
ngraph::evaluate_nodes(value_map, output_tensor_map, outputs, evaluation_context);
return true;
}
bool Function::visit_attributes(AttributeVisitor& visitor) {
bool ov::Function::visit_attributes(AttributeVisitor& visitor) {
visitor.on_attribute("parameters", m_parameters);
visitor.on_attribute("results", m_results);
return true;
}
void Function::add_sinks(const SinkVector& sinks) {
void ov::Function::add_sinks(const ngraph::SinkVector& sinks) {
m_sinks.insert(m_sinks.end(), sinks.begin(), sinks.end());
for (const auto& sink : sinks) {
if (const auto& variable_op = dynamic_pointer_cast<VariableExtension>(sink)) {
if (const auto& variable_op = dynamic_pointer_cast<op::util::VariableExtension>(sink)) {
if (find(m_variables.begin(), m_variables.end(), variable_op->get_variable()) == m_variables.end()) {
m_variables.push_back(variable_op->get_variable());
}
@@ -447,29 +451,29 @@ void Function::add_sinks(const SinkVector& sinks) {
}
}
void Function::remove_sink(const std::shared_ptr<op::Sink>& sink) {
void ov::Function::remove_sink(const std::shared_ptr<ngraph::op::Sink>& sink) {
m_sinks.erase(std::remove_if(m_sinks.begin(),
m_sinks.end(),
[&sink](std::shared_ptr<op::Sink>& s) {
[&sink](std::shared_ptr<ngraph::op::Sink>& s) {
return s == sink;
}),
m_sinks.end());
}
void Function::add_results(const ResultVector& results) {
void ov::Function::add_results(const ResultVector& results) {
m_results.insert(m_results.end(), results.begin(), results.end());
}
void Function::remove_result(const std::shared_ptr<op::Result>& result) {
void ov::Function::remove_result(const std::shared_ptr<ngraph::op::Result>& result) {
m_results.erase(std::remove_if(m_results.begin(),
m_results.end(),
[&result](std::shared_ptr<op::v0::Result>& r) {
[&result](std::shared_ptr<ngraph::op::v0::Result>& r) {
return r == result;
}),
m_results.end());
}
void Function::add_parameters(const ParameterVector& params) {
void ov::Function::add_parameters(const ngraph::ParameterVector& params) {
for (size_t i = 0; i < params.size(); i++) {
for (size_t j = 0; j < m_parameters.size(); j++) {
NGRAPH_CHECK(params[i] != m_parameters[j],
@@ -482,36 +486,37 @@ void Function::add_parameters(const ParameterVector& params) {
m_parameters.insert(m_parameters.end(), params.begin(), params.end());
}
void Function::remove_parameter(const std::shared_ptr<op::Parameter>& param) {
void ov::Function::remove_parameter(const std::shared_ptr<ngraph::op::Parameter>& param) {
m_parameters.erase(std::remove_if(m_parameters.begin(),
m_parameters.end(),
[&param](std::shared_ptr<op::v0::Parameter>& r) {
[&param](std::shared_ptr<ngraph::op::v0::Parameter>& r) {
return r == param;
}),
m_parameters.end());
}
void Function::add_variables(const VariableVector& variables) {
void ov::Function::add_variables(const op::util::VariableVector& variables) {
m_variables.insert(m_variables.end(), variables.begin(), variables.end());
}
void Function::remove_variable(const VariablePtr& variable) {
void ov::Function::remove_variable(const op::util::Variable::Ptr& variable) {
m_variables.erase(std::remove_if(m_variables.begin(),
m_variables.end(),
[&variable](VariablePtr& v) {
[&variable](op::util::Variable::Ptr& v) {
return v == variable;
}),
m_variables.end());
}
VariablePtr Function::get_variable_by_id(const string& variable_id) const {
auto variable = std::find_if(m_variables.begin(), m_variables.end(), [&variable_id](const VariablePtr& cur) {
return cur->get_info().variable_id == variable_id;
});
ov::op::util::Variable::Ptr ov::Function::get_variable_by_id(const string& variable_id) const {
auto variable =
std::find_if(m_variables.begin(), m_variables.end(), [&variable_id](const ov::op::util::Variable::Ptr& cur) {
return cur->get_info().variable_id == variable_id;
});
if (variable != m_variables.end())
return *variable;
else
return VariablePtr();
return ov::op::util::Variable::Ptr();
}
constexpr DiscreteTypeInfo AttributeAdapter<shared_ptr<Function>>::type_info;
constexpr ov::DiscreteTypeInfo ov::AttributeAdapter<shared_ptr<ov::Function>>::type_info;
+10 -10
View File
@@ -42,16 +42,16 @@ OV_ITT_DOMAIN(SIMPLE_ngraph_pass);
# define NGRAPH_PASS_CALLBACK(matcher)
#endif
#define NGRAPH_TYPE_CASE(region, a, ...) \
case element::Type_t::a: { \
OV_SCOPE(ngraph_op, OV_PP_CAT3(region, _, a)) { \
rc = evaluate<element::Type_t::a>(__VA_ARGS__); \
} \
#define NGRAPH_TYPE_CASE(region, a, ...) \
case ov::element::Type_t::a: { \
OV_SCOPE(ngraph_op, OV_PP_CAT3(region, _, a)) { \
rc = evaluate<ov::element::Type_t::a>(__VA_ARGS__); \
} \
} break
#define NGRAPH_COPY_TENSOR(region, a, ...) \
case element::Type_t::a: { \
OV_SCOPE(ngraph_op, OV_PP_CAT3(region, _, a)) { \
rc = copy_tensor<element::Type_t::a>(__VA_ARGS__); \
} \
#define NGRAPH_COPY_TENSOR(region, a, ...) \
case ov::element::Type_t::a: { \
OV_SCOPE(ngraph_op, OV_PP_CAT3(region, _, a)) { \
rc = copy_tensor<ov::element::Type_t::a>(__VA_ARGS__); \
} \
} break
+5 -5
View File
@@ -119,15 +119,15 @@ bool op::v1::BinaryConvolution::visit_attributes(AttributeVisitor& visitor) {
namespace ov {
template <>
NGRAPH_API EnumNames<op::v1::BinaryConvolution::BinaryConvolutionMode>&
EnumNames<op::v1::BinaryConvolution::BinaryConvolutionMode>::get() {
static auto enum_names = EnumNames<op::v1::BinaryConvolution::BinaryConvolutionMode>(
NGRAPH_API EnumNames<ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode>&
EnumNames<ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode>(
"op::v1::BinaryConvolution::BinaryConvolutionMode",
{{"xnor-popcount", op::v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT}});
{{"xnor-popcount", ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v1::BinaryConvolution::BinaryConvolutionMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v1::BinaryConvolution::BinaryConvolutionMode>::type_info;
} // namespace ov
std::ostream& operator<<(std::ostream& s, const op::v1::BinaryConvolution::BinaryConvolutionMode& type) {
+6 -5
View File
@@ -119,13 +119,14 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::DepthToSpace::DepthT
namespace ov {
template <>
NGRAPH_API EnumNames<op::DepthToSpace::DepthToSpaceMode>& EnumNames<op::DepthToSpace::DepthToSpaceMode>::get() {
static auto enum_names = EnumNames<op::DepthToSpace::DepthToSpaceMode>(
NGRAPH_API EnumNames<ngraph::op::DepthToSpace::DepthToSpaceMode>&
EnumNames<ngraph::op::DepthToSpace::DepthToSpaceMode>::get() {
static auto enum_names = EnumNames<ngraph::op::DepthToSpace::DepthToSpaceMode>(
"op::DepthToSpace::DepthToSpaceMode",
{{"blocks_first", op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST},
{"depth_first", op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}});
{{"blocks_first", ngraph::op::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST},
{"depth_first", ngraph::op::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::DepthToSpace::DepthToSpaceMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::DepthToSpace::DepthToSpaceMode>::type_info;
} // namespace ov
+4 -4
View File
@@ -53,14 +53,14 @@ void op::v0::Gelu::validate_and_infer_types() {
namespace ov {
template <>
NGRAPH_API EnumNames<op::GeluApproximationMode>& EnumNames<op::GeluApproximationMode>::get() {
static auto enum_names = EnumNames<op::GeluApproximationMode>(
NGRAPH_API EnumNames<ngraph::op::GeluApproximationMode>& EnumNames<ngraph::op::GeluApproximationMode>::get() {
static auto enum_names = EnumNames<ngraph::op::GeluApproximationMode>(
"op::GeluApproximationMode",
{{"TANH", op::GeluApproximationMode::TANH}, {"ERF", op::GeluApproximationMode::ERF}});
{{"TANH", ngraph::op::GeluApproximationMode::TANH}, {"ERF", ngraph::op::GeluApproximationMode::ERF}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::GeluApproximationMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::GeluApproximationMode>::type_info;
} // namespace ov
std::ostream& op::operator<<(std::ostream& s, const op::GeluApproximationMode& type) {
return s << as_string(type);
+41 -36
View File
@@ -75,17 +75,18 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v0::Interpolate::Int
namespace ov {
template <>
EnumNames<op::v0::Interpolate::InterpolateMode>& EnumNames<op::v0::Interpolate::InterpolateMode>::get() {
static auto enum_names =
EnumNames<op::v0::Interpolate::InterpolateMode>("op::v0::Interpolate::InterpolateMode",
{{"nearest", op::v0::Interpolate::InterpolateMode::NEAREST},
{"linear", op::v0::Interpolate::InterpolateMode::LINEAR},
{"cubic", op::v0::Interpolate::InterpolateMode::CUBIC},
{"area", op::v0::Interpolate::InterpolateMode::AREA}});
EnumNames<ngraph::op::v0::Interpolate::InterpolateMode>&
EnumNames<ngraph::op::v0::Interpolate::InterpolateMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v0::Interpolate::InterpolateMode>(
"op::v0::Interpolate::InterpolateMode",
{{"nearest", ngraph::op::v0::Interpolate::InterpolateMode::NEAREST},
{"linear", ngraph::op::v0::Interpolate::InterpolateMode::LINEAR},
{"cubic", ngraph::op::v0::Interpolate::InterpolateMode::CUBIC},
{"area", ngraph::op::v0::Interpolate::InterpolateMode::AREA}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v0::Interpolate::InterpolateMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v0::Interpolate::InterpolateMode>::type_info;
} // namespace ov
@@ -498,54 +499,58 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v4::Interpolate::Nea
namespace ov {
template <>
NGRAPH_API EnumNames<op::v4::Interpolate::InterpolateMode>& EnumNames<op::v4::Interpolate::InterpolateMode>::get() {
static auto enum_names = EnumNames<op::v4::Interpolate::InterpolateMode>(
NGRAPH_API EnumNames<ngraph::op::v4::Interpolate::InterpolateMode>&
EnumNames<ngraph::op::v4::Interpolate::InterpolateMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v4::Interpolate::InterpolateMode>(
"op::v4::Interpolate::InterpolateMode",
{{"nearest", op::v4::Interpolate::InterpolateMode::NEAREST},
{"linear", op::v4::Interpolate::InterpolateMode::LINEAR},
{"linear_onnx", op::v4::Interpolate::InterpolateMode::LINEAR_ONNX},
{"cubic", op::v4::Interpolate::InterpolateMode::CUBIC}});
{{"nearest", ngraph::op::v4::Interpolate::InterpolateMode::NEAREST},
{"linear", ngraph::op::v4::Interpolate::InterpolateMode::LINEAR},
{"linear_onnx", ngraph::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX},
{"cubic", ngraph::op::v4::Interpolate::InterpolateMode::CUBIC}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v4::Interpolate::InterpolateMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v4::Interpolate::InterpolateMode>::type_info;
template <>
NGRAPH_API EnumNames<op::v4::Interpolate::ShapeCalcMode>& EnumNames<op::v4::Interpolate::ShapeCalcMode>::get() {
static auto enum_names = EnumNames<op::v4::Interpolate::ShapeCalcMode>(
NGRAPH_API EnumNames<ngraph::op::v4::Interpolate::ShapeCalcMode>&
EnumNames<ngraph::op::v4::Interpolate::ShapeCalcMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v4::Interpolate::ShapeCalcMode>(
"op::v4::Interpolate::ShapeCalcMode",
{{"sizes", op::v4::Interpolate::ShapeCalcMode::SIZES}, {"scales", op::v4::Interpolate::ShapeCalcMode::SCALES}});
{{"sizes", ngraph::op::v4::Interpolate::ShapeCalcMode::SIZES},
{"scales", ngraph::op::v4::Interpolate::ShapeCalcMode::SCALES}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v4::Interpolate::ShapeCalcMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v4::Interpolate::ShapeCalcMode>::type_info;
template <>
NGRAPH_API EnumNames<op::v4::Interpolate::CoordinateTransformMode>&
EnumNames<op::v4::Interpolate::CoordinateTransformMode>::get() {
static auto enum_names = EnumNames<op::v4::Interpolate::CoordinateTransformMode>(
NGRAPH_API EnumNames<ngraph::op::v4::Interpolate::CoordinateTransformMode>&
EnumNames<ngraph::op::v4::Interpolate::CoordinateTransformMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v4::Interpolate::CoordinateTransformMode>(
"op::v4::Interpolate::CoordinateTransformMode",
{{"half_pixel", op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL},
{"pytorch_half_pixel", op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL},
{"asymmetric", op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC},
{"tf_half_pixel_for_nn", op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN},
{"align_corners", op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS}});
{{"half_pixel", ngraph::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL},
{"pytorch_half_pixel", ngraph::op::v4::Interpolate::CoordinateTransformMode::PYTORCH_HALF_PIXEL},
{"asymmetric", ngraph::op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC},
{"tf_half_pixel_for_nn", ngraph::op::v4::Interpolate::CoordinateTransformMode::TF_HALF_PIXEL_FOR_NN},
{"align_corners", ngraph::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v4::Interpolate::CoordinateTransformMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v4::Interpolate::CoordinateTransformMode>::type_info;
template <>
NGRAPH_API EnumNames<op::v4::Interpolate::NearestMode>& EnumNames<op::v4::Interpolate::NearestMode>::get() {
static auto enum_names = EnumNames<op::v4::Interpolate::NearestMode>(
NGRAPH_API EnumNames<ngraph::op::v4::Interpolate::NearestMode>&
EnumNames<ngraph::op::v4::Interpolate::NearestMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v4::Interpolate::NearestMode>(
"op::v4::Interpolate::NearestMode",
{{"round_prefer_floor", op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR},
{"round_prefer_ceil", op::v4::Interpolate::NearestMode::ROUND_PREFER_CEIL},
{"floor", op::v4::Interpolate::NearestMode::FLOOR},
{"ceil", op::v4::Interpolate::NearestMode::CEIL},
{"simple", op::v4::Interpolate::NearestMode::SIMPLE}});
{{"round_prefer_floor", ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR},
{"round_prefer_ceil", ngraph::op::v4::Interpolate::NearestMode::ROUND_PREFER_CEIL},
{"floor", ngraph::op::v4::Interpolate::NearestMode::FLOOR},
{"ceil", ngraph::op::v4::Interpolate::NearestMode::CEIL},
{"simple", ngraph::op::v4::Interpolate::NearestMode::SIMPLE}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v4::Interpolate::NearestMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v4::Interpolate::NearestMode>::type_info;
} // namespace ov
+1 -1
View File
@@ -307,5 +307,5 @@ op::v5::Loop::Loop(const op::v5::Loop& other) : SubGraphOp() {
}
namespace ov {
constexpr DiscreteTypeInfo AttributeAdapter<op::v5::Loop::SpecialBodyPorts>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v5::Loop::SpecialBodyPorts>::type_info;
}
+8 -8
View File
@@ -335,17 +335,17 @@ shared_ptr<Node> op::v0::LSTMCell::clone_with_new_inputs(const OutputVector& new
namespace ov {
template <>
EnumNames<op::LSTMWeightsFormat>& EnumNames<op::LSTMWeightsFormat>::get() {
static auto enum_names = EnumNames<op::LSTMWeightsFormat>("op::LSTMWeightsFormat",
{{"fico", op::LSTMWeightsFormat::FICO},
{"icof", op::LSTMWeightsFormat::ICOF},
{"ifco", op::LSTMWeightsFormat::IFCO},
{"ifoc", op::LSTMWeightsFormat::IFOC},
{"iofc", op::LSTMWeightsFormat::IOFC}});
EnumNames<ngraph::op::LSTMWeightsFormat>& EnumNames<ngraph::op::LSTMWeightsFormat>::get() {
static auto enum_names = EnumNames<ngraph::op::LSTMWeightsFormat>("op::LSTMWeightsFormat",
{{"fico", ngraph::op::LSTMWeightsFormat::FICO},
{"icof", ngraph::op::LSTMWeightsFormat::ICOF},
{"ifco", ngraph::op::LSTMWeightsFormat::IFCO},
{"ifoc", ngraph::op::LSTMWeightsFormat::IFOC},
{"iofc", ngraph::op::LSTMWeightsFormat::IOFC}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::LSTMWeightsFormat>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::LSTMWeightsFormat>::type_info;
} // namespace ov
+7 -6
View File
@@ -70,14 +70,15 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v8::MatrixNms::Decay
namespace ov {
template <>
NGRAPH_API EnumNames<op::v8::MatrixNms::DecayFunction>& EnumNames<op::v8::MatrixNms::DecayFunction>::get() {
static auto enum_names =
EnumNames<op::v8::MatrixNms::DecayFunction>("op::v8::MatrixNms::DecayFunction",
{{"gaussian", op::v8::MatrixNms::DecayFunction::GAUSSIAN},
{"linear", op::v8::MatrixNms::DecayFunction::LINEAR}});
NGRAPH_API EnumNames<ngraph::op::v8::MatrixNms::DecayFunction>&
EnumNames<ngraph::op::v8::MatrixNms::DecayFunction>::get() {
static auto enum_names = EnumNames<ngraph::op::v8::MatrixNms::DecayFunction>(
"op::v8::MatrixNms::DecayFunction",
{{"gaussian", ngraph::op::v8::MatrixNms::DecayFunction::GAUSSIAN},
{"linear", ngraph::op::v8::MatrixNms::DecayFunction::LINEAR}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v8::MatrixNms::DecayFunction>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v8::MatrixNms::DecayFunction>::type_info;
} // namespace ov
+5 -5
View File
@@ -72,18 +72,18 @@ bool op::v0::MVN::visit_attributes(AttributeVisitor& visitor) {
namespace ov {
template <>
NGRAPH_API EnumNames<op::MVNEpsMode>& EnumNames<op::MVNEpsMode>::get() {
static auto enum_names = EnumNames<op::MVNEpsMode>(
NGRAPH_API EnumNames<ngraph::op::MVNEpsMode>& EnumNames<ngraph::op::MVNEpsMode>::get() {
static auto enum_names = EnumNames<ngraph::op::MVNEpsMode>(
"op::MVNEpsMode",
{{"OUTSIDE_SQRT", op::MVNEpsMode::OUTSIDE_SQRT}, {"INSIDE_SQRT", op::MVNEpsMode::INSIDE_SQRT}});
{{"OUTSIDE_SQRT", ngraph::op::MVNEpsMode::OUTSIDE_SQRT}, {"INSIDE_SQRT", ngraph::op::MVNEpsMode::INSIDE_SQRT}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::MVNEpsMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::MVNEpsMode>::type_info;
} // namespace ov
std::ostream& op::operator<<(std::ostream& s, const op::MVNEpsMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::MVNEpsMode& type) {
return s << as_string(type);
}
+18 -15
View File
@@ -176,15 +176,16 @@ int64_t op::v1::NonMaxSuppression::max_boxes_output_from_input() const {
namespace ov {
template <>
EnumNames<op::v1::NonMaxSuppression::BoxEncodingType>& EnumNames<op::v1::NonMaxSuppression::BoxEncodingType>::get() {
static auto enum_names = EnumNames<op::v1::NonMaxSuppression::BoxEncodingType>(
EnumNames<ngraph::op::v1::NonMaxSuppression::BoxEncodingType>&
EnumNames<ngraph::op::v1::NonMaxSuppression::BoxEncodingType>::get() {
static auto enum_names = EnumNames<ngraph::op::v1::NonMaxSuppression::BoxEncodingType>(
"op::v1::NonMaxSuppression::BoxEncodingType",
{{"corner", op::v1::NonMaxSuppression::BoxEncodingType::CORNER},
{"center", op::v1::NonMaxSuppression::BoxEncodingType::CENTER}});
{{"corner", ngraph::op::v1::NonMaxSuppression::BoxEncodingType::CORNER},
{"center", ngraph::op::v1::NonMaxSuppression::BoxEncodingType::CENTER}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v1::NonMaxSuppression::BoxEncodingType>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v1::NonMaxSuppression::BoxEncodingType>::type_info;
} // namespace ov
@@ -363,15 +364,16 @@ int64_t op::v3::NonMaxSuppression::max_boxes_output_from_input() const {
namespace ov {
template <>
EnumNames<op::v3::NonMaxSuppression::BoxEncodingType>& EnumNames<op::v3::NonMaxSuppression::BoxEncodingType>::get() {
static auto enum_names = EnumNames<op::v3::NonMaxSuppression::BoxEncodingType>(
EnumNames<ngraph::op::v3::NonMaxSuppression::BoxEncodingType>&
EnumNames<ngraph::op::v3::NonMaxSuppression::BoxEncodingType>::get() {
static auto enum_names = EnumNames<ngraph::op::v3::NonMaxSuppression::BoxEncodingType>(
"op::v3::NonMaxSuppression::BoxEncodingType",
{{"corner", op::v3::NonMaxSuppression::BoxEncodingType::CORNER},
{"center", op::v3::NonMaxSuppression::BoxEncodingType::CENTER}});
{{"corner", ngraph::op::v3::NonMaxSuppression::BoxEncodingType::CORNER},
{"center", ngraph::op::v3::NonMaxSuppression::BoxEncodingType::CENTER}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v3::NonMaxSuppression::BoxEncodingType>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v3::NonMaxSuppression::BoxEncodingType>::type_info;
} // namespace ov
@@ -821,14 +823,15 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v5::NonMaxSuppressio
namespace ov {
template <>
EnumNames<op::v5::NonMaxSuppression::BoxEncodingType>& EnumNames<op::v5::NonMaxSuppression::BoxEncodingType>::get() {
static auto enum_names = EnumNames<op::v5::NonMaxSuppression::BoxEncodingType>(
EnumNames<ngraph::op::v5::NonMaxSuppression::BoxEncodingType>&
EnumNames<ngraph::op::v5::NonMaxSuppression::BoxEncodingType>::get() {
static auto enum_names = EnumNames<ngraph::op::v5::NonMaxSuppression::BoxEncodingType>(
"op::v5::NonMaxSuppression::BoxEncodingType",
{{"corner", op::v5::NonMaxSuppression::BoxEncodingType::CORNER},
{"center", op::v5::NonMaxSuppression::BoxEncodingType::CENTER}});
{{"corner", ngraph::op::v5::NonMaxSuppression::BoxEncodingType::CORNER},
{"center", ngraph::op::v5::NonMaxSuppression::BoxEncodingType::CENTER}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v5::NonMaxSuppression::BoxEncodingType>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v5::NonMaxSuppression::BoxEncodingType>::type_info;
} // namespace ov
+1 -1
View File
@@ -68,7 +68,7 @@ bool ov::AttributeAdapter<ParameterVector>::visit_attributes(AttributeVisitor& v
}
visitor.on_attribute(index.str(), id);
if (!m_ref[i]) {
m_ref[i] = ov::as_type_ptr<op::v0::Parameter>(visitor.get_registered_node(id));
m_ref[i] = ov::as_type_ptr<ngraph::op::v0::Parameter>(visitor.get_registered_node(id));
}
}
return true;
+1 -1
View File
@@ -82,7 +82,7 @@ bool ov::AttributeAdapter<ResultVector>::visit_attributes(AttributeVisitor& visi
}
visitor.on_attribute(index.str(), id);
if (!m_ref[i]) {
m_ref[i] = ov::as_type_ptr<op::v0::Result>(visitor.get_registered_node(id));
m_ref[i] = ov::as_type_ptr<ngraph::op::v0::Result>(visitor.get_registered_node(id));
}
}
return true;
+4 -4
View File
@@ -203,12 +203,12 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v1::Reverse::Mode& t
namespace ov {
template <>
EnumNames<op::v1::Reverse::Mode>& EnumNames<op::v1::Reverse::Mode>::get() {
static auto enum_names = EnumNames<op::v1::Reverse::Mode>(
EnumNames<ngraph::op::v1::Reverse::Mode>& EnumNames<ngraph::op::v1::Reverse::Mode>::get() {
static auto enum_names = EnumNames<ngraph::op::v1::Reverse::Mode>(
"op::v1::Reverse::Mode",
{{"index", op::v1::Reverse::Mode::INDEX}, {"mask", op::v1::Reverse::Mode::MASK}});
{{"index", ngraph::op::v1::Reverse::Mode::INDEX}, {"mask", ngraph::op::v1::Reverse::Mode::MASK}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v1::Reverse::Mode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v1::Reverse::Mode>::type_info;
} // namespace ov
+4 -4
View File
@@ -162,13 +162,13 @@ shared_ptr<Node> op::v3::ROIAlign::clone_with_new_inputs(const OutputVector& new
}
namespace ov {
constexpr DiscreteTypeInfo AttributeAdapter<op::v3::ROIAlign::PoolingMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v3::ROIAlign::PoolingMode>::type_info;
template <>
NGRAPH_API EnumNames<op::v3::ROIAlign::PoolingMode>& EnumNames<op::v3::ROIAlign::PoolingMode>::get() {
static auto enum_names = EnumNames<op::v3::ROIAlign::PoolingMode>(
NGRAPH_API EnumNames<ngraph::op::v3::ROIAlign::PoolingMode>& EnumNames<ngraph::op::v3::ROIAlign::PoolingMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v3::ROIAlign::PoolingMode>(
"op::v3::ROIAlign::PoolingMode",
{{"avg", op::v3::ROIAlign::PoolingMode::AVG}, {"max", op::v3::ROIAlign::PoolingMode::MAX}});
{{"avg", ngraph::op::v3::ROIAlign::PoolingMode::AVG}, {"max", ngraph::op::v3::ROIAlign::PoolingMode::MAX}});
return enum_names;
}
+6 -6
View File
@@ -119,13 +119,13 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v5::Round::RoundMode
namespace ov {
template <>
EnumNames<op::v5::Round::RoundMode>& EnumNames<op::v5::Round::RoundMode>::get() {
static auto enum_names =
EnumNames<op::v5::Round::RoundMode>("op::v5::Round::RoundMode",
{{"half_to_even", op::v5::Round::RoundMode::HALF_TO_EVEN},
{"half_away_from_zero", op::v5::Round::RoundMode::HALF_AWAY_FROM_ZERO}});
EnumNames<ngraph::op::v5::Round::RoundMode>& EnumNames<ngraph::op::v5::Round::RoundMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v5::Round::RoundMode>(
"op::v5::Round::RoundMode",
{{"half_to_even", ngraph::op::v5::Round::RoundMode::HALF_TO_EVEN},
{"half_away_from_zero", ngraph::op::v5::Round::RoundMode::HALF_AWAY_FROM_ZERO}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v5::Round::RoundMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v5::Round::RoundMode>::type_info;
} // namespace ov
+6 -5
View File
@@ -122,13 +122,14 @@ std::ostream& ngraph::operator<<(std::ostream& s, const op::v0::SpaceToDepth::Sp
namespace ov {
template <>
NGRAPH_API EnumNames<op::v0::SpaceToDepth::SpaceToDepthMode>& EnumNames<op::v0::SpaceToDepth::SpaceToDepthMode>::get() {
static auto enum_names = EnumNames<op::v0::SpaceToDepth::SpaceToDepthMode>(
NGRAPH_API EnumNames<ngraph::op::v0::SpaceToDepth::SpaceToDepthMode>&
EnumNames<ngraph::op::v0::SpaceToDepth::SpaceToDepthMode>::get() {
static auto enum_names = EnumNames<ngraph::op::v0::SpaceToDepth::SpaceToDepthMode>(
"op::v0::SpaceToDepth::SpaceToDepthMode",
{{"blocks_first", op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST},
{"depth_first", op::v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST}});
{{"blocks_first", ngraph::op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST},
{"depth_first", ngraph::op::v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST}});
return enum_names;
}
constexpr DiscreteTypeInfo AttributeAdapter<op::v0::SpaceToDepth::SpaceToDepthMode>::type_info;
constexpr DiscreteTypeInfo AttributeAdapter<ngraph::op::v0::SpaceToDepth::SpaceToDepthMode>::type_info;
} // namespace ov
@@ -16,43 +16,42 @@
#include "ngraph/op/tanh.hpp"
using namespace std;
using namespace ngraph;
static shared_ptr<Node> sigmoid(const shared_ptr<Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<op::Sigmoid>(arg);
static shared_ptr<ov::Node> sigmoid(const shared_ptr<ov::Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<ngraph::op::Sigmoid>(arg);
}
static shared_ptr<Node> tanh(const shared_ptr<Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<op::Tanh>(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 shared_ptr<Node> relu(const shared_ptr<Node>& arg, float /* alpha */, float /* beta */) {
return make_shared<op::Relu>(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 shared_ptr<Node> hardsigmoid(const shared_ptr<Node>& arg, float alpha, float beta) {
const auto alpha_node = op::Constant::create<float>(arg->get_element_type(), Shape{}, {alpha});
const auto beta_node = op::Constant::create<float>(arg->get_element_type(), Shape{}, {beta});
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});
return make_shared<op::HardSigmoid>(arg, alpha_node, beta_node);
return make_shared<ngraph::op::HardSigmoid>(arg, alpha_node, beta_node);
}
op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f, float alpha, float beta)
ov::op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f, float alpha, float beta)
: m_function{f},
m_alpha{alpha},
m_beta{beta} {}
op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f, float alpha)
ov::op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f, float alpha)
: ActivationFunction(f, alpha, nanf("")) {}
op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f)
ov::op::util::ActivationFunction::ActivationFunction(ActivationFunctionType f)
: ActivationFunction(f, nanf(""), nanf("")) {}
shared_ptr<Node> op::util::ActivationFunction::operator()(const shared_ptr<Node>& arg) const {
shared_ptr<ov::Node> ov::op::util::ActivationFunction::operator()(const shared_ptr<Node>& arg) const {
return m_function(arg, m_alpha, m_beta);
}
op::util::ActivationFunction op::util::get_activation_func_by_name(const string& func_name) {
ov::op::util::ActivationFunction ov::op::util::get_activation_func_by_name(const string& func_name) {
using ActivationFunctionMap = unordered_map<string, op::util::ActivationFunction>;
static ActivationFunctionMap func_map{
@@ -9,20 +9,19 @@
#include "ngraph/validation_util.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::ArithmeticReduction, "ArithmeticReduction", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::ArithmeticReduction, "ArithmeticReduction", 0);
op::util::ArithmeticReduction::ArithmeticReduction() {}
ov::op::util::ArithmeticReduction::ArithmeticReduction() = default;
op::util::ArithmeticReduction::ArithmeticReduction(const Output<Node>& arg, const Output<Node>& reduction_axes)
ov::op::util::ArithmeticReduction::ArithmeticReduction(const Output<Node>& arg, const Output<Node>& reduction_axes)
: ReductionBase(arg, reduction_axes) {}
bool op::util::ArithmeticReduction::reduction_axes_constant() const {
return ov::is_type<op::Constant>(input_value(1).get_node());
bool ov::op::util::ArithmeticReduction::reduction_axes_constant() const {
return ov::is_type<ngraph::op::Constant>(input_value(1).get_node());
}
const AxisSet op::util::ArithmeticReduction::get_reduction_axes() const {
const ov::AxisSet ov::op::util::ArithmeticReduction::get_reduction_axes() const {
AxisSet axes;
if (const auto& const_op = get_constant_from_source(input_value(1))) {
const auto const_data = const_op->cast_vector<int64_t>();
@@ -33,12 +32,13 @@ const AxisSet op::util::ArithmeticReduction::get_reduction_axes() const {
return axes;
}
void op::util::ArithmeticReduction::set_reduction_axes(const AxisSet& reduction_axes) {
void ov::op::util::ArithmeticReduction::set_reduction_axes(const AxisSet& reduction_axes) {
this->input(1).replace_source_output(
op::Constant::create(element::i64, Shape{reduction_axes.size()}, reduction_axes.to_vector())->output(0));
ngraph::op::Constant::create(element::i64, ngraph::Shape{reduction_axes.size()}, reduction_axes.to_vector())
->output(0));
}
void op::util::ArithmeticReduction::validate_and_infer_types() {
void ov::op::util::ArithmeticReduction::validate_and_infer_types() {
NGRAPH_OP_SCOPE(util_ArithmeticReduction_validate_and_infer_types);
const PartialShape& axes_shape = get_input_partial_shape(1);
@@ -10,23 +10,23 @@
#include "ngraph/validation_util.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::ArithmeticReductionKeepDims, "ArithmeticReductionKeepDims", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::ArithmeticReductionKeepDims, "ArithmeticReductionKeepDims", 0);
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 ngraph::Output<ngraph::Node>& arg,
const ngraph::Output<ngraph::Node>& reduction_axes,
bool keep_dims)
: ArithmeticReduction(arg, reduction_axes),
m_keep_dims{keep_dims} {}
bool ngraph::op::util::ArithmeticReductionKeepDims::visit_attributes(AttributeVisitor& visitor) {
bool ov::op::util::ArithmeticReductionKeepDims::visit_attributes(AttributeVisitor& visitor) {
NGRAPH_OP_SCOPE(v0_util_ArithmeticReductionKeepDims_visit_attributes);
visitor.on_attribute("keep_dims", m_keep_dims);
return true;
}
void op::util::ArithmeticReductionKeepDims::validate_and_infer_types() {
void ov::op::util::ArithmeticReductionKeepDims::validate_and_infer_types() {
NGRAPH_OP_SCOPE(v0_util_ArithmeticReductionKeepDims_validate_and_infer_types);
const element::Type& data_et = get_input_element_type(0);
+13 -13
View File
@@ -140,44 +140,43 @@ NGRAPH_API EnumNames<ngraph::op::RecurrentSequenceDirection>& EnumNames<ngraph::
{"bidirectional", ngraph::op::RecurrentSequenceDirection::BIDIRECTIONAL}});
return enum_names;
}
} // namespace ov
const ngraph::op::AutoBroadcastSpec ngraph::op::AutoBroadcastSpec::NUMPY(AutoBroadcastType::NUMPY, 0);
const ngraph::op::AutoBroadcastSpec ngraph::op::AutoBroadcastSpec::NONE{AutoBroadcastType::NONE, 0};
const op::AutoBroadcastSpec op::AutoBroadcastSpec::NUMPY(AutoBroadcastType::NUMPY, 0);
const op::AutoBroadcastSpec op::AutoBroadcastSpec::NONE{AutoBroadcastType::NONE, 0};
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::PadMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::PadMode& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::PadType& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::PadType& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::RoundingType& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::RoundingType& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::BroadcastType& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::BroadcastType& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::AutoBroadcastType& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::AutoBroadcastType& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::EpsMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::EpsMode& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::TopKSortType& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::TopKSortType& type) {
return s << as_string(type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::TopKMode& type) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::TopKMode& type) {
return s << as_string(type);
}
ngraph::op::AutoBroadcastType ngraph::op::AutoBroadcastSpec::type_from_string(const std::string& type) const {
op::AutoBroadcastType op::AutoBroadcastSpec::type_from_string(const std::string& type) const {
auto lowercase_type = type;
std::transform(lowercase_type.begin(), lowercase_type.end(), lowercase_type.begin(), [](char c) {
return std::tolower(c);
@@ -193,6 +192,7 @@ ngraph::op::AutoBroadcastType ngraph::op::AutoBroadcastSpec::type_from_string(co
return allowed_values.at(lowercase_type);
}
std::ostream& ngraph::op::operator<<(std::ostream& s, const ngraph::op::RecurrentSequenceDirection& direction) {
std::ostream& op::operator<<(std::ostream& s, const ngraph::op::RecurrentSequenceDirection& direction) {
return s << as_string(direction);
}
} // namespace ov
@@ -11,19 +11,19 @@
#include "ngraph/op/util/elementwise_args.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::BinaryElementwiseArithmetic, "BinaryElementwiseArithmetic", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::BinaryElementwiseArithmetic, "BinaryElementwiseArithmetic", 0);
op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic(const AutoBroadcastSpec& autob) : m_autob(autob) {}
ov::op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic(const AutoBroadcastSpec& autob)
: m_autob(autob) {}
op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob)
ov::op::util::BinaryElementwiseArithmetic::BinaryElementwiseArithmetic(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob)
: Op({arg0, arg1}),
m_autob(autob) {}
void op::util::BinaryElementwiseArithmetic::validate_and_infer_elementwise_arithmetic(
void ov::op::util::BinaryElementwiseArithmetic::validate_and_infer_elementwise_arithmetic(
const op::AutoBroadcastSpec& autob) {
auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this, autob);
element::Type& args_et = std::get<0>(args_et_pshape);
@@ -38,35 +38,35 @@ void op::util::BinaryElementwiseArithmetic::validate_and_infer_elementwise_arith
set_output_type(0, args_et, args_pshape);
}
void op::util::BinaryElementwiseArithmetic::validate_and_infer_types() {
void ov::op::util::BinaryElementwiseArithmetic::validate_and_infer_types() {
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseArithmetic_validate_and_infer_types);
validate_and_infer_elementwise_arithmetic(m_autob);
}
bool op::util::BinaryElementwiseArithmetic::visit_attributes(AttributeVisitor& visitor) {
bool ov::op::util::BinaryElementwiseArithmetic::visit_attributes(AttributeVisitor& visitor) {
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseArithmetic_visit_attributes);
visitor.on_attribute("auto_broadcast", m_autob);
return true;
}
bool op::util::BinaryElementwiseArithmetic::evaluate_upper(const HostTensorVector& output_values) const {
NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1));
bool ov::op::util::BinaryElementwiseArithmetic::evaluate_upper(const HostTensorVector& output_values) const {
NGRAPH_CHECK(ngraph::validate_host_tensor_vector(output_values, 1));
HostTensorVector lower_output_tensors;
for (const auto& output : output_values)
lower_output_tensors.push_back(
std::make_shared<HostTensor>(output->get_element_type(), output->get_partial_shape()));
if (!interval_bound_evaluator(this, lower_output_tensors, output_values))
if (!ngraph::interval_bound_evaluator(this, lower_output_tensors, output_values))
return false;
return true;
}
bool op::util::BinaryElementwiseArithmetic::evaluate_lower(const HostTensorVector& output_values) const {
NGRAPH_CHECK(validate_host_tensor_vector(output_values, 1));
bool ov::op::util::BinaryElementwiseArithmetic::evaluate_lower(const HostTensorVector& output_values) const {
NGRAPH_CHECK(ngraph::validate_host_tensor_vector(output_values, 1));
HostTensorVector upper_output_tensors;
for (const auto& output : output_values)
upper_output_tensors.push_back(
std::make_shared<HostTensor>(output->get_element_type(), output->get_partial_shape()));
if (!interval_bound_evaluator(this, output_values, upper_output_tensors))
if (!ngraph::interval_bound_evaluator(this, output_values, upper_output_tensors))
return false;
return true;
}
@@ -9,19 +9,19 @@
#include "ngraph/op/util/elementwise_args.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::BinaryElementwiseComparison, "BinaryElementwiseComparison", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::BinaryElementwiseComparison, "BinaryElementwiseComparison", 0);
op::util::BinaryElementwiseComparison::BinaryElementwiseComparison(const AutoBroadcastSpec& autob) : m_autob(autob) {}
ov::op::util::BinaryElementwiseComparison::BinaryElementwiseComparison(const AutoBroadcastSpec& autob)
: m_autob(autob) {}
op::util::BinaryElementwiseComparison::BinaryElementwiseComparison(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob)
ov::op::util::BinaryElementwiseComparison::BinaryElementwiseComparison(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob)
: Op({arg0, arg1}),
m_autob(autob) {}
void op::util::BinaryElementwiseComparison::validate_and_infer_types() {
void ov::op::util::BinaryElementwiseComparison::validate_and_infer_types() {
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseComparison_validate_and_infer_types);
auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this, m_autob);
PartialShape& args_pshape = std::get<1>(args_et_pshape);
@@ -29,7 +29,7 @@ void op::util::BinaryElementwiseComparison::validate_and_infer_types() {
set_output_type(0, element::boolean, args_pshape);
}
bool op::util::BinaryElementwiseComparison::visit_attributes(AttributeVisitor& visitor) {
bool ov::op::util::BinaryElementwiseComparison::visit_attributes(AttributeVisitor& visitor) {
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseComparison_visit_attributes);
visitor.on_attribute("auto_broadcast", m_autob);
return true;
@@ -9,19 +9,18 @@
#include "ngraph/op/util/elementwise_args.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::BinaryElementwiseLogical, "BinaryElementwiseLogical", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::BinaryElementwiseLogical, "BinaryElementwiseLogical", 0);
op::util::BinaryElementwiseLogical::BinaryElementwiseLogical() {}
ov::op::util::BinaryElementwiseLogical::BinaryElementwiseLogical() = default;
op::util::BinaryElementwiseLogical::BinaryElementwiseLogical(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob)
ov::op::util::BinaryElementwiseLogical::BinaryElementwiseLogical(const Output<Node>& arg0,
const Output<Node>& arg1,
const AutoBroadcastSpec& autob)
: Op({arg0, arg1}),
m_autob(autob) {}
void op::util::BinaryElementwiseLogical::validate_and_infer_types() {
void ov::op::util::BinaryElementwiseLogical::validate_and_infer_types() {
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseLogical_validate_and_infer_types);
auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this, m_autob);
@@ -37,7 +36,7 @@ void op::util::BinaryElementwiseLogical::validate_and_infer_types() {
set_output_type(0, element::boolean, args_pshape);
}
bool op::util::BinaryElementwiseLogical::visit_attributes(AttributeVisitor& visitor) {
bool ov::op::util::BinaryElementwiseLogical::visit_attributes(AttributeVisitor& visitor) {
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseLogical_visit_attributes);
visitor.on_attribute("auto_broadcast", m_autob);
return true;
+80 -80
View File
@@ -16,29 +16,28 @@
#include "ngraph/runtime/reference/broadcast.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::BroadcastBase, "BroadcastBase", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::BroadcastBase, "BroadcastBase", 0);
op::util::BroadcastBase::BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const Output<Node>& axes_mapping,
const BroadcastModeSpec& broadcast_mode)
ov::op::util::BroadcastBase::BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const Output<Node>& axes_mapping,
const BroadcastModeSpec& broadcast_mode)
: Op({arg, target_shape, axes_mapping}),
m_mode{broadcast_mode} {}
op::util::BroadcastBase::BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const BroadcastModeSpec& broadcast_mode)
ov::op::util::BroadcastBase::BroadcastBase(const Output<Node>& arg,
const Output<Node>& target_shape,
const BroadcastModeSpec& broadcast_mode)
: Op({arg, target_shape}),
m_mode{broadcast_mode} {}
PartialShape op::util::BroadcastBase::get_result_shape_pdpd(const PartialShape& arg0_shape,
const PartialShape& target_pshape,
const op::BroadcastModeSpec& broadcast_spec) const {
ov::PartialShape ov::op::util::BroadcastBase::get_result_shape_pdpd(const PartialShape& arg0_shape,
const PartialShape& target_pshape,
const op::BroadcastModeSpec& broadcast_spec) const {
if (target_pshape.is_dynamic())
return PartialShape::dynamic(target_pshape.rank());
Shape target_shape = target_pshape.to_shape();
ngraph::Shape target_shape = target_pshape.to_shape();
if (arg0_shape.rank().is_dynamic()) {
return PartialShape::dynamic(target_shape.size());
}
@@ -69,8 +68,8 @@ PartialShape op::util::BroadcastBase::get_result_shape_pdpd(const PartialShape&
return result_shape;
}
void op::util::BroadcastBase::validate_target_shape_numpy(const PartialShape& arg_shape,
const PartialShape& target_shape) const {
void ov::op::util::BroadcastBase::validate_target_shape_numpy(const PartialShape& arg_shape,
const PartialShape& target_shape) const {
if (arg_shape.rank().is_dynamic() || target_shape.rank().is_dynamic()) {
return;
}
@@ -98,9 +97,9 @@ void op::util::BroadcastBase::validate_target_shape_numpy(const PartialShape& ar
}
}
void op::util::BroadcastBase::validate_target_shape_none(const PartialShape& arg_shape,
const AxisVector& axes_mapping_val,
const PartialShape& target_shape) const {
void ov::op::util::BroadcastBase::validate_target_shape_none(const PartialShape& arg_shape,
const AxisVector& axes_mapping_val,
const PartialShape& target_shape) const {
if (arg_shape.rank().is_dynamic() || target_shape.rank().is_dynamic()) {
return;
}
@@ -144,7 +143,7 @@ void op::util::BroadcastBase::validate_target_shape_none(const PartialShape& arg
}
}
void op::util::BroadcastBase::validate_and_infer_types() {
void ov::op::util::BroadcastBase::validate_and_infer_types() {
NGRAPH_OP_SCOPE(util_BroadcastBase_validate_and_infer_types);
// shape node should have integer data type. For now we only allow i64
auto shape_et = get_input_element_type(1);
@@ -191,9 +190,9 @@ void op::util::BroadcastBase::validate_and_infer_types() {
}
PartialShape output_shape;
bool output_shape_defined = evaluate_as_partial_shape(get_input_source_output(1), output_shape);
bool output_shape_defined = ngraph::evaluate_as_partial_shape(get_input_source_output(1), output_shape);
if (auto concat = ov::as_type_ptr<op::v0::Concat>(input_value(1).get_node_shared_ptr())) {
if (auto concat = ov::as_type_ptr<ngraph::op::v0::Concat>(input_value(1).get_node_shared_ptr())) {
auto concat_inputs = concat->inputs();
if (!output_shape_defined && concat->get_output_partial_shape(0).is_static() &&
@@ -201,8 +200,8 @@ void op::util::BroadcastBase::validate_and_infer_types() {
auto output_partial_shape = vector<Dimension>{};
for (const auto& concat_input : concat_inputs) {
auto source_node_ptr = concat_input.get_source_output().get_node_shared_ptr();
if (auto source_const_ptr = ov::as_type_ptr<op::v0::Constant>(source_node_ptr)) {
output_partial_shape.push_back(source_const_ptr->get_axis_vector_val()[0]);
if (auto source_const_ptr = ov::as_type_ptr<ngraph::op::v0::Constant>(source_node_ptr)) {
output_partial_shape.emplace_back(source_const_ptr->get_axis_vector_val()[0]);
} else {
output_partial_shape.push_back(Dimension::dynamic());
}
@@ -231,7 +230,7 @@ void op::util::BroadcastBase::validate_and_infer_types() {
" doesn't match rank of input tensor ",
input_rank);
if (output_shape_defined && has_and_set_equal_bounds(input_value(2))) {
if (output_shape_defined && ngraph::has_and_set_equal_bounds(input_value(2))) {
auto axes_mapping_val = get_constant_from_source(input_value(2))->get_axis_vector_val();
validate_target_shape_none(arg_shape, axes_mapping_val, output_shape);
}
@@ -249,9 +248,9 @@ void op::util::BroadcastBase::validate_and_infer_types() {
set_output_type(0, get_input_element_type(0), result_shape);
}
std::pair<bool, AxisSet> op::util::BroadcastBase::get_broadcast_axes_numpy_pdpd(
const Shape& arg_shape,
const Shape& result_shape,
std::pair<bool, ov::AxisSet> ov::op::util::BroadcastBase::get_broadcast_axes_numpy_pdpd(
const ngraph::Shape& arg_shape,
const ngraph::Shape& result_shape,
const op::BroadcastModeSpec& broadcast_spec) {
AxisSet broadcast_axes;
bool axes_known = false;
@@ -267,8 +266,8 @@ std::pair<bool, AxisSet> op::util::BroadcastBase::get_broadcast_axes_numpy_pdpd(
return std::make_pair(axes_known, broadcast_axes);
}
std::pair<bool, AxisSet> op::util::BroadcastBase::get_broadcast_axes_none(const AxisVector axes_mapping_val,
const size_t target_shape_size) {
std::pair<bool, ov::AxisSet> ov::op::util::BroadcastBase::get_broadcast_axes_none(const AxisVector& axes_mapping_val,
const size_t target_shape_size) {
AxisSet broadcast_axes;
bool axes_known = false;
@@ -283,7 +282,7 @@ std::pair<bool, AxisSet> op::util::BroadcastBase::get_broadcast_axes_none(const
return std::make_pair(axes_known, broadcast_axes);
}
std::pair<bool, AxisSet> op::util::BroadcastBase::get_broadcast_axes() const {
std::pair<bool, ov::AxisSet> ov::op::util::BroadcastBase::get_broadcast_axes() const {
AxisSet broadcast_axes;
bool axes_known = false;
@@ -302,44 +301,46 @@ std::pair<bool, AxisSet> op::util::BroadcastBase::get_broadcast_axes() const {
return get_broadcast_axes_numpy_pdpd(arg_shape, result_shape, m_mode);
}
} else {
throw ngraph_error("Unknown autobroadcast type");
throw ov::Exception("Unknown autobroadcast type");
}
return std::make_pair(axes_known, broadcast_axes);
}
bool op::util::BroadcastBase::evaluate_broadcast(const HostTensorPtr& arg0,
const HostTensorPtr& out,
const AxisSet& broadcast_axes) const {
bool ov::op::util::BroadcastBase::evaluate_broadcast(const HostTensorPtr& arg0,
const HostTensorPtr& out,
const AxisSet& broadcast_axes) const {
NGRAPH_OP_SCOPE(util_BroadcastBase_evaluate_axes);
auto arg0_shape = arg0->get_shape();
if (arg0_shape.size() == 0) {
arg0_shape = Shape{1};
arg0_shape = ngraph::Shape{1};
}
runtime::reference::broadcast(arg0->get_data_ptr<const char>(),
out->get_data_ptr<char>(),
arg0_shape,
out->get_shape(),
broadcast_axes,
arg0->get_element_type().size());
ngraph::runtime::reference::broadcast(arg0->get_data_ptr<const char>(),
out->get_data_ptr<char>(),
arg0_shape,
out->get_shape(),
broadcast_axes,
arg0->get_element_type().size());
return true;
}
namespace {
template <element::Type_t ET>
void get_axis_vector_from_hosttensor(const HostTensorPtr& arg, AxisVector& axes_vector) {
using T = typename element_type_traits<ET>::value_type;
template <ov::element::Type_t ET>
void get_axis_vector_from_hosttensor(const ngraph::HostTensorPtr& arg, ov::AxisVector& axes_vector) {
using T = typename ov::element_type_traits<ET>::value_type;
auto rank = arg->get_shape().at(0);
std::vector<T> axes_vec(rank);
arg->read(axes_vec.data(), rank * sizeof(T));
axes_vector = AxisVector(axes_vec.begin(), axes_vec.end());
axes_vector = ov::AxisVector(axes_vec.begin(), axes_vec.end());
}
#define GET_AXIS_VECTOR(a) \
case element::Type_t::a: \
get_axis_vector_from_hosttensor<element::Type_t::a>
#define GET_AXIS_VECTOR(a) \
case ov::element::Type_t::a: \
get_axis_vector_from_hosttensor<ov::element::Type_t::a>
void get_axis_vector_from_ht(const HostTensorPtr& arg, AxisVector& axis_vector, const Shape& arg_shape) {
void get_axis_vector_from_ht(const ngraph::HostTensorPtr& arg,
ov::AxisVector& axis_vector,
const ngraph::Shape& arg_shape) {
switch (arg->get_element_type()) {
GET_AXIS_VECTOR(i8)(arg, axis_vector);
break;
@@ -359,8 +360,7 @@ void get_axis_vector_from_ht(const HostTensorPtr& arg, AxisVector& axis_vector,
break;
default:
// other types are not supported and would have thrown in ctor
ngraph_error("get_axis_vector_from_ht: type is not integral\n");
break;
throw ov::Exception("get_axis_vector_from_ht: type is not integral");
}
// Rank(arg_shape) == shape_size(axes_mapping)
NGRAPH_CHECK(axis_vector.size() == arg_shape.size(),
@@ -370,21 +370,21 @@ void get_axis_vector_from_ht(const HostTensorPtr& arg, AxisVector& axis_vector,
arg_shape.size());
}
template <element::Type_t ET>
void get_shape_from_hosttensor(const HostTensorPtr& input1, Shape& target_shape) {
using T = typename element_type_traits<ET>::value_type;
template <ov::element::Type_t ET>
void get_shape_from_hosttensor(const ngraph::HostTensorPtr& input1, ngraph::Shape& target_shape) {
using T = typename ov::element_type_traits<ET>::value_type;
auto rank = input1->get_shape().at(0);
std::vector<T> target_shape_vec(rank);
input1->read(target_shape_vec.data(), rank * sizeof(T));
target_shape = Shape(target_shape_vec.begin(), target_shape_vec.end());
target_shape = ngraph::Shape(target_shape_vec.begin(), target_shape_vec.end());
}
#define CASE_GET_SHAPE(a) \
case element::Type_t::a: \
get_shape_from_hosttensor<element::Type_t::a>
#define CASE_GET_SHAPE(a) \
case ov::element::Type_t::a: \
get_shape_from_hosttensor<ov::element::Type_t::a>
Shape get_target_shape_from_ht(const HostTensorPtr& input1) {
Shape target_shape;
ngraph::Shape get_target_shape_from_ht(const ngraph::HostTensorPtr& input1) {
ngraph::Shape target_shape;
switch (input1->get_element_type()) {
CASE_GET_SHAPE(i8)(input1, target_shape);
break;
@@ -404,31 +404,30 @@ Shape get_target_shape_from_ht(const HostTensorPtr& input1) {
break;
default:
// other types are not supported and would have thrown in ctor
ngraph_error("get_target_shape_from_ht: type is not integral\n");
break;
throw ov::Exception("get_target_shape_from_ht: type is not integral");
}
return target_shape;
}
} // namespace
bool op::util::BroadcastBase::evaluate_broadcast(const HostTensorPtr& arg0,
const HostTensorPtr& out,
const std::pair<bool, AxisSet> pair_broadcast_axes,
const Shape output_shape) const {
bool ov::op::util::BroadcastBase::evaluate_broadcast(const HostTensorPtr& arg0,
const HostTensorPtr& out,
const std::pair<bool, AxisSet>& pair_broadcast_axes,
const ngraph::Shape& output_shape) const {
if (!pair_broadcast_axes.first) {
// broadcast_axes not known deterministically
return false;
}
Shape in_shape = arg0->get_shape();
ngraph::Shape in_shape = arg0->get_shape();
out->set_shape(output_shape);
out->set_element_type(arg0->get_element_type());
return evaluate_broadcast(arg0, out, pair_broadcast_axes.second);
}
Shape op::util::BroadcastBase::get_target_shape(const HostTensorPtr& input1) const {
Shape target_shape;
const auto shape_constant = ov::as_type_ptr<op::v0::Constant>(input_value(1).get_node_shared_ptr());
ngraph::Shape ov::op::util::BroadcastBase::get_target_shape(const HostTensorPtr& input1) const {
ngraph::Shape target_shape;
const auto shape_constant = ov::as_type_ptr<ngraph::op::v0::Constant>(input_value(1).get_node_shared_ptr());
if (shape_constant) {
target_shape = shape_constant->get_shape_val();
} else {
@@ -437,12 +436,12 @@ Shape op::util::BroadcastBase::get_target_shape(const HostTensorPtr& input1) con
return target_shape;
}
bool op::util::BroadcastBase::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
bool ov::op::util::BroadcastBase::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
NGRAPH_OP_SCOPE(util_BroadcastBase_evaluate);
NGRAPH_CHECK(validate_host_tensor_vector(inputs, 2) || validate_host_tensor_vector(inputs, 3));
NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1));
NGRAPH_CHECK(ngraph::validate_host_tensor_vector(inputs, 2) || ngraph::validate_host_tensor_vector(inputs, 3));
NGRAPH_CHECK(ngraph::validate_host_tensor_vector(outputs, 1));
Shape target_shape = get_target_shape(inputs[1]);
ngraph::Shape target_shape = get_target_shape(inputs[1]);
PartialShape result_shape;
std::pair<bool, AxisSet> pair_broadcast_axes;
@@ -450,7 +449,8 @@ bool op::util::BroadcastBase::evaluate(const HostTensorVector& outputs, const Ho
if (m_mode.m_type == BroadcastType::NONE) {
AxisVector axes_mapping_val;
const auto axes_mapping_constant = ov::as_type_ptr<op::v0::Constant>(input_value(2).get_node_shared_ptr());
const auto axes_mapping_constant =
ov::as_type_ptr<ngraph::op::v0::Constant>(input_value(2).get_node_shared_ptr());
if (axes_mapping_constant) {
axes_mapping_val = axes_mapping_constant->get_axis_vector_val();
} else {
@@ -468,22 +468,22 @@ bool op::util::BroadcastBase::evaluate(const HostTensorVector& outputs, const Ho
validate_target_shape_numpy(arg_shape, target_shape);
pair_broadcast_axes = get_broadcast_axes_numpy_pdpd(arg_shape, result_shape.to_shape(), m_mode);
} else {
ngraph_error("Unsupported BroadcastType ");
throw ov::Exception("Unsupported BroadcastType ");
}
return evaluate_broadcast(inputs[0], outputs[0], pair_broadcast_axes, result_shape.to_shape());
}
bool op::util::BroadcastBase::evaluate_lower(const HostTensorVector& output_values) const {
bool ov::op::util::BroadcastBase::evaluate_lower(const HostTensorVector& output_values) const {
if (!input_value(1).get_tensor().has_and_set_bound() ||
(get_input_size() > 2 && !input_value(2).get_tensor().has_and_set_bound()))
return false;
return default_lower_bound_evaluator(this, output_values);
return ngraph::default_lower_bound_evaluator(this, output_values);
}
bool op::util::BroadcastBase::evaluate_upper(const HostTensorVector& output_values) const {
bool ov::op::util::BroadcastBase::evaluate_upper(const HostTensorVector& output_values) const {
if (!input_value(1).get_tensor().has_and_set_bound() ||
(get_input_size() > 2 && !input_value(2).get_tensor().has_and_set_bound()))
return false;
return default_upper_bound_evaluator(this, output_values);
return ngraph::default_upper_bound_evaluator(this, output_values);
}
@@ -12,18 +12,17 @@
#include "ngraph/validation_util.hpp"
using namespace std;
using namespace ngraph;
NGRAPH_RTTI_DEFINITION(op::util::DeformableConvolutionBase, "DeformableConvolutionBase", 0);
NGRAPH_RTTI_DEFINITION(ov::op::util::DeformableConvolutionBase, "DeformableConvolutionBase", 0);
op::util::DeformableConvolutionBase::DeformableConvolutionBase(const OutputVector& arguments,
const Strides& strides,
const CoordinateDiff& pads_begin,
const CoordinateDiff& pads_end,
const Strides& dilations,
const PadType& auto_pad,
const int64_t group,
const int64_t deformable_group)
ov::op::util::DeformableConvolutionBase::DeformableConvolutionBase(const OutputVector& arguments,
const Strides& strides,
const CoordinateDiff& pads_begin,
const CoordinateDiff& pads_end,
const Strides& dilations,
const PadType& auto_pad,
const int64_t group,
const int64_t deformable_group)
: Op(arguments),
m_strides(strides),
m_dilations(dilations),
@@ -33,7 +32,7 @@ op::util::DeformableConvolutionBase::DeformableConvolutionBase(const OutputVecto
m_group(group),
m_deformable_group(deformable_group) {}
bool op::util::DeformableConvolutionBase::visit_attributes(AttributeVisitor& visitor) {
bool ov::op::util::DeformableConvolutionBase::visit_attributes(AttributeVisitor& visitor) {
NGRAPH_OP_SCOPE(util_DeformableConvolutionBase_visit_attributes);
visitor.on_attribute("strides", m_strides);
visitor.on_attribute("dilations", m_dilations);
@@ -45,7 +44,7 @@ bool op::util::DeformableConvolutionBase::visit_attributes(AttributeVisitor& vis
return true;
}
void op::util::DeformableConvolutionBase::validate_and_infer_types() {
void ov::op::util::DeformableConvolutionBase::validate_and_infer_types() {
NGRAPH_OP_SCOPE(util_DeformableConvolutionBase_validate_and_infer_types);
const PartialShape& data_batch_pshape = get_input_partial_shape(0);
const PartialShape& offsets_pshape = get_input_partial_shape(1);
@@ -159,15 +158,15 @@ void op::util::DeformableConvolutionBase::validate_and_infer_types() {
}
return new_shape;
}(m_group);
PartialShape result_shape = validate_and_infer_convolution_forward_output_shape(this,
result_ps_rank,
data_batch_pshape,
new_filters_pshape,
m_auto_pad,
m_strides,
m_dilations,
m_pads_begin,
m_pads_end);
PartialShape result_shape = ngraph::validate_and_infer_convolution_forward_output_shape(this,
result_ps_rank,
data_batch_pshape,
new_filters_pshape,
m_auto_pad,
m_strides,
m_dilations,
m_pads_begin,
m_pads_end);
if (result_shape.rank().is_static() && offsets_pshape.rank().is_static()) {
PartialShape result_spatial_shape = [&result_shape]() {
+1 -3
View File
@@ -6,9 +6,7 @@
#include "ngraph/op/util/binary_elementwise_arithmetic.hpp"
using namespace ngraph;
std::tuple<element::Type, PartialShape> ngraph::op::util::validate_and_infer_elementwise_args(
std::tuple<ov::element::Type, ov::PartialShape> ov::op::util::validate_and_infer_elementwise_args(
Node* node,
const op::AutoBroadcastSpec& autob) {
NGRAPH_CHECK(node != nullptr, "nGraph node is empty! Cannot validate eltwise arguments.");
@@ -8,35 +8,34 @@
#include "ngraph/op/constant.hpp"
using namespace std;
using namespace ngraph;
constexpr NodeTypeInfo op::util::EmbeddingBagOffsetsBase::type_info;
constexpr ov::NodeTypeInfo ov::op::util::EmbeddingBagOffsetsBase::type_info;
op::util::EmbeddingBagOffsetsBase::EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index,
const Output<Node>& per_sample_weights)
ov::op::util::EmbeddingBagOffsetsBase::EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index,
const Output<Node>& per_sample_weights)
: Op({emb_table, indices, offsets, default_index, per_sample_weights}) {
constructor_validate_and_infer_types();
}
op::util::EmbeddingBagOffsetsBase::EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index)
ov::op::util::EmbeddingBagOffsetsBase::EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets,
const Output<Node>& default_index)
: Op({emb_table, indices, offsets, default_index}) {
constructor_validate_and_infer_types();
}
op::util::EmbeddingBagOffsetsBase::EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets)
ov::op::util::EmbeddingBagOffsetsBase::EmbeddingBagOffsetsBase(const Output<Node>& emb_table,
const Output<Node>& indices,
const Output<Node>& offsets)
: Op({emb_table, indices, offsets}) {
constructor_validate_and_infer_types();
}
void op::util::EmbeddingBagOffsetsBase::validate_and_infer_types() {
void ov::op::util::EmbeddingBagOffsetsBase::validate_and_infer_types() {
NGRAPH_OP_SCOPE(util_EmbeddingBagOffsetsBase_validate_and_infer_types);
NODE_VALIDATION_CHECK(
this,
@@ -120,7 +119,7 @@ void op::util::EmbeddingBagOffsetsBase::validate_and_infer_types() {
set_output_type(0, result_et, result_shape);
}
bool op::util::EmbeddingBagOffsetsBase::visit_attributes(AttributeVisitor& visitor) {
bool ov::op::util::EmbeddingBagOffsetsBase::visit_attributes(AttributeVisitor& visitor) {
NGRAPH_OP_SCOPE(util_EmbeddingBagOffsetsBase_visit_attributes);
return true;
}
Loaded 100 of 121 files, more files were not shown because too many files have changed in this diff. Show more