[GNA] Added tests for negative memory layer offset and split - trivial permute - concat scenario (#2989)
This commit is contained in:
parent
8c89d8d733
commit
a10f71feeb
@ -0,0 +1,41 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <vector>
|
||||
#include "subgraph_tests/negative_memory_layer_offset.hpp"
|
||||
#include "common_test_utils/test_constants.hpp"
|
||||
#include "gna/gna_config.hpp"
|
||||
|
||||
using namespace LayerTestsDefinitions;
|
||||
|
||||
namespace {
|
||||
std::vector<InferenceEngine::Precision> netPrecisions = { InferenceEngine::Precision::FP32,
|
||||
};
|
||||
|
||||
std::map<std::string, std::string> config = {
|
||||
{"GNA_COMPACT_MODE", "NO"}
|
||||
};
|
||||
|
||||
std::vector<size_t> inputSizes = {
|
||||
384,
|
||||
128,
|
||||
64,
|
||||
32
|
||||
};
|
||||
|
||||
std::vector<size_t> hiddenSizes = {
|
||||
384,
|
||||
128,
|
||||
64,
|
||||
32,
|
||||
100
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(smoke_negative_memory_layer_offset, NegativeMemoryOffsetTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(netPrecisions),
|
||||
::testing::Values(CommonTestUtils::DEVICE_GNA),
|
||||
::testing::ValuesIn(inputSizes),
|
||||
::testing::ValuesIn(hiddenSizes),
|
||||
::testing::Values(config)),
|
||||
NegativeMemoryOffsetTest::getTestCaseName);
|
||||
} // namespace
|
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <vector>
|
||||
#include "subgraph_tests/split_trivial_permute_concat.hpp"
|
||||
#include "common_test_utils/test_constants.hpp"
|
||||
#include "gna/gna_config.hpp"
|
||||
|
||||
using namespace LayerTestsDefinitions;
|
||||
|
||||
namespace {
|
||||
std::vector<InferenceEngine::Precision> netPrecisions = { InferenceEngine::Precision::FP32,
|
||||
};
|
||||
|
||||
std::map<std::string, std::string> config = {
|
||||
{"GNA_COMPACT_MODE", "NO"}
|
||||
};
|
||||
|
||||
std::vector<std::vector<size_t>> inputSizes = {
|
||||
{ 4, 2, 64, 6 },
|
||||
{ 4, 16, 4, 128},
|
||||
{ 2, 10, 16, 64},
|
||||
{ 2, 32, 64, 2},
|
||||
};
|
||||
|
||||
std::vector<size_t> split_axes = { 1 }; // only channels split is currently supported by gna for 4d inputs
|
||||
std::vector<size_t> concat_axes = { 1 }; // only channels concat is currently supported by gna for 4d inputs
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(smoke_split_trivial_permute_concat, SplitTrivialPermuteConcatTest,
|
||||
::testing::Combine(
|
||||
::testing::ValuesIn(netPrecisions),
|
||||
::testing::Values(CommonTestUtils::DEVICE_GNA),
|
||||
::testing::ValuesIn(inputSizes),
|
||||
::testing::ValuesIn(split_axes), // split axis
|
||||
::testing::ValuesIn(concat_axes), // concat axis
|
||||
::testing::Values(config)),
|
||||
SplitTrivialPermuteConcatTest::getTestCaseName);
|
||||
} // namespace
|
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "functional_test_utils/layer_test_utils.hpp"
|
||||
#include "ngraph_functions/utils/ngraph_helpers.hpp"
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
|
||||
typedef std::tuple<
|
||||
InferenceEngine::Precision, //Network precision
|
||||
std::string, //Device name
|
||||
size_t, //Input size
|
||||
size_t, //Hidden size
|
||||
std::map<std::string, std::string> //Configuration
|
||||
> NegativeMemoryLayerOffsetTuple;
|
||||
|
||||
class NegativeMemoryOffsetTest
|
||||
: public testing::WithParamInterface<NegativeMemoryLayerOffsetTuple>,
|
||||
public LayerTestsUtils::LayerTestsCommon {
|
||||
private:
|
||||
void switchToNgraphFriendlyModel();
|
||||
std::vector<float> memory_init;
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<NegativeMemoryLayerOffsetTuple>& obj);
|
||||
protected:
|
||||
void SetUp() override;
|
||||
void Run() override;
|
||||
};
|
||||
} // namespace LayerTestsDefinitions
|
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "functional_test_utils/layer_test_utils.hpp"
|
||||
#include "ngraph_functions/utils/ngraph_helpers.hpp"
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
|
||||
typedef std::tuple<
|
||||
InferenceEngine::Precision, //Network precision
|
||||
std::string, //Device name
|
||||
std::vector<size_t>, //Input sizes
|
||||
size_t, //Split axis
|
||||
size_t, //Concat axis
|
||||
std::map<std::string, std::string> //Configuration
|
||||
> SplitTrivialPermuteConcatTuple;
|
||||
|
||||
class SplitTrivialPermuteConcatTest
|
||||
: public testing::WithParamInterface<SplitTrivialPermuteConcatTuple>,
|
||||
public LayerTestsUtils::LayerTestsCommon {
|
||||
public:
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<SplitTrivialPermuteConcatTuple>& obj);
|
||||
protected:
|
||||
void SetUp() override;
|
||||
};
|
||||
} // namespace LayerTestsDefinitions
|
@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <debug.h>
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include "functional_test_utils/precision_utils.hpp"
|
||||
#include "functional_test_utils/skip_tests_config.hpp"
|
||||
#include "subgraph_tests/negative_memory_layer_offset.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
std::string NegativeMemoryOffsetTest::getTestCaseName(const testing::TestParamInfo<NegativeMemoryLayerOffsetTuple>& obj) {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::string targetName;
|
||||
size_t inputSize;
|
||||
size_t hiddenSize;
|
||||
std::tie(netPrecision, targetName, inputSize, hiddenSize, std::ignore) = obj.param;
|
||||
std::ostringstream results;
|
||||
|
||||
results << "netPRC=" << netPrecision.name() << "_";
|
||||
results << "IS=" << inputSize << "_";
|
||||
results << "HS=" << hiddenSize << "_";
|
||||
results << "targetDevice=" << targetName;
|
||||
return results.str();
|
||||
}
|
||||
|
||||
void NegativeMemoryOffsetTest::SetUp() {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
size_t inputSize;
|
||||
size_t hiddenSize;
|
||||
std::map<std::string, std::string> config;
|
||||
std::tie(netPrecision, targetDevice, inputSize, hiddenSize, config) = this->GetParam();
|
||||
configuration.insert(config.begin(), config.end());
|
||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||
|
||||
const int seed = 0;
|
||||
std::mt19937 gen(static_cast<float>(seed));
|
||||
std::uniform_real_distribution<float> dist(-0.2f, 0.2f);
|
||||
for (int i = 0; i < hiddenSize; ++i)
|
||||
memory_init.emplace_back(static_cast<float>(dist(gen)));
|
||||
|
||||
auto input = ngraph::builder::makeParams(ngPrc, { {1, inputSize} });
|
||||
|
||||
auto mem_c = std::make_shared<ngraph::op::Constant>(ngPrc, ngraph::Shape{ 1, hiddenSize }, memory_init);
|
||||
auto mem_r = std::make_shared<ngraph::opset3::ReadValue>(mem_c, "memory");
|
||||
|
||||
// Use memory layer as the second input of 'concat' to get negative offset
|
||||
auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{ input[0], mem_r }, 1);
|
||||
auto split = ngraph::builder::makeVariadicSplit(concat, { hiddenSize, inputSize }, 1);
|
||||
auto mem_w = std::make_shared<ngraph::opset3::Assign>(split->output(0), "memory");
|
||||
auto sigm = std::make_shared<ngraph::opset1::Sigmoid>(split->output(1));
|
||||
|
||||
mem_w->add_control_dependency(mem_r);
|
||||
sigm->add_control_dependency(mem_w);
|
||||
|
||||
function = std::make_shared<ngraph::Function>(sigm, input, "negative_memory_layer_offset_memory");
|
||||
}
|
||||
|
||||
void NegativeMemoryOffsetTest::switchToNgraphFriendlyModel() {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
size_t inputSize;
|
||||
size_t hiddenSize;
|
||||
std::tie(netPrecision, targetDevice, inputSize, hiddenSize, std::ignore) = this->GetParam();
|
||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||
auto input = ngraph::builder::makeParams(ngPrc, { {1, inputSize} });
|
||||
|
||||
auto mem_c = std::make_shared<ngraph::op::Constant>(ngPrc, ngraph::Shape{ 1, hiddenSize }, memory_init);
|
||||
auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{ input[0], mem_c }, 1);
|
||||
auto split = ngraph::builder::makeVariadicSplit(concat, { hiddenSize, inputSize }, 1);
|
||||
auto sigm = std::make_shared<ngraph::opset1::Sigmoid>(split->output(1));
|
||||
|
||||
function = std::make_shared<ngraph::Function>(sigm, input, "negative_memory_layer_offset_nonmemory");
|
||||
}
|
||||
|
||||
void NegativeMemoryOffsetTest::Run() {
|
||||
SKIP_IF_CURRENT_TEST_IS_DISABLED()
|
||||
|
||||
LoadNetwork();
|
||||
auto states = executableNetwork.QueryState();
|
||||
for (auto& state : states) {
|
||||
auto name = state.GetName();
|
||||
if (name == "memory") {
|
||||
auto blob = FuncTestUtils::createAndFillBlobWithFloatArray(state.GetLastState()->getTensorDesc(),
|
||||
memory_init.data(), memory_init.size());
|
||||
state.SetState(blob);
|
||||
} else {
|
||||
GTEST_FAIL() << "unknown memory state";
|
||||
}
|
||||
}
|
||||
Infer();
|
||||
switchToNgraphFriendlyModel();
|
||||
Validate();
|
||||
}
|
||||
|
||||
TEST_P(NegativeMemoryOffsetTest, CompareWithRefs) {
|
||||
Run();
|
||||
};
|
||||
} // namespace LayerTestsDefinitions
|
@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <debug.h>
|
||||
#include "common_test_utils/common_utils.hpp"
|
||||
#include "functional_test_utils/precision_utils.hpp"
|
||||
#include "functional_test_utils/skip_tests_config.hpp"
|
||||
#include "subgraph_tests/split_trivial_permute_concat.hpp"
|
||||
#include "ngraph_functions/utils/ngraph_helpers.hpp"
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
std::string SplitTrivialPermuteConcatTest::getTestCaseName(const testing::TestParamInfo<SplitTrivialPermuteConcatTuple>& obj) {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::string targetName;
|
||||
std::vector<size_t> inputShape;
|
||||
size_t splitAxis;
|
||||
size_t concatAxis;
|
||||
std::tie(netPrecision, targetName, inputShape, splitAxis, concatAxis, std::ignore) = obj.param;
|
||||
std::ostringstream results;
|
||||
|
||||
results << "netPRC=" << netPrecision.name() << "_";
|
||||
results << "IS=";
|
||||
for (size_t size : inputShape)
|
||||
results << size << "_";
|
||||
results << "SA=" << splitAxis << "_";
|
||||
results << "CA=" << concatAxis << "_";
|
||||
results << "targetDevice=" << targetName;
|
||||
return results.str();
|
||||
}
|
||||
|
||||
void SplitTrivialPermuteConcatTest::SetUp() {
|
||||
InferenceEngine::Precision netPrecision;
|
||||
std::vector<size_t> inputShape;
|
||||
size_t splitAxis;
|
||||
size_t concatAxis;
|
||||
std::map<std::string, std::string> config;
|
||||
std::tie(netPrecision, targetDevice, inputShape, splitAxis, concatAxis, config) = this->GetParam();
|
||||
configuration.insert(config.begin(), config.end());
|
||||
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
|
||||
auto input = ngraph::builder::makeParams(ngPrc, { inputShape });
|
||||
auto split = ngraph::builder::makeSplit(input[0], ngPrc, 2, splitAxis);
|
||||
|
||||
auto permute_in_params = std::make_shared<ngraph::opset1::Constant>(ngraph::element::i64,
|
||||
ngraph::Shape{ 4 },
|
||||
ngraph::Shape{ {0, 3, 2, 1} });
|
||||
auto permute_0 = std::make_shared<ngraph::opset1::Transpose>(split->output(0), permute_in_params);
|
||||
auto permute_1 = std::make_shared<ngraph::opset1::Transpose>(split->output(1), permute_in_params);
|
||||
|
||||
auto concat = std::make_shared<ngraph::opset1::Concat>(ngraph::OutputVector{ split->output(0), split->output(1) }, concatAxis);
|
||||
auto act = ngraph::builder::makeActivation(concat, ngPrc, ngraph::helpers::ActivationTypes::Relu);
|
||||
function = std::make_shared<ngraph::Function>(act, input, "split_trivial_permute_concat");
|
||||
}
|
||||
|
||||
TEST_P(SplitTrivialPermuteConcatTest, CompareWithRefs) {
|
||||
Run();
|
||||
};
|
||||
} // namespace LayerTestsDefinitions
|
Loading…
Reference in New Issue
Block a user