TmZn
TmZn

Reputation: 407

Compiling OpenCV 3.3 with CUDA 9.0RC

I'm currently trying to compile OpenCV 3.3 with CUDA 9.0RC, but can't manage to make it all work. (Compiling on Windows, with CMake 3.9 and Visual Studio 2017, for x64 Windows)

First of all, if I try to compile OpenCV without CUDA, everything works fine.

After that, i added the "WITH CUDA" option in CMake, with all the correct paths, and Visual Studio give me this error:

9>------ Build started: Project: opencv_world, Configuration: Release x64 ------
9>Building NVCC (Device) object modules/world/CMakeFiles/cuda_compile.dir/__/core/src/cuda/Release/cuda_compile_generated_gpu_mat.cu.obj
9>nvcc fatal   : Unsupported gpu architecture 'compute_20'
9>CMake Error at cuda_compile_generated_gpu_mat.cu.obj.cmake:206 (message):
9>  Error generating
9>  C:/OpenCV-3.3.0/opencv-3.3.0/build/modules/world/CMakeFiles/cuda_compile.dir/__/core/src/cuda/Release/cuda_compile_generated_gpu_mat.cu.obj

Thinking it's an "ARCH" problem, i tried to change, in CMake :

CUDA_ARCH_BIN : 2.0 3.0 3.5 3.7 5.0 5.2 6.0 6.1

to :

CUDA_ARCH_BIN : 6.0 6.1

(Since i'm using a 1080)

and Visual Studio give me now this error :

6>------ Build started: Project: opencv_world, Configuration: Release x64 ------
6>Building NVCC (Device) object modules/world/CMakeFiles/cuda_compile.dir/__/core/src/cuda/Release/cuda_compile_generated_gpu_mat.cu.obj
6>gpu_mat.cu
6>'bin' is not recognized as an internal or external command,
6>operable program or batch file.
6>CMake Error at cuda_compile_generated_gpu_mat.cu.obj.cmake:206 (message):
6>  Error generating
6>  C:/OpenCV-3.3.0/opencv-3.3.0/build/modules/world/CMakeFiles/cuda_compile.dir/__/core/src/cuda/Release/cuda_compile_generated_gpu_mat.cu.obj

I don't know where this "bin" is comming from, and I really don't know what I should do to make it work..

Thanks for you replies !

Upvotes: 4

Views: 6058

Answers (2)

eric frazer
eric frazer

Reputation: 1649

I have had to do several things to get VS 2017 + Cuda 9.0 + OpenCV 3.3.0 + CMake 3.10.0-rc2:

  1. Modify \cmake\FindCuda.cmake per instructions here:

https://devtalk.nvidia.com/default/topic/1024631/cuda-9-opencv-gt-building-errors/

Basically, you must add the newer npp libraries in Cuda 9... Keep in mind when following those instructions, nppic needs to read nppicc.

  1. Modify saturate_cast.hpp to handle the changes in __half with cuda 9, also in that doc.

  2. run cmake, and ensure that: a. WITH_CUBLAS is checked b. CUDA_NVCC_FLAGS set to "--cl-version=2017" c. CUDA_HOST_COMPILER set to wherever on your system "cl.exe" is located. (probably c:\program files (x86)\Microsoft Visual Studio\2017\enterprise..." (don't forget the line above needs to use FORWARD slashes, not backwards!)

  3. Press Configure then Generate

You will get a LOT of errors. I don't know why, they seem unavoidable in Windows + Visual Studio.

Upvotes: 0

Josh
Josh

Reputation: 2869

The error is because the path to the host compiler is wrong. It's specified in CMake as CUDA_HOST_COMPILER: $(VCInstallDir)/bin. As this is a path to a folder (in fact it's a non existing folder), and not an exe, the build fails.

This is likely because MSVC 2017 has a new, much more convoluted, path to the bin folder. It used to be:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin

The new path is something like this, and will vary depending on which version of MSVC you have:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64

More info here. There is a good logical argument for the change, but it's probably broken a ton of build scripts which haven't been updated yet.

You can brute force it by setting the variable to, for example:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64\cl.exe

You may get an error that the target OS is unsupported (even though it should be with CUDA 9).

7>nvcc fatal : Host compiler targets unsupported OS.

There are two fixes for this.

1) If you have the latest MSVC 2017, you need to trick CUDA into accepting it because it's version 1911, not 1910.

Open up C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include\crt\host_config.h and find this line:

#if _MSC_VER < 1600 || _MSC_VER > 1910

Change 1910 to 1911.

2) In CMake, add --cl-version=2017 to CUDA_NVCC_FLAGS. I'm not sure whether it's required, but it won't hurt.

That seems to have done the trick for me. You may also need to disable perf tests. You will also find that ncuvid.h doesn't exist at the moment, whether it's changed location or not I don't know. This prevents building opencv_cudacodec, but I suspect that's not a problem for most people.

Upvotes: 10

Related Questions