Enable state initialization params via compile_args
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GBACKEND_HPP
|
||||
@@ -87,14 +87,7 @@ struct GRuntimeArgs
|
||||
template<typename T>
|
||||
inline cv::util::optional<T> getCompileArg(const cv::GCompileArgs &args)
|
||||
{
|
||||
for (auto &compile_arg : args)
|
||||
{
|
||||
if (compile_arg.tag == cv::detail::CompileArgTag<T>::tag())
|
||||
{
|
||||
return cv::util::optional<T>(compile_arg.get<T>());
|
||||
}
|
||||
}
|
||||
return cv::util::optional<T>();
|
||||
return cv::gapi::getCompileArg<T>(args);
|
||||
}
|
||||
|
||||
void createMat(const cv::GMatDesc& desc, cv::Mat& mat);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
@@ -57,10 +57,10 @@ namespace
|
||||
}
|
||||
|
||||
virtual EPtr compile(const ade::Graph &graph,
|
||||
const cv::GCompileArgs &,
|
||||
const cv::GCompileArgs &compileArgs,
|
||||
const std::vector<ade::NodeHandle> &nodes) const override
|
||||
{
|
||||
return EPtr{new cv::gimpl::GCPUExecutable(graph, nodes)};
|
||||
return EPtr{new cv::gimpl::GCPUExecutable(graph, compileArgs, nodes)};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -73,8 +73,9 @@ cv::gapi::GBackend cv::gapi::cpu::backend()
|
||||
|
||||
// GCPUExecutable implementation //////////////////////////////////////////////
|
||||
cv::gimpl::GCPUExecutable::GCPUExecutable(const ade::Graph &g,
|
||||
const cv::GCompileArgs &compileArgs,
|
||||
const std::vector<ade::NodeHandle> &nodes)
|
||||
: m_g(g), m_gm(m_g)
|
||||
: m_g(g), m_gm(m_g), m_compileArgs(compileArgs)
|
||||
{
|
||||
// Convert list of operations (which is topologically sorted already)
|
||||
// into an execution script.
|
||||
@@ -166,7 +167,8 @@ void cv::gimpl::GCPUExecutable::setupKernelStates()
|
||||
const GCPUKernel& kernel = gcm.metadata(kernelNode).get<CPUUnit>().k;
|
||||
kernel.m_setupF(GModel::collectInputMeta(m_gm, kernelNode),
|
||||
m_gm.metadata(kernelNode).get<Op>().args,
|
||||
kernelState);
|
||||
kernelState,
|
||||
m_compileArgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GCPUBACKEND_HPP
|
||||
@@ -33,6 +33,7 @@ class GCPUExecutable final: public GIslandExecutable
|
||||
{
|
||||
const ade::Graph &m_g;
|
||||
GModel::ConstGraph m_gm;
|
||||
const cv::GCompileArgs m_compileArgs;
|
||||
|
||||
struct OperationInfo
|
||||
{
|
||||
@@ -42,22 +43,27 @@ class GCPUExecutable final: public GIslandExecutable
|
||||
|
||||
// Execution script, currently absolutely naive
|
||||
std::vector<OperationInfo> m_script;
|
||||
|
||||
// TODO: Check that it is thread-safe
|
||||
// Map of stateful kernel nodes to their kernels' states
|
||||
std::unordered_map<ade::NodeHandle, GArg,
|
||||
ade::HandleHasher<ade::Node>> m_nodesToStates;
|
||||
|
||||
// List of all resources in graph (both internal and external)
|
||||
std::vector<ade::NodeHandle> m_dataNodes;
|
||||
|
||||
// Actual data of all resources in graph (both internal and external)
|
||||
Mag m_res;
|
||||
|
||||
// Flag which identifies if new stream was started
|
||||
bool m_newStreamStarted = false;
|
||||
|
||||
GArg packArg(const GArg &arg);
|
||||
void setupKernelStates();
|
||||
|
||||
// TODO: Check that it is thread-safe
|
||||
std::unordered_map<ade::NodeHandle, GArg,
|
||||
ade::HandleHasher<ade::Node>> m_nodesToStates;
|
||||
|
||||
bool m_newStreamStarted = false;
|
||||
|
||||
public:
|
||||
GCPUExecutable(const ade::Graph &graph,
|
||||
const cv::GCompileArgs &compileArgs,
|
||||
const std::vector<ade::NodeHandle> &nodes);
|
||||
|
||||
virtual inline bool canReshape() const override { return false; }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
@@ -86,15 +86,15 @@ namespace
|
||||
return gim.metadata(nh).get<NodeKind>().k == NodeKind::ISLAND;
|
||||
});
|
||||
|
||||
const auto out_rois = cv::gimpl::getCompileArg<cv::GFluidOutputRois>(args);
|
||||
const auto out_rois = cv::gapi::getCompileArg<cv::GFluidOutputRois>(args);
|
||||
if (num_islands > 1 && out_rois.has_value())
|
||||
cv::util::throw_error(std::logic_error("GFluidOutputRois feature supports only one-island graphs"));
|
||||
|
||||
auto rois = out_rois.value_or(cv::GFluidOutputRois());
|
||||
|
||||
auto graph_data = fluidExtractInputDataFromGraph(graph, nodes);
|
||||
const auto parallel_out_rois = cv::gimpl::getCompileArg<cv::GFluidParallelOutputRois>(args);
|
||||
const auto gpfor = cv::gimpl::getCompileArg<cv::GFluidParallelFor>(args);
|
||||
const auto parallel_out_rois = cv::gapi::getCompileArg<cv::GFluidParallelOutputRois>(args);
|
||||
const auto gpfor = cv::gapi::getCompileArg<cv::GFluidParallelFor>(args);
|
||||
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
auto default_pfor = [](std::size_t count, std::function<void(std::size_t)> f){
|
||||
@@ -1236,7 +1236,7 @@ void cv::gimpl::GFluidExecutable::reshape(ade::Graph &g, const GCompileArgs &arg
|
||||
initLineConsumption(g);
|
||||
calcLatency(g);
|
||||
calcSkew(g);
|
||||
const auto out_rois = cv::gimpl::getCompileArg<cv::GFluidOutputRois>(args).value_or(cv::GFluidOutputRois());
|
||||
const auto out_rois = cv::gapi::getCompileArg<cv::GFluidOutputRois>(args).value_or(cv::GFluidOutputRois());
|
||||
makeReshape(out_rois.rois);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GOCLBACKEND_HPP
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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) 2019 Intel Corporation
|
||||
// Copyright (C) 2019-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifdef HAVE_PLAIDML
|
||||
@@ -57,7 +57,7 @@ namespace
|
||||
const std::vector<cv::gimpl::Data>& ins_data,
|
||||
const std::vector<cv::gimpl::Data>& outs_data) const override
|
||||
{
|
||||
auto has_config = cv::gimpl::getCompileArg<cv::gapi::plaidml::config>(args);
|
||||
auto has_config = cv::gapi::getCompileArg<cv::gapi::plaidml::config>(args);
|
||||
|
||||
if (!has_config)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace {
|
||||
const std::vector<ade::NodeHandle> &nodes) const override {
|
||||
|
||||
using namespace cv::gapi::wip::draw;
|
||||
auto has_freetype_font = cv::gimpl::getCompileArg<freetype_font>(args);
|
||||
auto has_freetype_font = cv::gapi::getCompileArg<freetype_font>(args);
|
||||
std::unique_ptr<FTTextRender> ftpr;
|
||||
if (has_freetype_font)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GCOMPILED_PRIV_HPP
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace
|
||||
return combine(pkg, aux_pkg);
|
||||
};
|
||||
|
||||
auto has_use_only = cv::gimpl::getCompileArg<cv::gapi::use_only>(args);
|
||||
auto has_use_only = cv::gapi::getCompileArg<cv::gapi::use_only>(args);
|
||||
if (has_use_only)
|
||||
return withAuxKernels(has_use_only.value().pkg);
|
||||
|
||||
@@ -75,20 +75,20 @@ namespace
|
||||
cv::gapi::GKernelPackage();
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
|
||||
auto user_pkg = cv::gimpl::getCompileArg<cv::gapi::GKernelPackage>(args);
|
||||
auto user_pkg = cv::gapi::getCompileArg<cv::gapi::GKernelPackage>(args);
|
||||
auto user_pkg_with_aux = withAuxKernels(user_pkg.value_or(cv::gapi::GKernelPackage{}));
|
||||
return combine(ocv_pkg, user_pkg_with_aux);
|
||||
}
|
||||
|
||||
cv::gapi::GNetPackage getNetworkPackage(cv::GCompileArgs &args)
|
||||
{
|
||||
return cv::gimpl::getCompileArg<cv::gapi::GNetPackage>(args)
|
||||
return cv::gapi::getCompileArg<cv::gapi::GNetPackage>(args)
|
||||
.value_or(cv::gapi::GNetPackage{});
|
||||
}
|
||||
|
||||
cv::util::optional<std::string> getGraphDumpDirectory(cv::GCompileArgs& args)
|
||||
{
|
||||
auto dump_info = cv::gimpl::getCompileArg<cv::graph_dump_path>(args);
|
||||
auto dump_info = cv::gapi::getCompileArg<cv::graph_dump_path>(args);
|
||||
if (!dump_info.has_value())
|
||||
{
|
||||
const char* path = std::getenv("GRAPH_DUMP_PATH");
|
||||
@@ -452,7 +452,8 @@ cv::GStreamingCompiled cv::gimpl::GCompiler::produceStreamingCompiled(GPtr &&pg)
|
||||
outMetas = GModel::ConstGraph(*pg).metadata().get<OutputMeta>().outMeta;
|
||||
}
|
||||
|
||||
std::unique_ptr<GStreamingExecutor> pE(new GStreamingExecutor(std::move(pg)));
|
||||
std::unique_ptr<GStreamingExecutor> pE(new GStreamingExecutor(std::move(pg),
|
||||
m_args));
|
||||
if (!m_metas.empty() && !outMetas.empty())
|
||||
{
|
||||
compiled.priv().setup(m_metas, outMetas, std::move(pE));
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// Copyright (C) 2018-2020 Intel Corporation
|
||||
|
||||
|
||||
#ifndef OPENCV_GAPI_GEXECUTOR_HPP
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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) 2019 Intel Corporation
|
||||
// Copyright (C) 2019-2020 Intel Corporation
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -603,10 +603,14 @@ void collectorThread(std::vector<Q*> in_queues,
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model)
|
||||
// GStreamingExecutor expects compile arguments as input to have possibility to do
|
||||
// proper graph reshape and islands recompilation
|
||||
cv::gimpl::GStreamingExecutor::GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
|
||||
const GCompileArgs &comp_args)
|
||||
: m_orig_graph(std::move(g_model))
|
||||
, m_island_graph(GModel::Graph(*m_orig_graph).metadata()
|
||||
.get<IslandModel>().model)
|
||||
, m_comp_args(comp_args)
|
||||
, m_gim(*m_island_graph)
|
||||
{
|
||||
GModel::Graph gm(*m_orig_graph);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// 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) 2019 Intel Corporation
|
||||
// Copyright (C) 2019-2020 Intel Corporation
|
||||
|
||||
#ifndef OPENCV_GAPI_GSTREAMING_EXECUTOR_HPP
|
||||
#define OPENCV_GAPI_GSTREAMING_EXECUTOR_HPP
|
||||
@@ -126,7 +126,8 @@ protected:
|
||||
void wait_shutdown();
|
||||
|
||||
public:
|
||||
explicit GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model);
|
||||
explicit GStreamingExecutor(std::unique_ptr<ade::Graph> &&g_model,
|
||||
const cv::GCompileArgs &comp_args);
|
||||
~GStreamingExecutor();
|
||||
void setSource(GRunArgs &&args);
|
||||
void start();
|
||||
|
||||
Reference in New Issue
Block a user