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: Connect OneVPL source and OpenCL backend #22559
Conversation
@mpashchenkov @TolyaTalamanov @sivanov-work @dmatveev please, take a look. In terms of design I suggest to merge this initial version for the functionality and redesign in the future if it will be needed for other adapters. Please, address the comments above. All this PR's credits go to @mpashchenkov |
I also need to double check local build after the changes |
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 we need Unit Tests for goclbackend functionality
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.cpp
Outdated
Show resolved
Hide resolved
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.cpp
Outdated
Show resolved
Hide resolved
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.cpp
Show resolved
Hide resolved
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.hpp
Outdated
Show resolved
Hide resolved
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.
Great work 🔥
I'd also add some tests since sample doesn't run on CI. I'd also think if sample is even needed :)
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.cpp
Outdated
Show resolved
Hide resolved
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.hpp
Outdated
Show resolved
Hide resolved
Do you have any performance numbers? |
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.
So.. does this actually work now? :)
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.
Please move out extra platform dependencies from utils.hpp/cpp. It must not be here, utils is supposed to be zero-dependency component
Once we are ready to merge it I'll measure the performance locally (since currently we might still be optimizing something) |
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 like 'default' functions and 'parse_cfg_params' inside VPL core utils: we had better separate high-level components and low-level components utilities in different files at least.
Also i see no reason to wrap up 3 rows in a single function with confusing meaning 'default_src'. Because there is no 'default' configuration at all
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.cpp
Show resolved
Hide resolved
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.
DefaultVPLSource must not be here
modules/gapi/src/streaming/onevpl/accelerators/surface/dx11_frame_adapter.cpp
Show resolved
Hide resolved
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.
LGTM
modules/gapi/src/streaming/onevpl/demux/async_mfp_demux_data_provider.cpp
Outdated
Show resolved
Hide resolved
Please,
|
146 fps on 768x576 input. If needed it could be optimized, I guess |
// FIXME: assuming here that the context is always the same | ||
// TODO: Textures are reusable, so to improve the peroformance here | ||
// consider creating a hash map texture <-> device/ctx | ||
static thread_local cv::ocl::Context& ctx = cv::directx::ocl::initializeContextFromD3D11Device(pD3D11Device); |
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.
static thread_local cv::ocl::Context&
Storing reference is unsafe in this way.
ocl::Context
is based on shared_ptr
approach (PImpl
pattern). So there is no huge problem to copy it.
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.
Fixed, thank you
94991ef
to
f3b5ca4
Compare
|
||
// Compare results | ||
// FIXME: investigate why 2 sources produce different number of frames sometimes | ||
for (size_t i = 0; i < std::min(ocl_mats.size(), cpu_mats.size()); ++i) |
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.
@TolyaTalamanov @SergeyIvanov87 @dmatveev any objections on that? If you have any ideas how to check ocl + vpl interaction differently please introduce them
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.
Does this check work?
If yes - i suggest we should keep it as is
And may be investigate the frames distinguish issue in next time if it should prioritized.
For troubleshooting it we need:
- at first - check frames count when decoding RAW file (without container). In this case we are cutting off WFP (multiple working threads & queues) and checking VPL decondig engine only
- If all is OK with 1 step then we need for decoding containerized video (as in your example). In this case additional thread-workers come in play.
But it seems like additional task might be required not related to current PR
So, i'm OK with it :)
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, it works. I opened a separate bug on that with a reproducer. I also suggest to merge as is if nobody objects
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.
LGTM
}; | ||
|
||
std::vector<CfgParam> source_cfgs; | ||
source_cfgs.push_back(create_from_string("mfxImplDescription.AccelerationMode:MFX_ACCEL_MODE_VIA_D3D11")); |
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 suppose it should be simple way, like: CfgParam::create()
please feel free to ignore it: comment not to apply
|
||
// Compare results | ||
// FIXME: investigate why 2 sources produce different number of frames sometimes | ||
for (size_t i = 0; i < std::min(ocl_mats.size(), cpu_mats.size()); ++i) |
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.
Does this check work?
If yes - i suggest we should keep it as is
And may be investigate the frames distinguish issue in next time if it should prioritized.
For troubleshooting it we need:
- at first - check frames count when decoding RAW file (without container). In this case we are cutting off WFP (multiple working threads & queues) and checking VPL decondig engine only
- If all is OK with 1 step then we need for decoding containerized video (as in your example). In this case additional thread-workers come in play.
But it seems like additional task might be required not related to current PR
So, i'm OK with it :)
@alalek can we merge this? |
@asmorkalov can we merge this? |
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.
All good but please be careful about headers!
#ifndef OPENCV_GAPI_STREAMING_ONEVPL_UTILS_HPP | ||
#define OPENCV_GAPI_STREAMING_ONEVPL_UTILS_HPP | ||
|
||
#include "opencv2/gapi/own/exports.hpp" // GAPI_EXPORTS |
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.
Shouldn't this be in <>
? Note it is a public header (shipped with the compiled OpenCV)
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.
cc: @alalek
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.
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
#include "backends/ocl/goclcore.hpp" | ||
#include <opencv2/gapi/util/throw.hpp> |
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.
Please order the includes properly (public headers mixed with the internal ones)
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
#pragma comment(lib, "dxgi") | ||
#undef NOMINMAX | ||
#undef D3D11_NO_HELPERS | ||
#include "opencv2/core/directx.hpp" |
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.
<>
?
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
#endif // HAVE_D3D11 | ||
#endif // HAVE_DIRECTX | ||
|
||
#include "opencv2/core/ocl.hpp" |
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.
<>
?
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
Minor refactoring Partially address review comments Move DX-related stuff from the sample to a default source Simplify the default OneVPL config Address minor review comments Add class for the default VPL source WIP: Add initial stub for tests with description Removing default vpl source and minor refactoring Refactor default files Fix build and application crash Address review comments Add test on VPL + OCL interaction compared to CPU behavior Fix test
f3b5ca4
to
4c74e6d
Compare
@alalek can we merge this? |
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.