使用CMake设置CUDA_NVCC_FLAGS

时间:2016-04-21 00:54:56

标签: c++ cuda cmake

我正在尝试使用Windows上的CMake编译CUDA项目。我不熟悉make或CMake,过去几天我做了一些阅读,但我仍然无法解决这个问题。我收到以下错误消息:

Chri@Riemann-PC /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64
$ make
[  1%] Built target lapacktest
[  1%] Building NVCC (Device) object CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o
nvcc fatal   : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions 2010, 2012, and 2013 are supported
CMake Error at magma_generated_zherk_batched_core.cu.o.cmake:207 (message):
  Error generating
  /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o


CMakeFiles/magma.dir/build.make:2058: recipe for target 'CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o' failed
make[2]: *** [CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o] Error 1
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/magma.dir/all' failed
make[1]: *** [CMakeFiles/magma.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

使用make VERBOSE = 1命令,我收到以下错误:

cd /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas && /usr/bin/cmake.exe -D verbose:BOOL=1 -D build_configuration:STRING= -D generated_file:STRING=/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o -D generated_cubin_file:STRING=/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o.cubin.txt -P /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o.cmake
-- Removing /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o
/usr/bin/cmake.exe -E remove /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/./magma_generated_zherk_batched_core.cu.o
-- Generating dependency file: /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o.NVCC-depend
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/bin/nvcc.exe" -M -D__CUDACC__ /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/magmablas/zherk_batched_core.cu -o /cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/build64/CMakeFiles/magma.dir/magmablas/magma_generated_zherk_batched_core.cu.o.NVCC-depend -ccbin /usr/bin/gcc.exe -m64 -Xcompiler ,\"-fopenmp\",\"-Wall\",\"-Wno-unused-function\",\"-g\" -DHAVE_CUBLAS -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35 -DNVCC "-I/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/include" "-I/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5/include" -I/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/include -I/cygdrive/c/Apps/ThirdParty/MAGMA/magma-2.0.1/control
nvcc fatal   : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions 2010, 2012, and 2013 are supported

它仍在使用gcc编译器(-ccbin /usr/bin/gcc.exe)。

我进入了文件:C:\Apps\ThirdParty\cygwin64\usr\share\cmake-3.3.2\Modules\FindCUDA.cmake并添加了以下行:

set(VS_DIR "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin")
message(${VS_DIR})
set(CUDA_NVCC_FLAGS "-ccbin ${VS_DIR}" CACHE STRING "Semi-colon delimit multiple arguments.")

我还在nvcc.profile文件中添加了以下行:

CUDA_NVCC_FLAGS += -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin";

仍然没有运气。我花了几天时间试图解决这个问题。我很感激在这件事上提供任何帮助。

1 个答案:

答案 0 :(得分:2)

FindCUDA中设置主机编译器的选项为CUDA_HOST_COMPILER,请参阅FindCUDA documentation

尝试

set(CUDA_HOST_COMPILER "<path to compiler executable>")

或者在调用cmake命令时设置它

cmake .. -DCUDA_HOST_COMPILER=<path to compiler executable>

我猜CUDA_HOST_COMPILER选项会覆盖ccbin的{​​{1}}设置。对于其他选项,您可以按照您尝试的方式使用CUDA_NVCC_FLAGS。 (因此,标题具有误导性。这不是如何设置CUDA_NVCC_FLAGS的问题。)

我经常在Linux上使用它,但是我没有Windows环境来测试它。