0

我的电脑有一个 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。

4

2 回答 2

2

从 CMake 3.1.0 开始,CMake 脚本无法创建用于放置中间文件的目录。在 FindCUDA.cmake 中添加以下代码段

get_filename_component(output_file_path "${output_file}" PATH)
add_custom_command(
  TARGET ${cuda_target}
  PRE_LINK
  COMMAND ${CMAKE_COMMAND} -E make_directory ${output_file_path}
)

就在之前

if (do_obj_build_rule)

在函数 CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS

于 2014-12-21T21:35:01.050 回答
1

原来是 FindCUDA.cmake 上的一个错误。

将 CUDA_SEPARABLE_COMPILATION 设置为 ON 时,如果 .cu 文件不在 CMakeLists.txt 的同一文件夹中,则会在错误文件夹中生成中间链接对象,从而导致编译错误,在 Visual Studio 上如下所示:

Cannot open compiler generated file: 'project_path/CMakeFiles/project_name/Debug/project_name_intermediate_link.obj': No such file or directory.

我在 CMake 错误跟踪器中打开了一个问题: http://public.kitware.com/Bug/view.php?id=15016 (那里的错误描述得更好)

于 2014-07-11T14:04:38.520 回答