[CMake] CUDA, CMAKE, and an attempt to build nbody

James Bigler jamesbigler at gmail.com
Tue Jan 26 18:21:02 EST 2010


First off, you can't set nvcc flags via the SET_PROPERTIES function, nor
should you set host compiled code properties here either, because these
properties will only work for the CXX code added to the project and not the
host compiled code nvcc generates.

If you want to do what you want you need to set the CUDA_NVCC_FLAGS_DEBUG or
use the OPTION DEBUG flag to the CUDA_ADD_EXECUTABLE.

cuda_add_executable( nbody
  mycode.cu
  OPTIONS -arch sm_10 -maxregcount=32
  DEBUG -Xcompiler /EHsc,/W3,/nologo,/Od,/Zi
  )

Second, try to keep straight what flags are for nvcc and what are for the
host code.  Host code flags should use -Xcompiler flag,flag,flag,flag.

Third, NVCC flags are lists not strings like the other CXX flags (this was a
conscious choice, because the CXX flags are difficult to deal with as
strings).  "-arch sm_10" will be one flag instead of two.  If you need to
use quotes, use ';' to separate arguments. "-arch;sm_10".

You should also set the definition before calling cuda_add_executable
(add_definitions(-D_HOWZ_ABOUT_THIS_DEF)) or add -D_HOWZ_ABOUT_THIS_DEF to
the OPTIONS or CUDA_NVCC_FLAGS.

The -m64 flag is added when CUDA_64_BIT_DEVICE_CODE is true.  This get's its
default from CMAKE_SIZEOF_VOIDP which defines the bitness of the regular
host code compiled from cxx files, but can be overridden in the CMake GUI or
via something like this:

set(CUDA_64_BIT_DEVICE_CODE OFF)
cuda_add_executable(...)

You typically want the bitness to match that of the host code unless you are
compiling to PTX.

James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100126/d2208710/attachment.htm>


More information about the CMake mailing list