Skip to content

Commit

Permalink
[CPU tests] migrate single layer test cases to be API 2.0 - part 4 (o…
Browse files Browse the repository at this point in the history
…penvinotoolkit#21488)

* [CPU tests] migrate single layer test cases to be API 2.0 - part 4

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [CPU tests] fix test error

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [CPU Func Test] revert single_layer_tests/group_convolution_backprop_data.cpp change

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

---------

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
  • Loading branch information
zhaixuejun1993 authored Dec 7, 2023
1 parent 23424ab commit e393678
Show file tree
Hide file tree
Showing 12 changed files with 1,552 additions and 1,606 deletions.
1,163 changes: 560 additions & 603 deletions src/plugins/intel_cpu/tests/functional/single_layer_tests/gather.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,26 @@
// SPDX-License-Identifier: Apache-2.0
//

#include "common_test_utils/ov_tensor_utils.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "ov_models/builders.hpp"
#include <common_test_utils/ov_tensor_utils.hpp>
#include "test_utils/cpu_test_utils.hpp"

using namespace ov::test;
using namespace ngraph;
using namespace CPUTestUtils;
using namespace InferenceEngine;
using namespace ngraph::helpers;

namespace CPULayerTestsDefinitions {
namespace ov {
namespace test {
using GatherElementsParams = std::tuple<std::vector<InputShape>, // Dynamic shape + Target static shapes
int, // Axis
ElementType, // Data precision
ElementType, // Indices precision
TargetDevice // Device name
>;

using GatherElementsParams = std::tuple<
std::vector<InputShape>, // Dynamic shape + Target static shapes
int, // Axis
ElementType, // Data precision
ElementType, // Indices precision
TargetDevice // Device name
>;

using GatherElementsCPUTestParamSet = std::tuple<
GatherElementsParams,
CPUSpecificParams
>;
using GatherElementsCPUTestParamSet = std::tuple<GatherElementsParams, CPUSpecificParams>;

class GatherElementsCPUTest : public testing::WithParamInterface<GatherElementsCPUTestParamSet>,
virtual public ov::test::SubgraphBaseTest, public CPUTestsBase {
virtual public ov::test::SubgraphBaseTest,
public CPUTestsBase {
public:
static std::string getTestCaseNameCommon(const testing::TestParamInfo<GatherElementsParams>& obj) {
std::vector<InputShape> shapes;
Expand Down Expand Up @@ -57,7 +49,7 @@ class GatherElementsCPUTest : public testing::WithParamInterface<GatherElementsC
return result.str();
}

static std::string getTestCaseName(const testing::TestParamInfo<GatherElementsCPUTestParamSet> &obj) {
static std::string getTestCaseName(const testing::TestParamInfo<GatherElementsCPUTestParamSet>& obj) {
GatherElementsParams basicParamsSet;
CPUSpecificParams cpuParams;
std::tie(basicParamsSet, cpuParams) = obj.param;
Expand All @@ -70,14 +62,18 @@ class GatherElementsCPUTest : public testing::WithParamInterface<GatherElementsC
return result.str();
}

void generate_inputs(const std::vector<ngraph::Shape>& targetInputStaticShapes) override {
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
inputs.clear();
const auto& funcInputs = function->inputs();
for (size_t i = 0; i < funcInputs.size(); ++i) {
const auto& funcInput = funcInputs[i];
ov::Tensor tensor;

tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i], 15, 0, 32768);
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(),
targetInputStaticShapes[i],
15,
0,
32768);

inputs.insert({funcInput.get_node_shared_ptr(), tensor});
}
Expand All @@ -98,13 +94,12 @@ class GatherElementsCPUTest : public testing::WithParamInterface<GatherElementsC
selectedType = std::string("ref_any_") + ov::element::Type(dPrecision).get_type_name();
init_input_shapes(shapes);

ngraph::ParameterVector params = {
std::make_shared<ngraph::opset1::Parameter>(dPrecision, inputDynamicShapes[0]),
std::make_shared<ngraph::opset1::Parameter>(iPrecision, inputDynamicShapes[1]),
ov::ParameterVector params = {
std::make_shared<ov::op::v0::Parameter>(dPrecision, inputDynamicShapes[0]),
std::make_shared<ov::op::v0::Parameter>(iPrecision, inputDynamicShapes[1]),
};

auto gather = std::make_shared<ngraph::op::v6::GatherElements>(
params[0], params[1], axis);
auto gather = std::make_shared<ov::op::v6::GatherElements>(params[0], params[1], axis);
function = makeNgraphFunction(dPrecision, params, gather, "GatherElements");
}
};
Expand All @@ -114,27 +109,24 @@ TEST_P(GatherElementsCPUTest, CompareWithRefs) {
}

namespace {
std::vector<CPUSpecificParams> cpuParams_4D = {
CPUSpecificParams({nchw}, {nchw}, {}, {})
};
std::vector<CPUSpecificParams> cpuParams_4D = {CPUSpecificParams({nchw}, {nchw}, {}, {})};

const std::vector<std::vector<InputShape>> inDynamicShapeParams = {
{{{-1, -1, -1, -1}, {{2, 3, 5, 7}, {3, 4, 6, 8}}},
{{-1, -1, -1, -1}, {{2, 3, 9, 7}, {3, 4, 4, 8}}}},
{{{-1, -1, -1, -1}, {{2, 3, 5, 7}, {3, 4, 6, 8}}}, {{-1, -1, -1, -1}, {{2, 3, 9, 7}, {3, 4, 4, 8}}}},
{{{{1, 10}, {1, 10}, {1, 10}, {1, 10}}, {{3, 4, 6, 8}, {2, 3, 5, 7}}},
{{{1, 10}, {1, 10}, {1, 10}, {1, 10}}, {{3, 4, 4, 8}, {2, 3, 9, 7}}}}
};

INSTANTIATE_TEST_SUITE_P(smoke_set1, GatherElementsCPUTest,
::testing::Combine(
::testing::Combine(
::testing::ValuesIn(inDynamicShapeParams), // shape
::testing::ValuesIn(std::vector<int>({2, -2})), // Axis
::testing::ValuesIn(std::vector<ElementType>({ElementType::bf16, ElementType::f32})),
::testing::Values(ElementType::i32),
::testing::Values(ov::test::utils::DEVICE_CPU)),
::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D))),
GatherElementsCPUTest::getTestCaseName);

} // namespace
} // namespace CPULayerTestsDefinitions
{{{1, 10}, {1, 10}, {1, 10}, {1, 10}}, {{3, 4, 4, 8}, {2, 3, 9, 7}}}}};

