Merge pull request #22451 from dmatveev:dm/abstract_execs
G-API: Introduce abstract base classes for GExecutor and GStreamingExecutorpull/22495/head
commit
c9060b053d
13 changed files with 209 additions and 95 deletions
@ -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; |
||||||
|
} |
@ -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
|
@ -0,0 +1,23 @@ |
|||||||
|
// 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/gabstractstreamingexecutor.hpp" |
||||||
|
|
||||||
|
cv::gimpl::GAbstractStreamingExecutor::GAbstractStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model, |
||||||
|
const GCompileArgs &comp_args) |
||||||
|
: m_orig_graph(std::move(g_model)) |
||||||
|
, m_island_graph(GModel::Graph(*m_orig_graph).metadata() |
||||||
|
.get<IslandModel>().model) |
||||||
|
, m_comp_args(comp_args) |
||||||
|
, m_gim(*m_island_graph) |
||||||
|
, m_desync(GModel::Graph(*m_orig_graph).metadata() |
||||||
|
.contains<Desynchronized>()) |
||||||
|
{ |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
// 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_STREAMING_EXECUTOR_HPP |
||||||
|
#define OPENCV_GAPI_GABSTRACT_STREAMING_EXECUTOR_HPP |
||||||
|
|
||||||
|
#include <memory> // unique_ptr, shared_ptr |
||||||
|
|
||||||
|
#include <ade/graph.hpp> |
||||||
|
|
||||||
|
#include "backends/common/gbackend.hpp" |
||||||
|
|
||||||
|
namespace cv { |
||||||
|
namespace gimpl { |
||||||
|
|
||||||
|
class GAbstractStreamingExecutor |
||||||
|
{ |
||||||
|
protected: |
||||||
|
std::unique_ptr<ade::Graph> m_orig_graph; |
||||||
|
std::shared_ptr<ade::Graph> m_island_graph; |
||||||
|
cv::GCompileArgs m_comp_args; |
||||||
|
|
||||||
|
cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const?
|
||||||
|
const bool m_desync; |
||||||
|
|
||||||
|
public: |
||||||
|
explicit GAbstractStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model, |
||||||
|
const cv::GCompileArgs &comp_args); |
||||||
|
virtual ~GAbstractStreamingExecutor() = default; |
||||||
|
virtual void setSource(GRunArgs &&args) = 0; |
||||||
|
virtual void start() = 0; |
||||||
|
virtual bool pull(cv::GRunArgsP &&outs) = 0; |
||||||
|
virtual bool pull(cv::GOptRunArgsP &&outs) = 0; |
||||||
|
|
||||||
|
using PyPullResult = std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>>; |
||||||
|
virtual PyPullResult pull() = 0; |
||||||
|
|
||||||
|
virtual bool try_pull(cv::GRunArgsP &&outs) = 0; |
||||||
|
virtual void stop() = 0; |
||||||
|
virtual bool running() const = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace gimpl
|
||||||
|
} // namespace cv
|
||||||
|
|
||||||
|
#endif // OPENCV_GAPI_GABSTRACT_STREAMING_EXECUTOR_HPP
|
Loading…
Reference in new issue