在Windows上配置CMake来设置CUDA。

时间:2022-12-23 12:46:00

I am trying to use CMake for compiling CUDA based application on Windows (Visual Studio 2005). Here is an example stripped down CMake file:

我正在尝试使用CMake来编译基于Windows的CUDA应用程序(Visual Studio 2005)。下面是一个简化的CMake文件示例:

cmake_minimum_required (VERSION 2.6)
project (HELLO)

#Support for CUDA Integration
FIND_PACKAGE(CUDA)
if(CUDA_FOUND)
    SET(CUDA_NVCC_FLAGS "-arch;sm_13")
CUDA_ADD_EXECUTABLE(Hello hello.cu)
else(CUDA_FOUND)
    message("CUDA is not installed on this system.")
endif()

There are a few issues I wish to understand with this.

有几个问题我希望能理解。

When I open the solution file (Hello.sln), I don't see any custom build rule setup for the project (Right click on Project -> Custom build rules)

当我打开解决方案文件(Hello.sln)时,我没有看到任何针对项目的自定义构建规则设置(右击项目->自定义构建规则)

I do see a "Hello_generated_hello.cu.obj" added to my project in Visual Studio. What is this file and why is it added to the project?

我确实看到了“Hello_generated_hello.cu”。obj在Visual Studio中加入了我的项目。这个文件是什么,为什么要添加到项目中?

By default CUDA Runtime API section doesn't come in Project properties.

在默认情况下,CUDA运行时API部分不会出现在项目属性中。

If I enable an appropriate custom build rule (NvCudaRuntimeApi.rules), I can now see CUDA runtime API section. If I now go to GPU subsection, I see the GPU architecture still set to be sm_10.

如果我启用了一个适当的自定义构建规则(NvCudaRuntimeApi.rules),那么我现在可以看到CUDA runtime API部分。如果现在切换到GPU小节,我看到GPU架构仍然设置为sm_10。

Even if I use CUDA_INCLUDE_DIRECTORIES() Macro to add some directories for CUDA compilation, I won't see these settings in Project Properties -> CUDA Runtime API -> General -> Additional Include Directories.

即使我使用cuda_include_directory()宏来为CUDA编译添加一些目录,我也不会在项目属性中看到这些设置—> CUDA Runtime API -> General ->附加包括目录。

I wish to know if FindCUDA() package is very able to properly configure VS 2005 project for CUDA based compilation. May be I need to specify additional options to properly configure the project. I would certainly wish to know that. I wish to make sure that whatever options I have specified through CMakeLists file, I should be able to review them easily in my generated VS 2005 project.

我希望知道FindCUDA()包是否能够正确配置VS 2005项目的基于CUDA的编译。可能我需要指定其他选项来正确配置项目。我当然希望知道这一点。我希望确保通过CMakeLists文件指定的任何选项,我都可以在我生成的VS 2005项目中轻松地查看它们。

What is appropriate way to configure this?

配置这个的合适方法是什么?

1 个解决方案

#1


4  

CMake does not support custom build rules (like the CUDA runtime API .rules file), and therefore you cannot edit the CUDA property sheets that the .rules files provide if you use CMake to configure your project. However you can set any CUDA settings directly in the CMakeLists.txt that generates the project, and rebuilding your project will detect these changes and regenerate and reload the project files automatically.

CMake不支持自定义构建规则(如CUDA runtime API .rules文件),因此您不能编辑.rules文件提供的CUDA属性表,如果您使用CMake来配置您的项目的话。不过,您可以直接在CMakeLists中设置任何CUDA设置。生成项目的txt和重建项目将检测这些更改并自动重新加载项目文件。

The additional benefit of FindCUDA (besides being cross-platform) is proper dependency analysis so that you never end up with stale builds like you normally do when using CUDA .cu files in Visual Studio (with or without .rules files).

FindCUDA(除了跨平台)的额外好处是适当的依赖分析,这样您就不会像通常在Visual Studio中使用CUDA .cu文件时那样(不管是否使用.rules文件)来结束那些过时的构建。

You can find an examples of using CMake with CUDA in the CUDPP project in the following files:

您可以在CUDPP项目中使用CUDA在以下文件中找到使用CMake的例子:

Hope that helps.

希望有帮助。

#1


4  

CMake does not support custom build rules (like the CUDA runtime API .rules file), and therefore you cannot edit the CUDA property sheets that the .rules files provide if you use CMake to configure your project. However you can set any CUDA settings directly in the CMakeLists.txt that generates the project, and rebuilding your project will detect these changes and regenerate and reload the project files automatically.

CMake不支持自定义构建规则(如CUDA runtime API .rules文件),因此您不能编辑.rules文件提供的CUDA属性表,如果您使用CMake来配置您的项目的话。不过,您可以直接在CMakeLists中设置任何CUDA设置。生成项目的txt和重建项目将检测这些更改并自动重新加载项目文件。

The additional benefit of FindCUDA (besides being cross-platform) is proper dependency analysis so that you never end up with stale builds like you normally do when using CUDA .cu files in Visual Studio (with or without .rules files).

FindCUDA(除了跨平台)的额外好处是适当的依赖分析,这样您就不会像通常在Visual Studio中使用CUDA .cu文件时那样(不管是否使用.rules文件)来结束那些过时的构建。

You can find an examples of using CMake with CUDA in the CUDPP project in the following files:

您可以在CUDPP项目中使用CUDA在以下文件中找到使用CMake的例子:

Hope that helps.

希望有帮助。