Ask Your Question
0

Issues compiling opencv-3.4.8 with cuda-10.2 in Ubuntu

asked 2020-01-29 21:31:07 -0600

Did anyone successfully compile opencv-3.4.x successfully with cuda 10.2?

It seems that cudu 10.2 has made some changes that breaks the opencv compilations.

**System description:**
OS: Ubuntu 18.04 LTS
Platform: Nvidia Drive AGX
CPU: aarch64
Cuda: 10.2
Cmake: 3.16.3

cmake command:

cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_PNG=OFF \
-DBUILD_TIFF=OFF \
-DBUILD_TBB=OFF \
-DBUILD_JPEG=OFF \
-DBUILD_JASPER=OFF \
-DBUILD_ZLIB=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=ON \
-DBUILD_opencv_python3=OFF \
-DENABLE_NEON=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENMP=OFF \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=OFF \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_CUDA=ON \
-DWITH_GTK=ON \
-DWITH_VTK=OFF \
-DWITH_TBB=ON \
-DWITH_1394=OFF \
-DWITH_OPENEXR=OFF \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-DCUDA_ARCH_BIN=7.2 \
-DCUDA_ARCH_PTX=7.2 \
-DINSTALL_C_EXAMPLES=OFF \
-DINSTALL_TESTS=OFF \
-DCUDA_cufft_LIBRARY=/usr/local/cuda/lib64/libcufft.so.10 \
-DCUDA_nppc_LIBRARY=/usr/local/cuda/lib64/libnppc.so.10 \
-DCUDA_npps_LIBRARY=/usr/local/cuda/lib64/libnpps.so.10 \
-DCUDA_nppial_LIBRARY=/usr/local/cuda/lib64/libnppial.so.10 \
-DCUDA_nppicc_LIBRARY=/usr/local/cuda/lib64/libnppicc.so.10 \
-DCUDA_nppicom_LIBRARY=/usr/local/cuda/lib64/libnppicom.so.10 \
-DCUDA_nppidei_LIBRARY=/usr/local/cuda/lib64/libnppidei.so.10 \
-DCUDA_nppif_LIBRARY=/usr/local/cuda/lib64/libnppif.so.10 \
-DCUDA_nppig_LIBRARY=/usr/local/cuda/lib64/libnppig.so.10 \
-DCUDA_nppim_LIBRARY=/usr/local/cuda/lib64/libnppim.so.10 \
-DCUDA_nppist_LIBRARY=/usr/local/cuda/lib64/libnppist.so.10 \
-DCUDA_nppisu_LIBRARY=/usr/local/cuda/lib64/libnppisu.so.10 \
-DCUDA_nppitc_LIBRARY=/usr/local/cuda/lib64/libnppitc.so.10 \
..

Output from console:

-- General configuration for OpenCV 3.4.8 =====================================
--   Version control:               unknown
-- 
--   Platform:
--     Timestamp:                   2020-01-30T02:15:35Z
--     Host:                        Linux 4.14.102-rt53-tegra aarch64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:
--       requested:                 NEON FP16
--       disabled:                  VFPV3 NEON
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++11:                       YES
--     C++ Compiler:                /usr/bin/c++  (ver 7.4.0)
--     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 -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 -pthread -fomit-frame-pointer -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 -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 -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     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 -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -fvisibility=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 -Wuninitialized -Winit-self -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -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 npps cublas cufft -L/usr/local/cuda/lib64 -L/usr/lib/aarch64-linux-gnu
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-04-17 09:59:19 -0600

DanK gravatar image

I was struggling with this same issue and needed opencv 3.4 with cuda 10.2. Tooks some digging but I believe I figured out what you need to do. It turns out that the opencv cmake search stuff use to deduce the CUDA information is reliant on a number of variables that do not normally get set, mostly because the root path of cuda was all that was needed. I found that if I declare the following setup of environmental variables, I am able to build OpenCV with CUDA enabled without much hassle.

I create the file cuda.sh. It's contents follow: -------------cuda.sh-------------

# location of cuda installation     
CUDA_PATH=/usr/local/cuda-10.2 

# location of lib & include paths  (this is what has changed in newer cuda setups)
CUDA_ARCH_PATH=$CUDA_PATH/targets/x86_64-linux

# location of nvcc
CUDA_BIN_PATH=$CUDA_PATH/bin

 CUDA_LIB_PATH=$CUDA_ARCH_PATH/lib
 CUDA_INC_PATH=$CUDA_ARCH_PATH/include

 PATH=$CUDA_BIN_PATH:$PATH

  export CUDA_PATH CUDA_BIN_PATH CUDA_ARCH_PATH CUDA_LIB_PATH
  export CUDA_INC_PATH PATH

The big ones to make sure are set are CUDA_PATH, CUDA_BIN_PATH, CUDA_LIB_PATH, CUDA_INC_PATH I created the other ones for myself.

If you search through all the cmake files, these variables help cmake properly configure compilation of opencv when available. What I have found is the newer versions of CUDA changed the location of the lib & include paths and that seemed to have broken the search and find parts of cmake. Setting these variables fixes that.

The last thing you should do if compiling opencv with CUDA is declare -DWITH_NVCUVID=OFF unless you are sure you have the prerequisites installed and in the correct places. If this is not set to off, the compilation of cuda fails when it searches for a header associated with this option. I've not used this feature so my process turns it off.

I generally add the 'cuda.sh' to /etc/profile.d on my system as adminstrator so these parameters are set for the system.

Hope this helps.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-01-29 21:31:07 -0600

Seen: 1,234 times

Last updated: Jan 29 '20