diff --git a/src/core/include/openvino/op/roi_align_rotated.hpp b/src/core/include/openvino/op/roi_align_rotated.hpp index 500988e8745971..5daaa9d4464212 100644 --- a/src/core/include/openvino/op/roi_align_rotated.hpp +++ b/src/core/include/openvino/op/roi_align_rotated.hpp @@ -38,6 +38,8 @@ class OPENVINO_API ROIAlignRotated : public util::ROIAlignBase { const float spatial_scale, const bool clockwise_mode); + bool evaluate(TensorVector& outputs, const TensorVector& inputs) const override; + bool has_evaluate() const override; void validate_and_infer_types() override; bool visit_attributes(AttributeVisitor& visitor) override; std::shared_ptr clone_with_new_inputs(const OutputVector& new_args) const override; diff --git a/src/core/src/op/roi_align_rotated.cpp b/src/core/src/op/roi_align_rotated.cpp index 4eec291bc468d7..9c5bd3b8bb7e1d 100644 --- a/src/core/src/op/roi_align_rotated.cpp +++ b/src/core/src/op/roi_align_rotated.cpp @@ -4,11 +4,52 @@ #include "openvino/op/roi_align_rotated.hpp" +#include "element_visitor.hpp" #include "itt.hpp" +#include "openvino/reference/roi_align.hpp" +#include "utils.hpp" namespace ov { namespace op { namespace v14 { + +namespace helpers { +struct Evaluate : element::NoAction { + using element::NoAction::visit; + + template + static result_type visit(const Tensor& input, + const Tensor& rois, + const Tensor& batch_indices, + Tensor& out, + int pooled_h, + int pooled_w, + int sampling_ratio, + float spatial_scale, + bool clockwise_mode) { + using T = fundamental_type_for; + const auto batch_indices_vec_scaled_up = ov::get_tensor_data_as(batch_indices); + ov::reference::roi_align( + input.data(), + rois.data(), + batch_indices_vec_scaled_up.data(), + out.data(), + input.get_shape(), + rois.get_shape(), + batch_indices.get_shape(), + out.get_shape(), + pooled_h, + pooled_w, + sampling_ratio, + spatial_scale, + ov::op::v3::ROIAlign::PoolingMode::AVG, + ov::op::v9::ROIAlign::AlignedMode::ASYMMETRIC, + clockwise_mode); + return true; + } +}; +} // namespace helpers + ROIAlignRotated::ROIAlignRotated(const Output& input, const Output& rois, const Output& batch_indices, @@ -49,6 +90,43 @@ std::shared_ptr ROIAlignRotated::clone_with_new_inputs(const OutputVector& get_spatial_scale(), get_clockwise_mode()); } + +bool ROIAlignRotated::evaluate(TensorVector& outputs, const TensorVector& inputs) const { + OPENVINO_ASSERT(outputs.size() == 1); + OPENVINO_ASSERT(inputs.size() == 3); + + using namespace ov::element; + return IF_TYPE_OF_CONVERT_TENSORS(v14_ROIAlignRotated_evaluate, + this, + outputs, + inputs, + OV_PP_ET_LIST(bf16, f16, f32, f64), + helpers::Evaluate, + inputs[0].get_element_type(), + inputs[0], + inputs[1], + inputs[2], + outputs[0], + get_pooled_h(), + get_pooled_w(), + get_sampling_ratio(), + get_spatial_scale(), + get_clockwise_mode()); + return true; +} + +bool ROIAlignRotated::has_evaluate() const { + OV_OP_SCOPE(v14_ROIAlignRotated_has_evaluate); + switch (get_input_element_type(0)) { + case element::bf16: + case element::f16: + case element::f32: + case element::f64: + return true; + default: + return false; + } +} } // namespace v14 } // namespace op } // namespace ov diff --git a/src/plugins/intel_cpu/CMakeLists.txt b/src/plugins/intel_cpu/CMakeLists.txt index a023f399ace217..e374b804d64a02 100644 --- a/src/plugins/intel_cpu/CMakeLists.txt +++ b/src/plugins/intel_cpu/CMakeLists.txt @@ -187,10 +187,6 @@ if (ENABLE_SNIPPETS_LIBXSMM_TPP) endif () target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $) -# Temporal solution to use template reference implementations in cases where optimizied implementation -# is not (yet) needed. -target_include_directories(${TARGET_NAME} PRIVATE $) - # Cross compiled function # TODO: The same for proposal, proposalONNX, topk cross_compiled_file(${TARGET_NAME} @@ -254,7 +250,6 @@ if(BUILD_SHARED_LIBS) $ $ $ - $ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src $) diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cpp index 3b9125f1a5e838..73ad7b36b4a459 100644 --- a/src/plugins/intel_cpu/src/cpu_types.cpp +++ b/src/plugins/intel_cpu/src/cpu_types.cpp @@ -116,7 +116,6 @@ static const TypeToNameMap& get_type_to_name_tbl() { {"Slice", Type::StridedSlice}, {"Tile", Type::Tile}, {"ROIAlign", Type::ROIAlign}, - {"ROIAlignRotated", Type::ROIAlignRotated}, {"ROIPooling", Type::ROIPooling}, {"PSROIPooling", Type::PSROIPooling}, {"DeformablePSROIPooling", Type::PSROIPooling}, @@ -281,7 +280,6 @@ std::string NameFromType(const Type type) { CASE(NonZero); CASE(Tile); CASE(ROIAlign); - CASE(ROIAlignRotated); CASE(ROIPooling); CASE(PSROIPooling); CASE(DepthToSpace); diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.h index 416ff8b7d027d1..45c3617f9b8e2d 100644 --- a/src/plugins/intel_cpu/src/cpu_types.h +++ b/src/plugins/intel_cpu/src/cpu_types.h @@ -41,7 +41,6 @@ enum class Type { NonZero, Tile, ROIAlign, - ROIAlignRotated, ROIPooling, PSROIPooling, BatchToSpace, diff --git a/src/plugins/intel_cpu/src/nodes/roi_align_rotated.cpp b/src/plugins/intel_cpu/src/nodes/roi_align_rotated.cpp deleted file mode 100644 index 2ce6f78e234389..00000000000000 --- a/src/plugins/intel_cpu/src/nodes/roi_align_rotated.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2018-2024 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "roi_align_rotated.h" - -#include - -#include "common/cpu_convert.h" -#include "openvino/reference/roi_align.hpp" - -namespace ov { -namespace intel_cpu { -namespace node { - -ROIAlignRotated::ROIAlignRotated(const std::shared_ptr& op, const GraphContext::CPtr context) - : Node(op, context, NgraphShapeInferFactory(op, EMPTY_PORT_MASK)) { - const auto roiAlign = ov::as_type_ptr(op); - pooledH = roiAlign->get_pooled_h(); - pooledW = roiAlign->get_pooled_w(); - spatialScale = roiAlign->get_spatial_scale(); - samplingRatio = roiAlign->get_sampling_ratio(); - clockwiseMode = roiAlign->get_clockwise_mode(); -} - -void ROIAlignRotated::getSupportedDescriptors() { - // Validation is already done in the ov::opset14::ROIAlignRotated. -} - -void ROIAlignRotated::initSupportedPrimitiveDescriptors() { - if (!supportedPrimitiveDescriptors.empty()) - return; - - ov::element::Type inputPrec0 = getOriginalInputPrecisionAtPort(0); - ov::element::Type outputPrec = getOriginalOutputPrecisionAtPort(0); - - addSupportedPrimDesc( - {{LayoutType::ncsp, inputPrec0}, {LayoutType::ncsp, ov::element::f32}, {LayoutType::ncsp, ov::element::i32}}, - {{LayoutType::ncsp, outputPrec}}, - impl_desc_type::ref); -} - -bool ROIAlignRotated::created() const { - return getType() == Type::ROIAlignRotated; -} - -bool ROIAlignRotated::needPrepareParams() const { - return false; -} - -void ROIAlignRotated::executeDynamicImpl(dnnl::stream strm) { - execute(strm); -} - -template -void ROIAlignRotated::executeImpl() { - using T = typename ov::element_type_traits::value_type; - - const size_t batch_indices_size = getSrcMemoryAtPort(2)->getShape().getElementsCount(); - - std::vector batch_indices_vec_scaled_up(batch_indices_size); - cpu_convert(getSrcMemoryAtPort(2)->getData(), - batch_indices_vec_scaled_up.data(), - getSrcMemoryAtPort(2)->getPrecision(), - ov::element::i64, - batch_indices_size); - - ov::reference::roi_align( - getSrcDataAtPortAs(0), - getSrcDataAtPortAs(1), - batch_indices_vec_scaled_up.data(), - getDstDataAtPortAs(0), - ov::Shape{getSrcMemoryAtPort(0)->getStaticDims()}, - ov::Shape{getSrcMemoryAtPort(1)->getStaticDims()}, - ov::Shape{getSrcMemoryAtPort(2)->getStaticDims()}, - ov::Shape{getDstMemoryAtPort(0)->getStaticDims()}, - pooledH, - pooledW, - samplingRatio, - spatialScale, - ov::op::v3::ROIAlign::PoolingMode::AVG, - ov::op::v9::ROIAlign::AlignedMode::ASYMMETRIC, - clockwiseMode); -} - -void ROIAlignRotated::execute(dnnl::stream) { - const ov::element::Type type = getOriginalInputPrecisionAtPort(0); - executeImpl(); - -#define CASE(OV_TYPE) \ - case ov::element::OV_TYPE: \ - executeImpl(); \ - break; - - switch (type) { - CASE(bf16); - CASE(f16); - CASE(f32); - CASE(f64); - default: - OPENVINO_THROW("[ROIAlignRotated]: Unhandled data type ", type, " in execute()"); - } -#undef CASE -} - -} // namespace node -} // namespace intel_cpu -} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes/roi_align_rotated.h b/src/plugins/intel_cpu/src/nodes/roi_align_rotated.h deleted file mode 100644 index ef29fe989b9964..00000000000000 --- a/src/plugins/intel_cpu/src/nodes/roi_align_rotated.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2018-2024 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "node.h" - -namespace ov { -namespace intel_cpu { -namespace node { - -class ROIAlignRotated : public Node { -public: - ROIAlignRotated(const std::shared_ptr& op, const GraphContext::CPtr context); - - void getSupportedDescriptors() override; - void initSupportedPrimitiveDescriptors() override; - void execute(dnnl::stream strm) override; - bool created() const override; - bool needPrepareParams() const override; - void executeDynamicImpl(dnnl::stream strm) override; - -private: - template - void executeImpl(); - - int pooledH; - int pooledW; - int samplingRatio; - float spatialScale; - bool clockwiseMode; -}; - -} // namespace node -} // namespace intel_cpu -} // namespace ov diff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cpp index 9cc09a17c9e259..2146601b1c4cdd 100644 --- a/src/plugins/intel_cpu/src/nodes_factory.cpp +++ b/src/plugins/intel_cpu/src/nodes_factory.cpp @@ -78,7 +78,6 @@ #include "nodes/reverse_sequence.h" #include "nodes/rnn.h" #include "nodes/roi_align.h" -#include "nodes/roi_align_rotated.h" #include "nodes/roi_pooling.h" #include "nodes/roll.h" #include "nodes/rope.h" @@ -194,7 +193,6 @@ Node::NodesFactory::NodesFactory() : Factory("NodesFactory") { INTEL_CPU_NODE(NonMaxSuppression, Type::NonMaxSuppression); INTEL_CPU_NODE(ROIPooling, Type::ROIPooling); INTEL_CPU_NODE(ROIAlign, Type::ROIAlign); - INTEL_CPU_NODE(ROIAlignRotated, Type::ROIAlignRotated); INTEL_CPU_NODE(TopK, Type::TopK); INTEL_CPU_NODE(Proposal, Type::Proposal); INTEL_CPU_NODE(RegionYolo, Type::RegionYolo);