-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
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
base: 4.x
Are you sure you want to change the base?
Conversation
@AsyaPronina Friendly reminder. |
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> |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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"; } |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.