INSTANTIATE_TEST_SUITE_P(smoke_set1,
GatherElementsCPUTest,
::testing::Combine(::testing::Combine(::testing::ValuesIn(inDynamicShapeParams), // shape
::testing::ValuesIn(std::vector<int>({2, -2})), // Axis
::testing::ValuesIn(std::vector<ElementType>(
{ElementType::bf16, ElementType::f32})),
::testing::Values(ElementType::i32),
::testing::Values(ov::test::utils::DEVICE_CPU)),
::testing::ValuesIn(filterCPUSpecificParams(cpuParams_4D))),
GatherElementsCPUTest::getTestCaseName);

} // namespace
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
// SPDX-License-Identifier: Apache-2.0
//

#include <shared_test_classes/single_layer/gather_nd.hpp>
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "ov_models/builders.hpp"

using namespace InferenceEngine;
using namespace ov;
using namespace test;
namespace ov {
namespace test {

namespace CPULayerTestsDefinitions {

using GatherNDLayerCPUTestParamSet = std::tuple<
InputShape, // Input shapes
std::pair<Shape, std::vector<int>>, // Indexes shape and values
ElementType, // Input element type
ElementType, // Indices element type
int // Batch dims
>;
using GatherNDLayerCPUTestParamSet = std::tuple<InputShape, // Input shapes
std::pair<Shape, std::vector<int>>, // Indexes shape and values
ElementType, // Input element type
ElementType, // Indices element type
int // Batch dims
>;

class GatherNDLayerCPUTest : public testing::WithParamInterface<GatherNDLayerCPUTestParamSet>,
virtual public SubgraphBaseTest {
Expand All @@ -42,7 +36,7 @@ class GatherNDLayerCPUTest : public testing::WithParamInterface<GatherNDLayerCPU
results << "BD=" << batchDims << "_";

return results.str();
}
}

protected:
void SetUp() override {
Expand All @@ -59,10 +53,10 @@ class GatherNDLayerCPUTest : public testing::WithParamInterface<GatherNDLayerCPU
for (auto&& shape : inputDynamicShapes) {
params.push_back(std::make_shared<ov::op::v0::Parameter>(dataElementType, shape));
}
auto indexes_node = ngraph::opset3::Constant::create(idxElementType, indexes.first, indexes.second);
auto gather_nd = std::make_shared<ngraph::opset5::GatherND>(params[0], indexes_node, batchDims);
ngraph::ResultVector results{std::make_shared<ngraph::opset3::Result>(gather_nd)};
function = std::make_shared<ngraph::Function>(results, params, "gatherND");
auto indexes_node = ov::op::v0::Constant::create(idxElementType, indexes.first, indexes.second);
auto gather_nd = std::make_shared<ov::op::v5::GatherND>(params[0], indexes_node, batchDims);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(gather_nd)};
function = std::make_shared<ov::Model>(results, params, "gatherND");
}
};

