Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/src/compiler/gmodelbuilder.hpp
16337 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
//
5
// Copyright (C) 2018 Intel Corporation
6
7
8
#ifndef OPENCV_GAPI_GMODEL_BUILDER_HPP
9
#define OPENCV_GAPI_GMODEL_BUILDER_HPP
10
11
#include <map>
12
#include <unordered_map>
13
14
#include "opencv2/gapi/gproto.hpp"
15
#include "opencv2/gapi/gcall.hpp"
16
17
#include "api/gapi_priv.hpp"
18
#include "api/gnode.hpp"
19
#include "compiler/gmodel.hpp"
20
21
namespace cv { namespace gimpl {
22
23
struct Unrolled
24
{
25
std::vector<cv::GNode> all_ops;
26
GOriginSet all_data;
27
28
// NB.: Right now, as G-API operates with GMats only and that
29
// GMats have no type or dimensions (when a computation is built),
30
// track only origins (data links) with no any additional meta.
31
};
32
33
// FIXME: GAPI_EXPORTS only because of tests!!!
34
GAPI_EXPORTS Unrolled unrollExpr(const GProtoArgs &ins, const GProtoArgs &outs);
35
36
// This class generates an ADE graph with G-API specific metadata
37
// to represent user-specified computation in terms of graph model
38
//
39
// Resulting graph is built according to the following rules:
40
// - Every operation is a node
41
// - Every dynamic object (GMat) is a node
42
// - Edges between nodes represent producer/consumer relationships
43
// between operations and data objects.
44
// FIXME: GAPI_EXPORTS only because of tests!!!
45
class GAPI_EXPORTS GModelBuilder
46
{
47
GModel::Graph m_g;
48
49
// Mappings of G-API user framework entities to ADE node handles
50
std::unordered_map<const cv::GNode::Priv*, ade::NodeHandle> m_graph_ops;
51
GOriginMap<ade::NodeHandle> m_graph_data;
52
53
// Internal methods for mapping APIs into ADE during put()
54
ade::NodeHandle put_OpNode(const cv::GNode &node);
55
ade::NodeHandle put_DataNode(const cv::GOrigin &origin);
56
57
public:
58
explicit GModelBuilder(ade::Graph &g);
59
60
// TODO: replace GMat with a generic type
61
// TODO: Cover with tests! (as the rest of internal stuff)
62
// FIXME: Calling this method multiple times is currently UB
63
// TODO: add a semantic link between "ints" returned and in-model data IDs.
64
typedef std::tuple<std::vector<RcDesc>,
65
std::vector<RcDesc>,
66
std::vector<ade::NodeHandle>,
67
std::vector<ade::NodeHandle> > ProtoSlots;
68
69
ProtoSlots put(const GProtoArgs &ins, const GProtoArgs &outs);
70
71
protected:
72
ade::NodeHandle opNode(cv::GMat gmat);
73
};
74
75
}}
76
77
#endif // OPENCV_GAPI_GMODEL_BUILDER_HPP
78
79