[Eye-9] Reference and CPU implementation for Eye-9 (#11538)

* Added shell for Eye-9

* Updated spec for Eye-9

* Added reference for Eye-9

* eye cpu

* Added op impl check for Eye-9

* Fix unallowed dynamic to static dim conversion in eye shape_infer

* Add template plugin tests for dynamic shapes

* Add template plugin tests for dynamic shapes batch input

* Enable batch shape input dynamic rank

* Uncomment 3D batch cpu Eye tests

* Update assertions and messages

* use ov::element type

* Remove redundant evaluate from eval map

* Style fix

* Add static_cast<T>(1) to cpu eye

* Add defaults to eye cpu class members

* Reuse out_ptr and checks

* Reutrn if onesPerBatchNum == 0

* Add Eye CPU Dynamic shape tests with 2D batch

* Additional test cases for CPU and reference

* Disable 3D batch eye cpu tests

* Fix CPU implementation for matrix with not equal cols and rows

* Update CPU test name

* Disable CPU Eye 3D batch static shapes tests

Co-authored-by: Alexandra Sidorova <alexandra.sidorova@intel.com>
Co-authored-by: Yury Gaydaychuk <yury.gaydaychuk@intel.com>
This commit is contained in:
authored and GitHub committed 2022-05-19 16:37:00 +03:00
1 parent f83530138e
commit 76dfeceb93
14 files changed
+1141 -22

No files matched your search

@@ -0,0 +1,411 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
#include "openvino/op/eye.hpp"
using namespace ov;
using namespace reference_tests;
namespace reference_tests {
namespace {
struct EyeParams {
EyeParams(const reference_tests::Tensor& num_rows,
const reference_tests::Tensor& num_columns,
const reference_tests::Tensor& diagonal_index,
const element::Type& output_type,
const reference_tests::Tensor& expected_tensor,
const std::string& test_case_name,
bool is_dyn_shape_test = false)
: num_rows(num_rows),
num_columns(num_columns),
diagonal_index(diagonal_index),
output_type(output_type),
expected_tensor(expected_tensor),
test_case_name(test_case_name),
set_dynamic_shape(is_dyn_shape_test) {}
reference_tests::Tensor num_rows;
reference_tests::Tensor num_columns;
reference_tests::Tensor diagonal_index;
element::Type output_type;
reference_tests::Tensor expected_tensor;
std::string test_case_name;
bool set_dynamic_shape = false;
};
struct EyeBatchShapeParams {
EyeBatchShapeParams(const reference_tests::Tensor& num_rows,
const reference_tests::Tensor& num_columns,
const reference_tests::Tensor& diagonal_index,
const reference_tests::Tensor& batch_shape,
const element::Type& output_type,
const reference_tests::Tensor& expected_tensor,
const std::string& test_case_name,
bool is_dyn_shape_test = false)
: num_rows(num_rows),
num_columns(num_columns),
diagonal_index(diagonal_index),
batch_shape(batch_shape),
output_type(output_type),
expected_tensor(expected_tensor),
test_case_name(test_case_name),
set_dynamic_shape(is_dyn_shape_test) {}
reference_tests::Tensor num_rows;
reference_tests::Tensor num_columns;
reference_tests::Tensor diagonal_index;
reference_tests::Tensor batch_shape;
element::Type output_type;
reference_tests::Tensor expected_tensor;
std::string test_case_name;
bool set_dynamic_shape = false;
};
class ReferenceEyeLayerTest : public testing::TestWithParam<EyeParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.num_rows,
params.num_columns,
params.diagonal_index,
params.output_type,
params.set_dynamic_shape);
inputData = {params.num_rows.data, params.num_columns.data, params.diagonal_index.data};
refOutData = {params.expected_tensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<EyeParams>& obj) {
return obj.param.test_case_name + (obj.param.set_dynamic_shape ? "_dyn_shape_inputs" : "");
}
private:
static std::shared_ptr<Model> CreateFunction(const reference_tests::Tensor& num_rows,
const reference_tests::Tensor& num_columns,
const reference_tests::Tensor& diagonal_index,
const element::Type& output_type,
bool set_dynamic_shape = false) {
const auto in1 = std::make_shared<op::v0::Parameter>(num_rows.type, set_dynamic_shape ? PartialShape::dynamic() : num_rows.shape);
const auto in2 = std::make_shared<op::v0::Parameter>(num_columns.type, set_dynamic_shape ? PartialShape::dynamic() : num_columns.shape);
const auto in3 = std::make_shared<op::v0::Parameter>(diagonal_index.type, set_dynamic_shape ? PartialShape::dynamic() : diagonal_index.shape);
const auto Eye = std::make_shared<op::v9::Eye>(in1, in2, in3, output_type);
return std::make_shared<Model>(NodeVector{Eye}, ParameterVector{in1, in2, in3});
}
};
class ReferenceEyeBatchShapeLayerTest : public testing::TestWithParam<EyeBatchShapeParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params.num_rows,
params.num_columns,
params.diagonal_index,
params.batch_shape,
params.output_type,
params.set_dynamic_shape);
inputData = {params.num_rows.data, params.num_columns.data, params.diagonal_index.data, params.batch_shape.data};
refOutData = {params.expected_tensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<EyeBatchShapeParams>& obj) {
return obj.param.test_case_name + (obj.param.set_dynamic_shape ? "_dyn_shape_inputs" : "");
}
private:
static std::shared_ptr<Model> CreateFunction(const reference_tests::Tensor& num_rows,
const reference_tests::Tensor& num_columns,
const reference_tests::Tensor& diagonal_index,
const reference_tests::Tensor& batch_shape,
const element::Type& output_type,
bool set_dynamic_shape = false) {
const auto in1 = std::make_shared<op::v0::Parameter>(num_rows.type, set_dynamic_shape ? PartialShape::dynamic() : num_rows.shape);
const auto in2 = std::make_shared<op::v0::Parameter>(num_columns.type, set_dynamic_shape ? PartialShape::dynamic() : num_columns.shape);
const auto in3 = std::make_shared<op::v0::Parameter>(diagonal_index.type, set_dynamic_shape ? PartialShape::dynamic() : diagonal_index.shape);
const auto in4 = std::make_shared<op::v0::Parameter>(batch_shape.type, set_dynamic_shape ? PartialShape::dynamic() : batch_shape.shape);
const auto Eye = std::make_shared<op::v9::Eye>(in1, in2, in3, in4, output_type);
return std::make_shared<Model>(NodeVector{Eye}, ParameterVector{in1, in2, in3, in4});
}
};
std::vector<EyeParams> generateEyeParams(bool is_dyn_shape_test = false) {
std::vector<EyeParams> test_params {
EyeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{0}},
element::Type_t::f32,
reference_tests::Tensor{{3, 2}, element::f32, std::vector<float>{1, 0,
0, 1,
0, 0}},
"float32_default_3x2", is_dyn_shape_test),
EyeParams(reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 4}, element::i8, std::vector<int8_t>{0, 0, 1, 0,
0, 0, 0, 1}},
"int8_diag=2_2x4", is_dyn_shape_test),
EyeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{-3}},
element::Type_t::i64,
reference_tests::Tensor{{4, 2}, element::i64, std::vector<int64_t>{0, 0,
0, 0,
0, 0,
1, 0}},
"int64_diag=-3_4x2", is_dyn_shape_test),
EyeParams(reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{1}},
reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{}, element::i32, std::vector<int32_t>{10}},
element::Type_t::i8,
reference_tests::Tensor{{1, 4}, element::i8, std::vector<int8_t>{0, 0, 0, 0}},
"int8_empty_1x4", is_dyn_shape_test)};
return test_params;
}
std::vector<EyeBatchShapeParams> generateEyeBatchShapeParams(bool is_dyn_shape_test = false) {
std::vector<EyeBatchShapeParams> test_params {
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{0}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::f32,
reference_tests::Tensor{{2, 3, 3}, element::f32, std::vector<float>{1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1}},
"f32_2x3x3_diag0", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{0}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::f32,
reference_tests::Tensor{{2, 3, 3}, element::f32, std::vector<float>{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1}},
"f32_2x4x4_diag0", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{0}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::f32,
reference_tests::Tensor{{2, 3, 4}, element::f32, std::vector<float>{1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0}},
"f32_2x3x4_diag0", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{0}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 4, 3}, element::i8, std::vector<int8_t>{1, 0, 0,
0, 1, 0,
0, 0, 1,
0, 0, 0,
1, 0, 0,
0, 1, 0,
0, 0, 1,
0, 0, 0}},
"f32_2x4x3_diag0", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{1}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::f32,
reference_tests::Tensor{{2, 3, 4}, element::f32, std::vector<float>{0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1}},
"f32_2x3x4_diag1", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{1}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::f32,
reference_tests::Tensor{{2, 4, 3}, element::f32, std::vector<float>{0, 1, 0,
0, 0, 1,
0, 0, 0,
0, 0, 0,
0, 1, 0,
0, 0, 1,
0, 0, 0,
0, 0, 0}},
"f32_2x4x3_diag1", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 3, 4}, element::i8, std::vector<int8_t>{0, 0, 1, 0,
0, 0, 0, 1,
0, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
0, 0, 0, 0}},
"i8_2x3x4_diag2", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 4, 3}, element::i8, std::vector<int8_t>{0, 0, 1,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 1,
0, 0, 0,
0, 0, 0,
0, 0, 0}},
"i8_2x4x3_diag2", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{-1}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 3, 4}, element::i8, std::vector<int8_t>{0, 0, 0, 0,
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,
1, 0, 0, 0,
0, 1, 0, 0}},
"i8_2x3x4_diag-1", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{-1}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 4, 3}, element::i8, std::vector<int8_t>{0, 0, 0,
1, 0, 0,
0, 1, 0,
0, 0, 1,
0, 0, 0,
1, 0, 0,
0, 1, 0,
0, 0, 1}},
"i8_2x4x3_diag-1", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{-2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 3, 4}, element::i8, std::vector<int8_t>{0, 0, 0, 0,
0, 0, 0, 0,
1, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
1, 0, 0, 0}},
"i8_2x3x4_diag-2", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{-2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i8,
reference_tests::Tensor{{2, 4, 3}, element::i8, std::vector<int8_t>{0, 0, 0,
0, 0, 0,
1, 0, 0,
0, 1, 0,
0, 0, 0,
0, 0, 0,
1, 0, 0,
0, 1, 0}},
"i8_2x4x3_diag-2", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{6}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{5}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{1}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
element::Type_t::i32,
reference_tests::Tensor{{2, 6, 5}, element::i32, std::vector<int32_t>{0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0}},
"int32_2x6x5_diag1", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{4}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{2}, element::i32, std::vector<int32_t>{2, 2}},
element::Type_t::i64,
reference_tests::Tensor{{2, 2, 4, 2}, element::i64, std::vector<int64_t>{0, 0, 1, 0,
0, 0, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1,
0, 0, 1, 0,
0, 0, 0, 1}},
"int64_2x2x3x3", is_dyn_shape_test),
EyeBatchShapeParams(reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{2}},
reference_tests::Tensor{{1}, element::i32, std::vector<int32_t>{3}},
reference_tests::Tensor{{2}, element::i32, std::vector<int32_t>{1, 3}},
element::Type_t::u8,
reference_tests::Tensor{{2, 3, 3}, element::u8, std::vector<uint8_t>{0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0}},
"uint8_1x3x2x2", is_dyn_shape_test)};
return test_params;
}
std::vector<EyeParams> generateEyeCombinedParams() {
std::vector<EyeParams> combined_params = generateEyeParams(false);
std::vector<EyeParams> dyn_shape_params = generateEyeParams(true);
combined_params.insert(combined_params.end(), dyn_shape_params.begin(), dyn_shape_params.end());
return combined_params;
}
std::vector<EyeBatchShapeParams> generateEyeBatchShapeCombinedParams() {
std::vector<EyeBatchShapeParams> combined_params = generateEyeBatchShapeParams(false);
std::vector<EyeBatchShapeParams> dyn_shape_params = generateEyeBatchShapeParams(true);
combined_params.insert(combined_params.end(), dyn_shape_params.begin(), dyn_shape_params.end());
return combined_params;
}
TEST_P(ReferenceEyeLayerTest, EyeWithHardcodedRefs) {
Exec();
}
TEST_P(ReferenceEyeBatchShapeLayerTest, EyeRectangleBatchShapeWithHardcodedRefs) {
Exec();
}
} // namespace
INSTANTIATE_TEST_SUITE_P(
smoke_Eye_With_Hardcoded_Refs,
ReferenceEyeLayerTest,
// Generate params (3 inputs) with static and dynamic shapes
::testing::ValuesIn(generateEyeCombinedParams()),
ReferenceEyeLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(
smoke_EyeBatchShape_With_Hardcoded_Refs,
ReferenceEyeBatchShapeLayerTest,
// Generate params (4 inputs) with static and dynamic shapes
::testing::ValuesIn(generateEyeBatchShapeCombinedParams()),
ReferenceEyeBatchShapeLayerTest::getTestCaseName);
} // namespace reference_tests
+5
View File
@@ -55,6 +55,11 @@ public:
m_output_type = output_type;
}
OPENVINO_SUPPRESS_DEPRECATED_START
bool evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const override;
OPENVINO_SUPPRESS_DEPRECATED_END
bool has_evaluate() const override;
protected:
ov::element::Type m_output_type;
};
@@ -0,0 +1,41 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <cmath>
#include "ngraph/shape.hpp"
#include "utils/span.hpp"
namespace ngraph {
namespace runtime {
namespace reference {
template <typename T>
void eye(T* data, const Shape& out_shape, const int64_t diagonal_index) {
const int64_t num_matrices = shape_size(span(out_shape).subspan(0, out_shape.size() - 2));
const int64_t num_rows = out_shape[out_shape.size() - 2];
const int64_t num_columns = out_shape[out_shape.size() - 1];
const int64_t matrix_size = num_rows * num_columns;
// fill tensor by zero
std::memset(data, 0, num_matrices * num_columns * num_rows * sizeof(T));
// set ones on diagonal
const int64_t shift_by_columns = std::max(diagonal_index, int64_t(0));
const int64_t count_by_columns = std::max(num_columns - std::abs(diagonal_index), int64_t(0));
const int64_t count_by_rows = std::max(num_rows - std::abs(diagonal_index), int64_t(0));
const int64_t count =
diagonal_index > 0 ? std::min(count_by_columns, num_rows) : std::min(count_by_rows, num_columns);
for (auto i = 0; i < num_matrices; i++) {
for (auto j = 0; j < count; j++) {
const int64_t index = (j + shift_by_columns - diagonal_index) * num_columns + j + shift_by_columns;
data[index + i * matrix_size] = static_cast<T>(1);
}
}
}
} // namespace reference
} // namespace runtime
} // namespace ngraph
@@ -24,16 +24,6 @@ void check_1D_or_scalar_shape(const ov::op::v9::Eye* op, const T& input_shape, c
}
}
template<class T>
void check_batch_shape_shape(const ov::op::v9::Eye* op, const T& input_shape) {
if (input_shape.is_static()) {
const auto& diagonal_index_rank = input_shape.rank().get_length();
NODE_VALIDATION_CHECK(op, diagonal_index_rank == 1, "'batch_shape' value must be a 1D tensor.");
} else {
NODE_VALIDATION_CHECK(op, input_shape.rank().is_static(), "'batch_shape' should have static shape rank");
NODE_VALIDATION_CHECK(op, input_shape.rank() == 1, "'batch_shape' value must be a 1D tensor.");
}
}
} // namespace util
@@ -43,9 +33,7 @@ void shape_infer(const ov::op::v9::Eye* op, const std::vector<T> &input_shapes,
NODE_VALIDATION_CHECK(op, input_shapes.size() == op->get_input_size() && output_shapes.size() == 1);
// output_shape = dims_batch_shape + dims_matrix
T batch_shape;
T dims_matrix = {ov::Dimension::dynamic(), ov::Dimension::dynamic()};
auto& dim_num_rows = dims_matrix[0];
auto& dim_num_columns = dims_matrix[1];
T dims_matrix;
auto& output_shape = output_shapes[0];
util::check_1D_or_scalar_shape(op, input_shapes[0], "'num_rows'");
@@ -62,7 +50,9 @@ void shape_infer(const ov::op::v9::Eye* op, const std::vector<T> &input_shapes,
num_rows.front() >= 0,
"'num_rows' must be non-negative value. Got: ",
num_rows.front());
dim_num_rows = num_rows.front();
dims_matrix.push_back(num_rows.front());
} else {
dims_matrix.push_back(Dimension::dynamic());
}
std::vector<int64_t> num_columns;
@@ -75,12 +65,14 @@ void shape_infer(const ov::op::v9::Eye* op, const std::vector<T> &input_shapes,
num_columns.front() >= 0,
"'num_columns' must be non-negative value. Got: ",
num_columns.front());
dim_num_columns = num_columns.front();
dims_matrix.push_back(num_columns.front());
} else {
dims_matrix.push_back(Dimension::dynamic());
}
if (op->get_input_size() == 4) {
const auto batch_shape_pshape = input_shapes[3];
util::check_batch_shape_shape(op, batch_shape_pshape);
NODE_VALIDATION_CHECK(op, batch_shape_pshape.rank().compatible(1), "'batch_shape' input must be a 1D tensor.");
if (batch_shape_pshape.is_static()) {
if (get_data_as_shape<T>(3, op, batch_shape, constant_data)) {
NODE_VALIDATION_CHECK(op, batch_shape_pshape[0].get_length() == batch_shape.rank().get_length());
@@ -98,4 +90,4 @@ void shape_infer(const ov::op::v9::Eye* op, const std::vector<T> &input_shapes,
}
} // namespace op
} // namespace ov
} // namespace ov
+99
View File
@@ -6,6 +6,35 @@
#include "eye_shape_inference.hpp"
#include "itt.hpp"
#include "ngraph/runtime/reference/eye.hpp"
#include "ngraph/validation_util.hpp"
namespace eye {
namespace {
template <ov::element::Type_t ET>
bool evaluate(const ov::HostTensorPtr& out, const int64_t diagonal_index) {
ngraph::runtime::reference::eye(out->get_data_ptr<ET>(), out->get_shape(), diagonal_index);
return true;
}
bool evaluate_eye(const ov::HostTensorPtr& out, const int64_t diagonal_index) {
bool rc = true;
switch (out->get_element_type()) {
NGRAPH_TYPE_CASE(evaluate, i8, out, diagonal_index);
NGRAPH_TYPE_CASE(evaluate, u8, out, diagonal_index);
NGRAPH_TYPE_CASE(evaluate, f16, out, diagonal_index);
NGRAPH_TYPE_CASE(evaluate, bf16, out, diagonal_index);
NGRAPH_TYPE_CASE(evaluate, i32, out, diagonal_index);
NGRAPH_TYPE_CASE(evaluate, f32, out, diagonal_index);
NGRAPH_TYPE_CASE(evaluate, i64, out, diagonal_index);
default:
rc = false;
break;
}
return rc;
}
} // namespace
} // namespace eye
ov::op::v9::Eye::Eye(const Output<Node>& num_rows,
const Output<Node>& num_columns,
@@ -81,3 +110,73 @@ std::shared_ptr<ov::Node> ov::op::v9::Eye::clone_with_new_inputs(const ov::Outpu
throw ov::Exception("Eye has incorrect input number: " + std::to_string(new_args.size()));
}
}
bool ov::op::v9::Eye::has_evaluate() const {
NGRAPH_OP_SCOPE(v9_Eye_has_evaluate);
switch (m_output_type) {
case ov::element::i8:
case ov::element::u8:
case ov::element::f16:
case ov::element::bf16:
case ov::element::i32:
case ov::element::f32:
case ov::element::i64:
return true;
default:
break;
}
return false;
}
bool ov::op::v9::Eye::evaluate(const ov::HostTensorVector& outputs, const ov::HostTensorVector& inputs) const {
NGRAPH_OP_SCOPE(v9_Eye_evaluate);
OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(inputs, get_input_size()), "Invalid Eye input TensorVector.");
OPENVINO_ASSERT(ngraph::validate_host_tensor_vector(outputs, 1), "Invalid Eye output TensorVector.");
const auto& num_rows_data = inputs[0];
int64_t diagonal_index = 0;
std::vector<ov::PartialShape> input_shapes;
std::vector<ov::PartialShape> output_shapes = {ov::PartialShape::dynamic()};
std::map<size_t, std::shared_ptr<ngraph::runtime::HostTensor>> constant_data;
if (get_input_size() > 1) {
const auto& num_columns_data = inputs[1];
const auto& diagonal_index_data = inputs[2];
switch (diagonal_index_data->get_element_type()) {
case element::i32:
diagonal_index = diagonal_index_data->get_data_ptr<const int32_t>()[0];
break;
case element::i64:
diagonal_index = diagonal_index_data->get_data_ptr<const int64_t>()[0];
break;
default:
throw ov::Exception("Unsupported type of input `diagonal_index` in Eye operation: " +
diagonal_index_data->get_element_type().get_type_name());
}
constant_data = {{0, num_rows_data}, {1, num_columns_data}, {2, diagonal_index_data}};
input_shapes = {num_rows_data->get_partial_shape(),
num_columns_data->get_partial_shape(),
diagonal_index_data->get_partial_shape()};
if (get_input_size() > 3) {
const auto& batch_shape_data = inputs[3];
constant_data.insert({3, batch_shape_data});
input_shapes.push_back(batch_shape_data->get_partial_shape());
}
} else {
constant_data = {{0, num_rows_data}};
input_shapes = {num_rows_data->get_partial_shape()};
}
shape_infer(this, input_shapes, output_shapes, constant_data);
OPENVINO_ASSERT(ov::PartialShape(output_shapes[0]).is_static(), "Eye op evaluate needs output shape to be static.");
ov::Shape output_shape = output_shapes[0].to_shape();
outputs[0]->set_element_type(get_out_type());
outputs[0]->set_shape(output_shape);
return eye::evaluate_eye(outputs[0], diagonal_index);
}
+29 -5
View File
@@ -270,18 +270,42 @@ TEST(type_prop, eye_invalid_diagonal_index_rank) {
}
}
TEST(type_prop, eye_invalid_dynamic_batch_shape_rank) {
TEST(type_prop, eye_dynamic_batch_shape_dyn_rank) {
auto num_rows = op::v0::Constant::create(element::i32, Shape{}, {6});
auto num_columns = op::v0::Constant::create(element::i32, Shape{}, {2});
auto num_columns = op::v0::Constant::create(element::i32, Shape{}, {4});
auto diagonal_index = op::v0::Constant::create(element::i64, Shape{}, {2});
auto batch_shape = make_shared<op::v0::Parameter>(element::i64, PartialShape().dynamic());
auto batch_shape = make_shared<op::v0::Parameter>(element::i64, PartialShape::dynamic());
auto eye = make_shared<op::v9::Eye>(num_rows, num_columns, diagonal_index, batch_shape, element::i32);
EXPECT_EQ(eye->get_output_element_type(0), element::i32);
EXPECT_EQ(eye->get_output_partial_shape(0), PartialShape::dynamic());
}
TEST(type_prop, eye_dynamic_batch_shape_1D) {
auto num_rows = op::v0::Constant::create(element::i32, Shape{}, {6});
auto num_columns = op::v0::Constant::create(element::i32, Shape{}, {4});
auto diagonal_index = op::v0::Constant::create(element::i64, Shape{}, {2});
auto batch_shape = make_shared<op::v0::Parameter>(element::i64, PartialShape::dynamic(1));
auto eye = make_shared<op::v9::Eye>(num_rows, num_columns, diagonal_index, batch_shape, element::i32);
EXPECT_EQ(eye->get_output_element_type(0), element::i32);
EXPECT_EQ(eye->get_output_partial_shape(0), PartialShape::dynamic());
}
TEST(type_prop, eye_dynamic_batch_shape_invalid_rank) {
auto num_rows = op::v0::Constant::create(element::i32, Shape{}, {6});
auto num_columns = op::v0::Constant::create(element::i32, Shape{}, {4});
auto diagonal_index = op::v0::Constant::create(element::i64, Shape{}, {2});
auto batch_shape = make_shared<op::v0::Parameter>(element::i64, PartialShape::dynamic(2));
try {
auto Eye = make_shared<op::v9::Eye>(num_rows, num_columns, diagonal_index, batch_shape, element::i32);
auto eye = make_shared<op::v9::Eye>(num_rows, num_columns, diagonal_index, batch_shape, element::i32);
// Should have thrown, so fail if it didn't
FAIL() << "Unexpected pass with invalid 'batch_shape' value.";
} catch (const NodeValidationFailure& error) {
EXPECT_HAS_SUBSTRING(error.what(), std::string("'batch_shape' should have static shape rank"));
EXPECT_HAS_SUBSTRING(error.what(), std::string("'batch_shape' input must be a 1D tensor."));
} catch (...) {
FAIL() << "Check failed for unexpected reason";
}
+3
View File
@@ -16,6 +16,7 @@ const InferenceEngine::details::caseless_unordered_map<std::string, Type> type_t
{ "Constant", Type::Input },
{ "Parameter", Type::Input },
{ "Result", Type::Output },
{ "Eye", Type::Eye },
{ "Convolution", Type::Convolution },
{ "GroupConvolution", Type::Convolution },
{ "MatMul", Type::MatMul },
@@ -213,6 +214,8 @@ std::string NameFromType(const Type type) {
return "Input";
case Type::Output:
return "Output";
case Type::Eye:
return "Eye";
case Type::Convolution:
return "Convolution";
case Type::Deconvolution:
+1
View File
@@ -22,6 +22,7 @@ enum class Type {
Reorder,
Input,
Output,
Eye,
Convolution,
Deconvolution,
Lrn,
+145
View File
@@ -0,0 +1,145 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "eye.h"
#include <ie_ngraph_utils.hpp>
#include <utils/bfloat16.hpp>
#include <ie_parallel.hpp>
#define THROW_ERROR IE_THROW() << NameFromType(getType()) << " node with name '" << getName() << "' "
using namespace InferenceEngine;
namespace ov {
namespace intel_cpu {
namespace node {
using namespace InferenceEngine::details;
bool Eye::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept {
try {
if (op->get_type_info() != ngraph::op::v9::Eye::get_type_info_static()) {
errorMessage = "Node is not an instance of Eye form the operation set v9.";
return false;
}
} catch (...) {
return false;
}
return true;
}
Eye::Eye(const std::shared_ptr<ov::Node>& op, const dnnl::engine& eng,
WeightsSharing::Ptr &cache) : Node(op, eng, cache) {
std::string errorMessage;
if (!isSupportedOperation(op, errorMessage)) {
IE_THROW(NotImplemented) << errorMessage;
}
outType = op->get_output_element_type(0);
withBatchShape = (op->get_input_size() == 4);
if (!one_of(outType, ngraph::element::f32, ngraph::element::bf16,
ngraph::element::i32, ngraph::element::i8, ngraph::element::u8)) {
THROW_ERROR << errorPrefix << "doesn't support demanded output precision";
}
}
void Eye::getSupportedDescriptors() {
if (!descs.empty())
return;
if (!one_of(getParentEdges().size(), 3, 4))
THROW_ERROR << errorPrefix << "has incorrect number of input edges: " << getParentEdges().size();
if (getChildEdges().empty())
THROW_ERROR << errorPrefix << "has incorrect number of output edges: " << getChildEdges().size();
}
template<typename T>
struct Eye::EyeExecute {
void operator()(Eye *node) {
node->executeSpecified<T>();
}
};
void Eye::execute(dnnl::stream strm) {
auto outputPrec = getChildEdgesAtPort(0)[0]->getMemory().getDesc().getPrecision();
OV_SWITCH(intel_cpu, EyeExecute, this, outputPrec,
OV_CASE(Precision::FP32, float),
OV_CASE(Precision::BF16, bfloat16_t),
OV_CASE(Precision::I32, int),
OV_CASE(Precision::I8, int8_t),
OV_CASE(Precision::U8, uint8_t))
}
void Eye::initSupportedPrimitiveDescriptors() {
if (!supportedPrimitiveDescriptors.empty())
return;
std::vector<PortConfigurator> inDataConf;
std::vector<PortConfigurator> outDataConf;
inDataConf.reserve(inputShapes.size());
for (int i = 0; i < inputShapes.size(); ++i)
inDataConf.emplace_back(LayoutType::ncsp, Precision::I32);
outDataConf.reserve(1);
outDataConf.emplace_back(LayoutType::ncsp, convertPrecision(outType));
addSupportedPrimDesc(inDataConf, outDataConf, impl_desc_type::ref);
}
template <typename T>
void Eye::executeSpecified() {
const size_t rowNum = getRowNum();
const size_t colNum = getColNum();
const int64_t shift = getDiagIndex();
auto outPtr = getChildEdgeAt(0)->getMemoryPtr();
if (!outPtr || !outPtr ->isAllocated())
THROW_ERROR << errorPrefix << "Destination memory didn't allocate.";
T *dst = reinterpret_cast<T *>(outPtr->GetPtr());
const size_t batchVolume = getBatchVolume(getBatchShape());
const size_t spatialCount = colNum * rowNum;
const size_t spatialSize = spatialCount * sizeof(T);
const size_t l2CacheSize = dnnl::utils::get_cache_size(2, true);
const size_t elementsCount = colNum * rowNum * batchVolume;
const int64_t countByColumns = std::max(int64_t(colNum) - std::abs(shift), int64_t(0));
const int64_t countByRows = std::max(int64_t(rowNum) - std::abs(shift), int64_t(0));
const size_t onesPerBatchNum =
static_cast<size_t>(shift > 0 ? std::min(countByColumns, int64_t(rowNum)) : std::min(countByRows, int64_t(colNum)));
const size_t dataShift = static_cast<size_t>(shift >= 0 ? shift : -shift * colNum);
if (spatialSize >= l2CacheSize) {
parallel_nt(0, [&](const size_t ithr, const size_t nthr) {
size_t start = 0, end = 0;
splitter(elementsCount, nthr, ithr, start, end);
memset(dst + start, 0, (end - start) * sizeof(T));
});
if (onesPerBatchNum == 0) return;
for (size_t bShift = 0; bShift < batchVolume * spatialCount; bShift += spatialCount) {
parallel_nt(0, [&](const size_t ithr, const size_t nthr) {
size_t start = 0, end = 0;
splitter(onesPerBatchNum, nthr, ithr, start, end);
for (size_t j = start; j < end; j++) {
dst[dataShift + j * (colNum + 1) + bShift] = static_cast<T>(1);
}
});
}
} else {
parallel_nt(0, [&](const size_t ithr, const size_t nthr) {
size_t start = 0, end = 0;
splitter(batchVolume, nthr, ithr, start, end);
memset(dst + start * spatialCount, 0, (end - start) * spatialSize);
if (onesPerBatchNum == 0) return;
for (size_t spShift = start * spatialCount; spShift < end * spatialCount; spShift += spatialCount) {
for (size_t j = 0; j < onesPerBatchNum; j++) {
dst[dataShift + j * (colNum + 1) + spShift] = static_cast<T>(1);
}
}
});
}
}
bool Eye::created() const {
return getType() == Type::Eye;
}
} // namespace node
} // namespace intel_cpu
} // namespace ov
+94
View File
@@ -0,0 +1,94 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <node.h>
#include <string>
#include <memory>
#include <vector>
#include <dnnl_extension_utils.h>
namespace ov {
namespace intel_cpu {
namespace node {
class Eye : public Node {
public:
Eye(const std::shared_ptr<ngraph::Node>& op, const dnnl::engine& eng, WeightsSharing::Ptr &cache);
void getSupportedDescriptors() override;
void initSupportedPrimitiveDescriptors() override;
void execute(dnnl::stream strm) override;
bool created() const override;
bool needPrepareParams() const override {return false;};
bool needShapeInfer() const override {return true;};
void executeDynamicImpl(dnnl::stream strm) override { execute(strm); }
std::vector<VectorDims> shapeInfer() const override {
if (withBatchShape) {
return Node::shapeInferGeneric(PortMask(ROWS_NUM, COLS_NUM, DIAGONAL_INDEX, BATCH_SHAPE));
} else {
return Node::shapeInferGeneric(PortMask(ROWS_NUM, COLS_NUM, DIAGONAL_INDEX));
}
}
static bool isSupportedOperation(const std::shared_ptr<const ngraph::Node>& op, std::string& errorMessage) noexcept;
private:
std::string errorPrefix = "";
ov::element::Type outType = ov::element::Type_t::undefined;
template <typename inputType>
void executeSpecified();
template<typename T>
struct EyeExecute;
inline const size_t getRowNum() const {
auto rowMem = getParentEdgeAt(ROWS_NUM)->getMemoryPtr();
if (rowMem == nullptr)
IE_THROW() << errorPrefix << " doesn't contain row_count data";
const int *rowPtr = reinterpret_cast<const int *>(rowMem->GetPtr());
return rowPtr[0];
}
inline const size_t getColNum() const {
auto colMem = getParentEdgeAt(COLS_NUM)->getMemoryPtr();
if (colMem == nullptr)
IE_THROW() << errorPrefix << " doesn't contain col_count data";
const int *colPtr = reinterpret_cast<const int *>(colMem->GetPtr());
return colPtr[0];
}
inline const int getDiagIndex() const {
auto diagIndMem = getParentEdgeAt(DIAGONAL_INDEX)->getMemoryPtr();
if (diagIndMem == nullptr)
IE_THROW() << errorPrefix << " doesn't contain diag_index data";
const int *diagIndexPtr = reinterpret_cast<const int *>(diagIndMem->GetPtr());
return diagIndexPtr[0];
}
inline const std::vector<int> getBatchShape() const {
if (withBatchShape) {
const int batchShapeSize = static_cast<const int>(getParentEdgeAt(BATCH_SHAPE)->getMemoryPtr()->GetShape().getElementsCount());
std::vector<int> batchShape(batchShapeSize);
const int *batchShapePtr = reinterpret_cast<const int *>(getParentEdgeAt(BATCH_SHAPE)->getMemoryPtr()->GetPtr());
batchShape.assign(batchShapePtr, batchShapePtr + batchShapeSize);
return batchShape;
} else {
return std::vector<int> {};
}
}
inline const size_t getBatchVolume(const std::vector<int> &batchShape) {
return std::accumulate(begin(batchShape), end(batchShape), 1, std::multiplies<size_t>());
}
static constexpr size_t ROWS_NUM = 0lu;
static constexpr size_t COLS_NUM = 1lu;
static constexpr size_t DIAGONAL_INDEX = 2lu;
static constexpr size_t BATCH_SHAPE = 3lu;
bool withBatchShape = false;
};
} // namespace node
} // namespace intel_cpu
} // namespace ov
@@ -86,6 +86,7 @@
#include "nodes/subgraph.h"
#include "nodes/priorbox.h"
#include "nodes/priorbox_clustered.h"
#include "nodes/eye.h"
namespace ov {
namespace intel_cpu {
@@ -184,6 +185,7 @@ Node::NodesFactory::NodesFactory()
INTEL_CPU_NODE(ColorConvert, Type::ColorConvert);
INTEL_CPU_NODE(PriorBox, Type::PriorBox);
INTEL_CPU_NODE(PriorBoxClustered, Type::PriorBoxClustered);
INTEL_CPU_NODE(Eye, Type::Eye);
}
#undef INTEL_CPU_NODE
@@ -0,0 +1,290 @@
/// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <ngraph/opsets/opset9.hpp>
#include <common_test_utils/ov_tensor_utils.hpp>
#include "test_utils/cpu_test_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
using namespace InferenceEngine;
using namespace CPUTestUtils;
using namespace ov::test;
namespace CPULayerTestsDefinitions {
namespace {
std::vector<InputShape> inputShape;
std::vector<int> outBatchShape;
int rowNum, colNum;
int shift;
} // namespace
using EyeLayerTestParams = std::tuple<
std::vector<InputShape>, // eye shape
std::vector<int>, // output batch shape
std::vector<int>, // eye params (rows, cols, diag_shift)
ElementType, // Net precision
TargetDevice>; // Device name
using EyeLayerCPUTestParamsSet = std::tuple<
CPULayerTestsDefinitions::EyeLayerTestParams,
CPUSpecificParams>;
class EyeLayerCPUTest : public testing::WithParamInterface<EyeLayerCPUTestParamsSet>,
virtual public SubgraphBaseTest, public CPUTestsBase {
public:
static std::string getTestCaseName(testing::TestParamInfo<EyeLayerCPUTestParamsSet> obj) {
CPULayerTestsDefinitions::EyeLayerTestParams basicParamsSet;
CPUSpecificParams cpuParams;
std::tie(basicParamsSet, cpuParams) = obj.param;
std::string td;
ElementType netPr;
std::vector<int> eyePar;
std::tie(inputShape, outBatchShape, eyePar, netPr, td) = basicParamsSet;
std::ostringstream result;
result << "EyeTest_";
result << "IS=(";
for (const auto& shape : inputShape) {
result << CommonTestUtils::partialShape2str({shape.first}) << "_";
}
result << ")_TS=(";
for (const auto& shape : inputShape) {
for (const auto& item : shape.second) {
result << CommonTestUtils::vec2str(item) << "_";
}
}
result << "rowNum=" << eyePar[0] << "_";
result << "colNum=" << eyePar[1] << "_";
result << "diagShift=" << eyePar[2] << "_";
result << "batchShape=" << CommonTestUtils::vec2str(outBatchShape) << "_";
result << netPr << "_";
result << CPUTestsBase::getTestCaseName(cpuParams) << "_";
result << std::to_string(obj.index);
return result.str();
}
protected:
void SetUp() override {
CPULayerTestsDefinitions::EyeLayerTestParams basicParamsSet;
CPUSpecificParams cpuParams;
std::tie(basicParamsSet, cpuParams) = this->GetParam();
std::tie(inFmts, outFmts, priority, selectedType) = cpuParams;
ElementType netPrecision;
std::vector<int> eyePar;
std::tie(inputShape, outBatchShape, eyePar, netPrecision, targetDevice) = basicParamsSet;
rowNum = eyePar[0];
colNum = eyePar[1];
shift = eyePar[2];
init_input_shapes(inputShape);
selectedType = std::string("ref_I32");
function = createFunction();
}
std::shared_ptr<ngraph::Function> createFunction() {
auto inputParams = ngraph::builder::makeDynamicParams(ngraph::element::i32, inputDynamicShapes);
auto rowsPar = inputParams[0];
rowsPar->set_friendly_name("rows");
auto colsPar = inputParams[1];
colsPar->set_friendly_name("cols");
auto diagPar = inputParams[2];
diagPar->set_friendly_name("diagInd");
if (inputParams.size() == 4) {
auto batchShapePar = inputParams[3];
batchShapePar->set_friendly_name("batchShape");
auto eyelikeBatchShape = std::make_shared<ngraph::op::v9::Eye>(rowsPar, colsPar, diagPar, batchShapePar, ngraph::element::i32);
eyelikeBatchShape->get_rt_info() = getCPUInfo();
return makeNgraphFunction(ngraph::element::i32, inputParams, eyelikeBatchShape, "Eye");
} else {
auto eyelikePure = std::make_shared<ngraph::op::v9::Eye>(rowsPar, colsPar, diagPar, ngraph::element::i32);
eyelikePure->get_rt_info() = getCPUInfo();
return makeNgraphFunction(ngraph::element::i32, inputParams, eyelikePure, "Eye");
}
}
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
inputs.clear();
const auto& funcInputs = function->inputs();
for (int i = 0; i < funcInputs.size(); ++i) {
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;
if (i == 3) { // batch shape
tensor = ov::Tensor(funcInput.get_element_type(), targetInputStaticShapes[i]);
int *batchShapePtr = tensor.data<int>();
for (size_t j = 0; j < targetInputStaticShapes[i].size(); j++) {
batchShapePtr[j] = outBatchShape[j];
}
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 1,
(i == 0 ? rowNum : (i == 1 ? colNum : shift)));
}
inputs.insert({funcInput.get_node_shared_ptr(), tensor});
}
}
};
TEST_P(EyeLayerCPUTest, CompareWithRefs) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
run();
CheckPluginRelatedResults(compiledModel, "Eye");
}
namespace {
const std::vector<ElementType> netPrecisions = {
ElementType::f32, ElementType::bf16, ElementType::i32,
ElementType::i8, ElementType::u8
};
const std::vector<std::vector<int>> eyePars = { // rows, cols, diag_shift
{3, 3, 0},
{3, 4, 1},
{4, 3, 1},
{3, 4, 0},
{4, 3, 0},
{3, 4, -1},
{4, 3, -1},
{3, 4, 10},
{4, 4, -2},
{0, 0, 0}
};
// dummy parameter to prevent empty set of test cases
const std::vector<std::vector<int>> emptyBatchShape = {{0}};
const std::vector<std::vector<int>> batchShapes1D = {
{3}, {2}, {1}, {0}
};
const std::vector<std::vector<int>> batchShapes2D = {
{3, 2}, {2, 1}, {0, 0}
};
// Ticket: 85127
// const std::vector<std::vector<int>> batchShapes3D = {
// {3, 2, 1}, {1, 1, 1}
// };
INSTANTIATE_TEST_SUITE_P(smoke_Eye2D_PureScalar_Test, EyeLayerCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(static_shapes_to_test_representation(
std::vector<std::vector<ov::Shape>> {{{}, {}, {}}})),
::testing::ValuesIn(emptyBatchShape),
::testing::ValuesIn(eyePars),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
EyeLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Eye2D_WithNonScalar_Test, EyeLayerCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(static_shapes_to_test_representation(
std::vector<std::vector<ov::Shape>> {{{1}, {1}, {1}}})),
::testing::ValuesIn(emptyBatchShape),
::testing::ValuesIn(eyePars),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
EyeLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Eye_1DBatch_Test, EyeLayerCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(static_shapes_to_test_representation(
std::vector<std::vector<ov::Shape>> {{{}, {}, {}, {1}}})),
::testing::ValuesIn(batchShapes1D),
::testing::ValuesIn(eyePars),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
EyeLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Eye_2DBatch_Test, EyeLayerCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(static_shapes_to_test_representation(
std::vector<std::vector<ov::Shape>> {{{}, {}, {}, {2}}})),
::testing::ValuesIn(batchShapes2D),
::testing::ValuesIn(eyePars),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
EyeLayerCPUTest::getTestCaseName);
// Ticket: 85127
// INSTANTIATE_TEST_SUITE_P(smoke_Eye_3DBatch_Test, EyeLayerCPUTest,
// ::testing::Combine(
// ::testing::Combine(
// ::testing::ValuesIn(static_shapes_to_test_representation(
// std::vector<std::vector<ov::Shape>> {{{}, {}, {}, {3}}})),
// ::testing::ValuesIn(batchShapes3D),
// ::testing::ValuesIn(eyePars),
// ::testing::ValuesIn(netPrecisions),
// ::testing::Values(CommonTestUtils::DEVICE_CPU)),
// ::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
// EyeLayerCPUTest::getTestCaseName);
const std::vector<std::vector<InputShape>> dynShapes = {
{
{{-1}, {{1}, {1}}}, // input 0
{{-1}, {{1}, {1}}}, // input 1
{{-1}, {{1}, {1}}} // input 2
},
};
const std::vector<std::vector<InputShape>> dynShapesWith2DBatches = {
{
{{-1}, {{1}, {1}, {1}}}, // input 0
{{-1}, {{1}, {1}, {1}}}, // input 1
{{-1}, {{1}, {1}, {1}}}, // input 2
{{2}, {{2}, {2}, {2}}} // input 3
},
};
// Ticket: 85127
// const std::vector<std::vector<InputShape>> dynShapesWith3DBatches = {
// {
// {{-1}, {{1}, {1}, {1}}}, // input 0
// {{-1}, {{1}, {1}, {1}}}, // input 1
// {{-1}, {{1}, {1}, {1}}}, // input 2
// {{3}, {{3}, {3}, {3}}} // input 3
// },
// };
INSTANTIATE_TEST_SUITE_P(smoke_Eye_Dynamic_Test, EyeLayerCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(dynShapes),
::testing::ValuesIn(emptyBatchShape),
::testing::ValuesIn(eyePars),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
EyeLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Eye_With2DBatchShape_Dynamic_Test, EyeLayerCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(dynShapesWith2DBatches),
::testing::ValuesIn(batchShapes2D),
::testing::ValuesIn(eyePars),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
EyeLayerCPUTest::getTestCaseName);
// Ticket: 85127
// INSTANTIATE_TEST_SUITE_P(smoke_Eye_With3DBatchShape_Dynamic_Test, EyeLayerCPUTest,
// ::testing::Combine(
// ::testing::Combine(
// ::testing::ValuesIn(dynShapesWith3DBatches),
// ::testing::ValuesIn(batchShapes3D),
// ::testing::ValuesIn(eyePars),
// ::testing::ValuesIn(netPrecisions),
// ::testing::Values(CommonTestUtils::DEVICE_CPU)),
// ::testing::Values(CPUSpecificParams{{}, {}, {}, {}})),
// EyeLayerCPUTest::getTestCaseName);
} // namespace
} // namespace CPULayerTestsDefinitions
@@ -367,6 +367,17 @@ std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v3::ExtractIma
return std::make_shared<ov::Model>(results, params, "ExtractImagePatches");
}
std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v9::Eye> &node) {
const auto params = ngraph::builder::makeDynamicParams(ov::element::i64, {{1}, {1}, {1}, {3}});
const auto eye = std::make_shared<ov::op::v9::Eye>(params[0],
params[1],
params[2],
params[3],
ov::element::f32);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(eye)};
return std::make_shared<ov::Model>(results, params, "Eye");
}
std::shared_ptr<ov::Model> generate(const std::shared_ptr<ov::op::v0::FakeQuantize> &node) {
const auto params = ngraph::builder::makeDynamicParams(ov::element::f16, {{1, 2, 3, 4}});
const auto input_low = ngraph::builder::makeConstant<float16>(ov::element::f16, {}, {0.f});
@@ -704,6 +704,7 @@ InputsMap getInputMap() {
#include "ngraph/opsets/opset6_tbl.hpp"
#include "ngraph/opsets/opset7_tbl.hpp"
#include "ngraph/opsets/opset8_tbl.hpp"
#include "ngraph/opsets/opset9_tbl.hpp"
#undef NGRAPH_OP
};