Expand All @@ -88,10 +82,10 @@ class GatherND8LayerCPUTest : public testing::WithParamInterface<GatherNDLayerCP
for (auto&& shape : inputDynamicShapes) {
params.push_back(std::make_shared<ov::op::v0::Parameter>(dataElementType, shape));
}
auto indexes_node = ngraph::opset3::Constant::create(idxElementType, indexes.first, indexes.second);
auto gather_nd = std::make_shared<ngraph::opset8::GatherND>(params[0], indexes_node, batchDims);
ngraph::ResultVector results{std::make_shared<ngraph::opset3::Result>(gather_nd)};
function = std::make_shared<ngraph::Function>(results, params, "gatherND");
auto indexes_node = ov::op::v0::Constant::create(idxElementType, indexes.first, indexes.second);
auto gather_nd = std::make_shared<ov::op::v8::GatherND>(params[0], indexes_node, batchDims);
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(gather_nd)};
function = std::make_shared<ov::Model>(results, params, "gatherND");
}
};

Expand All @@ -105,91 +99,100 @@ TEST_P(GatherND8LayerCPUTest, CompareWithRefs) {

namespace {

const std::vector<ElementType> inputPrecisions = {
ElementType::f32,
ElementType::bf16,
ElementType::i8
};
const std::vector<ElementType> inputPrecisions = {ElementType::f32, ElementType::bf16, ElementType::i8};

const std::vector<ElementType> indexesPrecisions = {
ElementType::i32
};
const std::vector<ElementType> indexesPrecisions = {ElementType::i32};

const std::vector<InputShape> inputShapesDynamicBD_0 = {
{{-1, -1, -1}, // dynamic
{{5, 10, 5}, {4, 12, 4}, {4, 12, 4}, {5, 5, 5}}}, // target
{{-1, -1, -1}, // dynamic
{{5, 10, 5}, {4, 12, 4}, {4, 12, 4}, {5, 5, 5}}}, // target

{{-1, 5, -1, -1}, // dynamic
{{8, 5, 5, 5}, {5, 5, 8, 4}, {4, 5, 4, 5}}}, // target
{{-1, 5, -1, -1}, // dynamic
{{8, 5, 5, 5}, {5, 5, 8, 4}, {4, 5, 4, 5}}}, // target

{{{4, 10}, {5, 10}, {5, 10}, {5, 10}, {5, 10}}, // dynamic
{{4, 5, 5, 5, 5}, {4, 5, 5, 8, 5}, {10, 8, 5, 5, 5}}}, // target
{{{4, 10}, {5, 10}, {5, 10}, {5, 10}, {5, 10}}, // dynamic
{{4, 5, 5, 5, 5}, {4, 5, 5, 8, 5}, {10, 8, 5, 5, 5}}}, // target
};

const std::vector<std::pair<Shape, std::vector<int>>> indexesShapesBD_0 = {
std::pair<Shape, std::vector<int>>{{2, 2}, {3, 3, 2, 1}},
std::pair<Shape, std::vector<int>>{{1, 2, 3}, {0, 1, 1, 1, 0, 2}},
std::pair<Shape, std::vector<int>>{{2, 1, 1, 2}, {0, 2, 1, 1}},
std::pair<Shape, std::vector<int>>{{2, 2}, {3, 3, 2, 1}},
std::pair<Shape, std::vector<int>>{{1, 2, 3}, {0, 1, 1, 1, 0, 2}},
std::pair<Shape, std::vector<int>>{{2, 1, 1, 2}, {0, 2, 1, 1}},
};

const auto subset_BD0 = ::testing::Combine(
::testing::ValuesIn(inputShapesDynamicBD_0),
::testing::ValuesIn(indexesShapesBD_0),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(indexesPrecisions),
::testing::Values(0));

INSTANTIATE_TEST_SUITE_P(smoke_GatherND5DynamicBD_0, GatherNDLayerCPUTest, subset_BD0, GatherNDLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GatherND8DynamicBD_0, GatherND8LayerCPUTest, subset_BD0, GatherNDLayerCPUTest::getTestCaseName);
const auto subset_BD0 = ::testing::Combine(::testing::ValuesIn(inputShapesDynamicBD_0),
::testing::ValuesIn(indexesShapesBD_0),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(indexesPrecisions),
::testing::Values(0));

INSTANTIATE_TEST_SUITE_P(smoke_GatherND5DynamicBD_0,
GatherNDLayerCPUTest,
subset_BD0,
GatherNDLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GatherND8DynamicBD_0,
GatherND8LayerCPUTest,
subset_BD0,
GatherNDLayerCPUTest::getTestCaseName);

const std::vector<InputShape> inputShapesDynamicBD_1 = {
{{3, -1, -1}, // dynamic
{{3, 10, 5}, {3, 10, 5}, {3, 12, 8}, {3, 8, 8}}}, // target
{{3, -1, -1}, // dynamic
{{3, 10, 5}, {3, 10, 5}, {3, 12, 8}, {3, 8, 8}}}, // target

{{3, {5, 10}, {5, 10}, {5, 10}, {5, 10}}, // dynamic
{{3, 5, 5, 5, 5}, {3, 8, 10, 10, 10}, {3, 8, 6, 8, 7}}}, // target
{{3, {5, 10}, {5, 10}, {5, 10}, {5, 10}}, // dynamic
{{3, 5, 5, 5, 5}, {3, 8, 10, 10, 10}, {3, 8, 6, 8, 7}}}, // target
};

const std::vector<std::pair<Shape, std::vector<int>>> indexesShapesBD_1 = {
std::pair<Shape, std::vector<int>>{{3, 2}, {0, 1, 2, 1, 0, 0}},
std::pair<Shape, std::vector<int>>{{3, 2, 2}, {0, 1, 1, 1, 0, 2, 0, 1, 1, 1, 0, 2}},
std::pair<Shape, std::vector<int>>{{3, 1, 1, 2}, {0, 2, 1, 1, 0, 2}},
std::pair<Shape, std::vector<int>>{{3, 2}, {0, 1, 2, 1, 0, 0}},
std::pair<Shape, std::vector<int>>{{3, 2, 2}, {0, 1, 1, 1, 0, 2, 0, 1, 1, 1, 0, 2}},
std::pair<Shape, std::vector<int>>{{3, 1, 1, 2}, {0, 2, 1, 1, 0, 2}},
};

const auto subset_BD1 = ::testing::Combine(
::testing::ValuesIn(inputShapesDynamicBD_1),
::testing::ValuesIn(indexesShapesBD_1),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(indexesPrecisions),
::testing::Values(0));

INSTANTIATE_TEST_SUITE_P(smoke_GatherND5DynamicBD_1, GatherNDLayerCPUTest, subset_BD1, GatherNDLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GatherND8DynamicBD_1, GatherND8LayerCPUTest, subset_BD1, GatherNDLayerCPUTest::getTestCaseName);
const auto subset_BD1 = ::testing::Combine(::testing::ValuesIn(inputShapesDynamicBD_1),
::testing::ValuesIn(indexesShapesBD_1),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(indexesPrecisions),
::testing::Values(0));

INSTANTIATE_TEST_SUITE_P(smoke_GatherND5DynamicBD_1,
GatherNDLayerCPUTest,
subset_BD1,
GatherNDLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GatherND8DynamicBD_1,
GatherND8LayerCPUTest,
subset_BD1,
GatherNDLayerCPUTest::getTestCaseName);

const std::vector<InputShape> inputShapesDynamicBD_2 = {
{{2, 2, -1, -1, -1}, // dynamic
{{2, 2, 5, 6, 5}, {2, 2, 2, 3, 3}, {2, 2, 2, 3, 3}, {2, 2, 7, 2, 3}}}, // target
{{2, 2, -1, -1, -1}, // dynamic
{{2, 2, 5, 6, 5}, {2, 2, 2, 3, 3}, {2, 2, 2, 3, 3}, {2, 2, 7, 2, 3}}}, // target

{{2, 2, {5, 10}, {5, 10}, {5, 10}}, // dynamic
{{2, 2, 5, 5, 5}, {2, 2, 10, 10, 5}, {2, 2, 7, 8, 7}}}, // target
{{2, 2, {5, 10}, {5, 10}, {5, 10}}, // dynamic
{{2, 2, 5, 5, 5}, {2, 2, 10, 10, 5}, {2, 2, 7, 8, 7}}}, // target
};

const std::vector<std::pair<Shape, std::vector<int>>> indexesShapesBD_2 = {
std::pair<Shape, std::vector<int>>{{2, 2, 3}, {0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0}},
std::pair<Shape, std::vector<int>>{{2, 2, 2, 3}, {0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0,
0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0}},
std::pair<Shape, std::vector<int>>{{2, 2, 3}, {0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0}},
std::pair<Shape, std::vector<int>>{{2, 2, 2, 3},
{0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0}},
};

const auto subset_BD2 = ::testing::Combine(
::testing::ValuesIn(inputShapesDynamicBD_2),
::testing::ValuesIn(indexesShapesBD_2),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(indexesPrecisions),
::testing::Values(0));

INSTANTIATE_TEST_SUITE_P(smoke_GatherND5DynamicBD_2, GatherNDLayerCPUTest, subset_BD2, GatherNDLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GatherND8DynamicBD_2, GatherND8LayerCPUTest, subset_BD2, GatherNDLayerCPUTest::getTestCaseName);

const auto subset_BD2 = ::testing::Combine(::testing::ValuesIn(inputShapesDynamicBD_2),
::testing::ValuesIn(indexesShapesBD_2),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(indexesPrecisions),
::testing::Values(0));

INSTANTIATE_TEST_SUITE_P(smoke_GatherND5DynamicBD_2,
GatherNDLayerCPUTest,
subset_BD2,
GatherNDLayerCPUTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_GatherND8DynamicBD_2,
GatherND8LayerCPUTest,
subset_BD2,
GatherNDLayerCPUTest::getTestCaseName);

} // namespace
} // namespace CPULayerTestsDefinitions
} // namespace test
} // namespace ov
Loading

0 comments on commit e393678

Please sign in to comment.