<div class="gmail_quote">On Mon, Aug 16, 2010 at 2:17 PM, Brian Davis <span dir="ltr">&lt;<a href="mailto:bitminer@gmail.com">bitminer@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

James I was going to cc you on my latest findings.  Thanks for giving me a &quot;way out&quot; with out having to patch the FindCUDA.  I recently came to the same conclusion as your recent post.<br><br></blockquote><div>
<br>
I just noticed your email in my FindCUDA filter from the CMake list.  I&#39;m not sure why it didn&#39;t show up sooner.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

1. CUDA_ATTACH_VS_BUILD_RULE_TO_<div><div class="im">
CUDA_FILE can really only cause problems with parallel builds.  Are you performing parallel builds?<br><br></div>No I am not<div class="im"><br><br>2. Have you tried to disable this flag? </div></div><br>Yes I have and it turns out I must in order for me to get my .cu file to be compiled with correct -DDefines.  <br>


<br></blockquote><div><br>I don&#39;t believe this is true.  So what happens when you add the same file to more than one project in the same directory is this (more or less).<br><br>project1<br>  -- <a href="http://myfile.cu">myfile.cu</a>: had rule to build project1_myfile.cu.obj from <a href="http://myfile.cu">myfile.cu</a><br>

<br>project2<br>  CMake Rules<br>    -- cmake_build_..._myfile.rule: has rule to build project2_myfile.cu.obj from <a href="http://myfile.cu">myfile.cu</a><br>  -- <a href="http://myfile.cu">myfile.cu</a>: has rule to build project1_myfile.cu.obj from <a href="http://myfile.cu">myfile.cu</a><br>

<br>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 <a href="http://myfile.cu">myfile.cu</a>&#39;s rule, but see that it is done (from project1).  At any rate, I&#39;m not sure if this is ultimately related to your problem or the other issue you described were at the root of the problem.<br>

<br>Incidentily, 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.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

I also did as you suggested above though I wish I would have looked at my email sooner as I ended up coming to the same conclusion.<br><br>first it appears I must remove<br>--snip--<div class="im"><br>        foreach( DEFINE_STR ${ARG_DEFINES} )<br>


            message( &quot;DEFINE_STR = ${DEFINE_STR}&quot; )<br></div><div class="im">            add_definitions( -D${DEFINE_STR} )<br>        endforeach()<br></div>--end snip--<br><br>and change as you stated:<br><br>

--snip--<div class="im"><br>        CUDA_ADD_LIBRARY( ${LIB_NAME} SHARED ${MATLAB_CUDA_FILES} <span style="background-color: rgb(255, 255, 102);">OPTIONS ${my_nvcc_flags}</span> )<br></div>
--end snip<br><br>to <br><br>-snip--    <br><div class="im"><br>if(DEFINED ARG_CU_SOURCES )<br></div>        message(&quot;\tARG_CU_SOURCES is defined as = ${ARG_CU_SOURCES}&quot; )<div class="im"><br>        CUDA_ADD_LIBRARY( ${LIB_NAME} SHARED ${MATLAB_CUDA_FILES} <br>


            OPTIONS <br></div>                DEBUG ${DEFINITIONS_STRING}<br>                RELEASE ${DEFINITIONS_STRING}<br>                MINSIZEREL ${DEFINITIONS_STRING}<br>                RELWITHDEBINFO ${DEFINITIONS_STRING}<br>


        )<br>    else()<br>--end snip--<br><br></blockquote><div><br>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.<br>

 <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">as <br><br>--snip from FindCuda.cmake--<br>macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix)<br>

  set( _found_config )<br>  foreach(arg ${ARGN})<br>    # Determine if we are dealing with a perconfiguration flag<br>
    foreach(config ${CUDA_configuration_types})<br>      string(TOUPPER ${config} config_upper)<br>      if (arg STREQUAL &quot;${config_upper}&quot;)<br>        set( _found_config _${arg})<br>message( &quot;_found_config = ${_found_config}&quot; )       <br>


        # Set arg to nothing to keep it from being processed further<br>        set( arg )<br>      endif()<br>    endforeach()<br><br>    if ( arg )<br>      list(APPEND ${_option_prefix}${_found_config} &quot;${arg}&quot;)<br>


    endif()<br>  endforeach()<br>endmacro()<br>--end snip--<br><br>searches for DEBUG, RELEASE, ... etc to append to <br><br>which give me the MSVS output I am looking for.<br><br>--snip-- <br>2&gt;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_13 --ptxas-options=-v -maxrregcount=32 -Xcompiler /EHsc,/W3,/nologo,/Od,/Zi,/MTd -DCUDADeviceProperties_DLLExport=yes -DCPU_RECON=yes -m64 -DcpuPMatrixRecon_EXPORTS -ccbin &quot;c:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin&quot; -DNVCC -M -o C:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/build/dvip4-Win64/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/CMakeFiles/cpuPMatrixRecon_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 &quot;-IC:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK/C/common/inc&quot; -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 &quot;-IC:/Program Files/MATLAB/R2010a/extern/include&quot; -IC:/Users/bdavis5/Documents/QS/QS-NIH/source/branches/trunk/source/Matlab/lib/3rdParty/Siemens/gpu/PMatrixRecon/. -IC:/CUDA/include<br>


2&gt;gpuPMatrixRecon.cu<br>--end snip--<br><br>Note no more -DGPU_RECON ... Yippie!!!<br><br>in response to:<br><br>--snip--<div class="im"><br>FindCUDA.cmake can&#39;t use the target properties, because target 
properties can be set anytime, and the FindCUDA.cmake script needs the 
properties at the time cuda_add_libraries is called.  This is because 
FindCUDA.cmake generates build scripts at configure time and not at 
generate time.<br></div>--end snip--<br><br>Yes I noticed this when looking, debugging, testing FindCuda.  It is the infamous chicken-in-egg problem.  get_target_properties can&#39;t be used in the FindCuda.cmake script (I tried modifying it)  as I cannot call set_target_properties before calling CUDA_ADD_LIBRARY as the target does not exist until after this call.<br>


<br></blockquote><div><br>I really wish there was a generate time hook I could use, but alas there isn&#39;t.  This is as good as it&#39;s going to get with how CMake is currently implemented.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>I appreciate the help and hope this helps someone else<br>
</blockquote></div><br>Again, sorry I didn&#39;t notice your email sooner.  I believe my email address (at least my NVIDIA one) is in the documentation.<br><br>James<br>