|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef OPENCV_GAPI_GMODEL_HPP
|
|
|
#define OPENCV_GAPI_GMODEL_HPP
|
|
|
|
|
|
#include <memory>
|
|
|
#include <unordered_map>
|
|
|
#include <functional>
|
|
|
|
|
|
#include <ade/graph.hpp>
|
|
|
#include <ade/typed_graph.hpp>
|
|
|
#include <ade/passes/topological_sort.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <opencv2/gapi/util/any.hpp>
|
|
|
|
|
|
#include <opencv2/gapi/garg.hpp>
|
|
|
#include <opencv2/gapi/gkernel.hpp>
|
|
|
#include <opencv2/gapi/gcommon.hpp>
|
|
|
|
|
|
#include "compiler/gobjref.hpp"
|
|
|
#include "compiler/gislandmodel.hpp"
|
|
|
|
|
|
namespace cv { namespace gimpl {
|
|
|
|
|
|
|
|
|
|
|
|
struct NodeType
|
|
|
{
|
|
|
static const char *name() { return "NodeType"; }
|
|
|
enum { OP, DATA } t;
|
|
|
};
|
|
|
|
|
|
struct Input
|
|
|
{
|
|
|
static const char *name() { return "Input"; }
|
|
|
std::size_t port;
|
|
|
};
|
|
|
|
|
|
struct Output
|
|
|
{
|
|
|
static const char *name() { return "Output"; }
|
|
|
std::size_t port;
|
|
|
};
|
|
|
|
|
|
struct Op
|
|
|
{
|
|
|
static const char *name() { return "Op"; }
|
|
|
cv::GKernel k;
|
|
|
std::vector<GArg> args;
|
|
|
std::vector<RcDesc> outs;
|
|
|
|
|
|
cv::gapi::GBackend backend;
|
|
|
cv::util::any params;
|
|
|
};
|
|
|
|
|
|
struct Data
|
|
|
{
|
|
|
static const char *name() { return "Data"; }
|
|
|
|
|
|
|
|
|
GShape shape;
|
|
|
int rc;
|
|
|
GMetaArg meta;
|
|
|
HostCtor ctor;
|
|
|
cv::detail::OpaqueKind kind;
|
|
|
|
|
|
|
|
|
enum class Storage: int
|
|
|
{
|
|
|
INTERNAL,
|
|
|
INPUT,
|
|
|
OUTPUT,
|
|
|
CONST_VAL,
|
|
|
|
|
|
};
|
|
|
Storage storage;
|
|
|
};
|
|
|
|
|
|
struct ConstValue
|
|
|
{
|
|
|
static const char *name() { return "ConstValue"; }
|
|
|
GRunArg arg;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Island
|
|
|
{
|
|
|
static const char *name() { return "Island"; }
|
|
|
std::string island;
|
|
|
};
|
|
|
|
|
|
struct Protocol
|
|
|
{
|
|
|
static const char *name() { return "Protocol"; }
|
|
|
|
|
|
std::vector<RcDesc> inputs;
|
|
|
std::vector<RcDesc> outputs;
|
|
|
|
|
|
std::vector<ade::NodeHandle> in_nhs;
|
|
|
std::vector<ade::NodeHandle> out_nhs;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct OriginalInputMeta
|
|
|
{
|
|
|
static const char *name() { return "OriginalInputMeta"; }
|
|
|
GMetaArgs inputMeta;
|
|
|
};
|
|
|
|
|
|
struct OutputMeta
|
|
|
{
|
|
|
static const char *name() { return "OutputMeta"; }
|
|
|
GMetaArgs outMeta;
|
|
|
};
|
|
|
|
|
|
struct Journal
|
|
|
{
|
|
|
static const char *name() { return "Journal"; }
|
|
|
std::vector<std::string> messages;
|
|
|
};
|
|
|
|
|
|
|
|
|
class DataObjectCounter
|
|
|
{
|
|
|
public:
|
|
|
static const char* name() { return "DataObjectCounter"; }
|
|
|
int GetNewId(GShape shape) { return m_next_data_id[shape]++; }
|
|
|
|
|
|
|
|
|
|
|
|
std::unordered_map<cv::GShape, int> m_next_data_id;
|
|
|
};
|
|
|
|
|
|
|
|
|
struct IslandModel
|
|
|
{
|
|
|
static const char* name() { return "IslandModel"; }
|
|
|
std::shared_ptr<ade::Graph> model;
|
|
|
};
|
|
|
|
|
|
|
|
|
struct ActiveBackends
|
|
|
{
|
|
|
static const char *name() { return "ActiveBackends"; }
|
|
|
std::unordered_set<cv::gapi::GBackend> backends;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Streaming
|
|
|
{
|
|
|
static const char *name() { return "StreamingFlag"; }
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Deserialized
|
|
|
{
|
|
|
static const char *name() { return "DeserializedFlag"; }
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct NetworkParams
|
|
|
{
|
|
|
static const char *name() { return "NetworkParams"; }
|
|
|
cv::util::any opaque;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct CustomMetaFunction
|
|
|
{
|
|
|
static const char *name() { return "CustomMetaFunction"; }
|
|
|
using CM = std::function< cv::GMetaArgs( const ade::Graph &,
|
|
|
const ade::NodeHandle &,
|
|
|
const cv::GMetaArgs &,
|
|
|
const cv::GArgs &)>;
|
|
|
CM customOutMeta;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct HasIntrinsics
|
|
|
{
|
|
|
static const char *name() { return "HasIntrinsicsFlag"; }
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct DesyncPath
|
|
|
{
|
|
|
static const char *name() { return "DesynchronizedPath"; }
|
|
|
|
|
|
|
|
|
|
|
|
int index;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct DesyncEdge
|
|
|
{
|
|
|
static const char *name() { return "DesynchronizedEdge"; }
|
|
|
|
|
|
|
|
|
|
|
|
int index;
|
|
|
};
|
|
|
|
|
|
|
|
|
struct Desynchronized
|
|
|
{
|
|
|
static const char *name() { return "Desynchronized"; }
|
|
|
};
|
|
|
|
|
|
|
|
|
struct CompileArgs
|
|
|
{
|
|
|
static const char *name() { return "CompileArgs"; }
|
|
|
GCompileArgs args;
|
|
|
};
|
|
|
|
|
|
namespace GModel
|
|
|
{
|
|
|
using Graph = ade::TypedGraph
|
|
|
< NodeType
|
|
|
, Input
|
|
|
, Output
|
|
|
, Op
|
|
|
, Data
|
|
|
, ConstValue
|
|
|
, Island
|
|
|
, Protocol
|
|
|
, OriginalInputMeta
|
|
|
, OutputMeta
|
|
|
, Journal
|
|
|
, ade::passes::TopologicalSortData
|
|
|
, DataObjectCounter
|
|
|
, IslandModel
|
|
|
, ActiveBackends
|
|
|
, CustomMetaFunction
|
|
|
, Streaming
|
|
|
, Deserialized
|
|
|
, HasIntrinsics
|
|
|
, DesyncPath
|
|
|
, DesyncEdge
|
|
|
, Desynchronized
|
|
|
, CompileArgs
|
|
|
>;
|
|
|
|
|
|
|
|
|
using ConstGraph = ade::ConstTypedGraph
|
|
|
< NodeType
|
|
|
, Input
|
|
|
, Output
|
|
|
, Op
|
|
|
, Data
|
|
|
, ConstValue
|
|
|
, Island
|
|
|
, Protocol
|
|
|
, OriginalInputMeta
|
|
|
, OutputMeta
|
|
|
, Journal
|
|
|
, ade::passes::TopologicalSortData
|
|
|
, DataObjectCounter
|
|
|
, IslandModel
|
|
|
, ActiveBackends
|
|
|
, CustomMetaFunction
|
|
|
, Streaming
|
|
|
, Deserialized
|
|
|
, HasIntrinsics
|
|
|
, DesyncPath
|
|
|
, DesyncEdge
|
|
|
, Desynchronized
|
|
|
, CompileArgs
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GAPI_EXPORTS void init (Graph& g);
|
|
|
|
|
|
GAPI_EXPORTS ade::NodeHandle mkOpNode(Graph &g,
|
|
|
const GKernel &k,
|
|
|
const std::vector<GArg>& args,
|
|
|
const cv::util::any& params,
|
|
|
const std::string &island);
|
|
|
|
|
|
GAPI_EXPORTS ade::NodeHandle mkDataNode(Graph &g, const GShape shape);
|
|
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
GAPI_EXPORTS void log_clear(Graph &g, ade::NodeHandle node);
|
|
|
|
|
|
GAPI_EXPORTS ade::EdgeHandle linkIn (Graph &g, ade::NodeHandle op, ade::NodeHandle obj, std::size_t in_port);
|
|
|
GAPI_EXPORTS ade::EdgeHandle linkOut (Graph &g, ade::NodeHandle op, ade::NodeHandle obj, std::size_t out_port);
|
|
|
|
|
|
GAPI_EXPORTS std::vector<ade::EdgeHandle> redirectReaders(Graph &g, ade::NodeHandle from, ade::NodeHandle to);
|
|
|
GAPI_EXPORTS ade::EdgeHandle redirectWriter (Graph &g, ade::NodeHandle from, ade::NodeHandle to);
|
|
|
|
|
|
GAPI_EXPORTS std::vector<ade::NodeHandle> orderedInputs (const ConstGraph &g, ade::NodeHandle nh);
|
|
|
GAPI_EXPORTS std::vector<ade::NodeHandle> orderedOutputs(const ConstGraph &g, ade::NodeHandle nh);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GAPI_EXPORTS GMetaArgs collectInputMeta(const GModel::ConstGraph &cg, ade::NodeHandle node);
|
|
|
GAPI_EXPORTS GMetaArgs collectOutputMeta(const GModel::ConstGraph &cg, ade::NodeHandle node);
|
|
|
|
|
|
GAPI_EXPORTS ade::EdgeHandle getInEdgeByPort(const GModel::ConstGraph& cg, const ade::NodeHandle& nh, std::size_t in_port);
|
|
|
|
|
|
|
|
|
GAPI_EXPORTS bool isActive(const GModel::Graph &cg, const cv::gapi::GBackend &backend);
|
|
|
}
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
#endif
|
|
|
|