Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / src / executor / gexecutor.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-2019 Intel Corporation
6
7
8 #ifndef OPENCV_GAPI_GEXECUTOR_HPP
9 #define OPENCV_GAPI_GEXECUTOR_HPP
10
11 #include <memory> // unique_ptr, shared_ptr
12
13 #include <utility> // tuple, required by magazine
14 #include <unordered_map> // required by magazine
15
16 #include <ade/graph.hpp>
17
18 #include "backends/common/gbackend.hpp"
19
20 namespace cv {
21 namespace gimpl {
22
23 // Graph-level executor interface.
24 //
25 // This class specifies API for a "super-executor" which orchestrates
26 // the overall Island graph execution.
27 //
28 // Every Island (subgraph) execution is delegated to a particular
29 // backend and is done opaquely to the GExecutor.
30 //
31 // Inputs to a GExecutor instance are:
32 // - GIslandModel - a high-level graph model which may be seen as a
33 //   "procedure" to execute.
34 //   - GModel - a low-level graph of operations (from which a GIslandModel
35 //     is projected)
36 // - GComputation runtime arguments - vectors of input/output objects
37 //
38 // Every GExecutor is responsible for
39 // a. Maintaining non-island (intermediate) data objects within graph
40 // b. Providing GIslandExecutables with input/output data according to
41 //    their protocols
42 // c. Triggering execution of GIslandExecutables when task/data dependencies
43 //    are met.
44 //
45 // By default G-API stores all data on host, and cross-Island
46 // exchange happens via host buffers (and CV data objects).
47 //
48 // Today's exchange data objects are:
49 // - cv::Mat               - for image buffers
50 // - cv::Scalar            - for single values (with up to four components inside)
51 // - cv::detail::VectorRef - an untyped wrapper over std::vector<T>
52 //
53
54 class GExecutor
55 {
56 protected:
57     std::unique_ptr<ade::Graph> m_orig_graph;
58     std::shared_ptr<ade::Graph> m_island_graph;
59
60     cv::gimpl::GModel::Graph       m_gm;  // FIXME: make const?
61     cv::gimpl::GIslandModel::Graph m_gim; // FIXME: make const?
62
63     // FIXME: Naive executor details are here for now
64     // but then it should be moved to another place
65     struct OpDesc
66     {
67         std::vector<RcDesc> in_objects;
68         std::vector<RcDesc> out_objects;
69         std::shared_ptr<GIslandExecutable> isl_exec;
70     };
71     std::vector<OpDesc> m_ops;
72
73     struct DataDesc
74     {
75         ade::NodeHandle slot_nh;
76         ade::NodeHandle data_nh;
77     };
78     std::vector<DataDesc> m_slots;
79
80     Mag m_res;
81
82     void initResource(const ade::NodeHandle &orig_nh); // FIXME: shouldn't it be RcDesc?
83
84 public:
85     explicit GExecutor(std::unique_ptr<ade::Graph> &&g_model);
86     void run(cv::gimpl::GRuntimeArgs &&args);
87
88     bool canReshape() const;
89     void reshape(const GMetaArgs& inMetas, const GCompileArgs& args);
90
91     const GModel::Graph& model() const; // FIXME: make it ConstGraph?
92 };
93
94 } // namespace gimpl
95 } // namespace cv
96
97 #endif // OPENCV_GAPI_GEXECUTOR_HPP