我的电脑有一个 GTX 580(计算能力 2.0)。
我想编译一个使用动态并行性的 CUDA 源代码,这是计算能力 3.5 中引入的一项功能。
我知道我将无法在我的 GPU 上运行该程序,但是,应该可以在我的机器上编译此代码。我假设这是因为我可以毫无问题地编译使用 3.5 功能的 CUDA 示例。这些示例带有“手动生成”的 Visual Studio 项目(我猜)。
我相信我的问题在于 CMake。我正在使用 CMake 生成 Visual Studio 2012 项目。
我的第一个 CMakeLists.txt 看起来像这样:
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})
然后,在使用生成的 Visual Studio 2012 项目进行编译时,我收到一个警告,然后是一个错误:
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
预期什么。然后我加了
list(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_35,code=sm_35)
到 CMakeLists。警告消失了,但我得到了:
error : kernel launch from __device__ or __global__ functions requires separate compilation mode
好的。所以我添加到 CMakeLists:
set(CUDA_SEPARABLE_COMPILATION ON)
...并收到了这个:
fatal error : nvcc supports '--relocatable-device-code=true (-rdc=true)', '--device-c (-dc)', and '--device-link (-dlink)' only when targeting sm_20 or higher
奇怪的是,我以为我的目标是 sm_35(高于 sm_20)。
后来我发现我可以直接在 CUDA_ADD_EXECUTABLE 命令中设置一些选项。所以我删除了将值附加到 CUDA_NVCC_FLAGS 的行并将 CUDA_ADD_EXECUTABLE 命令更改为:
CUDA_ADD_EXECUTABLE(sample-cuda-tests ${includes} ${sources} OPTIONS -gencode arch=compute_35,code=sm_35)
我得到的是:
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
现在不知道该去哪里。感谢任何帮助。
我在 Windows 7 上使用 CUDA SDK 6.0。