Path: blob/master/modules/gapi/src/compiler/gcompiled.cpp
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#include "precomp.hpp"89#include <ade/graph.hpp>1011#include "opencv2/gapi/gproto.hpp" // descr_of12#include "opencv2/gapi/gcompiled.hpp"1314#include "compiler/gcompiled_priv.hpp"15#include "backends/common/gbackend.hpp"1617// GCompiled private implementation ////////////////////////////////////////////18void cv::GCompiled::Priv::setup(const GMetaArgs &_metaArgs,19const GMetaArgs &_outMetas,20std::unique_ptr<cv::gimpl::GExecutor> &&_pE)21{22m_metas = _metaArgs;23m_outMetas = _outMetas;24m_exec = std::move(_pE);25}2627bool cv::GCompiled::Priv::isEmpty() const28{29return !m_exec;30}3132void cv::GCompiled::Priv::run(cv::gimpl::GRuntimeArgs &&args)33{34// Strip away types since ADE knows nothing about that35// args will be taken by specific GBackendExecutables36checkArgs(args);37m_exec->run(std::move(args));38}3940const cv::GMetaArgs& cv::GCompiled::Priv::metas() const41{42return m_metas;43}4445const cv::GMetaArgs& cv::GCompiled::Priv::outMetas() const46{47return m_outMetas;48}4950void cv::GCompiled::Priv::checkArgs(const cv::gimpl::GRuntimeArgs &args) const51{52const auto runtime_metas = descr_of(args.inObjs);53if (runtime_metas != m_metas)54{55util::throw_error(std::logic_error("This object was compiled "56"for different metadata!"));57// FIXME: Add details on what is actually wrong58}59}6061const cv::gimpl::GModel::Graph& cv::GCompiled::Priv::model() const62{63GAPI_Assert(nullptr != m_exec);64return m_exec->model();65}6667// GCompiled public implementation /////////////////////////////////////////////68cv::GCompiled::GCompiled()69: m_priv(new Priv())70{71}7273cv::GCompiled::operator bool() const74{75return !m_priv->isEmpty();76}7778void cv::GCompiled::operator() (GRunArgs &&ins, GRunArgsP &&outs)79{80// FIXME: Check that <outs> matches the protocol81m_priv->run(cv::gimpl::GRuntimeArgs{std::move(ins),std::move(outs)});82}8384#if !defined(GAPI_STANDALONE)85void cv::GCompiled::operator ()(cv::Mat in, cv::Mat &out)86{87(*this)(cv::gin(in), cv::gout(out));88}8990void cv::GCompiled::operator() (cv::Mat in, cv::Scalar &out)91{92(*this)(cv::gin(in), cv::gout(out));93}9495void cv::GCompiled::operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out)96{97(*this)(cv::gin(in1, in2), cv::gout(out));98}99100void cv::GCompiled::operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out)101{102(*this)(cv::gin(in1, in2), cv::gout(out));103}104105void cv::GCompiled::operator ()(const std::vector<cv::Mat> &ins,106const std::vector<cv::Mat> &outs)107{108GRunArgs call_ins;109GRunArgsP call_outs;110111// Make a temporary copy of vector outs - cv::Mats are copies anyway112auto tmp = outs;113for (const cv::Mat &m : ins) { call_ins.emplace_back(m); }114for ( cv::Mat &m : tmp) { call_outs.emplace_back(&m); }115116(*this)(std::move(call_ins), std::move(call_outs));117}118#endif // !defined(GAPI_STANDALONE)119120121const cv::GMetaArgs& cv::GCompiled::metas() const122{123return m_priv->metas();124}125126const cv::GMetaArgs& cv::GCompiled::outMetas() const127{128return m_priv->outMetas();129}130131132cv::GCompiled::Priv& cv::GCompiled::priv()133{134return *m_priv;135}136137138