[CMake] FindCUDA ignores project dependencies when separable compilation is on

James Bigler jamesbigler at gmail.com
Tue Jan 6 18:50:33 EST 2015


I've pushed a change into 'stage' [1] that I hope to get into 'next'
(something isn't working with my ssh authentication).

James

[1] commit b4e54f9b8c748f78d16e9da055a7e0436d7654ef
Author: James Bigler <@>
Date:   Tue Jan 6 16:28:05 2015 -0700

    FindCUDA: Add relevant CMAKE_{C,CXX}_FLAGS for separable compilation

    Previously only the CMAKE_{C,CXX}_FLAGS_<CONFIG> flags were inspected
    for relevant flags when compiling the intermediate link file.  We need
    to also consider the configuration agnostic flags, CMAKE_{C,CXX}_FLAGS
    as well.

On Tue, Jan 6, 2015 at 4:29 PM, Irwin Zaid <irwin.zaid at physics.ox.ac.uk>
wrote:

> Okay, so to conclude:
>
> Should we make a PR to include your patched code so CMAKE_CXX_FLAGS just
> works? I think this makes sense, as I would never have thought to do the
> DEBUG / RELEASE stuff. I can do the PR, unless you want to.
>
> And, of course, thanks for all your help!
>
> Irwin
>
> James Bigler wrote:
>
>> Right, if you don't specify the CMAKE_BUILD_TYPE you are only getting the
>> CMAKE_CXX_FLAGS and none of the build type specific flags such as
>> CMAKE_CXX_FLAGS_DEBUG.
>>
>> There is still the issue that I wasn't bringing in the CMAKE_CXX_FLAGS
>> (which is why my patch helped).
>>
>> James
>>
>> On Tue, Jan 6, 2015 at 1:32 PM, Irwin Zaid <irwin.zaid at physics.ox.ac.uk
>> <mailto:irwin.zaid at physics.ox.ac.uk>> wrote:
>>
>>     Wait, hold on. The -fPIC does get passed to everything if I set
>>     the build mode to Debug by passing -DCMAKE_BUILD_TYPE=Debug to
>>     CMake. Is that what I should be doing? (Sorry about that, if yes.)
>>
>>     If that's the case, what is the correct way to get -fPIC passed to
>>     the intermediate linking? Am I meant to always build in Debug mode
>>     just for that?
>>
>>     Irwin
>>
>>     Irwin Zaid wrote:
>>
>>         I just double-checked. The -fPIC is definitely there for each
>>         individual
>>         object file, but not for the *_intermediate_link.o.
>>
>>         Irwin
>>
>>         James Bigler wrote:
>>
>>
>>             James
>>
>>                 On Jan 6, 2015, at 11:29 AM, Irwin
>>                 Zaid<irwin.zaid at physics.ox.ac.__uk
>>                 <mailto:irwin.zaid at physics.ox.ac.uk>> wrote:
>>
>>                 Okay, so I've gone and put the messages into
>>                 FindCUDA.cmake. I specifically put them right before
>>                 and after the foreach() in
>>                 CUDA_LINK_SEPARARABLE___COMPILATION_OBJECTS. The
>>                 output is the following.
>>
>>                 Is
>>                 "$<$<CONFIG:Debug>:-Xcompiler>
>> __;$<$<CONFIG:Debug>:-fPIC>"
>>                 supposed to be that way? That looks weird.
>>
>>             Yeah. That looks right. It means the argument will only be
>>             run when the build configuration matches DEBUG. This is
>>             less exciting for Makefiles builds since there is only one
>>             configuration preset at a time, but for things like Visual
>>             Studio where you have multiple build configs from a single
>>             CMake configure this makes a custom command for each
>>             without having to rely on scripts to dispatch the correct
>>             command (that's how the rest of FindCUDA works by the way).
>>
>>             As far as the rest of these, I'm concerned the fPIC flag
>>             comes and goes. Perhaps something is modifying the flags.
>>             Do the commands with fPIC actually get run with fPIC (use
>>             make VERBOSE=1)?
>>
>>                 --
>>
>>                 going to run COMMAND /usr/local/cuda/bin/nvcc
>>                 -m64;-ccbin;"/usr/bin/cc" -dlink
>>                 /home/irwin/Repositories/__libdynd/build/CMakeFiles/__
>> libdynd.dir/src/dynd/kernels/.__/libdynd_generated_
>> assignment___kernels.cu.o;/home/irwin/__Repositories/
>> libdynd/build/__CMakeFiles/libdynd.dir/src/__dynd/func/./
>> libdynd_generated___arithmetic.cu.o;/home/irwin/__
>> Repositories/libdynd/build/__CMakeFiles/libdynd.dir/src/__
>> dynd/func/./libdynd_generated___elwise.cu.o;/home/irwin/__
>> Repositories/libdynd/build/__CMakeFiles/libdynd.dir/src/__dynd/kernels/./
>> libdynd___generated_ckernel_builder.cu
>>                 <http://generated_ckernel_builder.cu>.__o;/home/irwin/
>> Repositories/__libdynd/build/CMakeFiles/__libdynd.dir/src/
>> dynd/types/./__libdynd_generated_dynd___complex.cu.o;
>> /home/irwin/__Repositories/libdynd/build/__CMakeFiles/
>> libdynd.dir/src/__dynd/types/./libdynd___generated_dynd_
>> float16.cu.o;/__home/irwin/Repositories/__libdynd/build/
>> CMakeFiles/__libdynd.dir/src/dynd/types/./__libdynd_
>> generated_dynd___float128.cu.o;/home/irwin/__Repositories/
>> libdynd/build/__CMakeFiles/libdynd.dir/src/__dynd/types/.
>> /libdynd___generated_d
>>
>>     y
>>
>>         nd_int128.cu.o;/home/irwin/__Repositories/libdynd/build/__
>> CMakeFiles/libdynd.dir/src/d
>>
>>                 ynd/types/./libdynd_generated___dynd_uint128.cu.o -o
>>                 /home/irwin/Repositories/__libdynd/build/CMakeFiles/__
>> libdynd.dir/./libdynd___intermediate_link.o
>>
>>                 going to run COMMAND /usr/local/cuda/bin/nvcc
>>                 -m64;-ccbin;"/usr/bin/cc" -dlink
>>                 /home/irwin/Repositories/__libdynd/build/CMakeFiles/__
>> libdynd.dir/src/dynd/kernels/.__/libdynd_generated_
>> assignment___kernels.cu.o;/home/irwin/__Repositories/
>> libdynd/build/__CMakeFiles/libdynd.dir/src/__dynd/func/./
>> libdynd_generated___arithmetic.cu.o;/home/irwin/__
>> Repositories/libdynd/build/__CMakeFiles/libdynd.dir/src/__
>> dynd/func/./libdynd_generated___elwise.cu.o;/home/irwin/__
>> Repositories/libdynd/build/__CMakeFiles/libdynd.dir/src/__dynd/kernels/./
>> libdynd___generated_ckernel_builder.cu
>>                 <http://generated_ckernel_builder.cu>.__o;/home/irwin/
>> Repositories/__libdynd/build/CMakeFiles/__libdynd.dir/src/
>> dynd/types/./__libdynd_generated_dynd___complex.cu.o;
>> /home/irwin/__Repositories/libdynd/build/__CMakeFiles/
>> libdynd.dir/src/__dynd/types/./libdynd___generated_dynd_
>> float16.cu.o;/__home/irwin/Repositories/__libdynd/build/
>> CMakeFiles/__libdynd.dir/src/dynd/types/./__libdynd_
>> generated_dynd___float128.cu.o;/home/irwin/__Repositories/
>> libdynd/build/__CMakeFiles/libdynd.dir/src/__dynd/types/.
>> /libdynd___generated_d
>>
>>     y
>>
>>         nd_int128.cu.o;/home/irwin/__Repositories/libdynd/build/__
>> CMakeFiles/libdynd.dir/src/d
>>
>>                 ynd/types/./libdynd_generated___dynd_uint128.cu.o -o
>>                 /home/irwin/Repositories/__libdynd/build/CMakeFiles/__
>> libdynd.dir/./libdynd___intermediate_link.o
>>                 $<$<CONFIG:Debug>:-Xcompiler>;__$<$<CONFIG:Debug>:-fPIC>
>>                 going to run COMMAND /usr/local/cuda/bin/nvcc
>>                 -m64;-ccbin;"/usr/bin/cc" -dlink
>>                 /home/irwin/Repositories/__libdynd/build/tests/__
>> CMakeFiles/test_libdynd.dir/__func/./test_libdynd_generated_
>> __test_apply.cu.o;/home/irwin/__Repositories/libdynd/build/_
>> _tests/CMakeFiles/test_libdynd.__dir/func/./test_
>> libdynd___generated_test_lift_arrfunc.__cu.o
>>                 -o
>>                 /home/irwin/Repositories/__libdynd/build/tests/__
>> CMakeFiles/test_libdynd.dir/./__test_libdynd_intermediate___link.o
>>
>>                 going to run COMMAND /usr/local/cuda/bin/nvcc
>>                 -m64;-ccbin;"/usr/bin/cc" -dlink
>>                 /home/irwin/Repositories/__libdynd/build/tests/__
>> CMakeFiles/test_libdynd.dir/__func/./test_libdynd_generated_
>> __test_apply.cu.o;/home/irwin/__Repositories/libdynd/build/_
>> _tests/CMakeFiles/test_libdynd.__dir/func/./test_
>> libdynd___generated_test_lift_arrfunc.__cu.o
>>                 -o
>>                 /home/irwin/Repositories/__libdynd/build/tests/__
>> CMakeFiles/test_libdynd.dir/./__test_libdynd_intermediate___link.o
>>                 $<$<CONFIG:Debug>:-Xcompiler>;__$<$<CONFIG:Debug>:-fPIC>
>>
>>                 James Bigler wrote:
>>
>>                     I meant putting messages into FindCUDA.cmake itself.
>>
>>                     Only certain flags are propagated for the
>>                     intermediate link file
>>                     compilation, because I've had a lot of trouble
>>                     over the years for
>>                     propagating all the host flags. This set of flags
>>                     is filtered by the
>>                     function _cuda_get_important_host___flags. Right
>>                     now only the
>>                     CMAKE_CXX_FLAGS_*CONFIG* are being processed. None
>>                     of the flags in the
>>                     configuration free variable are passed. That was
>>                     the "patch" I wanted
>>                     you to try. Why -fPIC in the configuration
>>                     specific CMAKE_CXX_FLAGS
>>                     wasn't working, I'm not sure. The code is there to
>>                     do it.
>>
>>                     On Tue, Jan 6, 2015 at 10:05 AM, Irwin
>>                     Zaid<irwin.zaid at physics.ox.ac.__uk
>>                     <mailto:irwin.zaid at physics.ox.ac.uk>
>>                     <mailto:irwin.zaid at physics.ox.__ac.uk
>>                     <mailto:irwin.zaid at physics.ox.ac.uk>>> wrote:
>>
>>                     Right, when I modify FindCUDA.cmake as you
>>                     describe everything
>>                     works. So that's good.
>>
>>                     Without doing that, I still don't see
>>                     CMAKE_CXX_FLAGS_DEBUG
>>                     propagating its flags to the intermediate link
>>                     file. Did you mean to
>>                     put message commands into
>>                     CUDA_LINK_SEPARABLE_____COMPILATION_OBJECTS
>>                     itself? When I put them into my main
>>                     CMakeLists.txt, nothing is
>>                     printed for ${nvcc_flags} or the other variables.
>>
>>                     James Bigler wrote:
>>
>>                     On Tue, Jan 6, 2015 at 8:54 AM, Irwin Zaid
>>                     <irwin.zaid at physics.ox.ac.uk
>>                     <mailto:irwin.zaid at physics.ox.ac.uk>
>>                     <mailto:irwin.zaid at physics.ox.__ac.uk
>>                     <mailto:irwin.zaid at physics.ox.ac.uk>>
>>                     <mailto:irwin.zaid at physics.ox.
>>                     <mailto:irwin.zaid at physics.ox.>____ac.uk
>>                     <http://ac.uk>
>>                     <mailto:irwin.zaid at physics.ox.__ac.uk
>>                     <mailto:irwin.zaid at physics.ox.ac.uk>>>> wrote:
>>
>>                     Okay, an update on this.
>>
>>                     2) This is trickier and, unfortunately, still not
>>                     working. We are
>>                     already adding -fPIC to CMAKE_CXX_FLAGS, should
>>                     that not be
>>                     enough? I also tried adding it to both
>>                     CMAKE_CXX_FLAGS_DEBUG and
>>                     CMAKE_CXX_FLAGS_RELEASE, with no effect.
>>
>>                     Looking into FindCUDA.CMake at
>>                     CUDA_LINK_SEPARABLE_______COMPILATION_OBJECTS, I
>>                     find code very
>>                     similar to what you are describing. Are you saying
>>                     that in
>>                     addition to what is below, we need to add what you
>>                     proposed? This
>>                     is what I see.
>>
>>                     --
>>
>>
>>                     It can be put here (before this foreach).
>>
>>                     foreach(config ${CUDA_configuration_types})
>>                     string(TOUPPER ${config} config_upper)
>>                     # Add config specific flags
>>                     foreach(f ${CUDA_NVCC_FLAGS_${config_______upper}})
>>                     list(APPEND config_specific_flags
>>                     $<$<CONFIG:${config}>:${f}>)
>>                     endforeach()
>>                     set(important_host_flags)
>>                     _cuda_get_important_host______
>> _flags(important_host_flags
>>                     ${CMAKE_${CUDA_C_OR_CXX}______
>> _FLAGS_${config_upper}})
>>                     foreach(f ${important_host_flags})
>>                     list(APPEND flags
>>                     $<$<CONFIG:${config}>:-______Xcompiler>
>>                     $<$<CONFIG:${config}>:${f}>)
>>                     endforeach()
>>                     endforeach()
>>
>>
>>                     Or it can be put here (or after the foreach).
>>
>>                     I'm concerned that the flag didn't show up after
>>                     adding it to
>>                     the _DEBUG or _RELEASE variants. If you could add
>>                     a few message
>>                     commands around that might help see what is going
>>                     on. The flag
>>                     needs to be propagated.
>>
>>                     You could sprinkle a few commands like this:
>>                     message("going to run COMMAND ${CUDA_NVCC_EXECUTABLE}
>>                     ${nvcc_flags} -dlink ${object_files} -o ${output_file}
>>                     ${flags}")
>>
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150106/29c359f6/attachment-0001.html>


More information about the CMake mailing list