[TEST] One more trivial test case on Loop
authorAlexander Peskov <alexander.peskov@intel.com>
Tue, 27 Oct 2020 22:42:52 +0000 (01:42 +0300)
committerAlexander Peskov <alexander.peskov@intel.com>
Mon, 2 Nov 2020 09:37:48 +0000 (12:37 +0300)
Also fixed compilation with gcc4.8

Signed-off-by: Alexander Peskov <alexander.peskov@intel.com>
inference-engine/tests/functional/plugin/cpu/shared_tests_instances/single_layer_tests/loop.cpp
inference-engine/tests/functional/plugin/shared/include/single_layer_tests/loop.hpp
inference-engine/tests/functional/plugin/shared/src/single_layer_tests/loop.cpp

index 398d9b9..c4ae2bb 100644 (file)
@@ -31,26 +31,36 @@ namespace {
                                     ::testing::Values(CommonTestUtils::DEVICE_CPU)),
                             LoopTest::getTestCaseName);
 
-    static const std::vector<std::tuple<bool, int64_t, int64_t, int64_t>> 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<std::tuple<bool, int64_t, int64_t, int64_t>> static_loop_types {
+            //  GCC4.8 limitation: have to specify type of each element in list
+            //                               static_trip_count |  max | dynamic_exit | axis
+            std::tuple<bool, int64_t, int64_t, int64_t>{  true ,  5, -1, -1 },  // n_iter 5, no dynamic exit
+            std::tuple<bool, int64_t, int64_t, int64_t>{  true ,  5,  3, -1 },  // n_iter 3, dynamic exit on 3
+            std::tuple<bool, int64_t, int64_t, int64_t>{  true ,  5,  7, -1 },  // n_iter 5, dynamic exit not reached
+            std::tuple<bool, int64_t, int64_t, int64_t>{  true , -1,  5, -1 },  // n_iter 5, inf loop with dynamic exit on 5
+            std::tuple<bool, int64_t, int64_t, int64_t>{  true ,  5, -1,  1 },  // n_iter 5, const for loop with auto concatenated out
+            std::tuple<bool, int64_t, int64_t, int64_t>{ false ,  5, -1, -1 },  // |
+            std::tuple<bool, int64_t, int64_t, int64_t>{ false ,  5,  3, -1 },  // | same with dynamic trip count
+            std::tuple<bool, int64_t, int64_t, int64_t>{ false ,  5,  7, -1 },  // |
+            std::tuple<bool, int64_t, int64_t, int64_t>{ 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<int64_t>(7),
                                     Values<InferenceEngine::SizeVector>({2, 1, 4}),
-                                    Values<InferenceEngine::Precision>(InferenceEngine::Precision::FP32, InferenceEngine::Precision::I32),
+                                    Values<InferenceEngine::Precision>(Precision::FP32, Precision::I32),
                                     Values(CommonTestUtils::DEVICE_CPU)));
+    using namespace testing;
+    INSTANTIATE_TEST_CASE_P(smoke_TrivialLoop, TrivialLoopTest,
+                            Combine(
+                                    Values<InferenceEngine::Precision>(Precision::FP32, Precision::I32),
+                                    Values<InferenceEngine::SizeVector>({2, 3, 4}),
+                                    Values(CommonTestUtils::DEVICE_CPU)));
+
 }  // namespace
index deb55cf..6d87854 100644 (file)
@@ -79,4 +79,66 @@ protected:
     void SetUp() override;
 };
 
+
+class TrivialLoopTest : public testing::WithParamInterface<LayerTestsUtils::basicParams>,
+                        virtual public LayerTestsUtils::LayerTestsCommon {
+protected:
+    using RefBlobGenerator = std::function<InferenceEngine::Blob::Ptr (const InferenceEngine::TensorDesc &info)>;
+    std::map<std::string, RefBlobGenerator> 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<std::vector<std::uint8_t>> 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<std::vector<std::uint8_t>> 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<uint8_t*>();
+
+            auto &res = res_collection[i];
+            res.resize(blob_size);
+            std::copy(blob_ptr, blob_ptr + blob_size, res.begin());
+        }
+        return res_collection;
+    }
+};
+
 }  // namespace LayerTestsDefinitions
index f11c55b..68db20c 100644 (file)
@@ -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<ngraph::op::Parameter>(prc, shape);
+        auto count = std::make_shared<ngraph::op::Constant>(ngraph::element::i64, scalarShape, 5);
+        auto icond = std::make_shared<ngraph::op::Constant>(ngraph::element::boolean, scalarShape, true);
+
+        // Loop body
+        auto b_data = std::make_shared<ngraph::op::Parameter>(prc, shape);
+        auto b_cond = std::make_shared<ngraph::op::Parameter>(ngraph::element::boolean, scalarShape);
+
+        auto body = std::make_shared<ngraph::Function>(
+                ngraph::OutputVector    {b_cond, b_data},   // | passthrough body, no data changes
+                ngraph::ParameterVector {b_cond, b_data});  // | input -> output
+
+        auto loop = std::make_shared<ngraph::opset5::Loop>(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::Function>(
+                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