Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help on building OpenCV with CUDA #1609

Closed
jasjuang opened this issue Aug 8, 2017 · 17 comments
Closed

Need help on building OpenCV with CUDA #1609

jasjuang opened this issue Aug 8, 2017 · 17 comments
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist

Comments

@jasjuang
Copy link
Contributor

jasjuang commented Aug 8, 2017

I am on vs2015, x64-windows. I am attempting to build OpenCV with CUDA by simply changing the -DWITH_CUDA=OFF to -DWITH_CUDA=ON. In the end I get a compilation error,

"C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\install.vcxproj" (default target) (1) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\ALL_BUILD.vcxproj" (default target) (3) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\modules\cudaimgproc\opencv_cudaimgproc.vcxproj" (default target) (22) ->
       (CustomBuild target) -> 
         C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include\thrust/detail/integer_traits.h(68): error C2137: empty character constant [C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\modules\cudaimgproc\opencv_cudaimgproc.vcxproj]


       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\install.vcxproj" (default target) (1) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\ALL_BUILD.vcxproj" (default target) (3) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\modules\cudafeatures2d\opencv_cudafeatures2d.vcxproj" (default target) (18) ->
         C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include\thrust/detail/integer_traits.h(68): error C2137: empty character constant [C:\dev\vcpkg\buildtrees\opencv\x64-windows-rel\modules\cudafeatures2d\opencv_cudafeatures2d.vcxproj]

    5767 Warning(s)
    2 Error(s)

But the problem is I am unable to reproduce this when building from source with the same cmake options. The module opencv_cudafeatures2d compiles successfully. The whole thing compiles successfully. I browsed through the fix patches for opencv in vcpkg, and nothing looks like it could cause a problem. Could anyone give me some insights?

@ras0219-msft ras0219-msft added the category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist label Aug 9, 2017
@icedream2linxi
Copy link
Contributor

When using "-Xcompiler utf-8", you can reproduce the problem.

当使用"-Xcompiler utf-8"时,可以重现问题现象。

G:\Temp\tt>nvcc tt.cu -o tt.obj -Xcompiler ,\"/utf-8\"
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
tt.cu
C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/BIN/../../VC/INCLUDE\stdint.h(32): warning C4828: The file contains a character starting at offset 0x9aadf that is illegal in the current source character set (codepage 65001).
tt.cu(22): error C2137: empty character constant

tt.cu

#include <limits>
#include <cstdint>

template<typename T>
class integer_traits
{
public:
	static const bool is_integral = false;
};

template<typename T, T min_val, T max_val>
class integer_traits_base
{
public:
	static const bool is_integral = true;
	static const T const_min = min_val;
	static const T const_max = max_val;
};

template<>
class integer_traits<unsigned char>
	: public std::numeric_limits<unsigned char>,
	public integer_traits_base<unsigned char, 0, UCHAR_MAX>
{};

@jasjuang
Copy link
Contributor Author

@icedream2linxi Thanks a lot for identifying the problem. I am able to reproduce it with your code. Now I just have to figure out a way to turn off "-Xcompiler utf-8" when compiling. Problem is I have no idea how to adjust the compilation flags in vcpkg. Can @ras0219-msft @KindDragon give me some pointers?

@ras0219-msft
Copy link
Contributor

This is probably being percolated from the /utf-8 we pass into our base compiler flags[1]. The ideal fix would be to patch the sources to be pure utf-8 (or better, ascii). However, if that won't work, it should be possible to override the charset.

Here're the relevant docs:
https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8

[1] https://github.com/Microsoft/vcpkg/blob/91e7d010999afd137c128b61c4df27b39a645d0f/scripts/cmake/vcpkg_configure_cmake.cmake#L130

@jasjuang
Copy link
Contributor Author

@ras0219-msft I don't think it's appropriate to patch the source, because CUDA is actually installed separately by it's own installer.

I manually remove the /utf-8 in vcpkg_configure_cmake.cmake and it actually compiles. But I am unable to patch it in the opencv portfile. I tried

