opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.39k stars 5.76k forks source link

OpenCL error CL_MEM_OBJECT_ALLOCATION_FAILURE (-4) #2114

Open chenchuangc opened 5 years ago

chenchuangc commented 5 years ago
System information (version)
Detailed description

my code is like this

import cv2 as cv

pic1 = "image1.jpg"
pic2 = "image2.jpg"

mat1 = cv.imread(pic1)
mat2 = cv.imread(pic2)

print('image1 shape:'+str(mat1.shape))
print('image2 shape:'+str(mat2.shape))

print(cv.quality.QualityPSNR_compute([mat1], [mat2])[0])
print(cv.quality.QualitySSIM_compute([mat1], [mat2])[0])
print(cv.quality.QualityGMSD_compute([mat1], [mat2])[0])

but when i run the code , it be this

image1 shape:(27500, 2894, 3)
image2 shape:(27500, 2894, 3)
OpenCL error CL_MEM_OBJECT_ALLOCATION_FAILURE (-4) during call: clEnqueueNDRangeKernel('KF', dims=2, globalsize=8704x6880x1, localsize=NULL) sync=false
OpenCL error CL_MEM_OBJECT_ALLOCATION_FAILURE (-4) during call: clEnqueueNDRangeKernel('KF', dims=2, globalsize=8704x6880x1, localsize=NULL) sync=false

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

is there something wrong ? and how can i avoid this ? sorry for boring you

alalek commented 5 years ago
chenchuangc commented 5 years ago
  • print(cv.getBuildInformation())
  • opencv_version --opencl

thank you for reply me so fast @alalek

i follow your instructions

1. print(cv.getBuildInformation())

the print(cv.getBuildInformation()) shows

