diff --git a/src/core/include/openvino/op/matmul.hpp b/src/core/include/openvino/op/matmul.hpp index 96aab8a1c46..302b3b9b167 100644 --- a/src/core/include/openvino/op/matmul.hpp +++ b/src/core/include/openvino/op/matmul.hpp @@ -31,9 +31,7 @@ public: std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; - OPENVINO_SUPPRESS_DEPRECATED_START - bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override; - OPENVINO_SUPPRESS_DEPRECATED_END + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; bool has_evaluate() const override; bool get_transpose_a() const { diff --git a/src/core/src/op/matmul.cpp b/src/core/src/op/matmul.cpp index d43b787e032..06fd0a9f33e 100644 --- a/src/core/src/op/matmul.cpp +++ b/src/core/src/op/matmul.cpp @@ -2,110 +2,99 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "ngraph/op/matmul.hpp" - -#include +#include "openvino/op/matmul.hpp" +#include "element_visitor.hpp" #include "itt.hpp" #include "matmul_shape_inference.hpp" -#include "ngraph/attribute_visitor.hpp" #include "openvino/reference/matmul.hpp" -using namespace std; -using namespace ngraph; +namespace ov { +namespace op { +namespace matmul { -op::MatMul::MatMul(const Output& A, const Output& B, const bool& transpose_a, const bool& transpose_b) +struct Evaluate : element::NoAction { + using element::NoAction::visit; + + template > + static result_type visit(const Tensor& arg0, + const Tensor& arg1, + Tensor& out, + const Shape& shape0, + const Shape& shape1, + const Shape& out_shape, + const bool transpose_a, + const bool transpose_b) { + reference::matmul(arg0.data(), + arg1.data(), + out.data(), + shape0, + shape1, + out_shape, + transpose_a, + transpose_b); + return true; + } +}; +} // namespace matmul + +namespace v0 { + +MatMul::MatMul(const Output& A, const Output& B, const bool& transpose_a, const bool& transpose_b) : Op(OutputVector{A, B}), m_transpose_a{transpose_a}, m_transpose_b{transpose_b} { constructor_validate_and_infer_types(); } -bool ngraph::op::v0::MatMul::visit_attributes(AttributeVisitor& visitor) { +bool MatMul::visit_attributes(AttributeVisitor& visitor) { OV_OP_SCOPE(v0_MatMul_visit_attributes); visitor.on_attribute("transpose_a", m_transpose_a); visitor.on_attribute("transpose_b", m_transpose_b); return true; } -shared_ptr op::MatMul::clone_with_new_inputs(const OutputVector& new_args) const { +std::shared_ptr MatMul::clone_with_new_inputs(const OutputVector& new_args) const { OV_OP_SCOPE(v0_MatMul_clone_with_new_inputs); check_new_args_count(this, new_args); - return make_shared(new_args.at(0), new_args.at(1), m_transpose_a, m_transpose_b); + return std::make_shared(new_args.at(0), new_args.at(1), m_transpose_a, m_transpose_b); } -OPENVINO_SUPPRESS_DEPRECATED_START -namespace matmul { -namespace { -template -bool evaluate(const op::MatMul* op, const HostTensorPtr& arg0, const HostTensorPtr& arg1, const HostTensorPtr& output) { - using T = typename element_type_traits::value_type; - - ov::Shape arg0_shape = arg0->get_shape(); - ov::Shape arg1_shape = arg1->get_shape(); - - std::vector input_shapes = {arg0_shape, arg1_shape}; - std::vector output_shapes = shape_infer(op, input_shapes); - - ov::Shape output_shape = output_shapes[0].to_shape(); - output->set_element_type(arg0->get_element_type()); - output->set_shape(output_shape); - - ov::reference::matmul(arg0->get_data_ptr(), - arg1->get_data_ptr(), - output->get_data_ptr(), - arg0_shape, - arg1_shape, - output_shape, - op->get_transpose_a(), - op->get_transpose_b()); - return true; -} - -bool evaluate_matmul(const op::MatMul* op, - const HostTensorPtr& arg0, - const HostTensorPtr& arg1, - const HostTensorPtr& output) { - bool rc = true; - - switch (arg0->get_element_type()) { - OPENVINO_TYPE_CASE(evaluate_matmul, i32, op, arg0, arg1, output); - OPENVINO_TYPE_CASE(evaluate_matmul, i64, op, arg0, arg1, output); - OPENVINO_TYPE_CASE(evaluate_matmul, u32, op, arg0, arg1, output); - OPENVINO_TYPE_CASE(evaluate_matmul, u64, op, arg0, arg1, output); - OPENVINO_TYPE_CASE(evaluate_matmul, f16, op, arg0, arg1, output); - OPENVINO_TYPE_CASE(evaluate_matmul, f32, op, arg0, arg1, output); - default: - rc = false; - break; - } - return rc; -} -} // namespace -} // namespace matmul - -bool op::MatMul::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { +bool MatMul::evaluate(TensorVector& outputs, const TensorVector& inputs) const { OV_OP_SCOPE(v0_MatMul_evaluate); - return matmul::evaluate_matmul(this, inputs[0], inputs[1], outputs[0]); + OPENVINO_ASSERT(outputs.size() == 1); + + const auto out_shape = shape_infer(this, ov::util::get_tensors_partial_shapes(inputs)).front().to_shape(); + outputs[0].set_shape(out_shape); + + using namespace ov::element; + return IfTypeOf::apply(inputs[0].get_element_type(), + inputs[0], + inputs[1], + outputs[0], + inputs[0].get_shape(), + inputs[1].get_shape(), + out_shape, + m_transpose_a, + m_transpose_b); } -bool op::MatMul::has_evaluate() const { +bool MatMul::has_evaluate() const { OV_OP_SCOPE(v0_MatMul_has_evaluate); switch (get_input_element_type(0)) { - case ngraph::element::i32: - case ngraph::element::i64: - case ngraph::element::u32: - case ngraph::element::u64: - case ngraph::element::f16: - case ngraph::element::f32: + case element::f16: + case element::f32: + case element::i32: + case element::i64: + case element::u32: + case element::u64: return true; default: - break; + return false; } - return false; } -void ngraph::op::v0::MatMul::validate_and_infer_types() { +void MatMul::validate_and_infer_types() { OV_OP_SCOPE(v0_MatMul_validate_and_infer_types); element::Type result_et; @@ -117,8 +106,11 @@ void ngraph::op::v0::MatMul::validate_and_infer_types() { get_input_element_type(1), ")."); - const auto &A_shape = get_input_partial_shape(0), B_shape = get_input_partial_shape(1); - std::vector input_shapes = {A_shape, B_shape}; - std::vector output_shapes = shape_infer(this, input_shapes); + const auto& A_shape = get_input_partial_shape(0); + const auto& B_shape = get_input_partial_shape(1); + const auto output_shapes = shape_infer(this, std::vector{A_shape, B_shape}); set_output_type(0, result_et, output_shapes[0]); } +} // namespace v0 +} // namespace op +} // namespace ov