string(REPLACE "/utf-8" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

but it didn't work. Could you give me some pointers on how to remove the utf-8 flag in the opencv portfile?

However, after removing the utf-8 flag manually, opencv compiles successfully in release mode but fails to compile in debug mode. Again, I wasn't able to reproduce this if I build OpenCV from source. Below is the error message when OpenCV is compiled in debug mode,

 "C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\install.vcxproj" (default target) (1) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\ALL_BUILD.vcxproj" (default target) (3) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\modules\cudaobjdetect\opencv_cudaobjdetect.vcxproj" (default target) (39) ->
       (CustomBuild target) -> 
         CUSTOMBUILD : CMake error : CMake can not determine linker language for target: cmTC_b741d [C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\modules\cudaobjdetect\opencv_cudaobjdetect.vcxproj]


       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\install.vcxproj" (default target) (1) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\ALL_BUILD.vcxproj" (default target) (3) ->
       "C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\modules\videostab\opencv_videostab.vcxproj" (default target) (79) ->
         CUSTOMBUILD : CMake error : CMake can not determine linker language for target: cmTC_38cb2 [C:\dev\vcpkg\buildtrees\opencv\x64-windows-dbg\modules\videostab\opencv_videostab.vcxproj]

    2689 Warning(s)
    2 Error(s)

@icedream2linxi Can you help me again on identifying where this compilation error is from ?

@KindDragon
Copy link
Contributor

I tried

string(REPLACE "/utf-8" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
but it didn't work.

Try to do same for C compiler CMAKE_C_FLAGS

@jasjuang
Copy link
Contributor Author

@KindDragon I added that line too but it didn't work unfortunately

@icedream2linxi
Copy link
Contributor

I have also seen this error, did not appear again after building it again.

我这里也出现过这样的错误,再编译一遍后没出现。

@jasjuang
Copy link
Contributor Author

@icedream2linxi I tried rebuilding it 3 times and still see the error... What did you change before building it again?

@icedream2linxi
Copy link
Contributor

icedream2linxi commented Aug 26, 2017

I manually remove the /utf-8 in vcpkg_configure_cmake.cmake.

portfile.cmake:
WITH_CUDA=ON
WITH_CUBLAS=ON

@icedream2linxi
Copy link
Contributor

icedream2linxi commented Aug 26, 2017

Building environment:
OS: Windows 10 Enterprise Version 1703 x64 Enlish
Code Page: 936
VS: Visual Studio Enterprise 2015 Version 14.0.25431.01 Update 3 English
CUDA: Version 8.0.61
vcpkg: 57d078e
cmake: 3.9.1-win32-x86

triplet: x64-windows

@icedream2linxi
Copy link
Contributor

Today, I rebuilding it 2 times. No error. 😿

config-x64-windows-dbg-out.txt
config-x64-windows-rel-out.txt

@icedream2linxi
Copy link
Contributor

I building it on another computer. No error.

我在另外一台电脑上进行了编译。没有错误。

config-x64-windows-dbg-out.txt
config-x64-windows-rel-out.txt

@jasjuang
Copy link
Contributor Author

@icedream2linxi could you try building with the opencv 3.3 PR #1619 with CUDA enabled?

@cmpute
Copy link
Contributor

cmpute commented Feb 17, 2018

I have also encountered the "CMake can not determine linker language for target" error

@sparsebase
Copy link

@cmpute After applying your PR #2809 and using the platform toolset v140 with VS2017, I have ran into this exact problem. Strange thing is if I directly build and install the solution file created in the buildtree, it works perfectly. Were you able to install opencv[cuda] successfully?

@sparsebase
Copy link

This issue seems disappeared with CUDA 9.1 when using with platform toolset v140 under VS2017.

@jasjuang
Copy link
Contributor Author

I just tried with the latest master and it actually compiles now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-feature The issue is with a library, which is requesting new capabilities that didn’t exist
Projects
None yet
Development

No branches or pull requests

6 participants