配置CMake以在Windows上设置CUDA [英] configuring CMake to setup CUDA on Windows

查看:3366
本文介绍了配置CMake以在Windows上设置CUDA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用CMake编译基于CUDA的应用程序在Windows(Visual Studio 2005)。这里是一个拆卸CMake文件的示例:

  cmake_minimum_required(VERSION 2.6)
项目(HELLO)

#支持CUDA集成
FIND_PACKAGE(CUDA)
如果(CUDA_FOUND)
SET(CUDA_NVCC_FLAGS-arch; sm_13)
CUDA_ADD_EXECUTABLE(Hello hello.cu)
else(CUDA_FOUND)
消息(此系统上未安装CUDA)
endif()


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



我看到一个Hello_generated_hello.cu.obj添加到我的项目在Visual Studio。什么是这个文件,为什么它被添加到项目?



默认情况下,项目属性中不包含CUDA运行时API部分。



如果启用了适当的自定义构建规则(NvCudaRuntimeApi.rules),我现在可以看到CUDA运行时API部分。如果我现在去GPU子部分,我看到GPU架构仍然设置为sm_10。



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



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



什么是合适的配置方式?

解决方案

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



FindCUDA的额外好处(除了跨平台)是适当的依赖性分析,以便你永远不会像你通常在Visual Studio中使用CUDA .cu文件(有或没有.rules文件)结束过时的构建。



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





希望有帮助。


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_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)

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?

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

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.

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.

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.

What is appropriate way to configure this?

解决方案

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.

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).

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

Hope that helps.

这篇关于配置CMake以在Windows上设置CUDA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