Path: blob/master/modules/gapi/src/compiler/gislandmodel.hpp
16337 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_GISLANDMODEL_HPP8#define OPENCV_GAPI_GISLANDMODEL_HPP910#include <unordered_set>11#include <memory> // shared_ptr1213#include <ade/graph.hpp>14#include <ade/typed_graph.hpp>15#include <ade/passes/topological_sort.hpp>1617#include "opencv2/gapi/util/optional.hpp"18#include "opencv2/gapi/gkernel.hpp"1920#include "compiler/gobjref.hpp"2122namespace cv { namespace gimpl {232425// FIXME: GAPI_EXPORTS only because of tests!26class GAPI_EXPORTS GIsland27{28public:29using node_set = std::unordered_set30< ade::NodeHandle31, ade::HandleHasher<ade::Node>32>;3334// Initial constructor (constructs a single-op Island)35GIsland(const gapi::GBackend &bknd,36ade::NodeHandle op,37util::optional<std::string>&& user_tag);3839// Merged constructor40GIsland(const gapi::GBackend &bknd,41node_set &&all,42node_set &&in_ops,43node_set &&out_ops,44util::optional<std::string>&& user_tag);4546const node_set& contents() const;47const node_set& in_ops() const;48const node_set& out_ops() const;4950std::string name() const;51gapi::GBackend backend() const;5253/**54* Returns all GModel operation node handles which are _reading_55* from a GModel data object associated (wrapped in) the given56* Slot object.57*58* @param g an ade::Graph with GIslandModel information inside59* @param slot_nh Slot object node handle of interest60* @return a set of GModel operation node handles61*/62node_set consumers(const ade::Graph &g,63const ade::NodeHandle &slot_nh) const;6465/**66* Returns a GModel operation node handle which is _writing_67* to a GModel data object associated (wrapped in) the given68* Slot object.69*70* @param g an ade::Graph with GIslandModel information inside71* @param slot_nh Slot object node handle of interest72* @return a node handle of original GModel73*/74ade::NodeHandle producer(const ade::Graph &g,75const ade::NodeHandle &slot_nh) const;7677void debug() const;78bool is_user_specified() const;7980protected:81gapi::GBackend m_backend; // backend which handles this Island execution8283node_set m_all; // everything (data + operations) within an island84node_set m_in_ops; // operations island begins with85node_set m_out_ops; // operations island ends with8687// has island name IF specified by user. Empty for internal (inferred) islands88util::optional<std::string> m_user_tag;89};90919293// GIslandExecutable - a backend-specific thing which executes94// contents of an Island95// * Is instantiated by the last step of the Islands fusion procedure;96// * Is orchestrated by a GExecutor instance.97//98class GIslandExecutable99{100public:101using InObj = std::pair<RcDesc, cv::GRunArg>;102using OutObj = std::pair<RcDesc, cv::GRunArgP>;103104// FIXME: now run() requires full input vector to be available.105// actually, parts of subgraph may execute even if there's no all data106// slots in place.107// TODO: Add partial execution capabilities108virtual void run(std::vector<InObj> &&input_objs,109std::vector<OutObj> &&output_objs) = 0;110111virtual ~GIslandExecutable() = default;112};113114115116// Couldn't reuse NodeType here - FIXME unify (move meta to a shared place)117struct NodeKind118{119static const char *name() { return "NodeKind"; }120enum { ISLAND, SLOT} k;121};122123// FIXME: Rename to Island (as soon as current GModel::Island is renamed124// to IslandTag).125struct FusedIsland126{127static const char *name() { return "FusedIsland"; }128std::shared_ptr<GIsland> object;129};130131struct DataSlot132{133static const char *name() { return "DataSlot"; }134ade::NodeHandle original_data_node; // direct link to GModel135};136137struct IslandExec138{139static const char *name() { return "IslandExecutable"; }140std::shared_ptr<GIslandExecutable> object;141};142143namespace GIslandModel144{145using Graph = ade::TypedGraph146< NodeKind147, FusedIsland148, DataSlot149, IslandExec150, ade::passes::TopologicalSortData151>;152153// FIXME: derive from TypedGraph154using ConstGraph = ade::ConstTypedGraph155< NodeKind156, FusedIsland157, DataSlot158, IslandExec159, ade::passes::TopologicalSortData160>;161162// Top-level function163void generateInitial(Graph &g, const ade::Graph &src_g);164// "Building blocks"165ade::NodeHandle mkSlotNode(Graph &g, const ade::NodeHandle &data_nh);166ade::NodeHandle mkIslandNode(Graph &g, const gapi::GBackend &bknd, const ade::NodeHandle &op_nh, const ade::Graph &orig_g);167ade::NodeHandle mkIslandNode(Graph &g, std::shared_ptr<GIsland>&& isl);168169// GIslandModel API170void syncIslandTags(Graph &g, ade::Graph &orig_g);171void compileIslands(Graph &g, const ade::Graph &orig_g, const GCompileArgs &args);172173// Debug routines174// producerOf - returns an Island handle which produces given data object175// from the original model (! don't mix with DataSlot)176// FIXME: GAPI_EXPORTS because of tests only!177ade::NodeHandle GAPI_EXPORTS producerOf(const ConstGraph &g, ade::NodeHandle &data_nh);178179} // namespace GIslandModel180181}} // namespace cv::gimpl182183#endif // OPENCV_GAPI_GISLANDMODEL_HPP184185186