Skip to content

G-API: Add support to set workloadtype dynamically #27460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 4.x
Choose a base branch
from

Conversation

fcmiron
Copy link

@fcmiron fcmiron commented Jun 19, 2025

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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

@fcmiron fcmiron changed the title Add support to set workloadtype dynamically G-API: Add support to set workloadtype dynamically Jun 19, 2025
@fcmiron fcmiron marked this pull request as ready for review June 19, 2025 12:33
@asmorkalov asmorkalov added this to the 4.12.0 milestone Jun 19, 2025
@dmatveev dmatveev requested a review from AsyaPronina June 23, 2025 11:20
@asmorkalov
Copy link
Contributor

@AsyaPronina Friendly reminder.

@asmorkalov asmorkalov modified the milestones: 4.12.0, 4.13.0 Jun 26, 2025
@AsyaPronina
Copy link
Contributor

Hello Dear @fcmiron, could I please ask you to rename this PR to take into account that this change is only for OpenVINO backend?

@@ -702,6 +725,14 @@ namespace detail
{
static const char* tag() { return "gapi.wip.ov.benchmark_mode"; }
};
template<> struct CompileArgTag<cv::gapi::wip::ov::workload_type>
Copy link
Contributor

@AsyaPronina AsyaPronina Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just note: I think we will need the same compile argument for ONNXRT backends after.

@@ -1578,6 +1582,10 @@ cv::gimpl::ov::GOVExecutable::GOVExecutable(const ade::Graph &g,
}
}

void cv::gimpl::ov::GOVExecutable::setWorkLoadType(const std::string &type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I see in test it should be enum and not a string for OpenVINO:
https://github.com/dvpv/openvino/blob/master/src/plugins/intel_npu/tests/functional/internal/overload/compile_and_infer.hpp#L96

Please see the definition here:
https://github.com/dvpv/openvino/blob/master/src/inference/include/openvino/runtime/properties.hpp#L747

static constexpr Property<WorkloadType, PropertyMutability::RW> workload_type{"WORKLOAD_TYPE"};

@@ -1542,6 +1542,10 @@ cv::gimpl::ov::GOVExecutable::GOVExecutable(const ade::Graph &g,
const std::vector<ade::NodeHandle> &nodes)
: m_g(g), m_gm(m_g) {

if(cv::gapi::getCompileArg<std::reference_wrapper<cv::gapi::wip::ov::workload_type>>(compileArgs).has_value()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to split this check for two lines: to retrieve compile arg and then check if it has_value()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or might be create a brief alias for std::reference_wrapper here

@@ -1542,6 +1542,10 @@ cv::gimpl::ov::GOVExecutable::GOVExecutable(const ade::Graph &g,
const std::vector<ade::NodeHandle> &nodes)
: m_g(g), m_gm(m_g) {

if(cv::gapi::getCompileArg<std::reference_wrapper<cv::gapi::wip::ov::workload_type>>(compileArgs).has_value()) {
auto workload_type = cv::gapi::getCompileArg<std::reference_wrapper<cv::gapi::wip::ov::workload_type>>(compileArgs).value();
listenerRemover = workload_type.get().addListener(std::bind(&GOVExecutable::setWorkLoadType, this, std::placeholders::_1));
Copy link
Contributor

@AsyaPronina AsyaPronina Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to check workload_type.get() for nullptr if it is possible that workload_type.get() can have nullptr inside

};
template<> struct CompileArgTag<std::reference_wrapper<cv::gapi::wip::ov::workload_type>>
{
static const char* tag() { return "gapi.wip.ov.workload_type_ref"; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need both: ref and val cases?


auto remover = [this, id](void*){ removeListener(id);};

return std::shared_ptr<void>(nullptr, remover);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea to remove listeners that way. It seems a bit tricky. I understand that this variable may outlive G-API OV backend. But, might be, we can clean this variable's listeners in the destructor of G-API OV backend itself. Please note that we are the "users" of given API to add listeners and we 100% know when we add a listener and when we can remove it, so there is no need for some RAII idiom for remove. If this is allowable, we can preserve these compile args somewhere in backend to access variable in the destructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy