Publishing 2019 R3 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / src / compiler / gmodelbuilder.hpp
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/gorigin.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     ade::Graph &m_g;
48     GModel::Graph m_gm;
49
50     // Mappings of G-API user framework entities to ADE node handles
51     std::unordered_map<const cv::GNode::Priv*, ade::NodeHandle> m_graph_ops;
52     GOriginMap<ade::NodeHandle> m_graph_data;
53
54     // Internal methods for mapping APIs into ADE during put()
55     ade::NodeHandle put_OpNode(const cv::GNode &node);
56     ade::NodeHandle put_DataNode(const cv::GOrigin &origin);
57
58 public:
59     explicit GModelBuilder(ade::Graph &g);
60
61     // TODO: replace GMat with a generic type
62     // TODO: Cover with tests! (as the rest of internal stuff)
63     // FIXME: Calling this method multiple times is currently UB
64     // TODO: add a semantic link between "ints" returned and in-model data IDs.
65     typedef std::tuple<std::vector<RcDesc>,
66                        std::vector<RcDesc>,
67                        std::vector<ade::NodeHandle>,
68                        std::vector<ade::NodeHandle> > ProtoSlots;
69
70     ProtoSlots put(const GProtoArgs &ins, const GProtoArgs &outs);
71
72 protected:
73     ade::NodeHandle opNode(cv::GMat gmat);
74 };
75
76 }}
77
78 #endif // OPENCV_GAPI_GMODEL_BUILDER_HPP