Review slice for shape inference aspects (#14611)
* Review slice ope for - Interval dimension and label propagation - add template shape inference with static shape test - check preserve partial values on inputs - check upper/lower evaluate * Add bounds evaluation for inputs start, stop * Share code between slice and strided slice Use same function to calculate elements in step * Add array includes * Add to int64_t strides size * Fix windows compile warnings * Fix shape inference for unknown axes * Remove empty lines in slice shape inference * Correct slice static shape tests * Use arrays of const chars to store literals Remove and update exception messages for strided slice * Fix slice test and apply review comments * Fix compilation issues * Fix ellipsis when there is not begin * Fix get element type for const inputs * Insert optional axes as const or dynamic param * Remove temp vectors for dimensions calculation * Revert set optional input in ctor * Fix forward slicing for negative start and MAX end
This commit is contained in:
1 parent
3094384d74
commit
a1203b931a
13 files changed
+1004
-682
No files matched your search
@@ -11,9 +11,6 @@
|
||||
#include <openvino/opsets/opset7.hpp>
|
||||
#include <openvino/opsets/opset8.hpp>
|
||||
|
||||
#include "ov_ops/augru_cell.hpp"
|
||||
#include "ov_ops/augru_sequence.hpp"
|
||||
|
||||
#include "assign_shape_inference.hpp"
|
||||
#include "augru_cell_shape_inference.hpp"
|
||||
#include "augru_sequence_shape_inference.hpp"
|
||||
@@ -43,8 +40,8 @@
|
||||
#include "gather_shape_inference.hpp"
|
||||
#include "gather_tree_shape_inference.hpp"
|
||||
#include "grid_sample_shape_inference.hpp"
|
||||
#include "gru_sequence_shape_inference.hpp"
|
||||
#include "gru_cell_shape_inference.hpp"
|
||||
#include "gru_sequence_shape_inference.hpp"
|
||||
#include "interpolate_shape_inference.hpp"
|
||||
#include "lstm_cell_shape_inference.hpp"
|
||||
#include "matmul_shape_inference.hpp"
|
||||
@@ -65,6 +62,7 @@
|
||||
#include "shape_inference.hpp"
|
||||
#include "shape_nodes.hpp"
|
||||
#include "shuffle_channels_shape_inference.hpp"
|
||||
#include "slice_shape_inference.hpp"
|
||||
#include "space_to_batch_shape_inference.hpp"
|
||||
#include "space_to_depth_shape_inference.hpp"
|
||||
#include "split_shape_inference.hpp"
|
||||
@@ -467,6 +465,8 @@ std::shared_ptr<IShapeInferCommon> make_shape_inference(const std::shared_ptr<ng
|
||||
return make_shared_entryIOC(node);
|
||||
} else if (auto node = ov::as_type_ptr<ov::opset7::Einsum>(op)) {
|
||||
return make_shared_entryIO(node);
|
||||
} else if (auto node = ov::as_type_ptr<ov::opset8::Slice>(op)) {
|
||||
return make_shared_entryIOC(node);
|
||||
} else if (auto node = ov::as_type_ptr<ov::opset1::StridedSlice>(op)) {
|
||||
return make_shared_entryIOC(node);
|
||||
} else if (auto node = ov::as_type_ptr<ov::opset3::Assign>(op)) {
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright (C) 2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "openvino/op/parameter.hpp"
|
||||
#include "openvino/op/slice.hpp"
|
||||
#include "slice_shape_inference.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace ov;
|
||||
using namespace ov::intel_cpu;
|
||||
using namespace testing;
|
||||
|
||||
class SliceStaticShapeInferenceTest : public OpStaticShapeInferenceTest<op::v8::Slice> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
output_shapes.resize(num_of_outputs);
|
||||
}
|
||||
|
||||
size_t num_of_outputs = 1;
|
||||
StaticDimension::value_type max_d = std::numeric_limits<StaticDimension::value_type>::max();
|
||||
};
|
||||
|
||||
TEST_F(SliceStaticShapeInferenceTest, reverse_steps_start_stop_outside_dimension_default_axes) {
|
||||
const auto data = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic());
|
||||
const auto start = op::v0::Constant::create(element::i64, Shape{5}, std::vector<int64_t>{100, 5, -1, INT64_MAX, 5});
|
||||
const auto stop =
|
||||
op::v0::Constant::create(element::i64, Shape{5}, std::vector<int64_t>{-100, INT64_MIN, -6, 5, -10});
|
||||
const auto steps = op::v0::Constant::create(element::i64, Shape{5}, {-1, -2, -1, -1, -2});
|
||||
|
||||
const auto op = make_op(data, start, stop, steps);
|
||||
|
||||
input_shapes.push_back({3, 4, 5, max_d, max_d});
|
||||
input_shapes.resize(4, start->get_shape());
|
||||
|
||||
shape_inference(op.get(), input_shapes, output_shapes);
|
||||
|
||||
EXPECT_EQ(output_shapes.size(), num_of_outputs);
|
||||
EXPECT_EQ(output_shapes.front(), StaticShape({3, 2, 5, max_d, 3}));
|
||||
}
|
||||
|
||||
TEST_F(SliceStaticShapeInferenceTest, reverse_step_on_signle_axis_but_start_stop_steps_in_const_map) {
|
||||
constexpr auto et = element::i64;
|
||||
|
||||
const auto data = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic());
|
||||
const auto start = std::make_shared<op::v0::Parameter>(et, PartialShape::dynamic());
|
||||
const auto stop = std::make_shared<op::v0::Parameter>(et, PartialShape::dynamic());
|
||||
const auto steps = std::make_shared<op::v0::Parameter>(et, PartialShape::dynamic());
|
||||
const auto axes = op::v0::Constant::create(element::i64, Shape{1}, {-1});
|
||||
|
||||
auto start_buff = std::vector<int64_t>{100};
|
||||
auto stop_buff = std::vector<int64_t>{2};
|
||||
auto steps_buff = std::vector<int64_t>{-2};
|
||||
|
||||
const auto start_tensor = std::make_shared<HostTensor>(et, Shape{1}, static_cast<void*>(start_buff.data()));
|
||||
const auto stop_tensor = std::make_shared<HostTensor>(et, Shape{1}, static_cast<void*>(stop_buff.data()));
|
||||
const auto steps_tensor = std::make_shared<HostTensor>(et, Shape{1}, static_cast<void*>(steps_buff.data()));
|
||||
|
||||
const auto op = make_op(data, start, stop, steps, axes);
|
||||
|
||||
input_shapes = ShapeVector{{3, 4, 10}, {1}, {1}, {1}, axes->get_shape()};
|
||||
|
||||
const std::map<size_t, std::shared_ptr<HostTensor>>& constant_data = {{1, start_tensor},
|
||||
{2, stop_tensor},
|
||||
{3, steps_tensor}};
|
||||
|
||||
shape_inference(op.get(), input_shapes, output_shapes, constant_data);
|
||||
|
||||
EXPECT_EQ(output_shapes.size(), num_of_outputs);
|
||||
EXPECT_EQ(output_shapes.front(), StaticShape({3, 4, 4}));
|
||||
}
|
||||
|
||||
TEST_F(SliceStaticShapeInferenceTest, forward_step_all_data_in_const_map) {
|
||||
constexpr auto et = element::i64;
|
||||
|
||||
const auto data = std::make_shared<op::v0::Parameter>(element::f32, PartialShape::dynamic());
|
||||
const auto start = std::make_shared<op::v0::Parameter>(et, PartialShape::dynamic());
|
||||
const auto stop = std::make_shared<op::v0::Parameter>(et, PartialShape::dynamic());
|
||||
const auto steps = std::make_shared<op::v0::Parameter>(et, PartialShape::dynamic());
|
||||
|
||||
auto start_buff = std::vector<int64_t>{0, 2, 10, 3, 3, INT64_MIN, INT64_MIN};
|
||||
auto stop_buff = std::vector<int64_t>{10, 8, 12, 15, INT64_MAX, -5, -5};
|
||||
auto steps_buff = std::vector<int64_t>{1, 2, 1, 3, 4, 2, 2};
|
||||
auto axes_buff = std::vector<int64_t>{0, 1, 2, 3, 4, 5, 6};
|
||||
|
||||
const auto common_shape = Shape{start_buff.size()};
|
||||
|
||||
const auto start_tensor = std::make_shared<HostTensor>(et, common_shape, static_cast<void*>(start_buff.data()));
|
||||
const auto stop_tensor = std::make_shared<HostTensor>(et, common_shape, static_cast<void*>(stop_buff.data()));
|
||||
const auto steps_tensor = std::make_shared<HostTensor>(et, common_shape, static_cast<void*>(steps_buff.data()));
|
||||
const auto axes_tensor = std::make_shared<HostTensor>(et, common_shape, static_cast<void*>(axes_buff.data()));
|
||||
|
||||
const auto op = make_op(data, start, stop, steps);
|
||||
|
||||
input_shapes.push_back({10, 10, 8, max_d, max_d, max_d, 10});
|
||||
input_shapes.resize(5, common_shape);
|
||||
|
||||
const std::map<size_t, std::shared_ptr<HostTensor>>& constant_data = {{1, start_tensor},
|
||||
{2, stop_tensor},
|
||||
{3, steps_tensor},
|
||||
{4, axes_tensor}};
|
||||
|
||||
shape_inference(op.get(), input_shapes, output_shapes, constant_data);
|
||||
|
||||
EXPECT_EQ(output_shapes.size(), num_of_outputs);
|
||||
EXPECT_EQ(output_shapes.front(), StaticShape({10, 3, 0, 4, max_d, max_d, 3}));
|
||||
}
|
||||
Reference in new issue
Block a user