How do I change the output filename of cuda_compil

2019-06-22 00:09发布

问题:

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?

回答1:

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

Here are two alternate ways add CUDA compilation to your project

  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.


标签: cuda cmake