[CMake] Setting compile defs with: Cuda, add_subdirectory, and set_target_properties (COMPILE_DEFINITIONS)

Brian Davis bitminer at gmail.com
Mon Aug 16 18:21:47 EDT 2010


>> I just noticed your email in my FindCUDA filter from the CMake list.  I'm
not sure why it didn't show up sooner.

No worries. I let this thread die for a while while I worked on other
things.  I was back recently trying to fix this issue as I now want to
compare the cpu/gpu recons separately.  I appreciate the help.

--snip --
2. Have you tried to disable this flag?
Yes I have and it turns out I must in order for me to get my .cu file to be
compiled with correct -DDefines.

I don't believe this is true.  ....
--end snip

I tried it enable/disabling the flag again just to be sure I was seeing
correct output.


with CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE ON (default - with my set line
below commented out) and using the following:

-snip-
    # see
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#module:FindCUDA and
    # http://marc.info/?l=cmake&m=127920291014527&w=2
    # What this ends up doing is passing all defines to a single target i.e.
both GPU_RECON=yes and CPU_RECON=yes
    # which is not what is desired.
    set( CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF )

    if(DEFINED ARG_CU_SOURCES )
        message("\tARG_CU_SOURCES is defined as = ${ARG_CU_SOURCES}" )
        CUDA_ADD_LIBRARY( ${LIB_NAME} SHARED ${MATLAB_CUDA_FILES}
            OPTIONS
                DEBUG ${DEFINITIONS_STRING}
                RELEASE ${DEFINITIONS_STRING}
                MINSIZEREL ${DEFINITIONS_STRING}
                RELWITHDEBINFO ${DEFINITIONS_STRING}
        )
    else()
         message("\tARG_CU_SOURCES is not defined" )
         message("\tdefining library ${LIB_NAME} with sources
${ARG_CPP_SOURCES}")
        ADD_LIBRARY( ${LIB_NAME} SHARED ${ARG_CPP_SOURCES} )
    endif()
--end snip--

i get

--snip--
2>C:/CUDA/bin64/nvcc.exe
C:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/gpuPMatrixRecon.cu
-arch sm_11 --ptxas-options=-v -maxrregcount=32 -Xcompiler
/EHsc,/W3,/nologo,/Od,/Zi,/MTd -DCUDADeviceProperties_DLLExport=yes
-DGPU_RECON=yes -m64 -DgpuReconPlugin_EXPORTS -ccbin "c:/Program Files
(x86)/Microsoft Visual Studio 9.0/VC/bin" -DNVCC -M -o
C:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/dvip4-Win64/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/CMakeFiles/gpuReconPlugin_generated_gpuPMatrixRecon.cu.obj.NVCC-depend
-IC:/CUDA/include
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/cpp/lib/3rdParty/Win/boost-cmake-1_41_0
"-IC:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK/C/common/inc"
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/Windows-6.0/install/include/vtk-5.6
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/Windows-6.0/install/include/VTKEdge
"-IC:/Program Files/MATLAB/R2010a/extern/include"
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/.
-IC:/CUDA/include
2>gpuPMatrixRecon.cu
--end snip--


with it off (set line uncommented in) I get

--snip--
C:/CUDA/bin64/nvcc.exe
C:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/gpuPMatrixRecon.cu
-arch sm_11 --ptxas-options=-v -maxrregcount=32 -Xcompiler
/EHsc,/W3,/nologo,/Od,/Zi,/MTd -DCUDADeviceProperties_DLLExport=yes
-DCPU_RECON=yes -m64 -DcpuReconPlugin_EXPORTS -ccbin "c:/Program Files
(x86)/Microsoft Visual Studio 9.0/VC/bin" -DNVCC -c -o
C:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/dvip4-Win64/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/Debug/cpuReconPlugin_generated_gpuPMatrixRecon.cu.obj
-IC:/CUDA/include
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/cpp/lib/3rdParty/Win/boost-cmake-1_41_0
"-IC:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK/C/common/inc"
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/Windows-6.0/install/include/vtk-5.6
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/Windows-6.0/install/include/VTKEdge
"-IC:/Program Files/MATLAB/R2010a/extern/include"
-IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/.
-IC:/CUDA/include
2>gpuPMatrixRecon.cu
--end snip--

Which is what (I think) I desire... unless there is something else I am not
aware of.

I am reporting what I am seeing.  I have modified FindCUDA, but only with
messages so I can see what it is doing.  I have not changed the
functionality of FindCUDA at all.

--snip--
So what happens when you add the same file to more than one project in the
same directory is this (more or less).

project1
  -- myfile.cu: had rule to build project1_myfile.cu.obj from myfile.cu

project2
  CMake Rules
    -- cmake_build_..._myfile.rule: has rule to build project2_myfile.cu.obj
from myfile.cu
  -- myfile.cu: has rule to build project1_myfile.cu.obj from myfile.cu

The problem you have when building in parallel is there are two build
commands for project1_myfile.cu.obj.  If you compile project1 and project2
at the same time, you can get a race condition for project1_myfile.cu.obj.
If you build them one at a time, project2 will run the cmake....rule file
that compiles project2_myfile.cu.obj then try to compile myfile.cu's rule,
but see that it is done (from project1).  At any rate, I'm not sure if this
is ultimately related to your problem or the other issue you described were
at the root of the problem.
--end snip--

I am not parallel building so I do not think it is a problem.  As far as the
race to build project1_myfile.cu.obj I do not appear to be experiencing this
(as I am not parallel building).  I don't think I am experiencing the linear
build issue as it appears that if I select each lib which has the .cu file
and select rebuild... that each lib gets rebuilt as expected.  I did look
for this issue based on the CMake FindCUDA documentation.  This may be
related to the following output goop at msvc compiler window:

--snip--
Generating temporary cmake readable file:
C:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/dvip4-Win64/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/CMakeFiles/gpuReconPlugin_generated_gpuPMatrixRecon.cu.obj.depend.tmp
--end snip--

Note the prefix gpuReconPlugin and tmp possibly referring to a temporary
file with the .obj sandwiched in between.  It's a Cuda, CMake, obj
sandwich.  Mmmmm add pickles and a little mayo and it's tasty.  I should
coin this term and open up a Techno Deli :-)

