Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the output filename of cuda_compile_ptx in CMake?

Tags:

cuda

cmake

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?

like image 837
harrism Avatar asked Apr 13 '12 05:04

harrism


1 Answers

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.
like image 93
ds-bos-msk Avatar answered Nov 19 '22 03:11

ds-bos-msk