mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #20298 from mpashchenkov:mp/python-desync
G-API: Python. Desync. * Desync. GMat. * Alignment
This commit is contained in:
committed by
GitHub
parent
050ea9762f
commit
05f1939b02
@@ -1017,6 +1017,49 @@ void check_DesyncObjectConsumedByMultipleIslands(const cv::gimpl::GIslandModel::
|
||||
} // for(nodes)
|
||||
}
|
||||
|
||||
// NB: Construct GRunArgsP based on passed info and store the memory in passed cv::GRunArgs.
|
||||
// Needed for python bridge, because in case python user doesn't pass output arguments to apply.
|
||||
void constructOptGraphOutputs(const cv::GTypesInfo &out_info,
|
||||
cv::GOptRunArgs &args,
|
||||
cv::GOptRunArgsP &outs)
|
||||
{
|
||||
for (auto&& info : out_info)
|
||||
{
|
||||
switch (info.shape)
|
||||
{
|
||||
case cv::GShape::GMAT:
|
||||
{
|
||||
args.emplace_back(cv::optional<cv::Mat>{});
|
||||
outs.emplace_back(&cv::util::get<cv::optional<cv::Mat>>(args.back()));
|
||||
break;
|
||||
}
|
||||
case cv::GShape::GSCALAR:
|
||||
{
|
||||
args.emplace_back(cv::optional<cv::Scalar>{});
|
||||
outs.emplace_back(&cv::util::get<cv::optional<cv::Scalar>>(args.back()));
|
||||
break;
|
||||
}
|
||||
case cv::GShape::GARRAY:
|
||||
{
|
||||
cv::detail::VectorRef ref;
|
||||
cv::util::get<cv::detail::ConstructVec>(info.ctor)(ref);
|
||||
args.emplace_back(cv::util::make_optional(std::move(ref)));
|
||||
outs.emplace_back(wrap_opt_arg(cv::util::get<cv::optional<cv::detail::VectorRef>>(args.back())));
|
||||
break;
|
||||
}
|
||||
case cv::GShape::GOPAQUE:
|
||||
{
|
||||
cv::detail::OpaqueRef ref;
|
||||
cv::util::get<cv::detail::ConstructOpaque>(info.ctor)(ref);
|
||||
args.emplace_back(cv::util::make_optional(std::move(ref)));
|
||||
outs.emplace_back(wrap_opt_arg(cv::util::get<cv::optional<cv::detail::OpaqueRef>>(args.back())));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
cv::util::throw_error(std::logic_error("Unsupported optional output shape for Python"));
|
||||
}
|
||||
}
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
class cv::gimpl::GStreamingExecutor::Synchronizer final {
|
||||
@@ -1320,6 +1363,16 @@ cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr<ade::Graph> &&
|
||||
// per the same input frame, so the output traffic multiplies)
|
||||
GAPI_Assert(m_collector_map.size() > 0u);
|
||||
m_out_queue.set_capacity(queue_capacity * m_collector_map.size());
|
||||
|
||||
// FIXME: The code duplicates logic of collectGraphInfo()
|
||||
cv::gimpl::GModel::ConstGraph cgr(*m_orig_graph);
|
||||
auto meta = cgr.metadata().get<cv::gimpl::Protocol>().out_nhs;
|
||||
out_info.reserve(meta.size());
|
||||
|
||||
ade::util::transform(meta, std::back_inserter(out_info), [&cgr](const ade::NodeHandle& nh) {
|
||||
const auto& data = cgr.metadata(nh).get<cv::gimpl::Data>();
|
||||
return cv::GTypeInfo{data.shape, data.kind, data.ctor};
|
||||
});
|
||||
}
|
||||
|
||||
cv::gimpl::GStreamingExecutor::~GStreamingExecutor()
|
||||
@@ -1653,6 +1706,31 @@ bool cv::gimpl::GStreamingExecutor::pull(cv::GOptRunArgsP &&outs)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>> cv::gimpl::GStreamingExecutor::pull()
|
||||
{
|
||||
using RunArgs = cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>;
|
||||
bool is_over = false;
|
||||
|
||||
if (m_desync) {
|
||||
GOptRunArgs opt_run_args;
|
||||
GOptRunArgsP opt_outs;
|
||||
opt_outs.reserve(out_info.size());
|
||||
opt_run_args.reserve(out_info.size());
|
||||
|
||||
constructOptGraphOutputs(out_info, opt_run_args, opt_outs);
|
||||
is_over = pull(std::move(opt_outs));
|
||||
return std::make_tuple(is_over, RunArgs(opt_run_args));
|
||||
}
|
||||
|
||||
GRunArgs run_args;
|
||||
GRunArgsP outs;
|
||||
run_args.reserve(out_info.size());
|
||||
outs.reserve(out_info.size());
|
||||
|
||||
constructGraphOutputs(out_info, run_args, outs);
|
||||
is_over = pull(std::move(outs));
|
||||
return std::make_tuple(is_over, RunArgs(run_args));
|
||||
}
|
||||
|
||||
bool cv::gimpl::GStreamingExecutor::try_pull(cv::GRunArgsP &&outs)
|
||||
{
|
||||
|
||||
@@ -195,6 +195,8 @@ protected:
|
||||
|
||||
void wait_shutdown();
|
||||
|
||||
cv::GTypesInfo out_info;
|
||||
|
||||
public:
|
||||
explicit GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
|
||||
const cv::GCompileArgs &comp_args);
|
||||
@@ -203,6 +205,7 @@ public:
|
||||
void start();
|
||||
bool pull(cv::GRunArgsP &&outs);
|
||||
bool pull(cv::GOptRunArgsP &&outs);
|
||||
std::tuple<bool, cv::util::variant<cv::GRunArgs, cv::GOptRunArgs>> pull();
|
||||
bool try_pull(cv::GRunArgsP &&outs);
|
||||
void stop();
|
||||
bool running() const;
|
||||
|
||||
Reference in New Issue
Block a user