[CPU] Fix Parameter -> Result model for dynamic case (#10764)

This commit is contained in:
Maxim Andronov 2022-03-30 10:20:52 +03:00 committed by GitHub
parent 614a6a3457
commit 72f802f282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 138 additions and 46 deletions

View File

@ -642,11 +642,11 @@ void InferRequest::initBlobs() {
void InferRequest::SetBatch(int new_batch) {
if (!graph->getProperty().batchLimit || modelInputsMap.begin()->second->get_output_partial_shape(0).is_static()) {
IE_THROW() << "Can't SetBatch for model that can't be executed via legacy dynamic batch or for static model";
IE_THROW() << "Can't set batch for model that can't be executed via legacy dynamic batch or for static model";
}
if (new_batch < 1 || new_batch > graph->getProperty().batchLimit) {
IE_THROW() << "Can't set batch that more than upper bound";
IE_THROW() << "Can't set batch that is bigger than upper bound";
}
m_curBatch = new_batch;
@ -671,16 +671,16 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob:
if (inputNodeItr != modelInputsMap.end()) {
if (!inputNodeItr->second) {
IE_THROW() << "Can't SetBlob with name: " << name << ", because has null pointer to input node";
IE_THROW() << "Can't set blob with name: " << name << ", because has null pointer to input node";
}
isInput = true;
} else if (outputNodeItr != modelOutputsMap.end()) {
if (!outputNodeItr->second) {
IE_THROW() << "Can't SetBlob with name: " << name << ", because has null pointer to output node";
IE_THROW() << "Can't set blob with name: " << name << ", because has null pointer to output node";
}
isInput = false;
} else {
IE_THROW(NotFound) << "Can't SetBlob with name: " << name << ", because input/output with this name doesn't exist";
IE_THROW(NotFound) << "Can't set blob with name: " << name << ", because input/output with this name doesn't exist";
}
const bool compoundBlobPassed = data->is<InferenceEngine::CompoundBlob>();
@ -699,13 +699,14 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob:
const auto shape = inputNodeItr->second->get_output_partial_shape(0);
const bool isDynamic = shape.is_dynamic();
if (!shape.compatible(ov::PartialShape(data->getTensorDesc().getDims()))) {
IE_THROW() << "Can't SetBlob with name: " << name
IE_THROW() << "Can't set input blob with name: " << name
<< ", because model input (shape=" << shape
<< ") and blob (shape=" << vec2str(data->getTensorDesc().getDims()) << ") are incompatible";
}
if (!isDynamic && ngraph::shape_size(shape.to_shape()) != data->size()) {
IE_THROW() << "Can't SetBlob with name: " << name << ", because model input and blob have different size";
IE_THROW() << "Can't set input blob with name: " << name << ", because model input size = " << ngraph::shape_size(shape.to_shape())
<< " and blob size = " << data->size() << " are different.";
}
MemoryDescPtr actualDesc = graph->getInputNodeByName(name)->getBaseMemDescAtOutputPort(0);
@ -725,7 +726,7 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob:
_inputs[name] = data;
} else {
if (compoundBlobPassed) {
IE_THROW(NotImplemented) << "cannot set compound blob: supported only for input pre-processing";
IE_THROW(NotImplemented) << "Can't set compound blob: supported only for input pre-processing";
}
const auto netOutPrc = InferenceEngine::details::convertPrecision(outputNodeItr->second->get_input_element_type(0));
if (netOutPrc != blobDesc.getPrecision()) {
@ -737,11 +738,14 @@ void InferRequest::SetBlob(const std::string& name, const InferenceEngine::Blob:
const bool isDynamic = shape.is_dynamic();
if (!shape.compatible(ov::PartialShape(data->getTensorDesc().getDims()))) {
IE_THROW() << "Can't SetBlob with name: " << name << ", because model output and blob are incompatible";
IE_THROW() << "Can't set output blob with name: " << name
<< ", because model output (shape=" << shape
<< ") and blob (shape=" << vec2str(data->getTensorDesc().getDims()) << ") are incompatible";
}
if (!isDynamic && ngraph::shape_size(shape.to_shape()) != data->size()) {
IE_THROW() << "Can't SetBlob with name: " << name << ", because model output and blob have different size";
IE_THROW() << "Can't set output blob with name: " << name << ", because model output size = " << ngraph::shape_size(shape.to_shape())
<< " and blob size = " << data->size() << " are different.";
}
const auto &desc = graph->getOutputNodeByName(name)->getParentEdgesAtPort(0)[0]->getMemory().getDesc();
@ -769,7 +773,7 @@ InferenceEngine::Blob::Ptr InferRequest::GetBlob(const std::string& name) {
auto inputNode = modelInputsMap.find(name);
if (inputNode != modelInputsMap.end()) {
if (!inputNode->second) {
IE_THROW() << "Can't GetBlob with name: " << name << ", because has null pointer to input node";
IE_THROW() << "Can't get blob with name: " << name << ", because has null pointer to input node";
}
const auto shape = inputNode->second->get_output_partial_shape(0);
@ -822,8 +826,16 @@ InferenceEngine::Blob::Ptr InferRequest::GetBlob(const std::string& name) {
data = make_blob_with_precision(desc);
data->allocate();
} else {
if (!shape.compatible(ov::PartialShape(data->getTensorDesc().getDims()))) {
IE_THROW(ParameterMismatch) << "Network input and output use the same name: " << name << ", but expect blobs with different shapes.";
const auto& blobDims = data->getTensorDesc().getDims();
// in static shape case is enough information that shapes are incompatible to throw exception
// but in dynamic shape case we also need to handle following corner case:
// on blob initialization stage we create empty blob with dimensions equal 0
// so if we have blob with all zero dimension we mustn't throw exception
if (!shape.compatible(ov::PartialShape(blobDims)) && (!isDynamic || blobDims.size() != shape.rank().get_length() ||
std::any_of(blobDims.begin(), blobDims.end(), [](const size_t& dims) { return dims != 0; } ))) {
IE_THROW(ParameterMismatch) << "Network input and output use the same name: " << name
<< ", but expect blobs with different shapes. Input shape: "
<< ov::PartialShape(blobDims) << ", output shape: " << shape;
}
const auto netOutPrc = InferenceEngine::details::convertPrecision(outputNode->second->get_input_element_type(0));

View File

@ -8,7 +8,23 @@
using namespace SubgraphTestsDefinitions;
namespace {
INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTestLegacyApi,
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
ParameterResultSubgraphTestBase::getTestCaseName);
const std::vector<ov::test::InputShape> inputShapes = {
ov::test::InputShape{{1, 3, 10, 10}, {{ 1, 3, 10, 10}, { 1, 3, 10, 10}}},
ov::test::InputShape{{-1, -1, -1, -1}, {{ 1, 3, 10, 10}, { 2, 5, 3, 10}, { 1, 3, 10, 10}, { 1, 3, 10, 10}}},
ov::test::InputShape{{{1, 10}, {1, 10}, {1, 10}, {1, 10}}, {{ 1, 3, 10, 10}, { 2, 5, 3, 10}, { 1, 3, 10, 10}, { 1, 3, 10, 10}}},
};
INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest,
::testing::Values(CommonTestUtils::DEVICE_CPU),
ParameterResultSubgraphTest::getTestCaseName);
::testing::Combine(
::testing::ValuesIn(inputShapes),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
ParameterResultSubgraphTestBase::getTestCaseName);
} // namespace

View File

@ -10,7 +10,7 @@ using namespace InferenceEngine;
namespace CPULayerTestsDefinitions {
class ParameterResultCustomBlobTest : public ParameterResultSubgraphTest {
class ParameterResultCustomBlobTest : public ParameterResultSubgraphTestLegacyApi {
protected:
void Infer() override {
constexpr size_t inferIterations = 10lu;
@ -34,7 +34,7 @@ class ParameterResultCustomBlobTest : public ParameterResultSubgraphTest {
inferRequest.Infer();
ParameterResultSubgraphTest::Validate();
ParameterResultSubgraphTestLegacyApi::Validate();
}
}
void Validate() override {
@ -54,18 +54,20 @@ TEST_P(ParameterResultCustomBlobTest, CompareWithRefs) {
}
namespace {
INSTANTIATE_TEST_SUITE_P(smoke_Check_Custom_Blob, ParameterResultCustomBlobTest,
::testing::Values(CommonTestUtils::DEVICE_CPU),
ParameterResultSubgraphTest::getTestCaseName);
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{}}}),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
ParameterResultSubgraphTestBase::getTestCaseName);
} // namespace
class ParameterResultSameBlobTest : public ParameterResultSubgraphTest {
class ParameterResultSameBlobTest : public ParameterResultSubgraphTestLegacyApi {
protected:
void Infer() override {
constexpr size_t inferIterations = 10lu;
for (size_t i = 0; i < inferIterations; ++i) {
ParameterResultSubgraphTest::Infer();
ParameterResultSubgraphTest::Validate();
ParameterResultSubgraphTestLegacyApi::Infer();
ParameterResultSubgraphTestLegacyApi::Validate();
}
}
void Validate() override {
@ -80,7 +82,9 @@ TEST_P(ParameterResultSameBlobTest, CompareWithRefs) {
}
namespace {
INSTANTIATE_TEST_SUITE_P(smoke_Check_Same_Blob, ParameterResultSameBlobTest,
::testing::Values(CommonTestUtils::DEVICE_CPU),
ParameterResultSubgraphTest::getTestCaseName);
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{}}}),
::testing::Values(CommonTestUtils::DEVICE_CPU)),
ParameterResultSubgraphTestBase::getTestCaseName);
} // namespace
} // namespace CPULayerTestsDefinitions

View File

@ -10,7 +10,17 @@
using namespace SubgraphTestsDefinitions;
namespace {
INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTestLegacyApi,
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
ParameterResultSubgraphTestBase::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest,
::testing::Values(CommonTestUtils::DEVICE_GPU),
ParameterResultSubgraphTest::getTestCaseName);
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{1, 3, 10, 10}}}),
::testing::Values(CommonTestUtils::DEVICE_GPU)),
ParameterResultSubgraphTestBase::getTestCaseName);
} // namespace

