Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/src/backends/fluid/gfluidbackend.hpp
16354 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_FLUID_BACKEND_HPP
9
#define OPENCV_GAPI_FLUID_BACKEND_HPP
10
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"
15
16
// PRIVATE STUFF!
17
#include "backends/common/gbackend.hpp"
18
#include "compiler/gislandmodel.hpp"
19
20
namespace cv { namespace gimpl {
21
22
struct FluidUnit
23
{
24
static const char *name() { return "FluidUnit"; }
25
GFluidKernel k;
26
gapi::fluid::BorderOpt border;
27
int border_size;
28
int line_consumption;
29
double ratio;
30
};
31
32
struct FluidUseOwnBorderBuffer
33
{
34
static const char *name() { return "FluidUseOwnBorderBuffer"; }
35
bool use;
36
};
37
38
struct FluidData
39
{
40
static const char *name() { return "FluidData"; }
41
42
// FIXME: This structure starts looking like "FluidBuffer" meta
43
int latency = 0;
44
int skew = 0;
45
int max_consumption = 1;
46
int border_size = 0;
47
int lpi_write = 1;
48
bool internal = false; // is node internal to any fluid island
49
gapi::fluid::BorderOpt border;
50
};
51
52
struct FluidAgent
53
{
54
public:
55
virtual ~FluidAgent() = default;
56
FluidAgent(const ade::Graph &g, ade::NodeHandle nh);
57
58
GFluidKernel k;
59
ade::NodeHandle op_handle; // FIXME: why it is here??//
60
std::string op_name;
61
62
// < 0 - not a buffer
63
// >= 0 - a buffer with RcID
64
std::vector<int> in_buffer_ids;
65
std::vector<int> out_buffer_ids;
66
67
cv::GArgs in_args;
68
std::vector<cv::gapi::fluid::View> in_views; // sparce list of IN views
69
std::vector<cv::gapi::fluid::Buffer*> out_buffers;
70
71
// FIXME Current assumption is that outputs have EQUAL SIZES
72
int m_outputLines = 0;
73
int m_producedLines = 0;
74
75
double m_ratio = 0.0f;
76
77
// Execution methods
78
void reset();
79
bool canWork() const;
80
bool canRead() const;
81
bool canWrite() const;
82
void doWork();
83
bool done() const;
84
85
void debug(std::ostream& os);
86
// FIXME:
87
// refactor (implement a more solid replacement or
88
// drop this method completely)
89
virtual void setInHeight(int h) = 0;
90
private:
91
// FIXME!!!
92
// move to another class
93
virtual int firstWindow() const = 0;
94
virtual int nextWindow() const = 0;
95
virtual int linesRead() const = 0;
96
};
97
98
class GFluidExecutable final: public GIslandExecutable
99
{
100
const ade::Graph &m_g;
101
GModel::ConstGraph m_gm;
102
const std::vector<ade::NodeHandle> m_nodes;
103
104
std::vector<std::unique_ptr<FluidAgent>> m_agents;
105
std::vector<cv::gapi::fluid::Buffer> m_buffers;
106
107
using Magazine = detail::magazine<cv::gapi::own::Scalar>;
108
Magazine m_res;
109
110
std::size_t m_num_int_buffers; // internal buffers counter (m_buffers - num_scratch)
111
std::vector<std::size_t> m_scratch_users;
112
std::vector<cv::gapi::fluid::View> m_views;
113
114
std::vector<cv::gapi::own::Rect> m_outputRois;
115
116
std::unordered_map<int, std::size_t> m_id_map; // GMat id -> buffer idx map
117
118
void bindInArg (const RcDesc &rc, const GRunArg &arg);
119
void bindOutArg(const RcDesc &rc, const GRunArgP &arg);
120
void packArg (GArg &in_arg, const GArg &op_arg);
121
122
void initBufferRois(std::vector<int>& readStarts, std::vector<cv::gapi::own::Rect>& rois);
123
124
public:
125
GFluidExecutable(const ade::Graph &g,
126
const std::vector<ade::NodeHandle> &nodes,
127
const std::vector<cv::gapi::own::Rect> &outputRois);
128
129
virtual void run(std::vector<InObj> &&input_objs,
130
std::vector<OutObj> &&output_objs) override;
131
};
132
}} // cv::gimpl
133
134
135
#endif // OPENCV_GAPI_FLUID_BACKEND_HPP
136
137