mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #19112 from rgarnov:rg/generic_copy_kernel
Generic copy kernel * Moved RMat wrapping of cv::Mats to StreamingInput * Generalized GCopy kernel * Generic GCopy kernel: applied review comments
This commit is contained in:
@@ -146,16 +146,26 @@ void writeBackExec(const Mag& mag, const RcDesc &rc, GRunArgP &g_arg)
|
||||
writeBack(mag, rc, g_arg);
|
||||
return;
|
||||
}
|
||||
auto checkOutArgData = [&](const uchar* out_arg_data) {
|
||||
//simply check that memory was not reallocated, i.e.
|
||||
//both Mat and View pointing to the same memory
|
||||
auto mag_data = mag.template slot<cv::RMat>().at(rc.id).get<RMatAdapter>()->data();
|
||||
GAPI_Assert((out_arg_data == mag_data) && " data for output parameters was reallocated ?");
|
||||
};
|
||||
|
||||
switch (g_arg.index())
|
||||
{
|
||||
case GRunArgP::index_of<cv::Mat*>() : checkOutArgData(util::get<cv::Mat*>(g_arg)->data); break;
|
||||
case GRunArgP::index_of<cv::Mat*>() : {
|
||||
// If there is a copy intrinsic at the end of the graph
|
||||
// we need to actualy copy the data to the user buffer
|
||||
// since output runarg was optimized to simply point
|
||||
// to the input of the copy kernel
|
||||
// FIXME:
|
||||
// Rework, find a better way to check if there should be
|
||||
// a real copy (add a pass to StreamingBackend?)
|
||||
auto& out_mat = *util::get<cv::Mat*>(g_arg);
|
||||
const auto& rmat = mag.template slot<cv::RMat>().at(rc.id);
|
||||
auto mag_data = rmat.get<RMatAdapter>()->data();
|
||||
if (out_mat.data != mag_data) {
|
||||
auto view = rmat.access(RMat::Access::R);
|
||||
asMat(view).copyTo(out_mat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GRunArgP::index_of<cv::RMat*>() : /* do nothing */ break;
|
||||
default: util::throw_error(std::logic_error("content type of the runtime argument does not match to resource description ?"));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "api/gproto_priv.hpp" // ptr(GRunArgP)
|
||||
#include "compiler/passes/passes.hpp"
|
||||
#include "backends/common/gbackend.hpp" // createMat
|
||||
#include "backends/streaming/gstreamingbackend.hpp" // GCopy
|
||||
#include "compiler/gcompiler.hpp" // for compileIslands
|
||||
|
||||
#include "executor/gstreamingexecutor.hpp"
|
||||
@@ -535,6 +536,14 @@ class StreamingInput final: public cv::gimpl::GIslandExecutable::IInput
|
||||
// Stop case
|
||||
return cv::gimpl::StreamMsg{cv::gimpl::EndOfStream{}};
|
||||
}
|
||||
// Wrap all input cv::Mats with RMats
|
||||
for (auto& arg : isl_input_args) {
|
||||
if (arg.index() == cv::GRunArg::index_of<cv::Mat>()) {
|
||||
arg = cv::GRunArg{ cv::make_rmat<cv::gimpl::RMatAdapter>(cv::util::get<cv::Mat>(arg))
|
||||
, arg.meta
|
||||
};
|
||||
}
|
||||
}
|
||||
return cv::gimpl::StreamMsg{std::move(isl_input_args)};
|
||||
}
|
||||
virtual cv::gimpl::StreamMsg try_get() override
|
||||
@@ -1000,7 +1009,7 @@ cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr<ade::Graph> &&
|
||||
GAPI_Assert(GModel::Graph(*m_orig_graph)
|
||||
.metadata(*isl->in_ops().begin())
|
||||
.get<cv::gimpl::Op>()
|
||||
.k.name == cv::gapi::core::GCopy::id());
|
||||
.k.name == cv::gimpl::streaming::GCopy::id());
|
||||
#endif // GAPI_STANDALONE
|
||||
for (auto out_nh : nh->outNodes()) {
|
||||
for (auto out_eh : out_nh->outEdges()) {
|
||||
|
||||
Reference in New Issue
Block a user