mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #27460 from fcmiron:gapi_set_workloadtype_dynamically
G-API: Add support to set workload type dynamically in both OpenVINO and ONNX OVEP #27460 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [ ] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <opencv2/core/cvdef.h> // GAPI_EXPORTS
|
||||
#include <opencv2/gapi/gkernel.hpp> // GKernelPackage
|
||||
#include <opencv2/gapi/infer.hpp> // Generic
|
||||
#include <opencv2/gapi/infer/workload_type.hpp>
|
||||
|
||||
namespace cv {
|
||||
namespace gapi {
|
||||
@@ -752,8 +753,16 @@ protected:
|
||||
std::string m_tag;
|
||||
};
|
||||
|
||||
class WorkloadTypeONNX : public WorkloadType {};
|
||||
using WorkloadTypeONNXPtr = std::shared_ptr<cv::gapi::onnx::WorkloadTypeONNX>;
|
||||
|
||||
} // namespace onnx
|
||||
} // namespace gapi
|
||||
namespace detail {
|
||||
template<> struct CompileArgTag<cv::gapi::onnx::WorkloadTypeONNXPtr> {
|
||||
static const char* tag() { return "gapi.onnx.workload_type"; }
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
||||
#endif // OPENCV_GAPI_INFER_HPP
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <opencv2/gapi/own/exports.hpp> // GAPI_EXPORTS
|
||||
#include <opencv2/gapi/gkernel.hpp> // GKernelType[M], GBackend
|
||||
#include <opencv2/gapi/infer.hpp> // Generic
|
||||
#include <opencv2/gapi/infer/workload_type.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -745,6 +746,9 @@ namespace wip { namespace ov {
|
||||
*/
|
||||
struct benchmark_mode { };
|
||||
|
||||
class WorkloadTypeOV : public WorkloadType {};
|
||||
using WorkloadTypeOVPtr = std::shared_ptr<cv::gapi::wip::ov::WorkloadTypeOV>;
|
||||
|
||||
} // namespace ov
|
||||
} // namespace wip
|
||||
|
||||
@@ -756,6 +760,10 @@ namespace detail
|
||||
{
|
||||
static const char* tag() { return "gapi.wip.ov.benchmark_mode"; }
|
||||
};
|
||||
template<> struct CompileArgTag<cv::gapi::wip::ov::WorkloadTypeOVPtr>
|
||||
{
|
||||
static const char* tag() { return "gapi.wip.ov.workload_type"; }
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// 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) 2025 Intel Corporation
|
||||
|
||||
#ifndef OPENCV_WORKLOADTYPE_HPP
|
||||
#define OPENCV_WORKLOADTYPE_HPP
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using Callback = std::function<void(const std::string &type)>;
|
||||
|
||||
class WorkloadListener {
|
||||
Callback callback;
|
||||
public:
|
||||
uint64_t id;
|
||||
WorkloadListener(const Callback &cb, uint64_t listener_id) : callback(cb), id(listener_id) {}
|
||||
|
||||
void operator()(const std::string &type) const {
|
||||
if (callback) {
|
||||
callback(type);
|
||||
}
|
||||
}
|
||||
|
||||
bool operator==(const WorkloadListener& other) const {
|
||||
return id == other.id;
|
||||
}
|
||||
};
|
||||
class WorkloadType {
|
||||
std::vector<WorkloadListener> listeners;
|
||||
uint64_t nextId = 1;
|
||||
public:
|
||||
uint64_t addListener(const Callback &cb) {
|
||||
uint64_t id = nextId++;
|
||||
listeners.emplace_back(cb, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void removeListener(uint64_t id) {
|
||||
auto it = std::remove_if(listeners.begin(), listeners.end(),
|
||||
[id](const WorkloadListener& entry) { return entry.id == id; });
|
||||
if (it != listeners.end()) {
|
||||
listeners.erase(it, listeners.end());
|
||||
}
|
||||
}
|
||||
|
||||
void notify(const std::string &type) {
|
||||
for (const auto &listener : listeners) {
|
||||
listener(type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // OPENCV_WORKLOADTYPE_HPP
|
||||
Reference in New Issue
Block a user