Skip to content

core(OpenCL): fix lifetime handling of Image kernel args#19334

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:fix_19134
Jan 22, 2021
Merged

core(OpenCL): fix lifetime handling of Image kernel args#19334
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:fix_19134

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Jan 16, 2021

Keep Image instance alive while it is used in Kernel's argument.

resolves #19134
relates #2621
replaces #19135

force_builders=Custom,Linux AVX2,Linux OpenCL
build_image:Custom=ubuntu:18.04
buildworker:Custom=linux-5
test_opencl:Custom=ON

build_image:Linux AVX2=ubuntu:18.04
buildworker:Linux AVX2=linux-3
test_opencl:Linux AVX2=ON

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Jan 16, 2021

/cc @diablodale

@alalek
Copy link
Copy Markdown
Member Author

alalek commented Jan 22, 2021

👍

@rasmus25
Copy link
Copy Markdown
Contributor

This pull request has a bug that severely limits the number of kernel arguments. The intent of the code seems to be limiting the number of image arguments to MAX_ARRS, but it actually limits the number of all kinds of kernel arguments to MAX_ARRS.

registerImageArgument(int arg, const Image2D& image) treats int arg as image index and limits it to MAX_ARRS. However, Kernel::set(int i, const Image2D& image2D) calls registerImageArgument() treating int arg as kernel argument index. This means a kernel can not have Image2D arguments after MAX_ARRS arguments have been set.

As a result of this pull request, previously working code now fails at CV_CheckLT(arg, (int)MAX_ARRS, "");.

@diablodale
Copy link
Copy Markdown
Contributor

Would you write a test case that demonstrates that fail?
Such would both help us all understand the issue + add a good test case into the project for now and future regressions. :-)

@rasmus25
Copy link
Copy Markdown
Contributor

Here is the test that triggers the exception: https://github.com/rasmus25/opencv/commit/0365be4877d5f9428b72b58d5b32bdc8abaff9e1
The exception prints this in the terminal:

unknown file: Failure
C++ exception with description "OpenCV(4.5.2-dev) /home/rasmus/Allalaadimised/opencvbug/opencv/modules/core/src/ocl.cpp:3485: error: (-2:Unspecified error) in function 'void cv::ocl::Kernel::Impl::registerImageArgument(int, const cv::ocl::Image2D&)'
>  (expected: 'arg < (int)MAX_ARRS'), where
>     'arg' is 16
> must be less than
>     '(int)MAX_ARRS' is 16
" thrown in the test body.

MAX_ARRS is 16, but the test reaches that limit already with 4 arrays.

@alalek
Copy link
Copy Markdown
Member Author

alalek commented May 28, 2021

@rasmus25 Thank you for the report and the test!
This buggy check is removed here #20172 (not really necessary, because it is called iff clSetKernelArg() passes).
Please take a look.

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.

4 participants