MantisBT - CMake
View Issue Details
0015016CMakeModulespublic2014-07-10 20:192015-11-02 09:13
Marco Santos Souza 
James Bigler 
normalminoralways
closedfixed 
CMake 3.0 
CMake 3.3CMake 3.3 
0015016: FindCUDA creates intermediate objects in wrong place when CUDA_SEPARABLE_COMPILATION is ON.
When setting CUDA_SEPARABLE_COMPILATION to ON, if .cu files are not in the same folder of CMakeLists.txt, intermediate linkage objects are generated in the wrong folder, causing a compilation error that, on Visual Studio, looks like this:
Cannot open compiler generated file: 'project_path/CMakeFiles/project_name/Debug/project_name_intermediate_link.obj': No such file or directory.
The file attached to this report has a .cu file and a CMakeLists.txt. Generate a Visual Studio solution and try to compile the project to reproduce this bug.
CUDA, FindCUDA, linker, nvcc, visual studio
7z find_cuda_bug.7z (499) 2014-07-10 20:19
https://public.kitware.com/Bug/file/5190/*
log find_cuda_bug.log (8,203) 2014-07-15 17:22
https://public.kitware.com/Bug/file/5192/find_cuda_bug.log
Issue History
2014-07-10 20:19Marco Santos SouzaNew Issue
2014-07-10 20:19Marco Santos SouzaFile Added: find_cuda_bug.7z
2014-07-10 20:21Marco Santos SouzaTag Attached: FindCUDA
2014-07-10 20:21Marco Santos SouzaTag Attached: CUDA
2014-07-10 20:29Marco Santos SouzaTag Attached: visual studio
2014-07-10 20:32Marco Santos SouzaNote Added: 0036353
2014-07-10 20:40Marco Santos SouzaTag Attached: Windows 7
2014-07-10 20:40Marco Santos SouzaTag Detached: Windows 7
2014-07-10 20:40Marco Santos SouzaTag Attached: windows
2014-07-10 20:41Marco Santos SouzaTag Attached: linker
2014-07-10 20:41Marco Santos SouzaTag Detached: windows
2014-07-10 20:41Marco Santos SouzaTag Attached: nvcc
2014-07-14 08:44Brad KingAssigned To => James Bigler
2014-07-14 08:44Brad KingStatusnew => assigned
2014-07-15 16:53James BiglerNote Added: 0036398
2014-07-15 17:22Marco Santos SouzaFile Added: find_cuda_bug.log
2014-07-15 17:24Marco Santos SouzaNote Added: 0036399
2014-07-15 18:12James BiglerNote Added: 0036400
2014-07-15 19:30Marco Santos SouzaNote Added: 0036401
2014-07-16 12:09James BiglerNote Added: 0036402
2014-07-16 18:12James BiglerNote Edited: 0036402bug_revision_view_page.php?bugnote_id=36402#r1521
2014-09-19 15:35lingforsNote Added: 0036835
2015-04-20 13:39Wesley SmithNote Added: 0038559
2015-04-20 13:47James BiglerNote Added: 0038560
2015-04-20 14:40James BiglerNote Added: 0038561
2015-04-20 14:46Brad KingNote Added: 0038562
2015-04-20 14:46Brad KingStatusassigned => resolved
2015-04-20 14:46Brad KingResolutionopen => fixed
2015-04-20 14:46Brad KingFixed in Version => CMake 3.3
2015-04-20 14:46Brad KingTarget Version => CMake 3.3
2015-11-02 09:13Robert MaynardNote Added: 0039783
2015-11-02 09:13Robert MaynardStatusresolved => closed

Notes
(0036353)
Marco Santos Souza   
2014-07-10 20:32   
On Linux with GCC this bug seems to do not exist.
(0036398)
James Bigler   
2014-07-15 16:53   
I don't have access to windows machine for a bit.

I can also confirm this doesn't fail with a makefile build (I only have access to my mac at the moment).

Is this a working directory issue?

Can you tell what the command it is trying to run (set CUDA_VERBOSE_BUILD to TRUE/ON)?
(0036399)
Marco Santos Souza   
2014-07-15 17:24   
I've uploaded the compilation log file (find_cuda_bug.log). Please take a look. Thanks for your attention.
(0036400)
James Bigler   
2014-07-15 18:12   
My guess is that the target directory for the intermediate link file doesn't exist:

C:/Users/sms/Desktop/find_cuda_bug/find_cuda_bug/CMakeFiles/find_cuda_bug.dir/Debug/

Can you verify this?

The fix for this is to create this directory if it doesn't exist during configuration.

    get_filename_component(output_file_path "${output_file}" PATH)
    if(NOT EXISTS "${output_file_path}")
      execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_path}")
    endif()

And stick this before the if (do_obj_build_rule) code in CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS.
(0036401)
Marco Santos Souza   
2014-07-15 19:30   
The directory:
C:/Users/sms/Desktop/find_cuda_bug/find_cuda_bug/CMakeFiles/find_cuda_bug.dir/Debug/

...does not exist, indeed. What exist is:
C:/Users/sms/Desktop/find_cuda_bug/find_cuda_bug/CMakeFiles/find_cuda_bug.dir/src/Debug

Note the "src" directory in the path.

"src" is where .cu files are. CMakeLists.txt is in the parent directory.
Reinforcing that this only occurs when setting CUDA_SEPARABLE_COMPILATION to ON.

The fix you suggest make it create a directory called "$(Configuration)", literally (not the value of "Configuration" variable, as expected). I ended up with:

C:/Users/sms/Desktop/find_cuda_bug/find_cuda_bug/CMakeFiles/find_cuda_bug.dir/$(Configuration)

...and this folder is empty.
(0036402)
James Bigler   
2014-07-16 12:09   
(edited on: 2014-07-16 18:12)
Oh, yeah, I remember now why I made that part of the custom command for the CUDA_WRAP_SRCS version. Put the make_directory command in the add_custom_command (there's another one like this in CUDA_WRAP_SRCS). The problem is that $(Configuration) is a VS variable that is replaced with Debug/Release/etc. during build time. There might be some of those new generator variables $<CONFIG> or something like that which would be more appropriate, but moving the make_directory command into the add_custom_command would be consistent with the other one and should work.

(0036835)
lingfors   
2014-09-19 15:35   
I added the following code:

    get_filename_component(output_file_path "${output_file}" PATH)
    add_custom_command(
      TARGET ${cuda_target}
      PRE_LINK
      COMMAND ${CMAKE_COMMAND} -E make_directory ${output_file_path}
    )

before

if (do_obj_build_rule)

in the CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS function, and I got my project to successfully compile.
(0038559)
Wesley Smith   
2015-04-20 13:39   
I'm still getting the same bug in the latest CMAKE (3.2.2). If the proposed fix above works, could it please be committed for the next release? There hasn't been any activity here for 9 months. If the fix exists, it would be nice to have.
(0038560)
James Bigler   
2015-04-20 13:47   
I have a fix I'm ready to push to next. I forgot about this bug. I'll post here when I get it pushed to next.
(0038561)
James Bigler   
2015-04-20 14:40   
Fetching upstream next
Merge topic 'FindCUDA.cmake/Fix-MakeDirDuringSeparableCompilation' into next

e88217ce Fix Bug 0015016 - Create output dir while compiling intermediate link file.
(0038562)
Brad King   
2015-04-20 14:46   
Re 0015016:0038561: Thanks. I've revised the commit message:

 FindCUDA: Create output dir while compiling intermediate link file
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0ed22502 [^]
(0039783)
Robert Maynard   
2015-11-02 09:13   
Closing resolved issues that have not been updated in more than 4 months.