Skip to content
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

Merged
merged 1 commit into from Nov 16, 2022

Conversation

smirnov-alexey
Copy link
Contributor

@smirnov-alexey smirnov-alexey commented Sep 23, 2022

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

@smirnov-alexey
Copy link
Contributor Author

@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

@smirnov-alexey
Copy link
Contributor Author

I also need to double check local build after the changes

Copy link
Contributor

@SergeyIvanov87 SergeyIvanov87 left a 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/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@TolyaTalamanov TolyaTalamanov left a 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/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Show resolved Hide resolved
modules/gapi/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
modules/gapi/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
modules/gapi/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
@TolyaTalamanov
Copy link
Contributor

Do you have any performance numbers?

@dmatveev dmatveev self-assigned this Oct 3, 2022
@dmatveev dmatveev added this to the 4.7.0 milestone Oct 3, 2022
Copy link
Contributor

@dmatveev dmatveev left a 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? :)

modules/gapi/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
modules/gapi/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
modules/gapi/samples/one_vpl_source_to_bgr_conv.cpp Outdated Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Show resolved Hide resolved
modules/gapi/src/backends/ocl/goclcore.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@SergeyIvanov87 SergeyIvanov87 left a 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

@smirnov-alexey
Copy link
Contributor Author

Do you have any performance numbers?

Once we are ready to merge it I'll measure the performance locally (since currently we might still be optimizing something)

Copy link
Contributor

@SergeyIvanov87 SergeyIvanov87 left a 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

Copy link
Contributor

@SergeyIvanov87 SergeyIvanov87 left a 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

Copy link
Contributor

@SergeyIvanov87 SergeyIvanov87 left a comment

Choose a reason for hiding this comment

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

LGTM

@alalek
Copy link
Member

alalek commented Nov 3, 2022

wants to merge 10 commits

Conflicting files
modules/gapi/samples/onevpl_infer_single_roi.cpp

Please,

  1. squash commits into 1
  2. rebase patch to resolve conflicts

@smirnov-alexey
Copy link
Contributor Author

Do you have any performance numbers?

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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thank you

@smirnov-alexey smirnov-alexey force-pushed the as/vpl_ocl branch 3 times, most recently from 94991ef to f3b5ca4 Compare November 8, 2022 17:38

// 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)
Copy link
Contributor Author

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

Copy link
Contributor

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:

  1. 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
  2. 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 :)

Copy link
Contributor Author

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

Copy link
Contributor

@SergeyIvanov87 SergeyIvanov87 left a 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"));
Copy link
Contributor

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)
Copy link
Contributor

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:

  1. 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
  2. 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 :)

@smirnov-alexey
Copy link
Contributor Author

@alalek can we merge this?

@smirnov-alexey
Copy link
Contributor Author

@asmorkalov can we merge this?

@alalek
Copy link
Member

alalek commented Nov 11, 2022

dmatveev self-assigned this on Oct 3

Dmitry as G-API lead defines the final approver for G-API functionality. Currently he holds this role (no delegation) and there is no approval.

Copy link
Contributor

@dmatveev dmatveev left a 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
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

cc: @alalek

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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>
Copy link
Contributor

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)

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

<>?

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

<>?

Copy link
Contributor Author

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
@smirnov-alexey
Copy link
Contributor Author

@alalek can we merge this?

@alalek alalek merged commit ce80e0d into opencv:4.x Nov 16, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
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.

None yet

7 participants