Ask Your Question
0

Unable to build opencv 3.3.0 with cuda 9.0 on linux

asked 2017-09-27 09:28:46 -0600

mfisher gravatar image

updated 2017-10-10 11:58:01 -0600

I was unable to build opencv 3.3.0 with Cuda 9.0 on linux until I followed the directions in my "solution" I posted.

The problems were:

1. CUDA_nppi_LIBRARY not being set correctly when running cmake.
2. Compiling fails due to: nvcc fatal : Unsupported gpu architecture 'compute_20'
3. saturate_cast.hpp(277): error: identifier "__half2float" is undefined.

Original question about cmake not detecting Cuda 8.0 was due to an incomplete install of Cuda 8.0 on my system.

Original question is below.

Hello,

I have software I have written and profiled and now it's time for me to move some of the hot spots to the GPU. My previous installation of opencv was not build with CUDA, so I uninstalled it and obtained the 3.3.0 source. This is on linux.

I have an NVIDIA Quadro M1200 with Cuda 8.0.

$ nvidia-smi
Wed Sep 27 08:54:18 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.69                 Driver Version: 384.69                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Quadro M1200        Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   46C    P8    N/A /  N/A |   1145MiB /  4042MiB |     18%      Default |
+-------------------------------+----------------------+----------------------+
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

I have cuda-8.0 installed at /usr/local/cuda-8.0 with a symbolic link to it from /usr/local/cuda

I invoked cmake with the following arguments:

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

And the output of cmake shows that CUDA is unavailable:

--     Use Cuda:                    NO

What can I do to get opencv 3.3.0 building with gpu support? Thank you.

Full output of cmake below, although I don't see anything telling.

-- Detected version of GNU GCC: 54 (504)
-- Performing Test HAVE_CXX11 (check file: cmake/checks/cxx11.cpp)
-- Performing Test HAVE_CXX11 - Failed
-- Found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.12", minimum required is "2.7") 
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so (found suitable exact version "2.7.12") 
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.5.2", minimum required is "3.4") 
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.5m.so (found suitable exact version "3.5.2") 
-- Looking for ccache - not found
-- Performing Test HAVE_CXX_FSIGNED_CHAR
-- Performing Test HAVE_CXX_FSIGNED_CHAR - Success
-- Performing Test HAVE_C_FSIGNED_CHAR
-- Performing Test HAVE_C_FSIGNED_CHAR - Success
-- Performing Test HAVE_CXX_W
-- Performing Test HAVE_CXX_W - Success
-- Performing Test HAVE_C_W
-- Performing Test HAVE_C_W - Success
-- Performing Test HAVE_CXX_WALL
-- Performing Test HAVE_CXX_WALL - Success
-- Performing Test HAVE_C_WALL
-- Performing Test HAVE_C_WALL - Success
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE - Success
-- Performing Test HAVE_C_WERROR_RETURN_TYPE
-- Performing Test HAVE_C_WERROR_RETURN_TYPE - Success
-- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_WERROR_NON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR
-- Performing Test HAVE_C_WERROR_NON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_CXX_WERROR_ADDRESS
-- Performing Test HAVE_CXX_WERROR_ADDRESS - Success
-- Performing Test HAVE_C_WERROR_ADDRESS
-- Performing Test HAVE_C_WERROR_ADDRESS - Success
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT ...
(more)
edit retag flag offensive close merge delete

Comments

Have you delete your cmakecache.txt?

LBerger gravatar imageLBerger ( 2017-09-27 09:51:12 -0600 )edit

Ok. I deleted my CMakeCache.txt file and edited my post to show the full output. The output still shows Cuda as unavailable.

mfisher gravatar imagemfisher ( 2017-09-27 10:29:53 -0600 )edit

I dug into the FindCuda.cmake script. I found the CUDA_npp_LIBRARY variable was not being set. Not finding the npp* libraries, I suspected an incomplete install of CUDA. I uninstalled it completely and installed Cuda 9.0. Still fails. It seems in Cuda 9.0 the nppi library has been split into many different libraries: nppial nppicc nppicom etc .... After hacking the FindCuda.cmake script so that the CUDA_nppi_LIBRARY variable is set to a semicolon separated string of the nppi* libraries, cmake runs successfully with HAVE_CUDA = TRUE.

Compiling fails due to: nvcc fatal : Unsupported gpu architecture 'compute_20'

This architecture seems to be no longer supported in Cuda 9.0, but my video card is the sm50 arch. How do I modify the Makefile / cmake scripts to build with Cuda 9.0?

mfisher gravatar imagemfisher ( 2017-09-27 18:17:49 -0600 )edit

I dug into the OpenCVDetectCUDA.cmake script and found I should specify the CUDA_GENERATION variable to cmake. Yielding:

/home/mfisher/opencv-3.3.0/modules/cudev/include/opencv2/cudev/util/saturate_cast.hpp(277): error: identifier "__half2float" is undefined.

This function is defined in cuda_fp16.h. Not seeing where cuda_fp16.h is included, I included it from opencv2/cudev/common.h.

