CUDA 9 + OpenCV => Building errors

I am using: Visual Studio 2017, OpenCV 3.3 + contrib, CUDA 9, CMake 3.9.3, windows10

The project configuration in CMake always fails with the following message:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)

In the CUDA-directory i can only find : nppial.lib, nppicc.lib, nppicom.lib, nppidei.lib, nppif.lib, nppig.lib, nppist.lib nppisu.lib, nppitc.lib and npps.lib libraries but no nppi as expected.

I found two postings related to that problem:

  1. problem related to FindCUDA-module in CMake (superseded by first-class support for CUDA language)
    [url]Sign in · GitLab

  2. create nppi.lib from all the other libs mentioned above with “x64 Native Tools Command Prompt for VS 2017”:
    lib.exe /out:nppi.lib nppial.lib nppicc.lib nppicom.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib
    (Doesn’t work for me. CMake doesn’t show me errors anymore but I get a huge amount of errors in the Visual Studio building process.)
    [url]c++ - Installing OpenCV 3.3.0 with contrib modules using CMake, CUDA 9.0 RC and Visual Studio 2017 - Stack Overflow

I would appreciate it very much if someone could help me with my problem.

I tried to patch the OpenCV 3.3.0 cmake/FindCUDA.cmake file to fix this:

diff --git a/cmake/FindCUDA.cmake b/cmake/FindCUDA.cmake
index 678b450ab..c2a58bd00 100644
--- a/cmake/FindCUDA.cmake
+++ b/cmake/FindCUDA.cmake
@@ -283,7 +283,38 @@
 #   CUDA_nppc_LIBRARY     -- NVIDIA Performance Primitives lib (core).
 #                            Only available for CUDA version 5.5+.
 #   CUDA_nppi_LIBRARY     -- NVIDIA Performance Primitives lib (image processing).
-#                            Only available for CUDA version 5.5+.
+#                            Only available for CUDA version 5.5+ and was split up
+#                            in CUDA version 8.0+ and doesn't exist in combined
+#                            form in CUDA version 9.0+.
+#   CUDA_nppial_LIBRARY   -- NVIDIA Performance Primatives library (arithmetic and
+#                            logical operation functions). Only available for CUDA
+#                            version 8.0+.
+#   CUDA_nppicc_LIBRARY   -- NVIDIA Performance Primatives library (color conversion
+#                            and sampling functions). Only available for CUDA version
+#                            8.0+.
+#   CUDA_nppicom_LIBRARY  -- NVIDIA Performance Primatives library (JPEG compression
+#                            and decompression functions). Only available for CUDA
+#                            version 8.0+.
+#   CUDA_nppidei_LIBRARY  -- NVIDIA Performance Primatives library (data exchange and
+#                            initialization functions). Only available for CUDA
+#                            version 8.0+.
+#   CUDA_nppif_LIBRARY    -- NVIDIA Performance Primatives library (filtering and
+#                            computer vision functions). Only available for CUDA
+#                            version 8.0+.
+#   CUDA_nppig_LIBRARY    -- NVIDIA Performance Primatives library (geometry
+#                            transformation functions). Only available for CUDA
+#                            version 8.0+.
+#   CUDA_nppim_LIBRARY    -- NVIDIA Performance Primatives library (morphological
+#                            operation functions). Only available for CUDA version
+#                            8.0+.
+#   CUDA_nppist_LIBRARY   -- NVIDIA Performance Primatives library (statistics and
+#                            linear transform). Only available for CUDA version
+#                            8.0+.
+#   CUDA_nppisu_LIBRARY   -- NVIDIA Performance Primatives library (memory support
+#                            functions). Only available for CUDA version 8.0+.
+#   CUDA_nppitc_LIBRARY   -- NVIDIA Performance Primatives library (threshold and
+#                            compare operation functions). Only available for CUDA
+#                            version 8.0+.
 #   CUDA_npps_LIBRARY     -- NVIDIA Performance Primitives lib (signal processing).
 #                            Only available for CUDA version 5.5+.
 #   CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library.
@@ -522,6 +553,16 @@ macro(cuda_unset_include_and_libraries)
   unset(CUDA_npp_LIBRARY CACHE)
   unset(CUDA_nppc_LIBRARY CACHE)
   unset(CUDA_nppi_LIBRARY CACHE)
+  unset(CUDA_nppial_LIBRARY CACHE)
+  unset(CUDA_nppicc_LIBRARY CACHE)
+  unset(CUDA_nppicom_LIBRARY CACHE)
+  unset(CUDA_nppidei_LIBRARY CACHE)
+  unset(CUDA_nppif_LIBRARY CACHE)
+  unset(CUDA_nppig_LIBRARY CACHE)
+  unset(CUDA_nppim_LIBRARY CACHE)
+  unset(CUDA_nppist_LIBRARY CACHE)
+  unset(CUDA_nppisu_LIBRARY CACHE)
+  unset(CUDA_nppitc_LIBRARY CACHE)
   unset(CUDA_npps_LIBRARY CACHE)
   unset(CUDA_nvcuvenc_LIBRARY CACHE)
   unset(CUDA_nvcuvid_LIBRARY CACHE)
