// 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-2021 Intel Corporation #include "precomp.hpp" #include // cerr #include // hash #include // accumulate #include #include "logger.hpp" #include #include "api/gbackend_priv.hpp" // GKernelPackage public implementation //////////////////////////////////////// void cv::gapi::GKernelPackage::remove(const cv::gapi::GBackend& backend) { std::vector id_deleted_kernels; for (const auto& p : m_id_kernels) { if (p.second.first == backend) { id_deleted_kernels.push_back(p.first); } } for (const auto& kernel_id : id_deleted_kernels) { m_id_kernels.erase(kernel_id); } } bool cv::gapi::GKernelPackage::includesAPI(const std::string &id) const { return ade::util::contains(m_id_kernels, id); } void cv::gapi::GKernelPackage::removeAPI(const std::string &id) { m_id_kernels.erase(id); } std::size_t cv::gapi::GKernelPackage::size() const { return m_id_kernels.size(); } const std::vector &cv::gapi::GKernelPackage::get_transformations() const { return m_transformations; } std::vector cv::gapi::GKernelPackage::get_kernel_ids() const { std::vector ids; for (auto &&id : m_id_kernels) { ids.emplace_back(id.first); } return ids; } cv::gapi::GKernelPackage cv::gapi::combine(const GKernelPackage &lhs, const GKernelPackage &rhs) { // If there is a collision, prefer RHS to LHS // since RHS package has a precedense, start with its copy GKernelPackage result(rhs); // now iterate over LHS package and put kernel if and only // if there's no such one for (const auto& kernel : lhs.m_id_kernels) { if (!result.includesAPI(kernel.first)) { result.m_id_kernels.emplace(kernel.first, kernel.second); } } for (const auto &transforms : lhs.m_transformations){ result.m_transformations.push_back(transforms); } return result; } std::pair cv::gapi::GKernelPackage::lookup(const std::string &id) const { auto kernel_it = m_id_kernels.find(id); if (kernel_it != m_id_kernels.end()) { return kernel_it->second; } // If reached here, kernel was not found. util::throw_error(std::logic_error("Kernel " + id + " was not found")); } std::vector cv::gapi::GKernelPackage::backends() const { using kernel_type = std::pair>; std::unordered_set unique_set; ade::util::transform(m_id_kernels, std::inserter(unique_set, unique_set.end()), [](const kernel_type& k) { return k.second.first; }); return std::vector(unique_set.begin(), unique_set.end()); }