ration for OpenCV 4.1.0 =====================================
  Version control:               4.1.0

  Extra modules:
    Location (extra):            /Users/travis/build/skvark/opencv-python/opencv_contrib/modules
    Version control (extra):     4.1.0

  Platform:
    Timestamp:                   2019-04-11T23:12:47Z
    Host:                        Darwin 16.7.0 x86_64
    CMake:                       3.9.4
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3
      requested:                 DETECT
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (13 files):         + SSE4_1
      SSE4_2 (1 files):          + SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (27 files):           + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (2 files):      + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX

  C/C++:
    Built as dynamic libs?:      NO
    C++ Compiler:                /usr/local/opt/ccache/libexec/clang++  (ver 8.1.0.8020042)
    C++ flags (Release):         -stdlib=libc++   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -stdlib=libc++   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/local/opt/ccache/libexec/clang
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-dead_strip  
    Linker flags (Debug):        -Wl,-dead_strip  
    ccache:                      YES
    Precompiled headers:         NO
    Extra dependencies:          -framework OpenCL ade /usr/local/lib/QtGui.framework /usr/local/lib/QtTest.framework /usr/local/lib/QtCore.framework freetype harfbuzz tesseract lept
    3rdparty dependencies:       ittnotify libprotobuf zlib libjpeg-turbo libwebp libpng libtiff libjasper IlmImf quirc ippiw ippicv

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java js matlab ovis python2 sfm ts viz
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  GUI: 
    QT:                          YES (ver 4.8.7 EDITION = OpenSource)
      QT OpenGL support:         NO
    Cocoa:                       YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 2.0.2-62)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.36)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES
      avcodec:                   YES (58.35.100)
      avformat:                  YES (58.20.100)
      avutil:                    YES (56.22.100)
      swscale:                   YES (5.3.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    AVFoundation:                YES

  Parallel framework:            GCD

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2019.0.0 Gold [2019.0.0]
           at:                   /Users/travis/build/skvark/opencv-python/_skbuild/macosx-10.7-x86_64-3.7/cmake-build/3rdparty/ippicv/ippicv_mac/icv
    Intel IPP IW:                sources (2019.0.0)
              at:                /Users/travis/build/skvark/opencv-python/_skbuild/macosx-10.7-x86_64-3.7/cmake-build/3rdparty/ippicv/ippicv_mac/iw
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (no extra features)
    Include path:                NO
    Link libraries:              -framework OpenCL

  Python 3:
    Interpreter:                 /Users/travis/build/skvark/opencv-python/venv/bin/python (ver 3.7)
    Libraries:                   /Library/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib (ver 3.7.0)
    numpy:                       /Users/travis/build/skvark/opencv-python/venv/lib/python3.7/site-packages/numpy/core/include (ver 1.14.5)
    install path:                python

  Python (for build):            /Users/travis/build/skvark/opencv-python/venv/bin/python

  Java:                          
    ant:                         NO
    JNI:                         /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/JavaVM.framework/Headers /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/JavaVM.framework/Headers /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/JavaVM.framework/Headers
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /Users/travis/build/skvark/opencv-python/_skbuild/macosx-10.7-x86_64-3.7/cmake-install
-----------------------------------------------------------------

2. opencv_version --opencl

and the opencv_version --opencl shows

13.picture_work git:(master) ✗ opencv_version --opencl
4.0.1
OpenCL Platforms:
    Apple
        CPU: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz (OpenCL 1.2 )
        iGPU: Iris Pro (OpenCL 1.2 )
Current OpenCL device:
    Type = iGPU
    Name = Iris Pro
    Version = OpenCL 1.2
    Driver version = 1.2(Jun 15 2017 18:45:12)
    Address bits = 64
    Compute units = 40
    Max work group size = 512
    Local memory size = 64 KB
    Max memory allocation size = 384 MB
    Double support = No
    Host unified memory = Yes
    Device extensions:
        cl_APPLE_SetMemObjectDestructor
        cl_APPLE_ContextLoggingFunctions
        cl_APPLE_clut
        cl_APPLE_query_kernel_names
        cl_APPLE_gl_sharing
        cl_khr_gl_event
        cl_khr_global_int32_base_atomics
        cl_khr_global_int32_extended_atomics
        cl_khr_local_int32_base_atomics
        cl_khr_local_int32_extended_atomics
        cl_khr_byte_addressable_store
        cl_khr_image2d_from_buffer
        cl_khr_gl_depth_images
        cl_khr_depth_images
        cl_khr_3d_image_writes
    Has AMD Blas = No
    Has AMD Fft = No
    Preferred vector width char = 1
    Preferred vector width short = 1
    Preferred vector width int = 1
    Preferred vector width long = 1
    Preferred vector width float = 1
    Preferred vector width double = 0

thank you so much!

alalek commented 5 years ago

1.2(Jun 15 2017 18:45:12)

This version is not fresh enough.

If you can't update OpenCL runtime (probably it would require MacOSX full system upgrade), then you can disable OpenCL in OpenCV via environment variable:

export OPENCV_OPENCL_DEVICE=disabled
chenchuangc commented 5 years ago

1.2(Jun 15 2017 18:45:12)

This version is not fresh enough.

If you can't update OpenCL runtime (probably it would require MacOSX full system upgrade), then you can disable OpenCL in OpenCV via environment variable:

export OPENCV_OPENCL_DEVICE=disabled

after i disabled OpenCL , it works ! thank you very much , you help me a lot ! ! and may where can i find the OpenCL version it support?

KishoreKonakanti commented 4 years ago

@alalek I have compiled OPENCV on Google colab pro. Hitting this error with OPENCV 4.2.0...

Error: error: OpenCV(4.2.0) /content/opencv-4.2.0/modules/core/src/ocl.cpp:5487: error: (-220:Unknown error code -220) OpenCL error CL_MEM_OBJECT_ALLOCATION_FAILURE (-4) during call: clEnqueueWriteBuffer(q, handle=0x5f372d00, CL_TRUE, offset=0, sz=16, data=0x5e1d7970, 0, 0, 0) in function 'upload'

Following is the build information:

General configuration for OpenCV 4.2.0 ===================================== Version control: unknown

Extra modules: Location (extra): /content/opencv_contrib-4.2.0/modules Version control (extra): unknown

Platform: Timestamp: 2020-09-11T05:37:21Z Host: Linux 4.19.112+ x86_64 CMake: 3.12.0 CMake generator: Unix Makefiles CMake build tool: /usr/bin/make Configuration: RELEASE

CPU/HW features: Baseline: SSE SSE2 SSE3 requested: SSE3 Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX SSE4_1 (16 files): + SSSE3 SSE4_1 SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX AVX2 (29 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX512_SKX (6 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

C/C++: Built as dynamic libs?: YES C++ Compiler: /usr/bin/c++ (ver 7.5.0) C++ flags (Release): -std=c++11 -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG C++ flags (Debug): -std=c++11 -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG C Compiler: /usr/bin/gcc-7 C flags (Release): -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG C flags (Debug): -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG Linker flags (Release): -Wl,--gc-sections
Linker flags (Debug): -Wl,--gc-sections
ccache: NO Precompiled headers: NO Extra dependencies: m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu 3rdparty dependencies:

OpenCV modules: To be built: aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 quality reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto Disabled: cudacodec world Disabled by dependency: - Unavailable: cnn_3dobj cvv java js matlab ovis sfm viz Applications: tests perf_tests apps Documentation: NO Non-free algorithms: YES

GUI: GTK+: YES (ver 3.22.30) GThread : YES (ver 2.56.4) GtkGlExt: NO OpenGL support: NO VTK support: NO

Media I/O: ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11) JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80) WEBP: build (ver encoder: 0x020e) PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34) TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.9) JPEG 2000: build (ver 1.900.1) OpenEXR: build (ver 2.3.0) HDR: YES SUNRASTER: YES PXM: YES PFM: YES