@@ -787,7 +828,22 @@ if(NOT CUDA_VERSION VERSION_LESS "3.2")
     find_cuda_helper_libs(nvcuvid)
   endif()
 endif()
-if(CUDA_VERSION VERSION_GREATER "5.0")
+if(CUDA_VERSION VERSION_GREATER "7.5")
+  # In CUDA 8.0 NPP was splitted onto 12 separate libraries.
+  find_cuda_helper_libs(nppc)
+  find_cuda_helper_libs(nppial)
+  find_cuda_helper_libs(nppic)
+  find_cuda_helper_libs(nppicom)
+  find_cuda_helper_libs(nppidei)
+  find_cuda_helper_libs(nppif)
+  find_cuda_helper_libs(nppig)
+  find_cuda_helper_libs(nppim)
+  find_cuda_helper_libs(nppist)
+  find_cuda_helper_libs(nppisu)
+  find_cuda_helper_libs(nppitc)
+  find_cuda_helper_libs(npps)
+  set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
+elseif(CUDA_VERSION VERSION_GREATER "5.0")
   # In CUDA 5.5 NPP was splitted onto 3 separate libraries.
   find_cuda_helper_libs(nppc)
   find_cuda_helper_libs(nppi)

…but now I’m getting some compilation errors:

c:\externalpackages\opencv-3.3.0-t1-vc12\src\opencv\modules\cudev\include\opencv2\cudev/util/saturate_cast.hpp(277): error : identifier "__half2float" is undefined

See the patch in opencv to saturate_cast.hpp to handle the changes in __half with cuda 9 at
https://github.com/opencv/opencv/pull/9769/commits/5669ee815bf724a1f3bf12429a07e6199154e230

I, too, am using VS 2017, Open CV 3.3 + contrib, Cuda 9, CMake 3.9.4, and Windows 10…
I’ve applied the above patches, but what I’m getting is a compile error on the cuda files, it seems to want to find ccbin at $(VCInstallDir)bin, which isn’t present on my machine. CMake’s CUDA_HOST_COMPILER is set to $(VCInstallDir)bin, but even if I change it in cmake (to some other directory), then re-configure and re-generate, the vcxproj file still shows ccbin being located at $(VCInstallDir)bin! Nothing seems to change this path for me.

When I try to compile any .cu file it says "CMake Error at xxx.cu:206 (message): 1> Error generating filename.obj

and that’s it.

If one of you has successfully compiled opencv with the above software, please document what you had to do (in addition to the above steps) to get it to compile. What flags did you set up cmake with? Do you have other software packages installed? Do you run cmake from the UI or command line? Did you change any flags in cmake before configuring and generating? What does CUDA_HOST_COMPILER do, and what does it reference? What do I need to set it to? What is the issue with $(VCInstallDir)bin not being present?

thanks!

line 71 needs to read nppicc, not nppic.

I’m using VS2017, OpenCV3.3, CUDA 9, CMake 3.8, and Windows 10.

I fixed the "CMake Error at xxx.cu:206 (message): 1> Error generating filename.obj by force CUDA_HOST_COMPILER to the actual path instead of $(VCInstallDir)bin. You could refer to this page: [url]c++ - Compiling OpenCV 3.3 with CUDA 9.0RC - Stack Overflow

Instead of using $(VCInstallDir)bin, you’ll need to set the CUDA_HOST_COMPILER to something like: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX86\x64

treigilbert, I posted the pull request you referred to:

https://github.com/opencv/opencv/pull/9769/commits/5669ee815bf724a1f3bf12429a07e6199154e230

but I made it against the master branch, not the 3.3.0 tag. I didn’t even think to attempt to apply it to the 3.3.0 tag version of the source tree.

nvidia9dk7k, thanks for pointing out the typo in the patch I listed here.

Dawen, thanks for pointing out the error in the CUDA_HOST_COMPILER.

I’m attempting a VS 2017, OpenCV 3.3.0 with patches applied, CUDA 9.0 build as I write this.

Hi, Guy, I use Cmake to build opencv with CUDA, and also face the same problem with you, have u figure out this problem, if U build successfully, can u share the approach for us, thx

Hi nyb1992, you need to fix three problems.

I assume that you are using cmake with Visual Studio 2017 win64 compiler.

Firstly you need to refer pstieber’s comment and patch 3.3.0-src-folder/cmake/FindCUDA.cmake file:

Secondly, you need to follow treigilbert’s post to patch modules/cudev/include/opencv2/cudev/util/saturate_cast.hpp file.

Thirdly, after you use cmake (I recommend cmake-gui) for configuring, you need to manually set CUDA_HOST_COMPILER to your Visual Studio’s actual path to cl.exe. For example, my path for that is: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX86\x64

After doing so you should be able to build. If there are any other problems please post here.