From dd2823aaec8410ce5fa5fd3f5aeff34782f9b0cd Mon Sep 17 00:00:00 2001 From: Andrey Golubev Date: Mon, 18 Mar 2019 18:13:44 +0300 Subject: [PATCH] [G-API] Allow unused nodes in Fluid backend Allow nodes produced after some operation to be "unused": not being an output and not being used as inputs to other operations Add fluid test to cover this case --- modules/gapi/src/backends/fluid/gfluidbackend.cpp | 14 ++++++++++++++ modules/gapi/test/gapi_fluid_test.cpp | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/modules/gapi/src/backends/fluid/gfluidbackend.cpp b/modules/gapi/src/backends/fluid/gfluidbackend.cpp index b45b9b34ae..6aec049fb6 100644 --- a/modules/gapi/src/backends/fluid/gfluidbackend.cpp +++ b/modules/gapi/src/backends/fluid/gfluidbackend.cpp @@ -1399,6 +1399,20 @@ void GFluidBackendImpl::addBackendPasses(ade::ExecutionEngineSetupContext &ectx) // will be copied by views on each iteration and base our choice // on this criteria) auto readers = node->outNodes(); + + // There can be a situation when __internal__ nodes produced as part of some + // operation are unused later in the graph: + // + // in -> OP1 + // |------> internal_1 // unused node + // |------> internal_2 -> OP2 + // |------> out + // + // To allow graphs like the one above, skip nodes with empty outNodes() + if (readers.empty()) { + continue; + } + const auto &candidate = ade::util::find_if(readers, [&](ade::NodeHandle nh) { return fg.metadata(nh).contains() && fg.metadata(nh).get().border_size == fd.border_size; diff --git a/modules/gapi/test/gapi_fluid_test.cpp b/modules/gapi/test/gapi_fluid_test.cpp index 0f5a58e0a9..131f96aaa0 100644 --- a/modules/gapi/test/gapi_fluid_test.cpp +++ b/modules/gapi/test/gapi_fluid_test.cpp @@ -752,4 +752,19 @@ INSTANTIATE_TEST_CASE_P(Fluid, NV12RoiTest, ,std::make_pair(cv::Size{1920, 1080}, cv::Rect{0, 710, 1920, 270}) )); +TEST(Fluid, UnusedNodeTest) { + cv::GMat in; + cv::GMat a, b, c, d; + std::tie(a, b, c, d) = cv::gapi::split4(in); + cv::GMat out = cv::gapi::merge3(a, b, c); + + cv::Mat in_mat(cv::Size(8, 8), CV_8UC4); + cv::Mat out_mat(cv::Size(8, 8), CV_8UC3); + + cv::GComputation comp(cv::GIn(in), cv::GOut(out)); + + ASSERT_NO_THROW(comp.apply(cv::gin(in_mat), cv::gout(out_mat), + cv::compile_args(cv::gapi::core::fluid::kernels()))); +} + } // namespace opencv_test