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

Introduce a new abstraction layer over island input/output data

- Port GExecutor to this new interface
This commit is contained in:
Dmitry Matveev
2020-03-16 18:05:41 +03:00
committed by Ruslan Garnov
parent 277f0d270f
commit 1b5730a799
5 changed files with 94 additions and 25 deletions
+32 -22
View File
@@ -122,6 +122,29 @@ void cv::gimpl::GExecutor::initResource(const ade::NodeHandle &orig_nh)
}
}
class cv::gimpl::GExecutor::Input final: public cv::gimpl::GIslandExecutable::IInput
{
cv::gimpl::Mag &mag;
virtual cv::GRunArgs get() override
{
cv::GRunArgs res;
for (const auto &rc : desc()) { res.emplace_back(magazine::getArg(mag, rc)); }
return res;
}
virtual cv::GRunArgs try_get() override { return get(); }
public:
Input(cv::gimpl::Mag &m, const std::vector<RcDesc> &rcs) : mag(m) { set(rcs); }
};
class cv::gimpl::GExecutor::Output final: public cv::gimpl::GIslandExecutable::IOutput
{
cv::gimpl::Mag &mag;
virtual GRunArgP get(int idx) override { return magazine::getObjPtr(mag, desc()[idx]); }
virtual void post(GRunArgP&&) override { } // Do nothing here
public:
Output(cv::gimpl::Mag &m, const std::vector<RcDesc> &rcs) : mag(m) { set(rcs); }
};
void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args)
{
// (2)
@@ -144,8 +167,9 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args)
namespace util = ade::util;
//ensure that output Mat parameters are correctly allocated
for (auto index : util::iota(proto.out_nhs.size()) ) //FIXME: avoid copy of NodeHandle and GRunRsltComp ?
// ensure that output Mat parameters are correctly allocated
// FIXME: avoid copy of NodeHandle and GRunRsltComp ?
for (auto index : util::iota(proto.out_nhs.size()))
{
auto& nh = proto.out_nhs.at(index);
const Data &d = m_gm.metadata(nh).get<Data>();
@@ -162,8 +186,9 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args)
};
#if !defined(GAPI_STANDALONE)
// Building as part of OpenCV - follow OpenCV behavior
// In the case of cv::Mat if output buffer is not enough to hold the result, reallocate it
// Building as part of OpenCV - follow OpenCV behavior In
// the case of cv::Mat if output buffer is not enough to
// hold the result, reallocate it
if (cv::util::holds_alternative<cv::Mat*>(args.outObjs.at(index)))
{
auto& out_mat = *get<cv::Mat*>(args.outObjs.at(index));
@@ -204,24 +229,9 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args)
for (auto &op : m_ops)
{
// (5)
using InObj = GIslandExecutable::InObj;
using OutObj = GIslandExecutable::OutObj;
std::vector<InObj> in_objs;
std::vector<OutObj> out_objs;
in_objs.reserve (op.in_objects.size());
out_objs.reserve(op.out_objects.size());
for (const auto &rc : op.in_objects)
{
in_objs.emplace_back(InObj{rc, magazine::getArg(m_res, rc)});
}
for (const auto &rc : op.out_objects)
{
out_objs.emplace_back(OutObj{rc, magazine::getObjPtr(m_res, rc)});
}
// (6)
op.isl_exec->run(std::move(in_objs), std::move(out_objs));
Input i{m_res, op.in_objects};
Output o{m_res, op.out_objects};
op.isl_exec->run(i, o);
}
// (7)
+3
View File
@@ -77,6 +77,9 @@ protected:
};
std::vector<DataDesc> m_slots;
class Input;
class Output;
Mag m_res;
void initResource(const ade::NodeHandle &orig_nh); // FIXME: shouldn't it be RcDesc?