From 244511e434f45ee11a2cb1d4968e7a4ea6539b4a Mon Sep 17 00:00:00 2001 From: Anatoliy Talamanov Date: Thu, 24 Dec 2020 19:46:10 +0300 Subject: [PATCH] Merge pull request #19205 from TolyaTalamanov:at/remove-streamingbackend-export [G-API] Fix streaming kernels in standalone * Move streaming kernels from public header * Add streaming backend to standalone --- modules/gapi/cmake/standalone.cmake | 1 + .../backends/streaming/gstreamingbackend.cpp | 79 ++++++++++++++++--- .../backends/streaming/gstreamingbackend.hpp | 49 ------------ modules/gapi/src/compiler/gcompiler.cpp | 3 +- .../gapi/src/executor/gstreamingexecutor.cpp | 2 - 5 files changed, 69 insertions(+), 65 deletions(-) diff --git a/modules/gapi/cmake/standalone.cmake b/modules/gapi/cmake/standalone.cmake index 5cc57d8269..d08eda1be5 100644 --- a/modules/gapi/cmake/standalone.cmake +++ b/modules/gapi/cmake/standalone.cmake @@ -21,6 +21,7 @@ file(GLOB FLUID_sources "${FLUID_ROOT}/src/api/g*.cpp" "${FLUID_ROOT}/src/compiler/passes/*.cpp" "${FLUID_ROOT}/src/executor/*.cpp" "${FLUID_ROOT}/src/backends/fluid/*.cpp" + "${FLUID_ROOT}/src/backends/streaming/*.cpp" "${FLUID_ROOT}/src/backends/common/*.cpp") add_library(${FLUID_TARGET} STATIC ${FLUID_includes} ${FLUID_sources}) diff --git a/modules/gapi/src/backends/streaming/gstreamingbackend.cpp b/modules/gapi/src/backends/streaming/gstreamingbackend.cpp index d11d8b9203..a497b68ad4 100644 --- a/modules/gapi/src/backends/streaming/gstreamingbackend.cpp +++ b/modules/gapi/src/backends/streaming/gstreamingbackend.cpp @@ -4,7 +4,10 @@ // // Copyright (C) 2020 Intel Corporation +#if !defined(GAPI_STANDALONE) #include +#endif // !defined(GAPI_STANDALONE) + #include // throw_error #include // kernels @@ -32,7 +35,6 @@ using ConstStreamingGraph = ade::ConstTypedGraph , StreamingCreateFunction >; - class GStreamingIntrinExecutable final: public cv::gimpl::GIslandExecutable { virtual void run(std::vector &&, @@ -135,18 +137,30 @@ cv::gapi::GBackend cv::gapi::streaming::backend() return this_backend; } -cv::gapi::GKernelPackage cv::gapi::streaming::kernels() +struct Copy: public cv::detail::KernelTag { - return cv::gapi::kernels(); -} + using API = cv::gimpl::streaming::GCopy; -cv::gapi::GKernelPackage cv::gimpl::streaming::kernels() -{ - return cv::gapi::kernels(); -} + static cv::gapi::GBackend backend() { return cv::gapi::streaming::backend(); } + + class Actor final: public cv::gapi::streaming::IActor + { + public: + explicit Actor(const cv::GCompileArgs&) {} + virtual void run(cv::gimpl::GIslandExecutable::IInput &in, + cv::gimpl::GIslandExecutable::IOutput &out) override; + }; -void cv::gimpl::Copy::Actor::run(cv::gimpl::GIslandExecutable::IInput &in, - cv::gimpl::GIslandExecutable::IOutput &out) + static cv::gapi::streaming::IActor::Ptr create(const cv::GCompileArgs& args) + { + return cv::gapi::streaming::IActor::Ptr(new Actor(args)); + } + + static cv::gapi::streaming::GStreamingKernel kernel() { return {&create}; }; +}; + +void Copy::Actor::run(cv::gimpl::GIslandExecutable::IInput &in, + cv::gimpl::GIslandExecutable::IOutput &out) { const auto in_msg = in.get(); if (cv::util::holds_alternative(in_msg)) @@ -176,8 +190,34 @@ void cv::gimpl::Copy::Actor::run(cv::gimpl::GIslandExecutable::IInput &in, out.post(std::move(out_arg)); } -void cv::gimpl::BGR::Actor::run(cv::gimpl::GIslandExecutable::IInput &in, - cv::gimpl::GIslandExecutable::IOutput &out) +cv::gapi::GKernelPackage cv::gimpl::streaming::kernels() +{ + return cv::gapi::kernels(); +} + +#if !defined(GAPI_STANDALONE) + +struct GOCVBGR: public cv::detail::KernelTag +{ + using API = cv::gapi::streaming::GBGR; + static cv::gapi::GBackend backend() { return cv::gapi::streaming::backend(); } + + class Actor final: public cv::gapi::streaming::IActor { + public: + explicit Actor(const cv::GCompileArgs&) {} + virtual void run(cv::gimpl::GIslandExecutable::IInput &in, + cv::gimpl::GIslandExecutable::IOutput&out) override; + }; + + static cv::gapi::streaming::IActor::Ptr create(const cv::GCompileArgs& args) + { + return cv::gapi::streaming::IActor::Ptr(new Actor(args)); + } + static cv::gapi::streaming::GStreamingKernel kernel() { return {&create}; }; +}; + +void GOCVBGR::Actor::run(cv::gimpl::GIslandExecutable::IInput &in, + cv::gimpl::GIslandExecutable::IOutput &out) { const auto in_msg = in.get(); if (cv::util::holds_alternative(in_msg)) @@ -216,6 +256,21 @@ void cv::gimpl::BGR::Actor::run(cv::gimpl::GIslandExecutable::IInput &in, out.post(std::move(out_arg)); } +cv::gapi::GKernelPackage cv::gapi::streaming::kernels() +{ + return cv::gapi::kernels(); +} + +#else + +cv::gapi::GKernelPackage cv::gapi::streaming::kernels() +{ + // Still provide this symbol to avoid linking issues + util::throw_error(std::runtime_error("cv::gapi::streaming::kernels() isn't supported in standalone")); +} + +#endif // !defined(GAPI_STANDALONE) + cv::GMat cv::gapi::copy(const cv::GMat& in) { return cv::gimpl::streaming::GCopy::on(in); } diff --git a/modules/gapi/src/backends/streaming/gstreamingbackend.hpp b/modules/gapi/src/backends/streaming/gstreamingbackend.hpp index 28b15792b2..27b5443bb2 100644 --- a/modules/gapi/src/backends/streaming/gstreamingbackend.hpp +++ b/modules/gapi/src/backends/streaming/gstreamingbackend.hpp @@ -12,13 +12,6 @@ #include "gstreamingkernel.hpp" namespace cv { -namespace gapi { -namespace streaming { - -cv::gapi::GBackend backend(); - -}} // namespace gapi::streaming - namespace gimpl { namespace streaming { @@ -39,48 +32,6 @@ struct GCopy final : public cv::detail::NoTag }; } // namespace streaming - -struct Copy: public cv::detail::KernelTag -{ - using API = streaming::GCopy; - - static gapi::GBackend backend() { return cv::gapi::streaming::backend(); } - - class Actor final: public cv::gapi::streaming::IActor - { - public: - explicit Actor(const cv::GCompileArgs&) {} - virtual void run(cv::gimpl::GIslandExecutable::IInput &in, - cv::gimpl::GIslandExecutable::IOutput &out) override; - }; - - static cv::gapi::streaming::IActor::Ptr create(const cv::GCompileArgs& args) - { - return cv::gapi::streaming::IActor::Ptr(new Actor(args)); - } - - static cv::gapi::streaming::GStreamingKernel kernel() { return {&create}; }; -}; - -struct BGR: public cv::detail::KernelTag -{ - using API = cv::gapi::streaming::GBGR; - static gapi::GBackend backend() { return cv::gapi::streaming::backend(); } - - class Actor final: public cv::gapi::streaming::IActor { - public: - explicit Actor(const cv::GCompileArgs&) {} - virtual void run(cv::gimpl::GIslandExecutable::IInput &in, - cv::gimpl::GIslandExecutable::IOutput&out) override; - }; - - static cv::gapi::streaming::IActor::Ptr create(const cv::GCompileArgs& args) - { - return cv::gapi::streaming::IActor::Ptr(new Actor(args)); - } - static cv::gapi::streaming::GStreamingKernel kernel() { return {&create}; }; -}; - } // namespace gimpl } // namespace cv diff --git a/modules/gapi/src/compiler/gcompiler.cpp b/modules/gapi/src/compiler/gcompiler.cpp index 34585e2b3c..fc25aea0e4 100644 --- a/modules/gapi/src/compiler/gcompiler.cpp +++ b/modules/gapi/src/compiler/gcompiler.cpp @@ -36,7 +36,7 @@ #include "executor/gstreamingexecutor.hpp" #include "backends/common/gbackend.hpp" #include "backends/common/gmetabackend.hpp" -#include "backends/streaming/gstreamingbackend.hpp" +#include "backends/streaming/gstreamingbackend.hpp" // cv::gimpl::streaming::kernels() // #if !defined(GAPI_STANDALONE) @@ -44,7 +44,6 @@ #include // ...Imgproc #include // ...and Video kernel implementations #include // render::ocv::backend() -#include // streaming::kernels() #endif // !defined(GAPI_STANDALONE) // diff --git a/modules/gapi/src/executor/gstreamingexecutor.cpp b/modules/gapi/src/executor/gstreamingexecutor.cpp index ba58cfde60..c1de2e6aed 100644 --- a/modules/gapi/src/executor/gstreamingexecutor.cpp +++ b/modules/gapi/src/executor/gstreamingexecutor.cpp @@ -1005,12 +1005,10 @@ cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr && // In the current implementation, such islands // _must_ start with copy GAPI_Assert(isl->in_ops().size() == 1u); -#if !defined(GAPI_STANDALONE) GAPI_Assert(GModel::Graph(*m_orig_graph) .metadata(*isl->in_ops().begin()) .get() .k.name == cv::gimpl::streaming::GCopy::id()); -#endif // GAPI_STANDALONE for (auto out_nh : nh->outNodes()) { for (auto out_eh : out_nh->outEdges()) { qgr.metadata(out_eh).set(DesyncSpecialCase{});