View File

@ -87,5 +87,8 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*MultithreadingTests.*canRun.*RequestsConsistentlyFromThreads.*MYRIAD.*)",
// TODO: CVS-82012
R"(.*StridedSliceLayerTest\.CompareWithRefs/inShape=\(1\.12\.100\).*)",
// Issue: 81016
R"(.*ParameterResultSubgraphTest\.CompareWithRefs.*)",
};
}

View File

@ -8,8 +8,16 @@ using namespace SubgraphTestsDefinitions;
namespace {
INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTestLegacyApi,
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {}}),
::testing::Values(CommonTestUtils::DEVICE_MYRIAD)),
ParameterResultSubgraphTestBase::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_Check, ParameterResultSubgraphTest,
::testing::Values(CommonTestUtils::DEVICE_MYRIAD),
ParameterResultSubgraphTest::getTestCaseName);
::testing::Combine(
::testing::Values(ov::test::InputShape{{1, 3, 10, 10}, {{1, 3, 10, 10}}}),
::testing::Values(CommonTestUtils::DEVICE_MYRIAD)),
ParameterResultSubgraphTestBase::getTestCaseName);
} // namespace

View File

@ -8,8 +8,12 @@
namespace SubgraphTestsDefinitions {
TEST_P(ParameterResultSubgraphTest, CompareWithRefs) {
TEST_P(ParameterResultSubgraphTestLegacyApi, CompareWithRefs) {
Run();
}
TEST_P(ParameterResultSubgraphTest, CompareWithRefs) {
run();
}
} // namespace SubgraphTestsDefinitions

View File

@ -10,19 +10,31 @@
#include <memory>
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "ngraph_functions/builders.hpp"
namespace SubgraphTestsDefinitions {
typedef std::tuple<
std::string // Device name
> parameterResultParams;
using parameterResultParams = std::tuple<ov::test::InputShape, // Input shape
std::string>; // Device name
class ParameterResultSubgraphTest : public testing::WithParamInterface<parameterResultParams>,
virtual public LayerTestsUtils::LayerTestsCommon {
class ParameterResultSubgraphTestBase : public testing::WithParamInterface<parameterResultParams> {
public:
static std::string getTestCaseName(const testing::TestParamInfo<parameterResultParams>& obj);
protected:
std::shared_ptr<ov::Model> createModel(const ov::PartialShape& shape);
};
class ParameterResultSubgraphTestLegacyApi : public ParameterResultSubgraphTestBase,
virtual public LayerTestsUtils::LayerTestsCommon {
protected:
void SetUp() override;
};
class ParameterResultSubgraphTest : public ParameterResultSubgraphTestBase,
virtual public ov::test::SubgraphBaseTest {
protected:
void SetUp() override;
};
} // namespace SubgraphTestsDefinitions

View File

@ -6,22 +6,45 @@
namespace SubgraphTestsDefinitions {
std::string ParameterResultSubgraphTest::getTestCaseName(const testing::TestParamInfo<parameterResultParams>& obj) {
std::string ParameterResultSubgraphTestBase::getTestCaseName(const testing::TestParamInfo<parameterResultParams>& obj) {
ov::test::InputShape inShape;
std::string targetDevice;
std::tie(targetDevice) = obj.param;
std::tie(inShape, targetDevice) = obj.param;
std::ostringstream result;
result << "IS=";
result << CommonTestUtils::partialShape2str({inShape.first}) << "_";
result << "TS=";
for (const auto& shape : inShape.second) {
result << CommonTestUtils::vec2str(shape) << "_";
}
result << "TargetDevice=" << targetDevice;
return result.str();
}
void ParameterResultSubgraphTest::SetUp() {
InferenceEngine::SizeVector inputShapes;
std::tie(targetDevice) = this->GetParam();
auto parameter = std::make_shared<ngraph::opset1::Parameter>(ngraph::element::Type_t::f32, ngraph::Shape{1, 3, 10, 10});
std::shared_ptr<ov::Model> ParameterResultSubgraphTestBase::createModel(const ov::PartialShape& shape) {
auto parameter = std::make_shared<ngraph::opset1::Parameter>(ov::element::f32, shape);
const ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(parameter)};
ngraph::ParameterVector params = {parameter};
function = std::make_shared<ngraph::Function>(results, params, "ParameterResult");
auto model = std::make_shared<ov::Model>(results, params, "ParameterResult");
return model;
}
void ParameterResultSubgraphTestLegacyApi::SetUp() {
ov::test::InputShape inShape;
std::tie(inShape, targetDevice) = this->GetParam();
IE_ASSERT(inShape.first.is_static());
function = createModel(inShape.first);
}
void ParameterResultSubgraphTest::SetUp() {
ov::test::InputShape inShape;
std::tie(inShape, targetDevice) = this->GetParam();
init_input_shapes({inShape});
function = createModel(inShape.first);
}
} // namespace SubgraphTestsDefinitions