From 54ff72a1cce8cc77f8fb6e9f5cd4f840b4c8879e Mon Sep 17 00:00:00 2001 From: Ruslan Garnov Date: Wed, 22 May 2019 21:13:13 +0300 Subject: [PATCH] Merge pull request #14599 from rgarnov:gapi_aux_kernels G-API aux kernels (#14599) * Removed gcpuimgproc.hpp and gcpucore.hpp * Changed GModel::orderedInputs and orderedOutputs to get ConstGraph& * Added auxiliaryKernels() method of GBackend::Priv --- modules/gapi/src/api/gbackend.cpp | 5 ++++ modules/gapi/src/api/gbackend_priv.hpp | 2 ++ modules/gapi/src/backends/cpu/gcpubackend.cpp | 4 ++-- modules/gapi/src/backends/cpu/gcpucore.cpp | 2 +- modules/gapi/src/backends/cpu/gcpucore.hpp | 24 ------------------- modules/gapi/src/backends/cpu/gcpuimgproc.cpp | 2 +- modules/gapi/src/backends/cpu/gcpuimgproc.hpp | 23 ------------------ modules/gapi/src/compiler/gcompiler.cpp | 13 ++++++++-- modules/gapi/src/compiler/gmodel.cpp | 4 ++-- modules/gapi/src/compiler/gmodel.hpp | 4 ++-- 10 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 modules/gapi/src/backends/cpu/gcpucore.hpp delete mode 100644 modules/gapi/src/backends/cpu/gcpuimgproc.hpp diff --git a/modules/gapi/src/api/gbackend.cpp b/modules/gapi/src/api/gbackend.cpp index 3dfd2ef83b..0eb3793858 100644 --- a/modules/gapi/src/api/gbackend.cpp +++ b/modules/gapi/src/api/gbackend.cpp @@ -45,6 +45,11 @@ void cv::gapi::GBackend::Priv::addBackendPasses(ade::ExecutionEngineSetupContext // add custom (backend-specific) graph transformations } +cv::gapi::GKernelPackage cv::gapi::GBackend::Priv::auxiliaryKernels() const +{ + return {}; +} + // GBackend public implementation ////////////////////////////////////////////// cv::gapi::GBackend::GBackend() { diff --git a/modules/gapi/src/api/gbackend_priv.hpp b/modules/gapi/src/api/gbackend_priv.hpp index 1c6e297157..afc77b2163 100644 --- a/modules/gapi/src/api/gbackend_priv.hpp +++ b/modules/gapi/src/api/gbackend_priv.hpp @@ -47,6 +47,8 @@ public: virtual void addBackendPasses(ade::ExecutionEngineSetupContext &); + virtual cv::gapi::GKernelPackage auxiliaryKernels() const; + virtual ~Priv() = default; }; diff --git a/modules/gapi/src/backends/cpu/gcpubackend.cpp b/modules/gapi/src/backends/cpu/gcpubackend.cpp index 8924e3d21d..9da0641d2c 100644 --- a/modules/gapi/src/backends/cpu/gcpubackend.cpp +++ b/modules/gapi/src/backends/cpu/gcpubackend.cpp @@ -26,8 +26,8 @@ #include "compiler/gmodel.hpp" #include "backends/cpu/gcpubackend.hpp" -#include "backends/cpu/gcpuimgproc.hpp" -#include "backends/cpu/gcpucore.hpp" +#include "opencv2/gapi/cpu/imgproc.hpp" +#include "opencv2/gapi/cpu/core.hpp" #include "api/gbackend_priv.hpp" // FIXME: Make it part of Backend SDK! diff --git a/modules/gapi/src/backends/cpu/gcpucore.cpp b/modules/gapi/src/backends/cpu/gcpucore.cpp index cec9abcd5c..542fdb1cab 100644 --- a/modules/gapi/src/backends/cpu/gcpucore.cpp +++ b/modules/gapi/src/backends/cpu/gcpucore.cpp @@ -9,7 +9,7 @@ #include "opencv2/gapi/core.hpp" #include "opencv2/gapi/cpu/core.hpp" -#include "backends/cpu/gcpucore.hpp" +#include "opencv2/gapi/cpu/gcpukernel.hpp" GAPI_OCV_KERNEL(GCPUAdd, cv::gapi::core::GAdd) { diff --git a/modules/gapi/src/backends/cpu/gcpucore.hpp b/modules/gapi/src/backends/cpu/gcpucore.hpp deleted file mode 100644 index 77e9e82a00..0000000000 --- a/modules/gapi/src/backends/cpu/gcpucore.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// This file is part of OpenCV project. -// 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 - - -#ifndef OPENCV_GAPI_GCPUCORE_HPP -#define OPENCV_GAPI_GCPUCORE_HPP - -#include -#include - -#include "opencv2/gapi/cpu/gcpukernel.hpp" - -namespace cv { namespace gimpl { - -// NB: This is what a "Kernel Package" from the original Wiki doc should be. -void loadCPUCore(std::map &kmap); - -} -} - -#endif // OPENCV_GAPI_GCPUCORE_HPP diff --git a/modules/gapi/src/backends/cpu/gcpuimgproc.cpp b/modules/gapi/src/backends/cpu/gcpuimgproc.cpp index ab5d5d8fd4..e7ca1bb195 100644 --- a/modules/gapi/src/backends/cpu/gcpuimgproc.cpp +++ b/modules/gapi/src/backends/cpu/gcpuimgproc.cpp @@ -9,7 +9,7 @@ #include "opencv2/gapi/imgproc.hpp" #include "opencv2/gapi/cpu/imgproc.hpp" -#include "backends/cpu/gcpuimgproc.hpp" +#include "opencv2/gapi/cpu/gcpukernel.hpp" namespace { cv::Mat add_border(const cv::Mat& in, const int ksize, const int borderType, const cv::Scalar& bordVal){ diff --git a/modules/gapi/src/backends/cpu/gcpuimgproc.hpp b/modules/gapi/src/backends/cpu/gcpuimgproc.hpp deleted file mode 100644 index 172871a777..0000000000 --- a/modules/gapi/src/backends/cpu/gcpuimgproc.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// This file is part of OpenCV project. -// 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 - - -#ifndef OPENCV_GAPI_GCPUIMGPROC_HPP -#define OPENCV_GAPI_GCPUIMGPROC_HPP - -#include -#include - -#include "opencv2/gapi/cpu/gcpukernel.hpp" - -namespace cv { namespace gimpl { - -// NB: This is what a "Kernel Package" from the origianl Wiki doc should be. -void loadCPUImgProc(std::map &kmap); - -}} - -#endif // OPENCV_GAPI_GCPUIMGPROC_HPP diff --git a/modules/gapi/src/compiler/gcompiler.cpp b/modules/gapi/src/compiler/gcompiler.cpp index 667784171c..82e484daf3 100644 --- a/modules/gapi/src/compiler/gcompiler.cpp +++ b/modules/gapi/src/compiler/gcompiler.cpp @@ -48,9 +48,17 @@ namespace { cv::gapi::GKernelPackage getKernelPackage(cv::GCompileArgs &args) { + auto withAuxKernels = [](const cv::gapi::GKernelPackage& pkg) { + cv::gapi::GKernelPackage aux_pkg; + for (const auto &b : pkg.backends()) { + aux_pkg = combine(aux_pkg, b.priv().auxiliaryKernels()); + } + return combine(pkg, aux_pkg); + }; + auto has_use_only = cv::gimpl::getCompileArg(args); if (has_use_only) - return has_use_only.value().pkg; + return withAuxKernels(has_use_only.value().pkg); static auto ocv_pkg = #if !defined(GAPI_STANDALONE) @@ -60,7 +68,8 @@ namespace cv::gapi::GKernelPackage(); #endif // !defined(GAPI_STANDALONE) auto user_pkg = cv::gimpl::getCompileArg(args); - return combine(ocv_pkg, user_pkg.value_or(cv::gapi::GKernelPackage{})); + auto user_pkg_with_aux = withAuxKernels(user_pkg.value_or(cv::gapi::GKernelPackage{})); + return combine(ocv_pkg, user_pkg_with_aux); } cv::util::optional getGraphDumpDirectory(cv::GCompileArgs& args) diff --git a/modules/gapi/src/compiler/gmodel.cpp b/modules/gapi/src/compiler/gmodel.cpp index 92ffb2d670..180a0fb2ff 100644 --- a/modules/gapi/src/compiler/gmodel.cpp +++ b/modules/gapi/src/compiler/gmodel.cpp @@ -114,7 +114,7 @@ void GModel::linkOut(Graph &g, ade::NodeHandle opH, ade::NodeHandle objH, std::s op.outs[out_port] = RcDesc{gm.rc, gm.shape, {}}; } -std::vector GModel::orderedInputs(Graph &g, ade::NodeHandle nh) +std::vector GModel::orderedInputs(ConstGraph &g, ade::NodeHandle nh) { std::vector sorted_in_nhs(nh->inEdges().size()); for (const auto& in_eh : nh->inEdges()) @@ -126,7 +126,7 @@ std::vector GModel::orderedInputs(Graph &g, ade::NodeHandle nh) return sorted_in_nhs; } -std::vector GModel::orderedOutputs(Graph &g, ade::NodeHandle nh) +std::vector GModel::orderedOutputs(ConstGraph &g, ade::NodeHandle nh) { std::vector sorted_out_nhs(nh->outEdges().size()); for (const auto& out_eh : nh->outEdges()) diff --git a/modules/gapi/src/compiler/gmodel.hpp b/modules/gapi/src/compiler/gmodel.hpp index dfe65a1e83..5e951c74bc 100644 --- a/modules/gapi/src/compiler/gmodel.hpp +++ b/modules/gapi/src/compiler/gmodel.hpp @@ -201,8 +201,8 @@ namespace GModel GAPI_EXPORTS void redirectReaders(Graph &g, ade::NodeHandle from, ade::NodeHandle to); GAPI_EXPORTS void redirectWriter (Graph &g, ade::NodeHandle from, ade::NodeHandle to); - GAPI_EXPORTS std::vector orderedInputs (Graph &g, ade::NodeHandle nh); - GAPI_EXPORTS std::vector orderedOutputs(Graph &g, ade::NodeHandle nh); + GAPI_EXPORTS std::vector orderedInputs (ConstGraph &g, ade::NodeHandle nh); + GAPI_EXPORTS std::vector orderedOutputs(ConstGraph &g, ade::NodeHandle nh); // Returns input meta array for given op node // Array is sparse, as metadata for non-gapi input objects is empty