配置 CMake 以在 Windows 上设置 CUDA
我正在尝试使用 CMake 在 Windows (Visual Studio 2005) 上编译基于 CUDA 的应用程序。这是一个精简 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()
我希望了解一些问题。
当我打开解决方案文件 (Hello.sln) 时,我没有看到该项目的任何自定义构建规则设置(右键单击“项目 -> 自定义构建规则”),
我确实看到添加了“Hello_ generated_hello.cu.obj”我在 Visual Studio 中的项目。这个文件是什么以及为什么将其添加到项目中?
默认情况下,项目属性中不包含 CUDA Runtime API 部分。
如果我启用适当的自定义构建规则 (NvCudaRuntimeApi.rules),我现在可以看到 CUDA 运行时 API 部分。如果我现在转到 GPU 小节,我会看到 GPU 架构仍然设置为 sm_10。
即使我使用 CUDA_INCLUDE_DIRECTORIES() 宏为 CUDA 编译添加一些目录,我也不会在 Project Properties -> 中看到这些设置。 CUDA 运行时 API ->一般->附加包含目录。
我想知道 FindCUDA() 包是否能够正确配置 VS 2005 项目以进行基于 CUDA 的编译。可能我需要指定其他选项来正确配置项目。我当然想知道这一点。我希望确保通过 CMakeLists 文件指定的任何选项,我都应该能够在生成的 VS 2005 项目中轻松查看它们。
配置这个的合适方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CMake 不支持自定义构建规则(如 CUDA 运行时 API .rules 文件),因此,如果您使用 CMake 配置项目,则无法编辑 .rules 文件提供的 CUDA 属性表。但是,您可以直接在生成项目的 CMakeLists.txt 中设置任何 CUDA 设置,重建项目将检测这些更改并自动重新生成和重新加载项目文件。
FindCUDA 的额外好处(除了跨平台之外)是正确的依赖性分析,这样您就不会像在 Visual Studio 中使用 CUDA .cu 文件(带或不带 .rules 文件)时通常那样以过时的构建结束。
您可以在以下文件中的 CUDPP 项目中找到将 CMake 与 CUDA 结合使用的示例:
http://code.google.com/p/cudpp/source /browse/trunk/CMakeLists.txt
希望有所帮助。
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:
http://code.google.com/p/cudpp/source/browse/trunk/CMakeLists.txt
Hope that helps.