G-API: fix Fluid reshape with unused nodes (Merge pull request #15115)
authorAndrey Golubev <andrey.golubev@intel.com>
Tue, 30 Jul 2019 20:48:46 +0000 (23:48 +0300)
committerMaksim Shabunin <maksim.shabunin@gmail.com>
Tue, 30 Jul 2019 20:48:46 +0000 (23:48 +0300)
* G-API: fix fluid reshape with unused nodes

* Update test names

* Add FIXME for future improvement

modules/gapi/src/backends/fluid/gfluidbackend.cpp
modules/gapi/test/gapi_fluid_test.cpp

index 49bc584..10bf244 100644 (file)
@@ -1145,7 +1145,16 @@ void cv::gimpl::GFluidExecutable::makeReshape(const std::vector<gapi::own::Rect>
         // Introduce Storage::INTERNAL_GRAPH and Storage::INTERNAL_ISLAND?
         if (fd.internal == true)
         {
-            m_buffers[id].priv().allocate(fd.border, fd.border_size, fd.max_consumption, fd.skew);
+            // FIXME: do max_consumption calculation properly (e.g. in initLineConsumption)
+            int max_consumption = 0;
+            if (nh->outNodes().empty()) {
+                // nh is always a DATA node, so it is safe to get inNodes().front() since there's
+                // always a single writer (OP node)
+                max_consumption = fg.metadata(nh->inNodes().front()).get<FluidUnit>().k.m_lpi;
+            } else {
+                max_consumption = fd.max_consumption;
+            }
+            m_buffers[id].priv().allocate(fd.border, fd.border_size, max_consumption, fd.skew);
             std::stringstream stream;
             m_buffers[id].debug(stream);
             GAPI_LOG_INFO(NULL, stream.str());
index b919d99..f2d8432 100644 (file)
@@ -752,7 +752,7 @@ INSTANTIATE_TEST_CASE_P(Fluid, NV12RoiTest,
                               ,std::make_pair(cv::Size{1920, 1080}, cv::Rect{0, 710, 1920, 270})
                               ));
 
-TEST(Fluid, UnusedNodeTest) {
+TEST(Fluid, UnusedNodeOutputCompileTest) {
     cv::GMat in;
     cv::GMat a, b, c, d;
     std::tie(a, b, c, d) = cv::gapi::split4(in);
@@ -767,4 +767,28 @@ TEST(Fluid, UnusedNodeTest) {
         cv::compile_args(cv::gapi::core::fluid::kernels())));
 }
 
+TEST(Fluid, UnusedNodeOutputReshapeTest) {
+    const auto test_size = cv::Size(8, 8);
+    const auto get_compile_args =
+        [] () { return cv::compile_args(cv::gapi::core::fluid::kernels()); };
+
+    cv::GMat in;
+    cv::GMat a, b, c, d;
+    std::tie(a, b, c, d) = cv::gapi::split4(in);
+    cv::GMat out = cv::gapi::resize(cv::gapi::merge3(a, b, c), test_size, 0.0, 0.0,
+        cv::INTER_LINEAR);
+    cv::GComputation comp(cv::GIn(in), cv::GOut(out));
+
+    cv::Mat in_mat(test_size, CV_8UC4);
+    cv::Mat out_mat(test_size, CV_8UC3);
+
+    cv::GCompiled compiled;
+    ASSERT_NO_THROW(compiled = comp.compile(descr_of(in_mat), get_compile_args()));
+
+    in_mat = cv::Mat(test_size * 2, CV_8UC4);
+    ASSERT_TRUE(compiled.canReshape());
+    ASSERT_NO_THROW(compiled.reshape(descr_of(gin(in_mat)), get_compile_args()));
+    ASSERT_NO_THROW(compiled(in_mat, out_mat));
+}
+
 } // namespace opencv_test