Skip to content

Commit

Permalink
[CPU][IE TESTS] Added VariadicSplit and Pad subgraph tests (openvinot…
Browse files Browse the repository at this point in the history
…oolkit#4583)

* [IE TESTS] Added VariadicSplit and Pad subgraph tests

* Added more connectedIndexes
  • Loading branch information
a-sidorova authored Mar 18, 2021
1 parent 5bb8571 commit 704278e
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "subgraph_tests/variadic_split_pad.hpp"

using namespace SubgraphTestsDefinitions;

namespace {

const std::vector<InferenceEngine::Precision> netPrecision = {
InferenceEngine::Precision::FP32
};

const std::vector<InferenceEngine::SizeVector> shapes = {
{1, 8, 3, 2},
{3, 8, 8, 8},
};

const std::vector<std::vector<size_t>> connectedIndexes = {
{0},
{0, 2},
{0, 1, 3},
{0, 1, 1, 0},
{0, 0, 0, 1},
};

const std::vector<std::vector<size_t>> numSplits = {
{2, 2, 2, 2},
{1, 2, 4, 1},
{3, 2, 2, 1}
};

const std::vector<std::vector<int64_t>> padsBegin = {
{0, 0, 0, 0},
{0, 0, 1, 1},
};

const std::vector<std::vector<int64_t>> padsEnd = {
{0, 0, 0, 0},
{0, 0, 1, 1},
};

const std::vector<ngraph::helpers::PadMode> padMode = {
ngraph::helpers::PadMode::CONSTANT,
ngraph::helpers::PadMode::EDGE,
ngraph::helpers::PadMode::REFLECT,
ngraph::helpers::PadMode::SYMMETRIC
};

INSTANTIATE_TEST_CASE_P(smoke_CPU, VariadicSplitPad,
::testing::Combine(
::testing::ValuesIn(shapes),
::testing::Values(1),
::testing::ValuesIn(numSplits),
::testing::ValuesIn(connectedIndexes),
::testing::ValuesIn(padsBegin),
::testing::ValuesIn(padsEnd),
::testing::ValuesIn(padMode),
::testing::ValuesIn(netPrecision),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
VariadicSplitPad::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once

#include "shared_test_classes/subgraph/variadic_split_pad.hpp"

namespace SubgraphTestsDefinitions {

TEST_P(VariadicSplitPad, CompareWithRefs){
Run();
};

} // namespace SubgraphTestsDefinitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <tuple>
#include <string>
#include <vector>

#include "shared_test_classes/base/layer_test_utils.hpp"
#include "ngraph_functions/builders.hpp"

namespace SubgraphTestsDefinitions {

typedef std::tuple<
InferenceEngine::SizeVector, // Input shapes
size_t, // Axis
std::vector<size_t>, // Split number
std::vector<size_t>, // Index connected layer
std::vector<int64_t>, // Pad begin
std::vector<int64_t>, // Pad end
ngraph::helpers::PadMode, // Pad mode
InferenceEngine::Precision, // Network precision
std::string // Device name
> SplitPadTuple;


class VariadicSplitPad: public testing::WithParamInterface<SplitPadTuple>,
public LayerTestsUtils::LayerTestsCommon{
public:
static std::string getTestCaseName(const testing::TestParamInfo<SplitPadTuple> &obj);
protected:
void SetUp() override;
};
} // namespace SubgraphTestsDefinitions
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "shared_test_classes/subgraph/variadic_split_pad.hpp"

namespace SubgraphTestsDefinitions {

std::string VariadicSplitPad::getTestCaseName(const testing::TestParamInfo<SplitPadTuple> &obj) {
InferenceEngine::SizeVector inputShape;
size_t axis;
std::vector<size_t> numSplits, connectIndexes;
std::vector<int64_t> padsBegin, padsEnd;
ngraph::helpers::PadMode padMode;
InferenceEngine::Precision netPrecision;
std::string targetName;
std::tie(inputShape, axis, numSplits, connectIndexes, padsBegin, padsEnd, padMode, netPrecision, targetName) = obj.param;
std::ostringstream results;

results << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
results << "Axis=" << axis << "_";
results << "NumSplits=" << CommonTestUtils::vec2str(numSplits) << "_";
results << "ConnectIndexes=" << CommonTestUtils::vec2str(connectIndexes) << "_";
results << "padsBegin=" << CommonTestUtils::vec2str(padsBegin) << "_";
results << "padsEnd=" << CommonTestUtils::vec2str(padsEnd) << "_";
results << "PadMode=" << padMode << "_";
results << "netPRC=" << netPrecision.name() << "_";
results << "targetDevice=" << targetName << "_";
return results.str();
}

void VariadicSplitPad::SetUp() {
InferenceEngine::SizeVector inputs;
size_t axis;
std::vector<size_t> numSplits, connectIndexes;
std::vector<int64_t> padBegin, padEnd;
ngraph::helpers::PadMode padMode;
InferenceEngine::Precision netPrecision;
std::tie(inputs, axis, numSplits, connectIndexes, padBegin, padEnd, padMode, netPrecision, targetDevice) = this->GetParam();
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto input = ngraph::builder::makeParams(ngPrc, {inputs});
auto split = ngraph::builder::makeVariadicSplit(input[0], numSplits, axis);
ngraph::ResultVector results;

for (size_t i : connectIndexes) {
auto pad = ngraph::builder::makePad(split->output(i), padBegin, padEnd, 0, padMode);
results.push_back(std::make_shared<ngraph::opset1::Result>(pad));
}
function = std::make_shared<ngraph::Function>(results, input, "variadic_split_pad");
}
} // namespace SubgraphTestsDefinitions

0 comments on commit 704278e

Please sign in to comment.