Ask Your Question

Why were cmake options invalid? How can I disable OpenCL, IPP and enable CV_SIMD?

asked 2019-12-02 01:41:23 -0500

updated 2020-12-09 07:52:02 -0500

I was working on Canny Edge Detector. After reading the source code, I felt like the edge detector could work in one way among IPP/OPENCL/OPENVX/CV_SIMD(which uses, TBB, I think)/the most traditional and slowest way(to work on pixels one by one). However, I only wanted it parallelCanny with CV_SIMD defined to work.

I tried to call canny function and use "std::cout << cv::getBuildInformation() << std::endl;" to see the libraries being used in the process. Then, I wrote a short CMakeLists.txt file in this way:

# project name
# requirement of cmake version
cmake_minimum_required(VERSION 3.9)

# find required opencv
find_package(OpenCV REQUIRED)

# name of executable file and path of source file
add_executable(opencv_test main.cpp)

# opencv libraries
target_link_libraries(opencv_test ${OpenCV_LIBS})

After that, I ran the program with the following command in order:


Only to be told that:

 CMake Warning:
  Manually-specified variables were not used by the project:

Then, after my program ran, the line of code

 std::cout << cv::getBuildInformation() << std::endl;

printed out exactly the same things as I ran cmake command without any options as follows (I also wrote another function to check if CV_SIMD is enabled):

    ==================  macro dump  ===================
CV_SIMD is NOT defined

SIMD intrinsics are not available. Check compilation target and passed build options.
=====================  done  ======================

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

      Extra modules:
        Location (extra):            /tmp/opencv-20190826-34514-r5q5gz/opencv-4.1.1/opencv_contrib/modules
        Version control (extra):     unknown

    Timestamp:                   2019-08-26T13:40:01Z
    Host:                        Darwin 18.6.0 x86_64
    CMake:                       3.15.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/local/Homebrew/Library/Homebrew/shims/mac/super/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
      requested:                 DETECT
      disabled:                  AVX AVX2

Dispatched code generation:  FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      FP16 (0 files):            + FP16 AVX
      AVX (4 files):             + AVX
      AVX2 (27 files):           + FP16 FMA3 AVX AVX2
      AVX512_SKX (2 files):      + FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang++  (ver
    C++ flags (Release):         -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin   -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 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.1.jdk/Contents/Home/include/darwin   -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 ...
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2019-12-02 02:40:44 -0500

berak gravatar image

updated 2019-12-02 02:51:18 -0500


all those flags only apply when building the opencv libs, not when building your program

(you need to rebuild the libs with the flags of your choice)

however, you also can


in your main() to disable opencl at runtime

edit flag offensive delete link more


Thanks for answering!

May I ask what you mean by "building the opencv libs"? I thought the library of opencv was fixed once I installed it and which part of the library to use should only be dependent on the files included at the beginning of my program... If so, what's the meaning of adding those flags? To specify particular lib files of opencv to be used when my program runs?

And is there a possible way to disable some of those (such as OPENCL and IPP) and enable CV_SIMD only when my program runs?

Thank you very much for your patience!

rosaline1995 gravatar imagerosaline1995 ( 2019-12-02 02:47:53 -0500 )edit

once I installed it

it sounds like you use something prebuilt , meaning it has the capabilities (e.g avx) from the machine it was built on, not yours.

if you need more fine graded control, you have to build the opencv libs from src (github) using cmake. then you can apply all those flags, and cmake can explore your local SSE capabilities

berak gravatar imageberak ( 2019-12-02 02:59:32 -0500 )edit

I see...Thanks a lot! I will have a try later.

But another thing is, the same problem still happens: when I typed

std::cout << cv::getBuildInformation() << std::endl;

I still got the same result as before:

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

Doesn't it mean openCL is still used and my code "cv::ocl::setUseOpenCL(false);" is invalid?

rosaline1995 gravatar imagerosaline1995 ( 2019-12-02 03:10:53 -0500 )edit

the information from cv::getBuildInformation() is fixed, baked in,

cv::ocl::setUseOpenCL(false); sets a runtime flag, you can check it whith cv::ocl::useOpenCL();

berak gravatar imageberak ( 2019-12-02 03:19:23 -0500 )edit

Question Tools

1 follower


Asked: 2019-12-02 01:41:23 -0500

Seen: 967 times

Last updated: Dec 02 '19