Merge pull request #15238 from andrey-golubev:fluid_fix_journal

G-API: Fix Journal usage in Fluid backend (#15238)

* Fix Journal usage in Fluid backend

* Delete dumpDotRequired(): invalid check

* Update mem consumption test

* Test that new test works

* Debug memory consumption function

* Increase iterations in test

* Re-write memory consumption measurement part

* Restore correct fix for Fluid journals
pull/15298/head
Andrey Golubev 6 years ago committed by Alexander Alekhin
parent f7f2438478
commit f6bb900259
  1. 2
      modules/gapi/src/backends/fluid/gfluidbackend.cpp
  2. 10
      modules/gapi/src/compiler/gmodel.cpp
  3. 2
      modules/gapi/src/compiler/gmodel.hpp
  4. 57
      modules/gapi/test/gapi_fluid_test.cpp

@ -943,6 +943,8 @@ namespace
fd.skew = 0;
fd.max_consumption = 0;
}
GModel::log_clear(g, node);
}
}

@ -185,6 +185,16 @@ void GModel::log(Graph &g, ade::EdgeHandle eh, std::string &&msg, ade::NodeHandl
}
}
void GModel::log_clear(Graph &g, ade::NodeHandle node)
{
if (g.metadata(node).contains<Journal>())
{
// according to documentation, clear() doesn't deallocate (__capacity__ of vector preserved)
g.metadata(node).get<Journal>().messages.clear();
}
}
ade::NodeHandle GModel::detail::dataNodeOf(const ConstLayoutGraph &g, const GOrigin &origin)
{
// FIXME: Does it still work with graph transformations, e.g. redirectWriter()??

@ -226,6 +226,8 @@ namespace GModel
// appear in the dumped .dot file.x
GAPI_EXPORTS void log(Graph &g, ade::NodeHandle op, std::string &&message, ade::NodeHandle updater = ade::NodeHandle());
GAPI_EXPORTS void log(Graph &g, ade::EdgeHandle op, std::string &&message, ade::NodeHandle updater = ade::NodeHandle());
// Clears logged messages of a node.
GAPI_EXPORTS void log_clear(Graph &g, ade::NodeHandle node);
GAPI_EXPORTS void linkIn (Graph &g, ade::NodeHandle op, ade::NodeHandle obj, std::size_t in_port);
GAPI_EXPORTS void linkOut (Graph &g, ade::NodeHandle op, ade::NodeHandle obj, std::size_t out_port);

@ -826,4 +826,61 @@ TEST(Fluid, InvalidROIs)
}
}
namespace
{
#if defined(__linux__)
uint64_t currMemoryConsumption()
{
// check self-state via /proc information
constexpr const char stat_file_path[] = "/proc/self/statm";
std::ifstream proc_stat(stat_file_path);
if (!proc_stat.is_open() || !proc_stat.good())
{
CV_LOG_WARNING(NULL, "Failed to open stat file: " << stat_file_path);
return static_cast<uint64_t>(0);
}
std::string stat_line;
std::getline(proc_stat, stat_line);
uint64_t unused, rss;
// using resident set size
std::istringstream(stat_line) >> unused >> rss;
CV_Assert(rss != 0);
return rss;
}
#else
// FIXME: implement this part (at least for Windows?), right now it's enough to check Linux only
uint64_t currMemoryConsumption() { return static_cast<uint64_t>(0); }
#endif
} // anonymous namespace
TEST(Fluid, MemoryConsumptionDoesNotGrowOnReshape)
{
cv::GMat in;
cv::GMat a, b, c;
std::tie(a, b, c) = cv::gapi::split3(in);
cv::GMat merged = cv::gapi::merge4(a, b, c, a);
cv::GMat d, e, f, g;
std::tie(d, e, f, g) = cv::gapi::split4(merged);
cv::GMat out = cv::gapi::merge3(d, e, f);
cv::Mat in_mat(cv::Size(8, 8), CV_8UC3);
cv::randu(in_mat, cv::Scalar::all(0), cv::Scalar::all(100));
cv::Mat out_mat;
const auto compile_args = [] () {
return cv::compile_args(cv::gapi::core::fluid::kernels());
};
cv::GCompiled compiled = cv::GComputation(cv::GIn(in), cv::GOut(out)).compile(
cv::descr_of(in_mat), compile_args());
ASSERT_TRUE(compiled.canReshape());
const auto mem_before = currMemoryConsumption();
for (int _ = 0; _ < 1000; ++_) compiled.reshape(cv::descr_of(cv::gin(in_mat)), compile_args());
const auto mem_after = currMemoryConsumption();
ASSERT_GE(mem_before, mem_after);
}
} // namespace opencv_test

Loading…
Cancel
Save