[GNA] Add support for non-functional subgraphs (#9732)

* [GNA] Add support for non-functional subgraphs

Details:
* Insert copy before the last layer to allow nonfunc subgraphs

Tickets:
57363

* Traverse graph in upstream order

* Add param-reshape-result tests

* Fix insert condition

* review comments
This commit is contained in:
Anton Grishin
2022-02-07 12:21:23 +03:00
committed by GitHub
parent 3c13cea02b
commit b365e67561
6 changed files with 156 additions and 2 deletions

View File

@@ -879,6 +879,7 @@ void InsertCopyLayerPass::run() {
// One output goes to multiple concat and/or memory layers -> delayed copies before memory layers
// and copies before concat layers (one less copy than outputs)
// Concat has multiple connections to the same input
// Subgraph has only non-functional layers
for (auto & l : *pLayers) {
if (!LayerInfo(l).isConcat()) continue;
@@ -978,6 +979,31 @@ void InsertCopyLayerPass::run() {
}
}
}
for (auto & l : *pLayers) {
if (!l->outData.size() == 0 &&
!getInputTo(l->outData[0]).size() == 0) continue;
bool bNeedInsertCopyLayer = true;
CNNNetDFS(l, [&l, &bNeedInsertCopyLayer](CNNLayerPtr layer) {
if (!(LayerInfo(layer).isNonFunctional() || LayerInfo(layer).isSplit() || LayerInfo(layer).isCrop() || LayerInfo(layer).isInput())) {
bNeedInsertCopyLayer = false;
}
}, true, [&bNeedInsertCopyLayer](InferenceEngine::CNNLayer* from) {
// aborting UFS if we found functional layer (excluding Splits and Crops)
return make_upstream_order(bNeedInsertCopyLayer ? from : nullptr);
});
if (bNeedInsertCopyLayer) {
for (size_t inputIdx = 0; inputIdx < l->insData.size(); ++inputIdx) {
IE_ASSERT(l->insData[inputIdx].lock() != nullptr);
auto inputData = l->insData[inputIdx].lock();
auto parentLayer = getCreatorLayer(inputData);
IE_ASSERT(parentLayer.lock() != nullptr);
InsertCopyLayer(parentLayer.lock(), l, inputIdx, this->getPassManager(), CopyLayerName);
}
}
}
}
void FlattenTrivialConcatPass::run() {

View File

@@ -47,8 +47,6 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*importExportedIENetworkConstantResultOnly.*)",
R"(.*importExportedIENetworkParameterResultOnly.*)",
// TODO: Issue 57363 (Param -> Result subgraphs)
R"(.*smoke_MemoryTest.*LOW_LATENCY.*iteration_count=1_.*)",
// TODO: Issue 57368 (accuracy)
R"(.*smoke_MemoryTest.*LOW_LATENCY.*IS=\(1.10\).*)",
R"(.*smoke_MemoryTest.*iteration_count=3.*IS=\(1.10\).*)",

View File

@@ -0,0 +1,39 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "subgraph_tests/parameter_reshape_result.hpp"
#include "common_test_utils/test_constants.hpp"
#include "gna/gna_config.hpp"
using namespace SubgraphTestsDefinitions;
namespace {
std::vector<std::vector<size_t>> inputShape = {
{1, 1, 64},
{1, 1, 128}
};
std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
};
std::vector<std::map<std::string, std::string>> additional_config = {
{
{"GNA_DEVICE_MODE", "GNA_SW_FP32"}
},
{
{"GNA_DEVICE_MODE", "GNA_SW_EXACT"}
}
};
INSTANTIATE_TEST_SUITE_P(smoke_param_reshape_result, ParamReshapeResult,
::testing::Combine(
::testing::ValuesIn(inputShape),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GNA),
::testing::ValuesIn(additional_config)),
ParamReshapeResult::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,15 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/subgraph/parameter_reshape_result.hpp"
namespace SubgraphTestsDefinitions {
TEST_P(ParamReshapeResult, CompareWithRefs) {
Run();
};
} // namespace SubgraphTestsDefinitions

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include <vector>
#include <memory>
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "common_test_utils/test_constants.hpp"
namespace SubgraphTestsDefinitions {
typedef std::tuple<
std::vector<size_t>, // Input shape
InferenceEngine::Precision, // Network precision
std::string, // Device name
std::map<std::string, std::string> // Configuration
> ParamReshapeResultTuple;
class ParamReshapeResult:
public testing::WithParamInterface<ParamReshapeResultTuple>,
virtual public LayerTestsUtils::LayerTestsCommon {
public:
static std::string getTestCaseName(const testing::TestParamInfo<ParamReshapeResultTuple> &obj);
protected:
void SetUp() override;
};
} // namespace SubgraphTestsDefinitions

View File

@@ -0,0 +1,44 @@
// Copyright (C) 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/subgraph/parameter_reshape_result.hpp"
namespace SubgraphTestsDefinitions {
std::string ParamReshapeResult::getTestCaseName(const testing::TestParamInfo<ParamReshapeResultTuple> &obj) {
std::vector<size_t> inputShape;
InferenceEngine::Precision netPrecision;
std::string targetName;
std::map<std::string, std::string> config;
std::tie(inputShape, netPrecision, targetName, config) = obj.param;
std::ostringstream results;
results << "IS=" << CommonTestUtils::vec2str(inputShape) << "_";
results << "netPRC=" << netPrecision.name() << "_";
results << "targetDevice=" << targetName << "_";
for (auto const& configItem : config) {
results << "_configItem=" << configItem.first << "_" << configItem.second;
}
return results.str();
}
void ParamReshapeResult::SetUp() {
std::vector<size_t> inputShape;
InferenceEngine::Precision netPrecision;
std::map<std::string, std::string> additional_config;
std::tie(inputShape, netPrecision, targetDevice, additional_config) = this->GetParam();
configuration.insert(additional_config.begin(), additional_config.end());
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
auto params = ngraph::builder::makeParams(ngPrc, {inputShape});
auto shape = inputShape;
shape[shape.size() - 2] *= 2;
shape[shape.size() - 1] /= 2;
auto reshape_const = std::make_shared<ngraph::opset8::Constant>(ngraph::element::Type_t::i64,
ngraph::Shape{shape.size()}, shape);
auto reshape = std::make_shared<ngraph::opset8::Reshape>(params[0], reshape_const, false);
function = std::make_shared<ngraph::Function>(reshape, params, "ParamReshapeResult");
}
} // namespace SubgraphTestsDefinitions