Skip to content

Commit

Permalink
[cpu_plugin]: Added support for ROIAlignRotated by adding evaluate me…
Browse files Browse the repository at this point in the history
…thod.
  • Loading branch information
pkowalc1 committed May 13, 2024
1 parent 848af5a commit a7de6e2
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 155 deletions.
2 changes: 2 additions & 0 deletions src/core/include/openvino/op/roi_align_rotated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> clone_with_new_inputs(const OutputVector& new_args) const override;
Expand Down
78 changes: 78 additions & 0 deletions src/core/src/op/roi_align_rotated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
using element::NoAction<bool>::visit;

template <element::Type_t ET>
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<ET>;
const auto batch_indices_vec_scaled_up = ov::get_tensor_data_as<int64_t>(batch_indices);
ov::reference::roi_align<T, ov::reference::roi_policy::ROIAlignRotatedOpDefPolicy>(
input.data<const T>(),
rois.data<const T>(),
batch_indices_vec_scaled_up.data(),
out.data<T>(),
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<Node>& input,
const Output<Node>& rois,
const Output<Node>& batch_indices,
Expand Down Expand Up @@ -49,6 +90,43 @@ std::shared_ptr<Node> 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
5 changes: 0 additions & 5 deletions src/plugins/intel_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ if (ENABLE_SNIPPETS_LIBXSMM_TPP)
endif ()
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)

# Temporal solution to use template reference implementations in cases where optimizied implementation
# is not (yet) needed.
target_include_directories(${TARGET_NAME} PRIVATE $<TARGET_PROPERTY:openvino::reference,INTERFACE_INCLUDE_DIRECTORIES>)

# Cross compiled function
# TODO: The same for proposal, proposalONNX, topk
cross_compiled_file(${TARGET_NAME}
Expand Down Expand Up @@ -254,7 +250,6 @@ if(BUILD_SHARED_LIBS)
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::snippets,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::reference,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
$<TARGET_PROPERTY:openvino::conditional_compilation,INTERFACE_INCLUDE_DIRECTORIES>)
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/cpu_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -281,7 +280,6 @@ std::string NameFromType(const Type type) {
CASE(NonZero);
CASE(Tile);
CASE(ROIAlign);
CASE(ROIAlignRotated);
CASE(ROIPooling);
CASE(PSROIPooling);
CASE(DepthToSpace);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_cpu/src/cpu_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum class Type {
NonZero,
Tile,
ROIAlign,
ROIAlignRotated,
ROIPooling,
PSROIPooling,
BatchToSpace,
Expand Down
108 changes: 0 additions & 108 deletions src/plugins/intel_cpu/src/nodes/roi_align_rotated.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions src/plugins/intel_cpu/src/nodes/roi_align_rotated.h

This file was deleted.

2 changes: 0 additions & 2 deletions src/plugins/intel_cpu/src/nodes_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a7de6e2

Please sign in to comment.