Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Snippets] Introduce base class for horizon operations (#37102)

Arseniy Obolenskiydcecd70a6c2e
diff --git a/src/common/snippets/include/snippets/op/horizon.hpp b/src/common/snippets/include/snippets/op/horizon.hpp
new file mode 100644
index 00000000000..8519a578c85
--- /dev/null
+++ b/src/common/snippets/include/snippets/op/horizon.hpp
@@ -0,0 +1,30 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/core/node.hpp"
+#include "openvino/core/node_output.hpp"
+#include "openvino/core/node_vector.hpp"
+#include "openvino/op/op.hpp"
+
+namespace ov::snippets::op {
+
+/**
+ * @interface HorizonBase
+ * @brief Base class for horizon operations.
+ * @ingroup snippets
+ */
+class HorizonBase : public ov::op::Op {
+public:
+ OPENVINO_OP("HorizonBase", "SnippetsOpset");
+
+ explicit HorizonBase(const Output<Node>& x);
+ explicit HorizonBase(const OutputVector& x);
+ HorizonBase() = default;
+
+ void validate_and_infer_types() override;
+};
+
+} // namespace ov::snippets::op
diff --git a/src/common/snippets/include/snippets/op/horizon_max.hpp b/src/common/snippets/include/snippets/op/horizon_max.hpp
index 93dcdc0fb27..e581b64231c 100644
--- a/src/common/snippets/include/snippets/op/horizon_max.hpp
+++ b/src/common/snippets/include/snippets/op/horizon_max.hpp
@@ -6,11 +6,9 @@
#include <memory>
-#include "openvino/core/attribute_visitor.hpp"
#include "openvino/core/node.hpp"
-#include "openvino/core/node_output.hpp"
#include "openvino/core/node_vector.hpp"
-#include "openvino/op/op.hpp"
+#include "snippets/op/horizon.hpp"
namespace ov::snippets::op {
@@ -19,16 +17,14 @@ namespace ov::snippets::op {
* @brief The operation calculates a horizon maximum of a vector register
* @ingroup snippets
*/
-class HorizonMax : public ov::op::Op {
+class HorizonMax : public HorizonBase {
public:
- OPENVINO_OP("HorizonMax", "SnippetsOpset");
+ OPENVINO_OP("HorizonMax", "SnippetsOpset", HorizonBase);
- explicit HorizonMax(const Output<Node>& x);
- explicit HorizonMax(const OutputVector& x);
+ using HorizonBase::HorizonBase;
HorizonMax() = default;
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
- void validate_and_infer_types() override;
};
} // namespace ov::snippets::op
diff --git a/src/common/snippets/include/snippets/op/horizon_sum.hpp b/src/common/snippets/include/snippets/op/horizon_sum.hpp
index 2c5475f6667..d1bf3c7e4b1 100644
--- a/src/common/snippets/include/snippets/op/horizon_sum.hpp
+++ b/src/common/snippets/include/snippets/op/horizon_sum.hpp
@@ -6,11 +6,9 @@
#include <memory>
-#include "openvino/core/attribute_visitor.hpp"
#include "openvino/core/node.hpp"
-#include "openvino/core/node_output.hpp"
#include "openvino/core/node_vector.hpp"
-#include "openvino/op/op.hpp"
+#include "snippets/op/horizon.hpp"
namespace ov::snippets::op {
@@ -19,16 +17,14 @@ namespace ov::snippets::op {
* @brief The operation calculates a horizon sum of a vector register
* @ingroup snippets
*/
-class HorizonSum : public ov::op::Op {
+class HorizonSum : public HorizonBase {
public:
- OPENVINO_OP("HorizonSum", "SnippetsOpset");
+ OPENVINO_OP("HorizonSum", "SnippetsOpset", HorizonBase);
- explicit HorizonSum(const Output<Node>& x);
- explicit HorizonSum(const OutputVector& x);
+ using HorizonBase::HorizonBase;
HorizonSum() = default;
std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
- void validate_and_infer_types() override;
};
} // namespace ov::snippets::op
diff --git a/src/common/snippets/src/op/horizon.cpp b/src/common/snippets/src/op/horizon.cpp
new file mode 100644
index 00000000000..cd0a9fd63a9
--- /dev/null
+++ b/src/common/snippets/src/op/horizon.cpp
@@ -0,0 +1,32 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "snippets/op/horizon.hpp"
+
+#include "openvino/core/node.hpp"
+#include "openvino/core/node_output.hpp"
+#include "openvino/core/shape.hpp"
+#include "openvino/op/op.hpp"
+#include "snippets/itt.hpp"
+
+namespace ov::snippets::op {
+
+HorizonBase::HorizonBase(const Output<Node>& x) : Op({x}) {
+ constructor_validate_and_infer_types();
+}
+
+HorizonBase::HorizonBase(const OutputVector& x) : Op(x) {
+ constructor_validate_and_infer_types();
+}
+
+void HorizonBase::validate_and_infer_types() {
+ INTERNAL_OP_SCOPE(HorizonBase_validate_and_infer_types);
+ auto new_shape = get_input_partial_shape(0);
+ if (!ov::is_scalar(new_shape)) {
+ new_shape[new_shape.size() - 1] = 1LU;
+ }
+ set_output_type(0, get_input_element_type(0), new_shape);
+}
+
+} // namespace ov::snippets::op
diff --git a/src/common/snippets/src/op/horizon_max.cpp b/src/common/snippets/src/op/horizon_max.cpp
index 59ec72e59b4..a549efff227 100644
--- a/src/common/snippets/src/op/horizon_max.cpp
+++ b/src/common/snippets/src/op/horizon_max.cpp
@@ -7,33 +7,14 @@
#include <memory>
#include "openvino/core/node.hpp"
-#include "openvino/core/node_output.hpp"
-#include "openvino/core/shape.hpp"
-#include "openvino/op/op.hpp"
+#include "openvino/core/node_vector.hpp"
#include "snippets/itt.hpp"
namespace ov::snippets::op {
-HorizonMax::HorizonMax(const Output<Node>& x) : Op({x}) {
- constructor_validate_and_infer_types();
-}
-
-HorizonMax::HorizonMax(const OutputVector& x) : Op(x) {
- constructor_validate_and_infer_types();
-}
-
std::shared_ptr<Node> HorizonMax::clone_with_new_inputs(const OutputVector& new_args) const {
INTERNAL_OP_SCOPE(HorizonMax_clone_with_new_inputs);
return std::make_shared<HorizonMax>(new_args);
}
-void HorizonMax::validate_and_infer_types() {
- INTERNAL_OP_SCOPE(HorizonMax_validate_and_infer_types);
- auto new_shape = get_input_partial_shape(0);
- if (!ov::is_scalar(new_shape)) {
- new_shape[new_shape.size() - 1] = 1LU;
- }
- set_output_type(0, get_input_element_type(0), new_shape);
-}
-
} // namespace ov::snippets::op
diff --git a/src/common/snippets/src/op/horizon_sum.cpp b/src/common/snippets/src/op/horizon_sum.cpp
index 83cdd86d593..95d19a666b4 100644
--- a/src/common/snippets/src/op/horizon_sum.cpp
+++ b/src/common/snippets/src/op/horizon_sum.cpp
@@ -7,33 +7,14 @@
#include <memory>
#include "openvino/core/node.hpp"
-#include "openvino/core/node_output.hpp"
-#include "openvino/core/shape.hpp"
-#include "openvino/op/op.hpp"
+#include "openvino/core/node_vector.hpp"
#include "snippets/itt.hpp"
namespace ov::snippets::op {
-HorizonSum::HorizonSum(const Output<Node>& x) : Op({x}) {
- constructor_validate_and_infer_types();
-}
-
-HorizonSum::HorizonSum(const OutputVector& x) : Op(x) {
- constructor_validate_and_infer_types();
-}
-
std::shared_ptr<Node> HorizonSum::clone_with_new_inputs(const OutputVector& new_args) const {
INTERNAL_OP_SCOPE(HorizonSum_clone_with_new_inputs);
return std::make_shared<HorizonSum>(new_args);
}
-void HorizonSum::validate_and_infer_types() {
- INTERNAL_OP_SCOPE(HorizonSum_validate_and_infer_types);
- auto new_shape = get_input_partial_shape(0);
- if (!ov::is_scalar(new_shape)) {
- new_shape[new_shape.size() - 1] = 1LU;
- }
- set_output_type(0, get_input_element_type(0), new_shape);
-}
-
} // namespace ov::snippets::op