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.
5 // Copyright (C) 2018 Intel Corporation
8 #ifndef OPENCV_GAPI_GMODEL_BUILDER_HPP
9 #define OPENCV_GAPI_GMODEL_BUILDER_HPP
12 #include <unordered_map>
14 #include <opencv2/gapi/gproto.hpp>
15 #include <opencv2/gapi/gcall.hpp>
17 #include "api/gorigin.hpp"
18 #include "api/gnode.hpp"
19 #include "compiler/gmodel.hpp"
21 namespace cv { namespace gimpl {
25 std::vector<cv::GNode> all_ops;
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.
33 // FIXME: GAPI_EXPORTS only because of tests!!!
34 GAPI_EXPORTS Unrolled unrollExpr(const GProtoArgs &ins, const GProtoArgs &outs);
36 // This class generates an ADE graph with G-API specific metadata
37 // to represent user-specified computation in terms of graph model
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
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;
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);
59 explicit GModelBuilder(ade::Graph &g);
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>,
67 std::vector<ade::NodeHandle>,
68 std::vector<ade::NodeHandle> > ProtoSlots;
70 ProtoSlots put(const GProtoArgs &ins, const GProtoArgs &outs);
73 ade::NodeHandle opNode(cv::GMat gmat);
78 #endif // OPENCV_GAPI_GMODEL_BUILDER_HPP