gpt4 book ai didi

cmake - 如何使用现代 CMAKE(每个目标)添加多个 CUDA gencode?

转载 作者:行者123 更新时间:2023-12-04 01:47:57 26 4
gpt4 key购买 nike

我无法让现代 cmake(每个目标)设置 不止一个 CUDA gencode 标志。

CMake 示例:

target_compile_options(myHeaderLib INTERFACE                        
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_50,code=sm_50>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_52,code=sm_52>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_53,code=sm_53>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_60,code=sm_60>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_62,code=sm_62>
)

这将输出:
... -gencode arch=compute_50,code=sm_50 arch=compute_52,code=sm_52 arch=compute_53,code=sm_53

但需要的是:
... -gencode arch=compute_50,code=sm_50  -gencode arch=compute_52,code=sm_52  -gencode arch=compute_53,code=sm_53 ...

不只是 设置 ${CUDA_NVCC_FLAGS} 不是一个强大的解决方案 (这不是现代 CMAKE 应该如何完成)。

最佳答案

这是因为 CMake “ 重复数据删除 ” 编译选项的策略。
target_compile_options您创建了正确的选项列表

-gencode arch=compute_50,code=sm_50  -gencode arch=compute_52,code=sm_52 ...
但 CMake 删除了所有 -gencode除了第一个:
-gencode arch=compute_50,code=sm_50 arch=compute_52,code=sm_52 ...
bugreport关于在某些情况下需要禁用CMake“重复数据删除”,已在 3.12 version中解决通过添加 SHELL: build 。
由于 CMake 3.12 这应该工作:
target_compile_options(myHeaderLib INTERFACE
"SHELL:-gencode arch=compute_50,code=sm_50"
"SHELL:-gencode arch=compute_52,code=sm_52"
)

如何 SHELL:作品
首先,将组合选项放在双引号中可以防止 CMake 对常见选项进行“去重”:CMake 看到不同的字符串
-gencode arch=compute_50,code=sm_50
-gencode arch=compute_52,code=sm_52
并且不认为它们是重复的。
然后,一个建筑 SHELL解释 CMake 需要将给定双引号内的字符串拆分为单独的命令行选项。但是这个 split 是执行的 “重复数据删除”阶段,如此重复 -gencode来自不同 SHELL:字符串不会被删除。

关于cmake - 如何使用现代 CMAKE(每个目标)添加多个 CUDA gencode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54504253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com