Yielding the following linker errors. So something is still wrong with my generated Makefile. [ 42%] Linking CXX executable ../../bin/opencv_test_cudafilters ../../lib/libopencv_cudafilters.so.3.3.0: undefined reference to `nppiErode_8u_C1R' ...

mfisher gravatar imagemfisher ( 2017-09-27 20:19:36 -0600 )edit

I have: -- CUDA_npp_LIBRARY /usr/local/cuda/lib64/libnppc.so /usr/local/cuda/lib64/libnppial.so /usr/local/cuda/lib64/libnppicc.so /usr/local/cuda/lib64/libnppicom.so /usr/local/cuda/lib64/libnppidei.so /usr/local/cuda/lib64/libnppif.so /usr/local/cuda/lib64/libnppig.so /usr/local/cuda/lib64/libnppist.so /usr/local/cuda/lib64/libnppisu.so /usr/local/cuda/lib64/libnppitc.so /usr/local/cuda/lib64/libnpps.so

mfisher gravatar imagemfisher ( 2017-09-27 20:22:25 -0600 )edit

Was missing nppim library when I set the CUDA_npp_LIBRARY variable. It builds now. I'll test it tomorrow. But I am scared. I get a lot of warnings of the form:

/home/mfisher/opencv-3.3.0/modules/cudev/include/opencv2/cudev/warp/detail/../../warp/shuffle.hpp(374): warning: function "__shfl_xor(int, int, int)" /usr/local/cuda/include/sm_30_intrinsics.hpp(221): here was declared deprecated ("__shfl_xor() is deprecated in favor of __shfl_xor_sync() and may be removed in a future release (Use -Wno-deprecated-declarations to suppress this warning).")

mfisher gravatar imagemfisher ( 2017-09-27 20:41:42 -0600 )edit

Thanks a lot, mfisher. Now, I can finally build OpenCV with CUDA.

Amaro gravatar imageAmaro ( 2017-10-06 23:40:46 -0600 )edit

@Amaro@mfisher could you please share the solution i'm having the sale issue with nvcc fatal "compute_20"?

ROSpioneer gravatar imageROSpioneer ( 2017-10-09 16:54:50 -0600 )edit

Cuda 9.0 does not support the sm_20 architecture anymore. When you build openCV, run cmake with CUDA_GENERATION set to your target architecture.

  if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  elseif(CUDA_GENERATION STREQUAL "Maxwell")
    set(__cuda_arch_bin "5.0 5.2")
  elseif(CUDA_GENERATION STREQUAL "Pascal")
    set(__cuda_arch_bin "6.0 6.1")
  elseif(CUDA_GENERATION STREQUAL "Auto")
mfisher gravatar imagemfisher ( 2017-10-10 11:35:15 -0600 )edit

Yes you're right CUDA9 doesn''t support Fermi anymore

ROSpioneer gravatar imageROSpioneer ( 2017-10-11 09:01:06 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-10-10 11:50:16 -0600

mfisher gravatar image

updated 2017-10-11 10:35:26 -0600

I am posting an "answer" to this, although I ended up building opencv with Cuda 9.0 instead of Cuda 8.0.

The main problem I had was an incomplete install of Cuda 8.0 which was evidenced by my not having the nppi libraries. Thus, when invoking cmake, the CUDA_npp_LIBRARY variable was not being set causing HAVE_CUDA = 0.

I uninstalled Cuda 8.0 and installed Cuda 9.0.

I then ran into the following errors:

Problem 1: In Cuda 9.0 the nppi library has been split into many different libraries: nppial nppicc nppicom etc.
Solution 1: Hack the FindCuda.cmake script so that the CUDA_nppi_LIBRARY variable is set to a semicolon separated string of the nppi* libraries
Problem 2: Compiling fails due to: nvcc fatal : Unsupported gpu architecture 'compute_20'
Solution 2: Cuda 9.0 no longer supports the arch_20 architecture.  Run cmake with CUDA_GENERATION set to your target architecture.
Problem 3: saturate_cast.hpp(277): error: identifier "__half2float" is undefined.
Solution 3: Cuda 9.0 probably changed their header files.  But this function is declared in cuda_fp16.h. I included <cuda_fp16.h> at the top of opencv2/cudev/common.hpp.

OpenCV 3.3.0 now builds and runs successfully with Cuda 9.0 for me.

edit flag offensive delete link more

Comments

You didn't show how did you solve them. There's more details here

https://stackoverflow.com/questions/4...

ROSpioneer gravatar imageROSpioneer ( 2017-10-11 09:02:29 -0600 )edit

You are right. Thanks for linking that. Although we both solved the three issues the same way, the answer posted there is more verbose. [I didn't want people to blindly copy what I did because it was just a hack to get it built on my system -- and it breaks backwards compatibility building previous versions of CUDA.]

mfisher gravatar imagemfisher ( 2017-10-11 10:11:32 -0600 )edit

Well I don't agree with you on that point.. It is always good to post your solution and for people to take advantages from it. If they copy blindly that's not your issue, there's always people who to learn. So then why we call it solution or an answer to a problem ;)

ROSpioneer gravatar imageROSpioneer ( 2017-10-11 11:13:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-09-27 09:28:46 -0600

Seen: 12,923 times

Last updated: Oct 11 '17