<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 16, 2015 at 9:25 AM, Irwin Zaid <span dir="ltr"><<a href="mailto:irwin.zaid@physics.ox.ac.uk" target="_blank">irwin.zaid@physics.ox.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all (and James),<br>
<br>
I just have two other quick questions about FindCUDA. Here we go!<br>
<br>
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.<br>
<br>
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?<br>
<br>
Is there a way to force FindCUDA to either treat everything as a CUDA file, or treat specific files as CUDA files?<br>
<br></blockquote><div><br></div><div>FindCUDA only looks for .cu files.  In CUDA_WRAP_SRCS:</div><div><br></div><div><div>    get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)</div><div>    if(${file} MATCHES "\\.cu$" AND NOT _is_header)</div></div><div><br></div><div>What benefit is there in keeping cuda code in .cpp files?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
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.<br>
<br></blockquote><div><br></div><div>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.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
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.<br>
<br></blockquote><div><br></div><div>I'm not sure what is going wrong.  If you do this:</div><div><br></div><div>set(CUDA_NVCC_FLAGS -arch sm_20)</div><div>add_subdirectory(tests)</div><div><br></div><div>then CUDA_NVCC_FLAGS should have "-arch;sm_20" defined in tests/CMakeLists.txt.</div><div><br></div><div>James</div></div></div></div>