如何在CMake中更改cuda_compile_ptx的输出文件名? [英] How do I change the output filename of cuda_compile_ptx in CMake?

查看:911
本文介绍了如何在CMake中更改cuda_compile_ptx的输出文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CMAKE with FindCUDA中,给定一个输入文件 filename.cu cuda_compile_ptx 命令生成输出文件form cuda_compile_ptx_generated_filename.cu.ptx ,但我需要输出文件名为 filename.ptx

In CMAKE with FindCUDA, given an input file filename.cu, the cuda_compile_ptx command generates output filenames of the form cuda_compile_ptx_generated_filename.cu.ptx, but I need the output filenames to be of the form filename.ptx.

有没有简单的方法使这项工作?

Is there a simple way to make this work?

推荐答案

理想情况下,您应该能够指定 -o< outputName> 。然而,问题是 CUDA_COMPILE_PTX 宏实际上覆盖了 -o 选项与 cuda_compile_ptx_generated _ $ {文件名.ptx

Ideally you should be able to specify -o <outputName>. However the issue is that the CUDA_COMPILE_PTX macro actually overrides the -o option with cuda_compile_ptx_generated_${filename}.ptx

以下是向项目中添加CUDA编译的两种备选方法

Here are two alternate ways add CUDA compilation to your project


  1. 您仍然可以使用 CUDA_COMPILE_PTX ,但通过使用 add_custom_command add_custom_command(OUTPUT $ {CMAKE_BINARY_DIR} /my_ptx.ptx COMMAND $ {CMAKE_COMMAND} -E copy $ {cuda_ptx_files} $ {CMAKE_BINARY_DIR} /my_ptx.ptx DEPENDS $ {cuda_ptx_files})并使用 add_custom_target

  2. 中的 $ {CMAKE_BINARY_DIR} /my_ptx.ptx 有更好的选择编译CUDA PTX与CMake。宏的一个非常好的例子是: https: //github.com/nvpro-samples/shared_sources/blob/master/cmake/private/FindCuda.cmake 。有关如何使用此宏的示例,请访问以下网址: https:// github.com/nvpro-samples/gl_cuda_interop_pingpong_st/blob/master/CMakeLists.txt

  1. You can still use CUDA_COMPILE_PTX but work around the issue by renaming it with add_custom_command: add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/my_ptx.ptx COMMAND ${CMAKE_COMMAND} -E copy ${cuda_ptx_files} ${CMAKE_BINARY_DIR}/my_ptx.ptx DEPENDS ${cuda_ptx_files}) and use ${CMAKE_BINARY_DIR}/my_ptx.ptx in add_custom_target
  2. There are better alternatives for compiling CUDA PTXs with CMake. One very good example of a macro do to this: https://github.com/nvpro-samples/shared_sources/blob/master/cmake/private/FindCuda.cmake. An example of how to use this macro can be found here: https://github.com/nvpro-samples/gl_cuda_interop_pingpong_st/blob/master/CMakeLists.txt.

这篇关于如何在CMake中更改cuda_compile_ptx的输出文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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