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-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_FLUID_BACKEND_HPP
9 #define OPENCV_GAPI_FLUID_BACKEND_HPP
11 #include "opencv2/gapi/garg.hpp"
12 #include "opencv2/gapi/gproto.hpp"
13 #include "opencv2/gapi/fluid/gfluidkernel.hpp"
14 #include "opencv2/gapi/fluid/gfluidbuffer.hpp"
17 #include "backends/common/gbackend.hpp"
18 #include "compiler/gislandmodel.hpp"
20 namespace cv { namespace gimpl {
24 static const char *name() { return "FluidUnit"; }
26 gapi::fluid::BorderOpt border;
32 struct FluidUseOwnBorderBuffer
34 static const char *name() { return "FluidUseOwnBorderBuffer"; }
40 static const char *name() { return "FluidData"; }
42 // FIXME: This structure starts looking like "FluidBuffer" meta
45 int max_consumption = 1;
48 bool internal = false; // is node internal to any fluid island
49 gapi::fluid::BorderOpt border;
55 virtual ~FluidAgent() = default;
56 FluidAgent(const ade::Graph &g, ade::NodeHandle nh);
59 ade::NodeHandle op_handle; // FIXME: why it is here??//
63 // >= 0 - a buffer with RcID
64 std::vector<int> in_buffer_ids;
65 std::vector<int> out_buffer_ids;
68 std::vector<cv::gapi::fluid::View> in_views; // sparce list of IN views
69 std::vector<cv::gapi::fluid::Buffer*> out_buffers;
71 // FIXME Current assumption is that outputs have EQUAL SIZES
72 int m_outputLines = 0;
73 int m_producedLines = 0;
79 bool canWrite() const;
83 void debug(std::ostream& os);
86 // refactor (implement a more solid replacement or
87 // drop this method completely)
88 virtual void setRatio(double ratio) = 0;
92 // move to another class
93 virtual int firstWindow() const = 0;
94 virtual std::pair<int,int> linesReadAndnextWindow() const = 0;
97 class GFluidExecutable final: public GIslandExecutable
99 const ade::Graph &m_g;
100 GModel::ConstGraph m_gm;
102 std::vector<std::unique_ptr<FluidAgent>> m_agents;
103 std::vector<cv::gapi::fluid::Buffer> m_buffers;
105 std::vector<FluidAgent*> m_script;
107 using Magazine = detail::magazine<cv::gapi::own::Scalar>;
110 std::size_t m_num_int_buffers; // internal buffers counter (m_buffers - num_scratch)
111 std::vector<std::size_t> m_scratch_users;
113 std::unordered_map<int, std::size_t> m_id_map; // GMat id -> buffer idx map
114 std::map<std::size_t, ade::NodeHandle> m_all_gmat_ids;
116 void bindInArg (const RcDesc &rc, const GRunArg &arg);
117 void bindOutArg(const RcDesc &rc, const GRunArgP &arg);
118 void packArg (GArg &in_arg, const GArg &op_arg);
120 void initBufferRois(std::vector<int>& readStarts, std::vector<cv::gapi::own::Rect>& rois, const std::vector<gapi::own::Rect> &out_rois);
121 void makeReshape(const std::vector<cv::gapi::own::Rect>& out_rois);
124 GFluidExecutable(const ade::Graph &g,
125 const std::vector<ade::NodeHandle> &nodes,
126 const std::vector<cv::gapi::own::Rect> &outputRois);
128 virtual inline bool canReshape() const override { return true; }
129 virtual void reshape(ade::Graph& g, const GCompileArgs& args) override;
131 virtual void run(std::vector<InObj> &&input_objs,
132 std::vector<OutObj> &&output_objs) override;
137 #endif // OPENCV_GAPI_FLUID_BACKEND_HPP