CMake生成一个MSVC CUDA项目,目标较新的设备 [英] CMake to generate a MSVC CUDA project that targets newer devices
问题描述
我的电脑有一个GTX 580(计算能力2.0)。
我想编译一个使用动态并行性的CUDA源码,
我知道我不能在GPU上运行程序,但是,应该可以在我的机器上编译这个代码。我假设这是因为我可以编译没有问题使用3.5功能的CUDA示例。这些示例带有手动生成的Visual Studio项目(我猜)。
我相信我的问题是与CMake。我使用CMake生成Visual Studio 2012项目。
我的第一个CMakeLists.txt看起来像这样:
PROJECT(sample-cuda-tests)
FIND_PACKAGE(需要CUDA)
INCLUDE_DIRECTORIES($ {CUDA_INCLUDE_DIRS})
INCLUDE_DIRECTORIES($ {CMAKE_CURRENT_SOURCE_DIR} / include)
FILE(GLOB_RECURSE包括$ {CMAKE_CURRENT_SOURCE_DIR} / include / *。h)
FILE(GLOB_RECURSE sources $ {CMAKE_CURRENT_SOURCE_DIR} / src / *。 cc $ {CMAKE_CURRENT_SOURCE_DIR} / src / *。cu)
CUDA_ADD_EXECUTABLE(sample-cuda-tests $ {includes} $ {sources})
TARGET_LINK_LIBRARIES(sample-cuda-tests $ {CUDA_LIBRARIES })
然后,当使用生成的Visual Studio 2012项目进行编译时,错误:
警告:compute_10和sm_10体系结构已弃用,可能会在将来的版本中删除。
错误:从__global__函数调用__global__函数只允许在compute_35体系结构或以上
需要什么。然后我添加了
列表(APPEND CUDA_NVCC_FLAGS -gencode arch = compute_35,code = sm_35)
给CMakeLists。警告消失,但我得到:
错误:内核从__device__或__global__函数启动需要单独的编译模式
好的。所以我添加到CMakeLists:
set(CUDA_SEPARABLE_COMPILATION ON)
...并收到此:
致命错误:nvcc支持'--relocatable-device-code = true只有当定位到sm_20或更高版本时,才会显示rdc = true,'--device-c(-dc)'和'--device-link(-dlink)'
很奇怪,因为我认为我的目标是sm_35(高于sm_20)。
后来我发现我可以直接在CUDA_ADD_EXECUTABLE命令。所以我删除了附加值到CUDA_NVCC_FLAGS的行,并将CUDA_ADD_EXECUTABLE命令更改为:
CUDA_ADD_EXECUTABLE(sample-cuda-tests $ { include} $ {sources}选项-gencode arch = compute_35,code = sm_35)
:
C:\Program Files \ NVIDIA GPU计算工具包\CUDA\v6.0\bin\crt\ link.stub:致命错误C1083:无法打开编译器生成的文件:'C:/Users/sms/Desktop/sample-cuda-tests/CMakeFiles/sample-cuda-tests.dir/Debug/sample-cuda-tests_intermediate_link.obj' :没有这样的文件或目录
不知道现在去哪里。
我在Windows 7上使用CUDA SDK 6.0。
当设置CUDA_SEPARABLE_COMPILATION为ON时,如果.cu文件不在CMakeLists的同一文件夹中。 txt,中间链接对象生成在错误的文件夹中,导致编译错误,在Visual Studio中,如下所示:
无法打开编译器生成的文件:'project_path / CMakeFiles / project_name / Debug / project_name_intermediate_link.obj':没有这样的文件或目录。
CMake错误追踪程式中的问题:
http://public.kitware.com /Bug/view.php?id=15016
(错误最好在这里描述)
My PC has a GTX 580 (compute capability 2.0).
I want to compile a CUDA source that uses dynamic parallelism, a feature introduced in compute capability 3.5.
I know I will not be able to run the program on my GPU, however, it should be possible to compile this code on my machine. I'm assuming this because I can compile with no problems the CUDA samples that use 3.5 capability. These samples come with Visual Studio projects that were "manually generated" (I guess).
I believe my problem is with CMake. I'm using CMake to generate a Visual Studio 2012 project.
My first CMakeLists.txt looked like this:
PROJECT(sample-cuda-tests)
FIND_PACKAGE(CUDA REQUIRED)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
FILE(GLOB_RECURSE includes ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h )
FILE(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cu )
CUDA_ADD_EXECUTABLE(sample-cuda-tests ${includes} ${sources})
TARGET_LINK_LIBRARIES(sample-cuda-tests ${CUDA_LIBRARIES})
Then, when compiling with the generated Visual Studio 2012 project, I got a warning followed by an error:
warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release.
error : calling a __global__ function from a __global__ function is only allowed on the compute_35 architecture or above
What was expected. Then I added
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_35,code=sm_35)
to the CMakeLists. The warning disappeared, but I got:
error : kernel launch from __device__ or __global__ functions requires separate compilation mode
Ok. So I added to the CMakeLists:
set(CUDA_SEPARABLE_COMPILATION ON)
...and received this:
fatal error : nvcc supports '--relocatable-device-code=true (-rdc=true)', '--device-c (-dc)', and '--device-link (-dlink)' only when targeting sm_20 or higher
What is weird because I thought I was targeting sm_35 (higher than sm_20).
Later I discovered I can set some options directly in CUDA_ADD_EXECUTABLE command. So I removed the line that was appending values to CUDA_NVCC_FLAGS and changed CUDA_ADD_EXECUTABLE command to:
CUDA_ADD_EXECUTABLE(sample-cuda-tests ${includes} ${sources} OPTIONS -gencode arch=compute_35,code=sm_35)
What I got was:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\crt\link.stub : fatal error C1083: Cannot open compiler generated file: 'C:/Users/sms/Desktop/sample-cuda-tests/CMakeFiles/sample-cuda-tests.dir/Debug/sample-cuda-tests_intermediate_link.obj': No such file or directory
No idea where to go now. Appreciate any help.
I'm using CUDA SDK 6.0 on Windows 7.
Turned out to be a bug on FindCUDA.cmake.
When setting CUDA_SEPARABLE_COMPILATION to ON, if .cu files are not in the same folder of CMakeLists.txt, intermediate linkage objects are generated in the wrong folder, causing a compilation error that, on Visual Studio, looks like this:
Cannot open compiler generated file: 'project_path/CMakeFiles/project_name/Debug/project_name_intermediate_link.obj': No such file or directory.
I've opened an issue in CMake bug tracker: http://public.kitware.com/Bug/view.php?id=15016 (the bug is better described there)
这篇关于CMake生成一个MSVC CUDA项目,目标较新的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!