CUDA CMake 3.10 CMakeLists.txt [英] Cuda CMake 3.10 CMakeLists.txt

查看:190
本文介绍了CUDA CMake 3.10 CMakeLists.txt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可视化的c ++项目,可以创建一个dll。
对于这个项目,我有一个正常的CMakeLists.txt。

I have a visual c++ project which creates a dll. For this project I have a working CMakeLists.txt.

现在,我创建了两个cuda源文件来完成该项目,并创建了
(使用Visual Studio)建立正常。
我想将匹配的命令添加到我的cmake文件中。
谁能告诉我我需要添加的基本命令吗?

Now I created two cuda source files which complete the project and with visual studio the build works fine. I want to add the matching commands to my cmake file. Can anyone tell me the basic commands I need to add?

我尝试建立一个使用.cu和.cpp文件的dll库... 。
cmake文件的重要部分如下所示:

I try to build a dll library where i use .cu and .cpp files.... The important part of my cmake file looks like:

# ----------------------------------------------------------------------------
# Set Cuda properties
# ----------------------------------------------------------------------------
enable_language(CUDA)
set(CUDA_SEPARABLE_COMPILATION ON)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
  set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON)
endif()
set(CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50;-rdc=true;-use_fast_math")

message(STATUS "CUDA_PROPAGATE_HOST_FLAGS: ${CUDA_PROPAGATE_HOST_FLAGS}")
message(STATUS "CUDA_HOST_COMPILER: ${CUDA_HOST_COMPILER}")
message(STATUS "CUDA_NVCC_FLAGS: ${CUDA_NVCC_FLAGS}")

# ----------------------------------------------------------------------------
# Create shared library project
# ----------------------------------------------------------------------------
add_library(${LIB_NAME} SHARED ${HEADERS} ${SOURCES} ${CUDA_SOURCES})
set(CUDA_LIBRARIES "cudadevrt.lib;cudart.lib")
target_link_libraries(${LIB_NAME} ${CUDA_LIBRARIES})

但是它不会编译带有正确标志的cuda文件。
同样在Visual Studio中,预处理器定义也在属性的cuda部分中。...有任何建议吗?

But it doesn't compile the cuda files with the right flags. Also in visual studio the preprocessor definitions are also in the cuda part of the properties....any suggestions?

推荐答案

我将尝试通过评论中的讨论来回答这个问题,并添加一些额外的信息。

I'll try to answer this question using the discussion from the comments and add some extra information.

首先,有两种方法可以启用CUDA支持CMake。一个是旧的 FindCUDA 模块,另一个是CMake 3.8中新增的内置CUDA语言支持,并说明了此处
您可以选择其中一个(但是您可能要使用对新项目的内置支持),但随后您必须坚持选择。

First of all, there are two ways to enable CUDA support in CMake. One is the old FindCUDA module, and the other is the new built-in CUDA language support added in CMake 3.8, and explained here. You can choose one or the other (but you'll probably want to use the built-in support for new projects), but then you have to stick with your choice.

要使用内置支持,您可以将其添加到 project(...)语句中,或使用:

To use built-in support you either add it to the project(...) statement or use:

enable_language(CUDA);

要使用旧的 FindCUDA 软件包,您需要会使用:

To use the old FindCUDA package, you would use:

find_package(CUDA);

请注意,这两个选项使用完全不同的变量进行设置。要查看 FindCUDA 支持哪些变量,请参见此页面,有关内置CUDA的支持,请参见(不要忘记< LANG> 占位符可以用任何语言替换,这意味着 CUDA 也是可用的替代项之一。

Note that the two options use completely different variables for setup. To see what variables are supported by FindCUDA see this page, and for built-in CUDA support see this (don't forget that the <LANG> placeholder can be replaced by any language, which means that CUDA is also one of the available substitutions).

例如在 FindCUDA 中,您将使用 CUDA_NVCC_FLAGS 来手动设置编译器标志,而在内置语言支持下,您将使用 CMAKE_CUDA_FLAGS 出于相同的目的。根据经验:如果变量以 CUDA _ 开头,则它是 FindCUDA 包的一部分,如果它从 CMAKE _ 开始,然后它是内置支持的一部分。

E.g. with FindCUDA you would use CUDA_NVCC_FLAGS to set the compiler flags manually, and with built-in language support you would use CMAKE_CUDA_FLAGS for the same purpose. As a rule of thumb: if the variable starts with CUDA_ it is a part of the FindCUDA package, and if it starts with CMAKE_, then it is part of built-in support.

这篇关于CUDA CMake 3.10 CMakeLists.txt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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