|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
|
|
|
|
|
#include <ade/util/zip_range.hpp>
|
|
|
#include <ade/graph.hpp>
|
|
|
#include <ade/passes/check_cycles.hpp>
|
|
|
|
|
|
#include "compiler/gmodel.hpp"
|
|
|
#include "compiler/passes/passes.hpp"
|
|
|
#include "logger.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cv::gimpl::passes::initMeta(ade::passes::PassContext &ctx, const GMetaArgs &metas)
|
|
|
{
|
|
|
GModel::Graph gr(ctx.graph);
|
|
|
|
|
|
const auto &proto = gr.metadata().get<Protocol>();
|
|
|
|
|
|
for (const auto it : ade::util::indexed(proto.in_nhs))
|
|
|
{
|
|
|
auto& data = gr.metadata(ade::util::value(it)).get<Data>();
|
|
|
data.meta = metas.at(ade::util::index(it));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cv::gimpl::passes::inferMeta(ade::passes::PassContext &ctx, bool meta_is_initialized)
|
|
|
{
|
|
|
|
|
|
|
|
|
GModel::Graph gr(ctx.graph);
|
|
|
|
|
|
const auto sorted = gr.metadata().get<ade::passes::TopologicalSortData>() ;
|
|
|
for (const auto &nh : sorted.nodes())
|
|
|
{
|
|
|
if (gr.metadata(nh).get<NodeType>().t == NodeType::OP)
|
|
|
{
|
|
|
const auto& op = gr.metadata(nh).get<Op>();
|
|
|
GAPI_Assert(op.k.outMeta != nullptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GMetaArgs input_meta_args(op.args.size());
|
|
|
|
|
|
|
|
|
|
|
|
GAPI_Assert(nh->inEdges().size() > 0);
|
|
|
for (const auto &in_eh : nh->inEdges())
|
|
|
{
|
|
|
const auto& input_port = gr.metadata(in_eh).get<Input>().port;
|
|
|
const auto& input_nh = in_eh->srcNode();
|
|
|
GAPI_Assert(gr.metadata(input_nh).get<NodeType>().t == NodeType::DATA);
|
|
|
|
|
|
const auto& input_meta = gr.metadata(input_nh).get<Data>().meta;
|
|
|
if (util::holds_alternative<util::monostate>(input_meta))
|
|
|
{
|
|
|
|
|
|
|
|
|
util::throw_error(std::logic_error("Fatal: input object's metadata "
|
|
|
"not found!"));
|
|
|
|
|
|
}
|
|
|
input_meta_args.at(input_port) = input_meta;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto out_metas = gr.metadata(nh).contains<CustomMetaFunction>()
|
|
|
? gr.metadata(nh).get<CustomMetaFunction>().customOutMeta(ctx.graph,
|
|
|
nh,
|
|
|
input_meta_args,
|
|
|
op.args)
|
|
|
: op.k.outMeta(input_meta_args, op.args);
|
|
|
|
|
|
|
|
|
|
|
|
GAPI_Assert(nh->outEdges().size() > 0);
|
|
|
for (const auto &out_eh : nh->outEdges())
|
|
|
{
|
|
|
const auto &output_port = gr.metadata(out_eh).get<Output>().port;
|
|
|
const auto &output_nh = out_eh->dstNode();
|
|
|
GAPI_Assert(gr.metadata(output_nh).get<NodeType>().t == NodeType::DATA);
|
|
|
|
|
|
auto &output_meta = gr.metadata(output_nh).get<Data>().meta;
|
|
|
|
|
|
cv::util::suppress_unused_warning(meta_is_initialized);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output_meta = out_metas.at(output_port);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cv::gimpl::passes::storeResultingMeta(ade::passes::PassContext &ctx)
|
|
|
{
|
|
|
GModel::Graph gr(ctx.graph);
|
|
|
|
|
|
const auto &proto = gr.metadata().get<Protocol>();
|
|
|
GMetaArgs output_metas(proto.out_nhs.size());
|
|
|
|
|
|
for (const auto it : ade::util::indexed(proto.out_nhs))
|
|
|
{
|
|
|
auto& data = gr.metadata(ade::util::value(it)).get<Data>();
|
|
|
output_metas[ade::util::index(it)] = data.meta;
|
|
|
}
|
|
|
|
|
|
gr.metadata().set(OutputMeta{output_metas});
|
|
|
}
|
|
|
|