I'm building a project with CUDA code, using a recent CMake which has intrinsic CUDA support (version >= 3.8 or later if necessary).
How do I tell CMake to (also) generate PTX files for my various kernels?
Something I've tried which doesn't (?) work:
Beginning with CMake 3.9, we can define an object library to have PTXes rather than kinds of objects, using the CUDA_PTX_COMPILATION
property:
add_library(myptx OBJECT a.cu b.cu)
set_property(TARGET myptx PROPERTY CUDA_PTX_COMPILATION ON)
However, this isn't a proper solution to the problem - something is missing. Suppose we have in a.cu
:
__global__ void foo() { return; }
and in b.cu
:
__global__ void bar(int* a) { *a = 5; }
and we run cmake
and make
with the following CMakeLists.txt
:
cmake_minimum_required(VERSION 3.9)
add_library(myptx OBJECT a.cu b.cu)
set_property(TARGET myptx PROPERTY CUDA_PTX_COMPILATION ON)
no PTX files get generated and nvcc isn't run. Not sure why.