Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/gapi/src/compiler/gcompiled.cpp
16337 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
#include "precomp.hpp"
9
10
#include <ade/graph.hpp>
11
12
#include "opencv2/gapi/gproto.hpp" // descr_of
13
#include "opencv2/gapi/gcompiled.hpp"
14
15
#include "compiler/gcompiled_priv.hpp"
16
#include "backends/common/gbackend.hpp"
17
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)
22
{
23
m_metas = _metaArgs;
24
m_outMetas = _outMetas;
25
m_exec = std::move(_pE);
26
}
27
28
bool cv::GCompiled::Priv::isEmpty() const
29
{
30
return !m_exec;
31
}
32
33
void cv::GCompiled::Priv::run(cv::gimpl::GRuntimeArgs &&args)
34
{
35
// Strip away types since ADE knows nothing about that
36
// args will be taken by specific GBackendExecutables
37
checkArgs(args);
38
m_exec->run(std::move(args));
39
}
40
41
const cv::GMetaArgs& cv::GCompiled::Priv::metas() const
42
{
43
return m_metas;
44
}
45
46
const cv::GMetaArgs& cv::GCompiled::Priv::outMetas() const
47
{
48
return m_outMetas;
49
}
50
51
void cv::GCompiled::Priv::checkArgs(const cv::gimpl::GRuntimeArgs &args) const
52
{
53
const auto runtime_metas = descr_of(args.inObjs);
54
if (runtime_metas != m_metas)
55
{
56
util::throw_error(std::logic_error("This object was compiled "
57
"for different metadata!"));
58
// FIXME: Add details on what is actually wrong
59
}
60
}
61
62
const cv::gimpl::GModel::Graph& cv::GCompiled::Priv::model() const
63
{
64
GAPI_Assert(nullptr != m_exec);
65
return m_exec->model();
66
}
67
68
// GCompiled public implementation /////////////////////////////////////////////
69
cv::GCompiled::GCompiled()
70
: m_priv(new Priv())
71
{
72
}
73
74
cv::GCompiled::operator bool() const
75
{
76
return !m_priv->isEmpty();
77
}
78
79
void cv::GCompiled::operator() (GRunArgs &&ins, GRunArgsP &&outs)
80
{
81
// FIXME: Check that <outs> matches the protocol
82
m_priv->run(cv::gimpl::GRuntimeArgs{std::move(ins),std::move(outs)});
83
}
84
85
#if !defined(GAPI_STANDALONE)
86
void cv::GCompiled::operator ()(cv::Mat in, cv::Mat &out)
87
{
88
(*this)(cv::gin(in), cv::gout(out));
89
}
90
91
void cv::GCompiled::operator() (cv::Mat in, cv::Scalar &out)
92
{
93
(*this)(cv::gin(in), cv::gout(out));
94
}
95
96
void cv::GCompiled::operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out)
97
{
98
(*this)(cv::gin(in1, in2), cv::gout(out));
99
}
100
101
void cv::GCompiled::operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out)
102
{
103
(*this)(cv::gin(in1, in2), cv::gout(out));
104
}
105
106
void cv::GCompiled::operator ()(const std::vector<cv::Mat> &ins,
107
const std::vector<cv::Mat> &outs)
108
{
109
GRunArgs call_ins;
110
GRunArgsP call_outs;
111
112
// Make a temporary copy of vector outs - cv::Mats are copies anyway
113
auto tmp = outs;
114
for (const cv::Mat &m : ins) { call_ins.emplace_back(m); }
115
for ( cv::Mat &m : tmp) { call_outs.emplace_back(&m); }
116
117
(*this)(std::move(call_ins), std::move(call_outs));
118
}
119
#endif // !defined(GAPI_STANDALONE)
120
121
122
const cv::GMetaArgs& cv::GCompiled::metas() const
123
{
124
return m_priv->metas();
125
}
126
127
const cv::GMetaArgs& cv::GCompiled::outMetas() const
128
{
129
return m_priv->outMetas();
130
}
131
132
133
cv::GCompiled::Priv& cv::GCompiled::priv()
134
{
135
return *m_priv;
136
}
137
138