CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
G-API: Implement inference only mode for OV backend #24584
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
G-API: Implement inference only mode for OV backend #24584
Conversation
@dmatveev Could you have a look, please? |
* This mode is used to evaluate the pure inference performance of the model without | ||
* taking into account the i/o data transfer. | ||
*/ | ||
struct inference_only { }; |
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'd move it to
cv::gapi::wip
- I'd rename it to
benchmark_mode
to illustrate the purpose.
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.
Should it be cv::gapi::wip
or cv::gapi::wip::ov
?
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.
the latter, of course.
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.
Done
@@ -252,7 +252,8 @@ class OVCallContext | |||
const std::vector<cv::gimpl::RcDesc> & outs, | |||
cv::GRunArg::Meta && meta, | |||
std::vector<cv::gimpl::GIslandExecutable::InObj> && input_objs, | |||
std::vector<cv::gimpl::GIslandExecutable::OutObj> && output_objs); | |||
std::vector<cv::gimpl::GIslandExecutable::OutObj> && output_objs, | |||
const bool inference_only); |
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.
probably you can omit it from there - as it is not the mandatory parameter.
it can be false
internally by default.
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.
This is the place where inference_only
from GOVExecutable
is propogated to the specific inference kernel
(e.g Infer, InferList, etc):
https://github.com/TolyaTalamanov/opencv/blob/at/implement-inference-only-mode-for-ov-backend/modules/gapi/src/backends/ov/govbackend.cpp#L1501-L1502
I guess there is no sense to do something like that:
auto ctx = std::make_shared<OVCallContext>(uu, out, op.args, op.outs,
std::move(stub_meta), std::move(input_objs), std::move(output_objs));
if (m_inference_only) {
ctx->enableInferenceOnly();
}
It's easier to pass this straight to context ctor.
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.
It should remain in the class but it shouldn't be a mandatory constructor argument
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.
Done
m_inference_only = | ||
cv::gapi::getCompileArg<cv::gapi::ov::inference_only>(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.
probably you don't want to track all the individual fine-tuning knobs here, so I'd propose a configuration-like structure instead..
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.
Do you mean something like this?
namespace cv { namespace gapi { namespace wip { namespace { ov {
struct execution_config {
bool enable_benchmark_mode = false;
};
} // ov
} // wip
} // gapi
} // cv
// Example:
auto compile_args = cv::compile_args(cv::gapi::wip::ov::execution_config{ true /* benchmark mode */ };
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.
Not at the API level. Inside.
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.
Done
@@ -1471,7 +1499,7 @@ void cv::gimpl::ov::GOVExecutable::run(cv::gimpl::GIslandExecutable::IInput &in | |||
const auto &op = m_gm.metadata(this_nh).get<Op>(); | |||
|
|||
auto ctx = std::make_shared<OVCallContext>(uu, out, op.args, op.outs, | |||
std::move(stub_meta), std::move(input_objs), std::move(output_objs)); | |||
std::move(stub_meta), std::move(input_objs), std::move(output_objs), m_inference_only); |
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.
..and pass it as a whole thing here.
This method was quite generic, but now it knows explicitly about inference_only
mode - purely an abstraction leak.
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.
This method still doesn't know about inference only
implementation details it just propagates "some" configuration into the kernel. But your point is correct, need to decide who exactly should be responsible for handling this mode:
There are a few options:
-
Kernel
- This is the current approach.inference_only
is propagated as the following:
compileArgs
->GOVExecutable
->OVCallContext
->Kernel
(e.gInfer
,InferList
, etc)The benefit is that
IInferExecutor
that used as proxy to submit inference tasks don't know about this option at all, thekernel
hides this underset_input_data
andread_output_data
callbacks so it may continue work insync
/async
modes without knowledges about this mode. -
RequestPool / IInferExecutor
- In this apporachGOVExecutable
may configureRequestPool
the way it knows about benchmark mode.
- Prons:
- Kernels don't know about this mode so they continue submit their tasks through
RequestPool
API.
- Kernels don't know about this mode so they continue submit their tasks through
- Cons:
inference_only
mode will be enabled for allKernel
's (now it's only relevant forInfer
(InferList
,InferROI
,InferList2
throw exception if mode is enabled).- Mode should be handled for both
SyncInferExecutor
andAsyncInferExecutor
. This is a little bit tricky since currentlyread_output_data
is also responsible for posting outputs to maintain contract with streaming executor.
https://github.com/TolyaTalamanov/opencv/blob/at/implement-inference-only-mode-for-ov-backend/modules/gapi/src/backends/ov/govbackend.cpp#L471
Current approach looked less invasive.
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.
Yes and my point is to make some configuration
really a some configuration
but not a specific field.
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.
Done
3d2311d
to
8e9f224
Compare
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.
👍 !
@asmorkalov Can we merge it, please? |
…rence-only-mode-for-ov-backend G-API: Implement inference only mode for OV backend opencv#24584 ### Changes overview Introduced `cv::gapi::wip::ov::benchmark_mode{}` compile argument which if enabled force `OpenVINO` backend to run only inference without populating input and copying back output tensors. This mode is only relevant for measuring the performance of pure inference without data transfers. Similar approach is using on OpenVINO side in `benchmark_app`: https://github.com/openvinotoolkit/openvino/blob/master/samples/cpp/benchmark_app/benchmark_app.hpp#L134-L139 ### 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 - [x] 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. - [x] The feature is well documented and sample code can be built with the project CMake
…rence-only-mode-for-ov-backend G-API: Implement inference only mode for OV backend opencv#24584 ### Changes overview Introduced `cv::gapi::wip::ov::benchmark_mode{}` compile argument which if enabled force `OpenVINO` backend to run only inference without populating input and copying back output tensors. This mode is only relevant for measuring the performance of pure inference without data transfers. Similar approach is using on OpenVINO side in `benchmark_app`: https://github.com/openvinotoolkit/openvino/blob/master/samples/cpp/benchmark_app/benchmark_app.hpp#L134-L139 ### 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 - [x] 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. - [x] The feature is well documented and sample code can be built with the project CMake
Changes overview
Introduced
cv::gapi::wip::ov::benchmark_mode{}
compile argument which if enabled forceOpenVINO
backend to run only inference without populating input and copying back output tensors.This mode is only relevant for measuring the performance of pure inference without data transfers. Similar approach is using on OpenVINO side in
benchmark_app
: https://github.com/openvinotoolkit/openvino/blob/master/samples/cpp/benchmark_app/benchmark_app.hpp#L134-L139Pull 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.