diff --git a/modules/gapi/CMakeLists.txt b/modules/gapi/CMakeLists.txt index 63373ad9c4..962256cc88 100644 --- a/modules/gapi/CMakeLists.txt +++ b/modules/gapi/CMakeLists.txt @@ -113,6 +113,7 @@ set(gapi_srcs src/compiler/passes/intrin.cpp # Executor + src/executor/gabstractexecutor.cpp src/executor/gexecutor.cpp src/executor/gtbbexecutor.cpp src/executor/gstreamingexecutor.cpp diff --git a/modules/gapi/src/compiler/gcompiled.cpp b/modules/gapi/src/compiler/gcompiled.cpp index 263878ce0d..df4411e832 100644 --- a/modules/gapi/src/compiler/gcompiled.cpp +++ b/modules/gapi/src/compiler/gcompiled.cpp @@ -14,11 +14,12 @@ #include "compiler/gcompiled_priv.hpp" #include "backends/common/gbackend.hpp" +#include "executor/gexecutor.hpp" // GCompiled private implementation //////////////////////////////////////////// void cv::GCompiled::Priv::setup(const GMetaArgs &_metaArgs, const GMetaArgs &_outMetas, - std::unique_ptr<cv::gimpl::GExecutor> &&_pE) + std::unique_ptr<cv::gimpl::GAbstractExecutor> &&_pE) { m_metas = _metaArgs; m_outMetas = _outMetas; diff --git a/modules/gapi/src/compiler/gcompiled_priv.hpp b/modules/gapi/src/compiler/gcompiled_priv.hpp index f21bfc80bc..3f873aba23 100644 --- a/modules/gapi/src/compiler/gcompiled_priv.hpp +++ b/modules/gapi/src/compiler/gcompiled_priv.hpp @@ -12,7 +12,7 @@ #include "opencv2/gapi/util/optional.hpp" #include "compiler/gmodel.hpp" -#include "executor/gexecutor.hpp" +#include "executor/gabstractexecutor.hpp" // NB: BTW, GCompiled is the only "public API" class which // private part (implementation) is hosted in the "compiler/" module. @@ -36,14 +36,14 @@ class GAPI_EXPORTS GCompiled::Priv // If we want to go autonomous, we might to do something with this. GMetaArgs m_metas; // passed by user GMetaArgs m_outMetas; // inferred by compiler - std::unique_ptr<cv::gimpl::GExecutor> m_exec; + std::unique_ptr<cv::gimpl::GAbstractExecutor> m_exec; void checkArgs(const cv::gimpl::GRuntimeArgs &args) const; public: void setup(const GMetaArgs &metaArgs, const GMetaArgs &outMetas, - std::unique_ptr<cv::gimpl::GExecutor> &&pE); + std::unique_ptr<cv::gimpl::GAbstractExecutor> &&pE); bool isEmpty() const; bool canReshape() const; diff --git a/modules/gapi/src/executor/gabstractexecutor.cpp b/modules/gapi/src/executor/gabstractexecutor.cpp new file mode 100644 index 0000000000..e22b2eeb7c --- /dev/null +++ b/modules/gapi/src/executor/gabstractexecutor.cpp @@ -0,0 +1,25 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2022 Intel Corporation + +#include "precomp.hpp" + +#include <opencv2/gapi/opencv_includes.hpp> + +#include "executor/gabstractexecutor.hpp" + +cv::gimpl::GAbstractExecutor::GAbstractExecutor(std::unique_ptr<ade::Graph> &&g_model) + : m_orig_graph(std::move(g_model)) + , m_island_graph(GModel::Graph(*m_orig_graph).metadata() + .get<IslandModel>().model) + , m_gm(*m_orig_graph) + , m_gim(*m_island_graph) +{ +} + +const cv::gimpl::GModel::Graph& cv::gimpl::GAbstractExecutor::model() const +{ + return m_gm; +} diff --git a/modules/gapi/src/executor/gabstractexecutor.hpp b/modules/gapi/src/executor/gabstractexecutor.hpp new file mode 100644 index 0000000000..1657142021 --- /dev/null +++ b/modules/gapi/src/executor/gabstractexecutor.hpp @@ -0,0 +1,80 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. +// +// Copyright (C) 2022 Intel Corporation + + +#ifndef OPENCV_GAPI_GABSTRACT_EXECUTOR_HPP +#define OPENCV_GAPI_GABSTRACT_EXECUTOR_HPP + +#include <memory> // unique_ptr, shared_ptr + +#include <utility> // tuple, required by magazine +#include <unordered_map> // required by magazine + +#include <ade/graph.hpp> + +#include "backends/common/gbackend.hpp" + +namespace cv { +namespace gimpl { + +// Graph-level executor interface. +// +// This class specifies API for a "super-executor" which orchestrates +// the overall Island graph execution. +// +// Every Island (subgraph) execution is delegated to a particular +// backend and is done opaquely to the GExecutor. +// +// Inputs to a GExecutor instance are: +// - GIslandModel - a high-level graph model which may be seen as a +// "procedure" to execute. +// - GModel - a low-level graph of operations (from which a GIslandModel +// is projected) +// - GComputation runtime arguments - vectors of input/output objects +// +// Every GExecutor is responsible for +// a. Maintaining non-island (intermediate) data objects within graph +// b. Providing GIslandExecutables with input/output data according to +// their protocols +// c. Triggering execution of GIslandExecutables when task/data dependencies +// are met. +// +// By default G-API stores all data on host, and cross-Island +// exchange happens via host buffers (and CV data objects). +// +// Today's exchange data objects are: +// - cv::Mat, cv::RMat - for image buffers +// - cv::Scalar - for single values (with up to four components inside) +// - cv::detail::VectorRef - an untyped wrapper over std::vector<T> +// - cv::detail::OpaqueRef - an untyped wrapper over T +// - cv::MediaFrame - for image textures and surfaces (e.g. in planar format) + +class GAbstractExecutor +{ +protected: + std::unique_ptr<ade::Graph> m_orig_graph; + std::shared_ptr<ade::Graph> m_island_graph; + + cv::gimpl::GModel::Graph m_gm; // FIXME: make const? + cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const? + +public: + explicit GAbstractExecutor(std::unique_ptr<ade::Graph> &&g_model); + virtual ~GAbstractExecutor() = default; + virtual void run(cv::gimpl::GRuntimeArgs &&args) = 0; + + virtual bool canReshape() const = 0; + virtual void reshape(const GMetaArgs& inMetas, const GCompileArgs& args) = 0; + + virtual void prepareForNewStream() = 0; + + const GModel::Graph& model() const; // FIXME: make it ConstGraph? +}; + +} // namespace gimpl +} // namespace cv + +#endif // OPENCV_GAPI_GABSTRACT_EXECUTOR_HPP diff --git a/modules/gapi/src/executor/gexecutor.cpp b/modules/gapi/src/executor/gexecutor.cpp index 472abaaa14..6853c30d3e 100644 --- a/modules/gapi/src/executor/gexecutor.cpp +++ b/modules/gapi/src/executor/gexecutor.cpp @@ -16,11 +16,7 @@ #include "compiler/passes/passes.hpp" cv::gimpl::GExecutor::GExecutor(std::unique_ptr<ade::Graph> &&g_model) - : m_orig_graph(std::move(g_model)) - , m_island_graph(GModel::Graph(*m_orig_graph).metadata() - .get<IslandModel>().model) - , m_gm(*m_orig_graph) - , m_gim(*m_island_graph) + : GAbstractExecutor(std::move(g_model)) { // NB: Right now GIslandModel is acyclic, so for a naive execution, // simple unrolling to a list of triggers is enough @@ -424,11 +420,6 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args) } } -const cv::gimpl::GModel::Graph& cv::gimpl::GExecutor::model() const -{ - return m_gm; -} - bool cv::gimpl::GExecutor::canReshape() const { // FIXME: Introduce proper reshaping support on GExecutor level diff --git a/modules/gapi/src/executor/gexecutor.hpp b/modules/gapi/src/executor/gexecutor.hpp index 5d797ce604..67182fc8cc 100644 --- a/modules/gapi/src/executor/gexecutor.hpp +++ b/modules/gapi/src/executor/gexecutor.hpp @@ -8,58 +8,18 @@ #ifndef OPENCV_GAPI_GEXECUTOR_HPP #define OPENCV_GAPI_GEXECUTOR_HPP -#include <memory> // unique_ptr, shared_ptr - #include <utility> // tuple, required by magazine #include <unordered_map> // required by magazine -#include <ade/graph.hpp> - -#include "backends/common/gbackend.hpp" +#include "executor/gabstractexecutor.hpp" namespace cv { namespace gimpl { -// Graph-level executor interface. -// -// This class specifies API for a "super-executor" which orchestrates -// the overall Island graph execution. -// -// Every Island (subgraph) execution is delegated to a particular -// backend and is done opaquely to the GExecutor. -// -// Inputs to a GExecutor instance are: -// - GIslandModel - a high-level graph model which may be seen as a -// "procedure" to execute. -// - GModel - a low-level graph of operations (from which a GIslandModel -// is projected) -// - GComputation runtime arguments - vectors of input/output objects -// -// Every GExecutor is responsible for -// a. Maintaining non-island (intermediate) data objects within graph -// b. Providing GIslandExecutables with input/output data according to -// their protocols -// c. Triggering execution of GIslandExecutables when task/data dependencies -// are met. -// -// By default G-API stores all data on host, and cross-Island -// exchange happens via host buffers (and CV data objects). -// -// Today's exchange data objects are: -// - cv::Mat - for image buffers -// - cv::Scalar - for single values (with up to four components inside) -// - cv::detail::VectorRef - an untyped wrapper over std::vector<T> -// - -class GExecutor +class GExecutor final: public GAbstractExecutor { protected: Mag m_res; - std::unique_ptr<ade::Graph> m_orig_graph; - std::shared_ptr<ade::Graph> m_island_graph; - - cv::gimpl::GModel::Graph m_gm; // FIXME: make const? - cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const? // FIXME: Naive executor details are here for now // but then it should be moved to another place @@ -85,14 +45,12 @@ protected: public: explicit GExecutor(std::unique_ptr<ade::Graph> &&g_model); - void run(cv::gimpl::GRuntimeArgs &&args); - - bool canReshape() const; - void reshape(const GMetaArgs& inMetas, const GCompileArgs& args); + void run(cv::gimpl::GRuntimeArgs &&args) override; - void prepareForNewStream(); + bool canReshape() const override; + void reshape(const GMetaArgs& inMetas, const GCompileArgs& args) override; - const GModel::Graph& model() const; // FIXME: make it ConstGraph? + void prepareForNewStream() override; }; } // namespace gimpl