Repository navigation
Open
Description
When running opencv_perf_objdetect all haarcascade tests fail with the exception below.
This was introduced in commit ad70ab4, if i checkout 1 commit before that the tests run fine.
Time compensation is 0
CTEST_FULL_OUTPUT
OpenCV version: 3.1.0-dev
OpenCV VCS version: 3.1.0-315-gecf65a0-dirty
Build type: release
Parallel framework: pthreads
CPU features: mmx sse sse2 sse3
OpenCL Platforms:
Clover
iGPU: AMD TAHITI (DRM 2.43.0, LLVM 3.7.1) (OpenCL 1.1 MESA 11.1.2)
Current OpenCL device:
Type = iGPU
Name = AMD TAHITI (DRM 2.43.0, LLVM 3.7.1)
Version = OpenCL 1.1 MESA 11.1.2
Compute units = 28
Max work group size = 256
Local memory size = 32 kB
Max memory allocation size = 256 MB
Double support = Yes
Host unified memory = Yes
Has AMD Blas = No
Has AMD Fft = No
Preferred vector width char = 16
Preferred vector width short = 8
Preferred vector width int = 4
Preferred vector width long = 2
Preferred vector width float = 4
Preferred vector width double = 2
[==========] Running 28 tests from 2 test cases.
[----------] Global test environment set-up.
[ RUN ] OCL_Cascade_Image_MinSize_CascadeClassifier.CascadeClassifier/3
OpenCV Error: Assertion failed (u->origdata == data) in deallocate, file /usr/src/opencv/modules/core/src/ocl.cpp, line 4584
/usr/src/opencv/modules/ts/src/ts_perf.cpp:1721: Failure
Failed
Expected: PerfTestBody() doesn't throw an exception.
Actual: it throws cv::Exception:
/usr/src/opencv/modules/core/src/ocl.cpp:4584: error: (-215) u->origdata == data in function deallocate
params = ("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml", "cv/cascadeandhog/images/bttf301.png", 30)
termination reason: unhandled exception
bytesIn = 240950
bytesOut = 0
samples = 10 of 100
outliers = 0
frequency = 1000000000
min = 16528436 = 16.53ms
median = 16943004 = 16.94ms
gmean = 16932285 = 16.93ms
gstddev = 0.02050919 = 2.08ms for 97% dispersion interval
mean = 16935514 = 16.94ms
stddev = 351309 = 0.35ms
[ FAILED ] OCL_Cascade_Image_MinSize_CascadeClassifier.CascadeClassifier/3, where GetParam() = ("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml", "cv/cascadeandhog/images/bttf301.png", 30) (236 ms)
Activity
alalek commentedon Mar 17, 2016
Please add:
std::cout << cv::getBuildInformation().c_str() << std::endlGit commit is "3.1.0-315-gecf65a0-dirty" and it not very good: it is dirty and looks like it is non public.
Mentioned line is different (doesn't contain assertion, it is below):
ad70ab4#diff-ff67959a252bb213e2340f8557e16e84R4584
Please rerun test with added environment parameter
OPENCV_OPENCL_RAISE_ERROR=1This assertion checks this assumption from specifications:
(https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueMapBuffer.html)
Could you check used flags for created OpenCL buffer?
clCreateBuffercalls; also add dumping ofu->handlevalue before this assertionCL_MEM_FLAGSparameter before this assertion.sander1234567890 commentedon Mar 19, 2016
debug-patch.txt
The debug patch i used is attached.
alalek commentedon Mar 19, 2016
Thanks for update!
This means: 9 = 8 | 1 ~ (CL_MEM_USE_HOST_PTR | CL_MEM_READ_WRITE)
Could you please dump near point 2 value of
u->origdata?if it is equal to value on point 8 then it is unexpected behavior of OpenCL runtime:
(https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clEnqueueMapBuffer.html , cite from OpenCL 1.1, previous was from OpenCL 1.2 spec, but the problem is same: "derived from the host_ptr")
I have already guarded some cases with unaligned buffers (there was more worse case - silent memory corruption), but looks like this OpenCL runtime wants more relaxed parameters.
Currently I have no idea, what condition to place here, because it looks like a bug of OpenCL runtime and probably will be fixed in future OpenCL runtime updates.
Some workarounds:
CL_MEM_USE_HOST_PTRand disable it manually (via environment variable)https://github.com/Itseez/opencv/blob/3.1.0/modules/core/src/ocl.cpp#L4452
https://github.com/Itseez/opencv/blob/3.1.0/modules/core/include/opencv2/core/private.hpp#L137
https://github.com/Itseez/opencv/blob/3.1.0/modules/core/include/opencv2/core/private.hpp#L208
sander1234567890 commentedon Mar 20, 2016
Here is the output (debug-patch2.txt attached), it seems you are right:
[==========] Running 27 tests from 1 test case.
debug-patch2.txt
[----------] Global test environment set-up.
[----------] 27 tests from OCL_Cascade_Image_MinSize_CascadeClassifier
[ RUN ] OCL_Cascade_Image_MinSize_CascadeClassifier.CascadeClassifier/0
?!?!?: Me here 2 | clCreateBuffer retval:0
?!?!?: | ret:0 cl_mem_flags 0x9
?!?!?: | u->origdata:0xf6a7e0 createFlags:0
?!?!?: Me here 4 | u->handle:0xedf8f0 (262144) u->flags:0x28 u->allocatorFlags_:0
?!?!?: Me here 1 | u->handle:0x104b560 (136640) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
?!?!?: Me here 1 | u->handle:0x10dbe80 (600) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
?!?!?: Me here 1 | u->handle:0x16caa90 (6116352) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
?!?!?: Me here 1 | u->handle:0x16cb590 (120004) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
?!?!?: Me here 1 | u->handle:0x104bc00 (264) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
?!?!?: Me here 1 | u->handle:0x1f6ff90 (34160) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
?!?!?: Me here 1 | u->handle:0x10dba80 (17080) u->flags:0x2 u->allocatorFlags_:0x1
?!?!?: | ret:0 cl_mem_flags 0x1
?!?!?: | u->origdata:(nil) createFlags:0
.
?!?!?: Me here 5 | u->handle:0xedf8f0 (262144) u->flags:0x2a u->allocatorFlags_:0
?!?!?: Me here 6 | clEnqueueMapBuffer retval:0
?!?!?: Me here 7 | ret:0 cl_mem_flags 0x9
?!?!?: Me here 8 | u->origdata:0xf6a7e0 data:0x7fc1bff15000
OpenCV Error: Assertion failed (u->origdata == data) in deallocate, file /usr/src/opencv-vanilla/modules/core/src/ocl.cpp, line 4623
/usr/src/opencv-vanilla/modules/ts/src/ts_perf.cpp:1721: Failure
Failed
Expected: PerfTestBody() doesn't throw an exception.
Actual: it throws cv::Exception:
/usr/src/opencv-vanilla/modules/core/src/ocl.cpp:4623: error: (-215) u->origdata == data in function deallocate
Since i'm trying to get OpenCL to work that is not the direction i want to go to ;)
Tried something in this direction, by commenting out the code block around point2, so force it to go through point 3, which uses CL_MEM_COPY_HOST_PTR, although that is probably a lot slower since it needs to do extra copying. But if i do that it all works fine.
Another thing is to try to get another runtime working, though the whole AMD prop. driver is a PITA to install on linux (and a hassle since it breaks every kernel update). It would have been very nice if the OSS clover/mesa stuff did work out :(.
sander1234567890 commentedon Mar 20, 2016
Hmm CL_MEM_USE_HOST_PTR seems implemented in this patch:
https://cgit.freedesktop.org/mesa/mesa/commit/?id=f972b223c4cb4ec58a9451cbac5d120ac9deb336
and has a comment about alignment:
alalek commentedon Mar 20, 2016
Thanks for updates!
Extra copying is actual for most part of implementation with unaligned data (another OpenCL implementations tries to disable CPU cache for boundary pages, but it is hard to say what is worse).
From MESA patch comment:
Actually this fallback to
CL_MEM_COPY_HOST_PTRbreaks OpenCL specification statements forclEnqueueMapBufferbehavior.I believe
clCreateBuffershould just fail in this case:alalek commentedon Sep 25, 2019
Added workaround via runtime flag: #15579
edman007 commentedon Jan 29, 2022
Hi, so I encountered a bug that calls this issue out, and the workaround does not work. Specifically, I am converting an AVFrame (from FFMPEG) to a UMat. So I tried to make a Mat() and get the UMat, and I get this problem:
My Code is:
Also, if I set OPENCV_OPENCL_ENABLE_MEM_USE_HOST_PTR=0 it crashes with FFmpeg appearing to have corrupted allocator. It seems like getting the UMat() causes the destructor to deallocate the host pointer (which shouldn't even be attempted, because the docs say the caller owns the pointer and should deallocate it).
alalek commentedon Jan 29, 2022
@edman007 Please provide complete minimal reproducer (provided lines doesn't call
deallocate, it is done somewhere later). Add dump ofopencv_version --opencloutput.P.S.
myMatis created with RAW data pointer. It is not able to manage lifetime of the data, so some limitations may apply. At least you should guarantee that lifetime ofmyMatis bigger than lifetime ofbuf.edman007 commentedon Jan 29, 2022
@alalek It does deallocate on the second line, see the stack trace:
The = operator deallocates the UMat() returned by getUMat() (since that's the last and only place that UMat is referenced). And I changed the myMat to last longer than buf, that did not change the results. The Full function I have is (and the pointer is freed at av_frame_unref(input), which is the second call of this function, and the exception happens on the first call):
and the opencl_version info:
alalek commentedon Jan 31, 2022
It releases UMat from the previous loop (so just two lines are not enough):
No idea why this line doesn't release it:
Please provide complete minimal reproducer and ensure that it triggers the original problem.
edman007 commentedon Feb 7, 2022
@alalek Minimal reproducer is: https://gist.github.com/edman007/4191c998b27de381a14c7a6b8f328a1c (Build command and usage instructions are in the comment at the top)
If I call release() that causes it to deallocate, if I don't then assignment deallocates() the previous, but it doesn't actually matter, deallocation of the UMat fails if it was created from a Mat without using copyTo()
Also, in my testing, it doesn't actually matter if I use a pointer for the original Mat, or just write the data into the Mat with memcpy(), they both result in the same result. But copyTo() to go from Mat to UMat causes no such issues.
But my output of that command is:
alalek commentedon Feb 10, 2022
"Minimal" reproducer should not have 3rdparty external dependencies, like ffmpeg.
Reproducer for MESA looks like this:
With MESA we still need to use
OPENCV_OPENCL_ENABLE_MEM_USE_HOST_PTR=0workaround as mentioned above.Provide stacktrace for scenario with workaround.
Also you could enable OpenCL calls trace here.
Main difference between
.getUMat()andcopyTo()is a "map" semantic.Releasing of
.getUMat()result would try sync back data (even with ACCESS_READ - this parameter is ignored and RW access is forced).You could try to play with this code:
Details