Video I/O: DC1394: YES (2.2.5) FFMPEG: YES avcodec: YES (57.107.100) avformat: YES (57.83.100) avutil: YES (55.78.100) swscale: YES (4.8.100) avresample: YES (3.7.0) GStreamer: YES (1.14.5) v4l/v4l2: YES (linux/videodev2.h)

Parallel framework: TBB (ver 2017.0 interface 9107)

Trace: YES (with Intel ITT)

Other third-party libraries: Intel IPP: 2019.0.0 Gold [2019.0.0] at: /content/opencv-4.2.0/build/3rdparty/ippicv/ippicv_lnx/icv Intel IPP IW: sources (2019.0.0) at: /content/opencv-4.2.0/build/3rdparty/ippicv/ippicv_lnx/iw Lapack: NO Eigen: NO Custom HAL: NO Protobuf: build (3.5.1)

NVIDIA CUDA: YES (ver 10.1, CUFFT CUBLAS FAST_MATH) NVIDIA GPU arch: 70 NVIDIA PTX archs:

cuDNN: YES (ver 7.6.5)

OpenCL: YES (no extra features) Include path: /content/opencv-4.2.0/3rdparty/include/opencl/1.2 Link libraries: Dynamic load

Python 2: Interpreter: /usr/local/bin/python (ver 2.7.17) Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.17) numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.4) install path: lib/python2.7/dist-packages/cv2/python-2.7

Python 3: Interpreter: /usr/bin/python3 (ver 3.6.9) Libraries: /usr/lib/x86_64-linux-gnu/libpython3.6m.so (ver 3.6.9) numpy: /usr/local/lib/python3.6/dist-packages/numpy/core/include (ver 1.18.5) install path: lib/python3.6/dist-packages/cv2/python-3.6

Python (for build): /usr/local/bin/python

Java:
ant: NO JNI: NO Java wrappers: NO Java tests: NO

Install to: /usr/local

I have tried to disable OPENCL as per your suggestion with no success.

Any help please?

Thank you.

AlphaNext commented 3 years ago

cv2.ocl.setUseOpenCL(False)

vhchuong commented 3 years ago

cv2.ocl.setUseOpenCL(False)

works like a charm for me! I highly recommend this solution!!!