--snip--
Incidentally, you can use the same file in different projects if they are in
different directories (i.e. CMake directory scopes) without causing this to
happen.
--end snip--

Yes.... and my reply to this is a restatement of above.

--snip--
Have I mentioned to anyone lately why I can't understand CMake's (poor)
design choice in correlating directory structure to target build
specification. It would appear to me from this (if unmodified) that I must
create a new directory in order to get CMake to build 2 dlls in the same
directory based on the same source using different compiler defined.   I
have reached a state of boondogglement.
--end snip--

Why was this a design decision on CMake's part?

--snip--
Why are you specifying the same option for every type of build?  Any
arguments after OPTIONS and before DEBUG, RELEASE, etc. will be applied to
all build types.
--end snip--

I read through the FindCUDA source and thought this was how I should specify
this.  Output of my messages in FindCUDA supported the use of this syntax:

--snip--
_sources = _cuda_wrap_sources
_cmake_options = _cuda_wrap_cmake_options
_options = _cuda_wrap_options
_found_config = _DEBUG
_found_config = _RELEASE
_found_config = _MINSIZEREL
_found_config = _RELWITHDEBINFO
CUDA_WRAP_OPTION_NVCC_FLAGS =
CUDA_HOST_FLAGS = set(CMAKE_HOST_FLAGS )
CUDA_NVCC_FLAGS =
CUDA_NVCC_FLAGS_CONFIG = # Build specific configuration flags
set(CUDA_NVCC_FLAGS_DEBUG
"-arch;sm_11;--ptxas-options=-v;-maxrregcount=32;-Xcompiler;/EHsc,/W3,/nologo,/Od,/Zi,/MTd;;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes")
set(CUDA_NVCC_FLAGS_RELEASE
";;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes")
set(CUDA_NVCC_FLAGS_MINSIZEREL
";;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes")
set(CUDA_NVCC_FLAGS_RELWITHDEBINFO
";;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes")
CUDA_NVCC_DEFINITIONS = CUDA_NVCC_DEFINITIONS-NOTFOUND
nvcc_flags = -m64
nvcc_flags = -m64;-DgpuReconPlugin_EXPORTS
CUDA _options  =
DEBUG;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes;RELEASE;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes;MINSIZEREL;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes;RELWITHDEBINFO;-DCUDADeviceProperties_DLLExport=yes;-DGPU_RECON=yes

CUDA _cmake_options  = SHARED

--end snip--

note the set(CUDA_NVCC_FLAGS_.... ...).  Debug was being set so I thought
this was correct.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100816/273571a8/attachment.htm>


More information about the CMake mailing list