[CMake] Passing -x=cu to FindCUDA, and specifying libraries to nvcc
James Bigler
jamesbigler at gmail.com
Fri Jan 16 12:08:37 EST 2015
On Fri, Jan 16, 2015 at 9:25 AM, Irwin Zaid <irwin.zaid at physics.ox.ac.uk>
wrote:
> Hi all (and James),
>
> I just have two other quick questions about FindCUDA. Here we go!
>
> 1) I have a project that tries to keep all its CUDA code in .cpp files.
> I'm currently making this work with a lot of dummy .cu files that simply
> include the .cpp, but I'd like to get rid of these.
>
> nvcc does support a -x flag for specifying whether it should treat files
> as .c, .cpp, or .cu. However, FindCUDA seems unable to handle this and
> things break immediately. Is it because FindCUDA uses the file extension to
> determine what action to take?
>
> Is there a way to force FindCUDA to either treat everything as a CUDA
> file, or treat specific files as CUDA files?
>
>
FindCUDA only looks for .cu files. In CUDA_WRAP_SRCS:
get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)
if(${file} MATCHES "\\.cu$" AND NOT _is_header)
What benefit is there in keeping cuda code in .cpp files?
> 2) Is there a way to tell FindCUDA that a library needs to be linked in
> nvcc? What I have is a library built with nvcc that should go through the
> device linker. If I just pass it to target_link_libraries, then nvcc
> doesn't get it and only the host linker does.
>
>
You can't use nvcc to link. CMake makes this difficult, and in VS it is
impossible. Instead what I've done for device linking is to create an
intermediate object file that is the product of linking. FindCUDA supports
separable compilation for a single executable module, but not for multiple
ones. I had an example laying around for doing this, but I'm not sure
where it ended up. Basically you add a prelink custom command that takes
the objects and libraries that contain device code for your target
executable module and link them using nvcc producing another object file
that is then linked into the final executable module using the host linker.
Also, I'm in a subproject (think of a test program), and I find that using
> NVCC_FLAGS doesn't get it there either. What has worked is simply passing
> it as an option to cuda_add_executable, but that feels a little raw.
>
>
I'm not sure what is going wrong. If you do this:
set(CUDA_NVCC_FLAGS -arch sm_20)
add_subdirectory(tests)
then CUDA_NVCC_FLAGS should have "-arch;sm_20" defined in
tests/CMakeLists.txt.
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150116/73ce4976/attachment.html>
More information about the CMake
mailing list