From 5ac26ff3b61ccc87a978e968e909d77f5412e94e Mon Sep 17 00:00:00 2001 From: Alexander Peskov Date: Wed, 28 Oct 2020 01:42:52 +0300 Subject: [PATCH] [TEST] One more trivial test case on Loop Also fixed compilation with gcc4.8 Signed-off-by: Alexander Peskov --- .../single_layer_tests/loop.cpp | 34 ++++++---- .../include/single_layer_tests/loop.hpp | 62 +++++++++++++++++++ .../shared/src/single_layer_tests/loop.cpp | 47 +++++++++++++- 3 files changed, 130 insertions(+), 13 deletions(-) diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/loop.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/loop.cpp index 398d9b9c6f3..c4ae2bbaeff 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/loop.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/loop.cpp @@ -31,26 +31,36 @@ namespace { ::testing::Values(CommonTestUtils::DEVICE_CPU)), LoopTest::getTestCaseName); - static const std::vector> static_loop_types = { - // static_trip_count | max | dynamic_exit | axis - { true , 5, -1, -1 }, // n_iter 5, no dynamic exit - { true , 5, 3, -1 }, // n_iter 3, dynamic exit on 3 - { true , 5, 7, -1 }, // n_iter 5, dynamic exit not reached - { true , -1, 5, -1 }, // n_iter 5, inf loop with dynamic exit on 5 - { true , 5, -1, 1 }, // n_iter 5, const for loop with auto concatenated out - { false , 5, -1, -1 }, // | - { false , 5, 3, -1 }, // | same with dynamic trip count - { false , 5, 7, -1 }, // | - { false , -1, 5, -1 }, // | + static const std::vector> static_loop_types { + // GCC4.8 limitation: have to specify type of each element in list + // static_trip_count | max | dynamic_exit | axis + std::tuple{ true , 5, -1, -1 }, // n_iter 5, no dynamic exit + std::tuple{ true , 5, 3, -1 }, // n_iter 3, dynamic exit on 3 + std::tuple{ true , 5, 7, -1 }, // n_iter 5, dynamic exit not reached + std::tuple{ true , -1, 5, -1 }, // n_iter 5, inf loop with dynamic exit on 5 + std::tuple{ true , 5, -1, 1 }, // n_iter 5, const for loop with auto concatenated out + std::tuple{ false , 5, -1, -1 }, // | + std::tuple{ false , 5, 3, -1 }, // | same with dynamic trip count + std::tuple{ false , 5, 7, -1 }, // | + std::tuple{ false , -1, 5, -1 } // | }; using namespace testing; + using namespace InferenceEngine; + INSTANTIATE_TEST_CASE_P(smoke_StaticShapeLoop, StaticShapeLoopTest, Combine( Values(true), ValuesIn(static_loop_types), Values(7), Values({2, 1, 4}), - Values(InferenceEngine::Precision::FP32, InferenceEngine::Precision::I32), + Values(Precision::FP32, Precision::I32), Values(CommonTestUtils::DEVICE_CPU))); + using namespace testing; + INSTANTIATE_TEST_CASE_P(smoke_TrivialLoop, TrivialLoopTest, + Combine( + Values(Precision::FP32, Precision::I32), + Values({2, 3, 4}), + Values(CommonTestUtils::DEVICE_CPU))); + } // namespace diff --git a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/loop.hpp b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/loop.hpp index deb55cfdb0f..6d87854dbbd 100644 --- a/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/loop.hpp +++ b/inference-engine/tests/functional/plugin/shared/include/single_layer_tests/loop.hpp @@ -79,4 +79,66 @@ protected: void SetUp() override; }; + +class TrivialLoopTest : public testing::WithParamInterface, + virtual public LayerTestsUtils::LayerTestsCommon { +protected: + using RefBlobGenerator = std::function; + std::map inputGens, outputGens; + + InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &info) const override { + auto found = inputGens.find(info.name()); + if (found != inputGens.end()) { + return found->second(info.getTensorDesc()); + } + + found = inputGens.find(""); + if (found != inputGens.end()) { + return found->second(info.getTensorDesc()); + } + + return LayerTestsCommon::GenerateInput(info); + } + + std::vector> CalculateRefs() override { + if (outputGens.empty()) + return LayerTestsCommon::CalculateRefs(); + + const auto results = function->get_results(); + const auto outs_info = cnnNetwork.getOutputsInfo(); + const auto num_out_blob = results.size(); + + std::vector> res_collection(num_out_blob); + + for (int i = 0; i < num_out_blob; i++) { + // TODO: name of original NG result doesn't match with outs after conversion. + // Expected : auto name = results[i]->get_friendly_name(); + auto name = results[i]->get_input_node_ptr(0)->get_friendly_name(); + auto data = outs_info.at(name); + IE_ASSERT(data != nullptr); + + RefBlobGenerator generator; + auto found = outputGens.find(name); + if (found != outputGens.end()) { + generator = found->second; + } else { + found = outputGens.find(""); + if (found != outputGens.end()) { + generator = found->second; + } + } + + IE_ASSERT(generator != nullptr) << "Test output generator is not specified"; + auto blob = generator(data->getTensorDesc()); + auto blob_size = blob->byteSize(); + auto blob_ptr = blob->buffer().as(); + + auto &res = res_collection[i]; + res.resize(blob_size); + std::copy(blob_ptr, blob_ptr + blob_size, res.begin()); + } + return res_collection; + } +}; + } // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/loop.cpp b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/loop.cpp index f11c55b9fac..68db20c146c 100644 --- a/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/loop.cpp +++ b/inference-engine/tests/functional/plugin/shared/src/single_layer_tests/loop.cpp @@ -284,7 +284,7 @@ namespace LayerTestsDefinitions { if (auto_concat_out) fill_data_with_broadcast(out, axis, vals); else - fill_data_with_broadcast(out, 0, {val}); + fill_data_with_broadcast(out, 0, {val}); // broadcast scalar data return {res}; } @@ -292,4 +292,49 @@ namespace LayerTestsDefinitions { TEST_P(StaticShapeLoopTest, CompareWithRefs) { Run(); } + + TEST_P(TrivialLoopTest, CheckLoad) { + SKIP_IF_CURRENT_TEST_IS_DISABLED() + InferenceEngine::Precision iePrc; + InferenceEngine::SizeVector ieShape; + std::tie(iePrc, ieShape, targetDevice) = GetParam(); + + const auto prc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(iePrc); + const auto shape = ngraph::Shape{ieShape}; + const auto scalarShape = ngraph::Shape{}; + + auto start = std::make_shared(prc, shape); + auto count = std::make_shared(ngraph::element::i64, scalarShape, 5); + auto icond = std::make_shared(ngraph::element::boolean, scalarShape, true); + + // Loop body + auto b_data = std::make_shared(prc, shape); + auto b_cond = std::make_shared(ngraph::element::boolean, scalarShape); + + auto body = std::make_shared( + ngraph::OutputVector {b_cond, b_data}, // | passthrough body, no data changes + ngraph::ParameterVector {b_cond, b_data}); // | input -> output + + auto loop = std::make_shared(count, icond); + loop->set_function(body); + loop->set_special_body_ports({-1, 0}); + loop->set_invariant_input(b_cond, icond); + loop->set_invariant_input(b_data, start); + loop->get_iter_value(b_data, -1); + + function = std::make_shared( + ngraph::OutputVector {loop}, + ngraph::ParameterVector {start}); + + // Precalculated ref blobs + auto blob = make_blob_with_precision({iePrc, ieShape, InferenceEngine::TensorDesc::getLayoutByDims(ieShape)}); + blob->allocate(); + CommonTestUtils::fill_data_with_broadcast(blob, 0, {10}); + + inputGens[""] = [&] (InferenceEngine::TensorDesc tdesc) { return blob; }; + outputGens[""] = [&] (InferenceEngine::TensorDesc tdesc) { return blob; }; + + Run(); + } + } // namespace LayerTestsDefinitions