Path: blob/master/modules/gapi/src/backends/fluid/gfluidbackend.hpp
16354 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3//4// Copyright (C) 2018 Intel Corporation567#ifndef OPENCV_GAPI_FLUID_BACKEND_HPP8#define OPENCV_GAPI_FLUID_BACKEND_HPP910#include "opencv2/gapi/garg.hpp"11#include "opencv2/gapi/gproto.hpp"12#include "opencv2/gapi/fluid/gfluidkernel.hpp"13#include "opencv2/gapi/fluid/gfluidbuffer.hpp"1415// PRIVATE STUFF!16#include "backends/common/gbackend.hpp"17#include "compiler/gislandmodel.hpp"1819namespace cv { namespace gimpl {2021struct FluidUnit22{23static const char *name() { return "FluidUnit"; }24GFluidKernel k;25gapi::fluid::BorderOpt border;26int border_size;27int line_consumption;28double ratio;29};3031struct FluidUseOwnBorderBuffer32{33static const char *name() { return "FluidUseOwnBorderBuffer"; }34bool use;35};3637struct FluidData38{39static const char *name() { return "FluidData"; }4041// FIXME: This structure starts looking like "FluidBuffer" meta42int latency = 0;43int skew = 0;44int max_consumption = 1;45int border_size = 0;46int lpi_write = 1;47bool internal = false; // is node internal to any fluid island48gapi::fluid::BorderOpt border;49};5051struct FluidAgent52{53public:54virtual ~FluidAgent() = default;55FluidAgent(const ade::Graph &g, ade::NodeHandle nh);5657GFluidKernel k;58ade::NodeHandle op_handle; // FIXME: why it is here??//59std::string op_name;6061// < 0 - not a buffer62// >= 0 - a buffer with RcID63std::vector<int> in_buffer_ids;64std::vector<int> out_buffer_ids;6566cv::GArgs in_args;67std::vector<cv::gapi::fluid::View> in_views; // sparce list of IN views68std::vector<cv::gapi::fluid::Buffer*> out_buffers;6970// FIXME Current assumption is that outputs have EQUAL SIZES71int m_outputLines = 0;72int m_producedLines = 0;7374double m_ratio = 0.0f;7576// Execution methods77void reset();78bool canWork() const;79bool canRead() const;80bool canWrite() const;81void doWork();82bool done() const;8384void debug(std::ostream& os);85// FIXME:86// refactor (implement a more solid replacement or87// drop this method completely)88virtual void setInHeight(int h) = 0;89private:90// FIXME!!!91// move to another class92virtual int firstWindow() const = 0;93virtual int nextWindow() const = 0;94virtual int linesRead() const = 0;95};9697class GFluidExecutable final: public GIslandExecutable98{99const ade::Graph &m_g;100GModel::ConstGraph m_gm;101const std::vector<ade::NodeHandle> m_nodes;102103std::vector<std::unique_ptr<FluidAgent>> m_agents;104std::vector<cv::gapi::fluid::Buffer> m_buffers;105106using Magazine = detail::magazine<cv::gapi::own::Scalar>;107Magazine m_res;108109std::size_t m_num_int_buffers; // internal buffers counter (m_buffers - num_scratch)110std::vector<std::size_t> m_scratch_users;111std::vector<cv::gapi::fluid::View> m_views;112113std::vector<cv::gapi::own::Rect> m_outputRois;114115std::unordered_map<int, std::size_t> m_id_map; // GMat id -> buffer idx map116117void bindInArg (const RcDesc &rc, const GRunArg &arg);118void bindOutArg(const RcDesc &rc, const GRunArgP &arg);119void packArg (GArg &in_arg, const GArg &op_arg);120121void initBufferRois(std::vector<int>& readStarts, std::vector<cv::gapi::own::Rect>& rois);122123public:124GFluidExecutable(const ade::Graph &g,125const std::vector<ade::NodeHandle> &nodes,126const std::vector<cv::gapi::own::Rect> &outputRois);127128virtual void run(std::vector<InObj> &&input_objs,129std::vector<OutObj> &&output_objs) override;130};131}} // cv::gimpl132133134#endif // OPENCV_GAPI_FLUID_BACKEND_HPP135136137