如何将标志传递给CMAKE中的nvcc编译器 [英] Howto pass flag to nvcc compiler in CMAKE

查看:345
本文介绍了如何将标志传递给CMAKE中的nvcc编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Cmake 中有一个C项目,其中嵌入了 cuda 内核模块

I have a C project in Cmake in which I have embedded cuda kernel module.

我只想将-ptxas-options = -v 传递给 nvcc 以便查看
每个线程的寄存器使用次数
每个块的共享内存使用情况

I want to pass --ptxas-options=-v only to nvcc in-order to view Number of registers usage per thread and shared Memory usage per block.

通过搜索如何将标志传递给 Cmake 中的 nvcc ,我遇到了一个解决方案

By searching on howto pass flags to nvcc in Cmake, I came across a solution

add_compile_options(myprog
    PRIVATE
    $<$<COMPILE_LANGUAGE:C>:-Wall>
    $<$<COMPILE_LANGUAGE:CUDA>:-arch=sm_20 -ptxas-options=-v>
)

但这没有显示上述属性。我认为这些标志未正确传递给 nvcc

but this didn't show me the above properties. I think these flags aren't passed to nvcc properly.

如何传递 --ptxas-options = -v 到我的 nvcc 编译器?

How can I pass --ptxas-options=-v to my nvcc compiler ?

推荐答案

仅在目标上设置CUDA标志的正确方法是

The proper way to set CUDA flags only on a target is

target_compile_options(<my_target> PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:my_cuda_option>) 

这将通过生成器表达式设置仅针对以CUDA语言编译的文件的选项。

This will set the option, via the generator expression, only for files which are compiled for the CUDA language.

根据其他答案的建议,使用 CMAKE_CUDA_FLAGS 设置所有目标的全局属性,这可能是也可能不是正确的方法取决于用例。

Using CMAKE_CUDA_FLAGS as suggested by the other answer sets a global property for all targets, which might or might not be the right approach depending on the use-case.

这篇关于如何将标志传递给CMAKE中的nvcc编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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