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
10 #include <ade/graph.hpp>
12 #include "opencv2/gapi/gproto.hpp" // descr_of
13 #include "opencv2/gapi/gcompiled.hpp"
15 #include "compiler/gcompiled_priv.hpp"
16 #include "backends/common/gbackend.hpp"
18 // GCompiled private implementation ////////////////////////////////////////////
19 void cv::GCompiled::Priv::setup(const GMetaArgs &_metaArgs,
20 const GMetaArgs &_outMetas,
21 std::unique_ptr<cv::gimpl::GExecutor> &&_pE)
24 m_outMetas = _outMetas;
25 m_exec = std::move(_pE);
28 bool cv::GCompiled::Priv::isEmpty() const
33 void cv::GCompiled::Priv::run(cv::gimpl::GRuntimeArgs &&args)
35 // Strip away types since ADE knows nothing about that
36 // args will be taken by specific GBackendExecutables
38 m_exec->run(std::move(args));
41 const cv::GMetaArgs& cv::GCompiled::Priv::metas() const
46 const cv::GMetaArgs& cv::GCompiled::Priv::outMetas() const
51 void cv::GCompiled::Priv::checkArgs(const cv::gimpl::GRuntimeArgs &args) const
53 const auto runtime_metas = descr_of(args.inObjs);
54 if (runtime_metas != m_metas)
56 util::throw_error(std::logic_error("This object was compiled "
57 "for different metadata!"));
58 // FIXME: Add details on what is actually wrong
62 bool cv::GCompiled::Priv::canReshape() const
65 return m_exec->canReshape();
68 void cv::GCompiled::Priv::reshape(const GMetaArgs& inMetas, const GCompileArgs& args)
71 m_exec->reshape(inMetas, args);
75 const cv::gimpl::GModel::Graph& cv::GCompiled::Priv::model() const
77 GAPI_Assert(nullptr != m_exec);
78 return m_exec->model();
81 // GCompiled public implementation /////////////////////////////////////////////
82 cv::GCompiled::GCompiled()
87 cv::GCompiled::operator bool() const
89 return !m_priv->isEmpty();
92 void cv::GCompiled::operator() (GRunArgs &&ins, GRunArgsP &&outs)
94 // FIXME: Check that <outs> matches the protocol
95 m_priv->run(cv::gimpl::GRuntimeArgs{std::move(ins),std::move(outs)});
98 #if !defined(GAPI_STANDALONE)
99 void cv::GCompiled::operator ()(cv::Mat in, cv::Mat &out)
101 (*this)(cv::gin(in), cv::gout(out));
104 void cv::GCompiled::operator() (cv::Mat in, cv::Scalar &out)
106 (*this)(cv::gin(in), cv::gout(out));
109 void cv::GCompiled::operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out)
111 (*this)(cv::gin(in1, in2), cv::gout(out));
114 void cv::GCompiled::operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out)
116 (*this)(cv::gin(in1, in2), cv::gout(out));
119 void cv::GCompiled::operator ()(const std::vector<cv::Mat> &ins,
120 const std::vector<cv::Mat> &outs)
125 // Make a temporary copy of vector outs - cv::Mats are copies anyway
127 for (const cv::Mat &m : ins) { call_ins.emplace_back(m); }
128 for ( cv::Mat &m : tmp) { call_outs.emplace_back(&m); }
130 (*this)(std::move(call_ins), std::move(call_outs));
132 #endif // !defined(GAPI_STANDALONE)
134 const cv::GMetaArgs& cv::GCompiled::metas() const
136 return m_priv->metas();
139 const cv::GMetaArgs& cv::GCompiled::outMetas() const
141 return m_priv->outMetas();
144 cv::GCompiled::Priv& cv::GCompiled::priv()
149 bool cv::GCompiled::canReshape() const
151 return m_priv->canReshape();
154 void cv::GCompiled::reshape(const GMetaArgs& inMetas, const GCompileArgs& args)
156 m_priv->reshape(inMetas, args);