GatherND_8 reference implementation (#8257)

* Add GatherND_8 operation

* Update shape infer function and tests

* Initial commit for nGraph GatherND_8 operation

* Add GatherNDBase class implementation

* Fix base class errors

* Add missrd header

* Update base class

* Update GatherND_8 implementation

* Fix codestyle

* Fix wrong rank

* Implement tests for gatherND_8 shape inference function

* fix codestyle

* Add limitation to doc

* Siplyfy check in shape inference

* Add more test cases

* Update shape inference function

* Add more test cases to cover all case with dynamic input shapes

* Update shape inference function

* Refactor tests

* Initial commit for gatherND_8 reference implementation

* Add visitor tests for gatherND_8 operation

* Add visitor tests for gatherND_8 operation

* Correct comment

* Add additional check is shape inference function

* Update shape inference implementation for gathernd operartion

* Fix codestyle

* Remove restriction for data is fully defined

* Update shape inference functon

* Add gatherND_8 reference to evaluate map

* Add tests for gathernd_8 reference in batch_dims > 1

* Fix codestyle

* Fix codestyle

* Fix missed check for nonetype

* Remove redundant checks for batch_dims

* Use get_shape method instead of get_input_shape in GatherND reference implementation call

* update reference implementation call

* Properly add GatherND_8 to test opset table

* Update GatherND reference implementation for support opset8 version

* Add unit tests for gatherND_8 reference implementation

* Update gatherND reference implementation call in evaluate map

* Mark failed tests for missed plugin gatherND_8 implementations

* Fix codestyle

* Fix codestyle

* Fix codestyle

* Update tests

* Move common methods to base class

* Fix codestyle

* Revert clone_with_new_input function moving

* Add more test for reference

* partially revert API changes
This commit is contained in:
Anton Chetverikov
2021-11-16 10:58:06 +03:00
committed by GitHub
parent b6bdc4a567
commit d0f16d205a
9 changed files with 250 additions and 35 deletions

View File

@@ -25,7 +25,7 @@ struct GatherNDParams {
std::string testcaseName;
};
class ReferenceGatherNDTest : public testing::TestWithParam<GatherNDParams>, public CommonReferenceTest {
class ReferenceGatherND5Test : public testing::TestWithParam<GatherNDParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
@@ -59,18 +59,18 @@ private:
PartialShape{params.dataTensor.shape});
const auto indices = std::make_shared<op::v0::Parameter>(params.indicesTensor.type,
PartialShape{params.indicesTensor.shape});
std::shared_ptr<op::v5::GatherND> gatherElement;
std::shared_ptr<op::v5::GatherND> gatherND;
if (params.batchDims == 0) {
gatherElement = std::make_shared<op::v5::GatherND>(data, indices);
gatherND = std::make_shared<op::v5::GatherND>(data, indices);
} else {
gatherElement = std::make_shared<op::v5::GatherND>(data, indices, params.batchDims);
gatherND = std::make_shared<op::v5::GatherND>(data, indices, params.batchDims);
}
function = std::make_shared<ov::Function>(NodeVector {gatherElement}, ParameterVector {data, indices});
function = std::make_shared<ov::Function>(NodeVector {gatherND}, ParameterVector {data, indices});
return function;
}
};
TEST_P(ReferenceGatherNDTest, CompareWithRefs) {
TEST_P(ReferenceGatherND5Test, CompareWithRefs) {
Exec();
}
@@ -203,6 +203,207 @@ std::vector<GatherNDParams> generateCombinedParams() {
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_GatherND_With_Hardcoded_Refs, ReferenceGatherNDTest,
testing::ValuesIn(generateCombinedParams()), ReferenceGatherNDTest::getTestCaseName);
} // namespace
INSTANTIATE_TEST_SUITE_P(smoke_GatherND_With_Hardcoded_Refs, ReferenceGatherND5Test,
testing::ValuesIn(generateCombinedParams()), ReferenceGatherND5Test::getTestCaseName);
class ReferenceGatherND8Test : public testing::TestWithParam<GatherNDParams>, public CommonReferenceTest {
public:
void SetUp() override {
auto params = GetParam();
function = CreateFunction(params);
inputData = {params.dataTensor.data, params.indicesTensor.data};
refOutData = {params.expectedTensor.data};
}
static std::string getTestCaseName(const testing::TestParamInfo<GatherNDParams>& obj) {
auto param = obj.param;
std::ostringstream result;
result << "dType=" << param.dataTensor.type;
result << "_dShape=" << param.dataTensor.shape;
result << "_aType=" << param.indicesTensor.type;
result << "_aShape=" << param.indicesTensor.shape;
result << "_bDims=" << param.batchDims;
result << "_eType=" << param.expectedTensor.type;
if (param.testcaseName != "") {
result << "_eShape=" << param.expectedTensor.shape;
result << "_=" << param.testcaseName;
} else {
result << "_eShape=" << param.expectedTensor.shape;
}
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const GatherNDParams& params) {
std::shared_ptr<Function> function;
const auto data = std::make_shared<op::v0::Parameter>(params.dataTensor.type,
PartialShape{params.dataTensor.shape});
const auto indices = std::make_shared<op::v0::Parameter>(params.indicesTensor.type,
PartialShape{params.indicesTensor.shape});
std::shared_ptr<op::v8::GatherND> gatherND;
if (params.batchDims == 0) {
gatherND = std::make_shared<op::v8::GatherND>(data, indices);
} else {
gatherND = std::make_shared<op::v8::GatherND>(data, indices, params.batchDims);
}
function = std::make_shared<ov::Function>(NodeVector {gatherND}, ParameterVector {data, indices});
return function;
}
};
TEST_P(ReferenceGatherND8Test, CompareWithRefs) {
Exec();
}
template <element::Type_t IN_ET>
std::vector<GatherNDParams> generateParams_v8() {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<GatherNDParams> params {
GatherNDParams(
Tensor(IN_ET, {3, 3}, std::vector<T>{10, 11, 12, 13, 14, 15, 16, 17, 18}),
Tensor(element::i32, {2}, std::vector<int32_t>{1, 2}),
0,
Tensor(IN_ET, {}, std::vector<T>{15}),
"gather_nd_8_single_indices"),
GatherNDParams(
Tensor(IN_ET, {2, 2}, std::vector<T>{10, 11, 12, 13}),
Tensor(element::i32, {2, 2}, std::vector<int32_t>{0, 0, 1, 1}),
0,
Tensor(IN_ET, {2}, std::vector<T>{10, 13}),
"gather_nd_8_scalar_from_2d"),
GatherNDParams(
Tensor(IN_ET, {2, 2}, std::vector<T>{10, 11, 12, 13}),
Tensor(element::i32, {2, 1}, std::vector<int32_t>{1, 0}),
0,
Tensor(IN_ET, {2, 2}, std::vector<T>{12, 13, 10, 11}),
"gather_nd_8_1d_from_2d"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {2, 3}, std::vector<int32_t>{0, 0, 1, 1, 0, 1}),
0,
Tensor(IN_ET, {2}, std::vector<T>{11, 21}),
"gather_nd_8_scalar_from_3d"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {2, 2}, std::vector<int32_t>{0, 1, 1, 0}),
0,
Tensor(IN_ET, {2, 2}, std::vector<T>{12, 13, 20, 21}),
"gather_nd_8_1d_from_3d"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {1, 1}, std::vector<int32_t>{1}),
0,
Tensor(IN_ET, {1, 2, 2}, std::vector<T>{20, 21, 22, 23}),
"gather_nd_8_2d_from_3d"),
GatherNDParams(
Tensor(IN_ET, {2, 2}, std::vector<T>{10, 11, 12, 13}),
Tensor(element::i32, {2, 1, 2}, std::vector<int32_t>{0, 0, 0, 1}),
0,
Tensor(IN_ET, {2, 1}, std::vector<T>{10, 11}),
"gather_nd_8_batch_scalar_from_2d"),
GatherNDParams(
Tensor(IN_ET, {2, 2}, std::vector<T>{10, 11, 12, 13}),
Tensor(element::i32, {2, 1, 1}, std::vector<int32_t>{1, 0}),
0,
Tensor(IN_ET, {2, 1, 2}, std::vector<T>{12, 13, 10, 11}),
"gather_nd_8_batch_1d_from_2d"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {2, 2, 3}, std::vector<int32_t>{0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0}),
0,
Tensor(IN_ET, {2, 2}, std::vector<T>{11, 21, 13, 22}),
"gather_nd_8_batch_scalar_from_3d"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {2, 2, 2}, std::vector<int32_t>{0, 1, 1, 0, 0, 0, 1, 1}),
0,
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{12, 13, 20, 21, 10, 11, 22, 23}),
"gather_nd_8_batch_1d_from_3d"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {2, 2, 2}, std::vector<int32_t>{0, -1, -1, 0, 0, 0, 1, 1}),
0,
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{12, 13, 20, 21, 10, 11, 22, 23}),
"gather_nd_8_batch_1d_from_3d_negative"),
GatherNDParams(
Tensor(IN_ET, {2, 2, 2}, std::vector<T>{10, 11, 12, 13, 20, 21, 22, 23}),
Tensor(element::i32, {2, 1, 1}, std::vector<int32_t>{1, 0}),
0,
Tensor(IN_ET, {2, 1, 2, 2}, std::vector<T>{20, 21, 22, 23, 10, 11, 12, 13}),
"gather_nd_8_batch_2d_from_3d"),
GatherNDParams(
Tensor(IN_ET, {2, 3, 4}, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}),
Tensor(element::i32, {2, 1}, std::vector<int32_t>{1, 0}),
1,
Tensor(IN_ET, {2, 4}, std::vector<T>{5, 6, 7, 8, 13, 14, 15, 16}),
"gather_nd_8_batch_dims1"),
GatherNDParams(
Tensor(IN_ET, {2, 3, 4, 2}, std::vector<T>{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48}),
Tensor(element::i32, {2, 3, 3, 2}, std::vector<int32_t>{
1, 0, 3, 1, 2, 1, 0, 1, 1, 1, 2, 0, 3, 0, 3, 1, 2, 1,
2, 0, 1, 1, 3, 1, 1, 1, 2, 0, 2, 0, 0, 0, 3, 1, 3, 1}),
2,
Tensor(IN_ET, {2, 3, 3}, std::vector<T>{
3, 8, 6, 10, 12, 13, 23, 24, 22, 29, 28, 32, 36, 37, 37, 41, 48, 48}),
"gather_8_nd_batch_dims2"),
GatherNDParams(
Tensor(IN_ET, {2, 3, 4}, std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}),
Tensor(element::i32, {2, 3, 1, 1}, std::vector<int32_t>{1, 0, 2, 0, 2, 2}),
2,
Tensor(IN_ET, {2, 3, 1}, std::vector<T>{2, 5, 11, 13, 19, 23}),
"gather_8_nd_batch_dims2_lead_dims"),
GatherNDParams(
Tensor(IN_ET, {2, 3, 4, 5}, std::vector<T>{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
111, 112, 113, 114, 115, 116, 117, 118, 119, 120}),
Tensor(element::i32, {2, 3, 2, 1}, std::vector<int32_t>{
1, 0, 2, 0, 2, 0, 1, 0, 2, 0, 2, 0}),
2,
Tensor(IN_ET, {2, 3, 2, 5}, std::vector<T>{
6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 31, 32, 33, 34, 35, 21, 22, 23,
24, 25, 51, 52, 53, 54, 55, 41, 42, 43, 44, 45, 66, 67, 68, 69,
70, 61, 62, 63, 64, 65, 91, 92, 93, 94, 95, 81, 82, 83, 84, 85,
111, 112, 113, 114, 115, 101, 102, 103, 104, 105}),
"gather_8_nd_batch_dims2_non_scalar_slices"),
};
return params;
}
std::vector<GatherNDParams> generateCombinedParams_v8() {
const std::vector<std::vector<GatherNDParams>> generatedParams {
generateParams_v8<element::Type_t::i8>(),
generateParams_v8<element::Type_t::i16>(),
generateParams_v8<element::Type_t::i32>(),
generateParams_v8<element::Type_t::i64>(),
generateParams_v8<element::Type_t::u8>(),
generateParams_v8<element::Type_t::u16>(),
generateParams_v8<element::Type_t::u32>(),
generateParams_v8<element::Type_t::u64>(),
generateParams_v8<element::Type_t::bf16>(),
generateParams_v8<element::Type_t::f16>(),
generateParams_v8<element::Type_t::f32>(),
generateParams_v8<element::Type_t::f64>(),
};
std::vector<GatherNDParams> combinedParams;
for (const auto& params : generatedParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_GatherND_With_Hardcoded_Refs, ReferenceGatherND8Test,
testing::ValuesIn(generateCombinedParams_v8()), ReferenceGatherND8Test::getTestCaseName);
} // namespace