1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #12608 from dmatveev:gapi

* G-API Initial code upload

* Update G-API code base to Sep-24-2018

* The majority of OpenCV buildbot problems was addressed

* Update G-API code base to 24-Sep-18 EOD

* G-API code base update 25-Sep-2018

* Linux warnings should be resolved
* Documentation build should become green
* Number of Windows warnings should be reduced

* Update G-API code base to 25-Sep-18 EOD

* ARMv7 build issue should be resolved
* ADE is bumped to latest version and should fix Clang builds for macOS/iOS
* Remaining Windows warnings should be resolved
* New Linux32 / ARMv7 warnings should be resolved

* G-API code base update 25-Sep-2018-EOD2

* Final Windows warnings should be resolved now

* G-API code base update 26-Sep-2018

* Fixed issues with precompiled headers in module and its tests
This commit is contained in:
Dmitry Matveev
2018-09-26 21:50:39 +03:00
committed by Alexander Alekhin
parent 852f061b26
commit 29e88e50ff
166 changed files with 35254 additions and 0 deletions
+269
View File
@@ -0,0 +1,269 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018 Intel Corporation
#include <memory> // unique_ptr
#include "opencv2/gapi/gkernel.hpp"
#include "opencv2/gapi/own/convert.hpp"
#include "api/gbackend_priv.hpp"
#include "backends/common/gbackend.hpp"
#include "compiler/gobjref.hpp"
#include "compiler/gislandmodel.hpp"
// GBackend private implementation /////////////////////////////////////////////
void cv::gapi::GBackend::Priv::unpackKernel(ade::Graph & /*graph */ ,
const ade::NodeHandle & /*op_node*/ ,
const GKernelImpl & /*impl */ )
{
// Default implementation is still there as Priv
// is instantiated by some tests.
// Priv is even instantiated as a mock object in a number of tests
// as a backend and this method is called for mock objects (doing nothing).
// FIXME: add a warning message here
// FIXME: Do something with this! Ideally this function should be "=0";
}
std::unique_ptr<cv::gimpl::GIslandExecutable>
cv::gapi::GBackend::Priv::compile(const ade::Graph&,
const GCompileArgs&,
const std::vector<ade::NodeHandle> &) const
{
// ...and this method is here for the same reason!
GAPI_Assert(false);
return {};
}
void cv::gapi::GBackend::Priv::addBackendPasses(ade::ExecutionEngineSetupContext &)
{
// Do nothing by default, plugins may override this to
// add custom (backend-specific) graph transformations
}
// GBackend public implementation //////////////////////////////////////////////
cv::gapi::GBackend::GBackend()
{
}
cv::gapi::GBackend::GBackend(std::shared_ptr<cv::gapi::GBackend::Priv> &&p)
: m_priv(std::move(p))
{
}
cv::gapi::GBackend::Priv& cv::gapi::GBackend::priv()
{
return *m_priv;
}
const cv::gapi::GBackend::Priv& cv::gapi::GBackend::priv() const
{
return *m_priv;
}
std::size_t cv::gapi::GBackend::hash() const
{
return std::hash<const cv::gapi::GBackend::Priv*>{}(m_priv.get());
}
bool cv::gapi::GBackend::operator== (const cv::gapi::GBackend &rhs) const
{
return m_priv == rhs.m_priv;
}
// Abstract Host-side data manipulation ////////////////////////////////////////
// Reused between CPU backend and more generic GExecutor
namespace cv {
namespace gimpl {
namespace magazine {
// FIXME implement the below functions with visit()?
void bindInArg(Mag& mag, const RcDesc &rc, const GRunArg &arg)
{
switch (rc.shape)
{
case GShape::GMAT:
{
auto& mag_mat = mag.template slot<cv::gapi::own::Mat>()[rc.id];
switch (arg.index())
{
case GRunArg::index_of<cv::gapi::own::Mat>() : mag_mat = util::get<cv::gapi::own::Mat>(arg); break;
case GRunArg::index_of<cv::Mat>() : mag_mat = to_own(util::get<cv::Mat>(arg)); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
}
break;
}
case GShape::GSCALAR:
{
auto& mag_scalar = mag.template slot<cv::gapi::own::Scalar>()[rc.id];
switch (arg.index())
{
case GRunArg::index_of<cv::gapi::own::Scalar>() : mag_scalar = util::get<cv::gapi::own::Scalar>(arg); break;
case GRunArg::index_of<cv::Scalar>() : mag_scalar = to_own(util::get<cv::Scalar>(arg)); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
}
break;
}
case GShape::GARRAY:
mag.template slot<cv::detail::VectorRef>()[rc.id] = util::get<cv::detail::VectorRef>(arg);
break;
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
}
}
void bindOutArg(Mag& mag, const RcDesc &rc, const GRunArgP &arg)
{
switch (rc.shape)
{
case GShape::GMAT:
{
auto& mag_mat = mag.template slot<cv::gapi::own::Mat>()[rc.id];
switch (arg.index())
{
case GRunArgP::index_of<cv::gapi::own::Mat*>() : mag_mat = * util::get<cv::gapi::own::Mat*>(arg); break;
case GRunArgP::index_of<cv::Mat*>() : mag_mat = to_own(* util::get<cv::Mat*>(arg)); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
}
break;
}
case GShape::GSCALAR:
{
auto& mag_scalar = mag.template slot<cv::gapi::own::Scalar>()[rc.id];
switch (arg.index())
{
case GRunArgP::index_of<cv::gapi::own::Scalar*>() : mag_scalar = *util::get<cv::gapi::own::Scalar*>(arg); break;
case GRunArgP::index_of<cv::Scalar*>() : mag_scalar = to_own(*util::get<cv::Scalar*>(arg)); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
}
break;
}
case GShape::GARRAY:
mag.template slot<cv::detail::VectorRef>()[rc.id] = util::get<cv::detail::VectorRef>(arg);
break;
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
break;
}
}
void resetInternalData(Mag& mag, const Data &d)
{
if (d.storage != Data::Storage::INTERNAL)
return;
switch (d.shape)
{
case GShape::GARRAY:
util::get<cv::detail::ConstructVec>(d.ctor)
(mag.template slot<cv::detail::VectorRef>()[d.rc]);
break;
case GShape::GSCALAR:
mag.template slot<cv::gapi::own::Scalar>()[d.rc] = cv::gapi::own::Scalar();
break;
case GShape::GMAT:
// Do nothign here - FIXME unify with initInternalData?
break;
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
break;
}
}
cv::GRunArg getArg(const Mag& mag, const RcDesc &ref)
{
// Wrap associated CPU object (either host or an internal one)
switch (ref.shape)
{
case GShape::GMAT: return GRunArg(mag.template slot<cv::gapi::own::Mat>().at(ref.id));
case GShape::GSCALAR: return GRunArg(mag.template slot<cv::gapi::own::Scalar>().at(ref.id));
// Note: .at() is intentional for GArray as object MUST be already there
// (and constructed by either bindIn/Out or resetInternal)
case GShape::GARRAY: return GRunArg(mag.template slot<cv::detail::VectorRef>().at(ref.id));
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
break;
}
}
cv::GRunArgP getObjPtr(Mag& mag, const RcDesc &rc)
{
switch (rc.shape)
{
case GShape::GMAT: return GRunArgP(&mag.template slot<cv::gapi::own::Mat>() [rc.id]);
case GShape::GSCALAR: return GRunArgP(&mag.template slot<cv::gapi::own::Scalar>()[rc.id]);
// Note: .at() is intentional for GArray as object MUST be already there
// (and constructer by either bindIn/Out or resetInternal)
case GShape::GARRAY:
// FIXME(DM): For some absolutely unknown to me reason, move
// semantics is involved here without const_cast to const (and
// value from map is moved into return value GRunArgP, leaving
// map with broken value I've spent few late Friday hours
// debugging this!!!1
return GRunArgP(const_cast<const Mag&>(mag)
.template slot<cv::detail::VectorRef>().at(rc.id));
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
break;
}
}
void writeBack(const Mag& mag, const RcDesc &rc, GRunArgP &g_arg)
{
switch (rc.shape)
{
case GShape::GARRAY:
// Do nothing - should we really do anything here?
break;
case GShape::GMAT:
{
//simply check that memory was not reallocated, i.e.
//both instances of Mat pointing to the same memory
uchar* out_arg_data = nullptr;
switch (g_arg.index())
{
case GRunArgP::index_of<cv::gapi::own::Mat*>() : out_arg_data = util::get<cv::gapi::own::Mat*>(g_arg)->data; break;
case GRunArgP::index_of<cv::Mat*>() : out_arg_data = util::get<cv::Mat*>(g_arg)->data; break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
}
auto& in_mag = mag.template slot<cv::gapi::own::Mat>().at(rc.id);
GAPI_Assert((out_arg_data == in_mag.data) && " data for output parameters was reallocated ?");
break;
}
case GShape::GSCALAR:
{
switch (g_arg.index())
{
case GRunArgP::index_of<cv::gapi::own::Scalar*>() : *util::get<cv::gapi::own::Scalar*>(g_arg) = mag.template slot<cv::gapi::own::Scalar>().at(rc.id); break;
case GRunArgP::index_of<cv::Scalar*>() : *util::get<cv::Scalar*>(g_arg) = cv::gapi::own::to_ocv(mag.template slot<cv::gapi::own::Scalar>().at(rc.id)); break;
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
}
break;
}
default:
util::throw_error(std::logic_error("Unsupported GShape type"));
break;
}
}
} // namespace magazine
} // namespace gimpl
} // namespace cv