<div dir="ltr">Hi,<div><br></div><div>I use cuda as well, I have a different directory for my cuda parts of the application.</div><div>What I do is create a static library and link it to the application. </div><div>It might not be the best way, but it's been working so far.</div><div><br></div><div><br></div><div> -------------------cuda/CMakeLists.txt ------------------------</div><div><br></div><div>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">FIND_PACKAGE</span>(CUDA<span style="color:rgb(192,192,192)"> </span><span style="font-family:monospace;font-size:9.9pt;color:rgb(0,0,0)">REQUIRED</span>)</pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px">set<span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif">(CUDA_NVCC_FLAGS</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">"-g</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">-G</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">-lineinfo"</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-size:9.9pt;color:rgb(0,0,0)">CACHE</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-size:9.9pt;color:rgb(0,0,0)">STRING</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">"nvcc</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">flags"</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-size:9.9pt;color:rgb(0,0,0)">FORCE</span><span style="font-family:arial,sans-serif">)</span><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">SET</span><span style="color:rgb(192,192,192)"> </span>(CUDA_VERBOSE_BUILD<span style="color:rgb(192,192,192)"> </span>ON<span style="color:rgb(192,192,192)"> </span><span style="font-family:monospace;font-size:9.9pt;color:rgb(0,0,0)">CACHE</span><span style="color:rgb(192,192,192)"> </span><span style="font-family:monospace;font-size:9.9pt;color:rgb(0,0,0)">BOOL</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"nvcc</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">verbose"</span><span style="color:rgb(192,192,192)"> </span><span style="font-family:monospace;font-size:9.9pt;color:rgb(0,0,0)">FORCE</span>)<span style="color:rgb(192,192,192)"> </span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">SET</span>(LIB_TYPE<span style="color:rgb(192,192,192)"> </span><span style="font-family:monospace;font-size:9.9pt;color:rgb(0,0,0)">STATIC</span>)<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">#set</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">the</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">lib</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">type</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">CUDA_ADD_LIBRARY</span>(cudaLibName<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">${LIB_TYPE}</span><span style="color:rgb(192,192,192)"> </span>visual.h<span style="color:rgb(192,192,192)"> </span><a href="http://visual.cu">visual.cu</a><span style="color:rgb(192,192,192)"> </span>)</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">--------------------------------------------------</pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><p style="margin:0px"><br></p><p style="margin:0px">and in the main project directory </p><p style="margin:0px"><br></p><p style="margin:0px">------- CMakeLists.txt---------------------</p><pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">find_package</span>(CUDA<span style="color:rgb(192,192,192)"> </span><span style="font-family:monospace;font-size:9.9pt;color:rgb(0,0,0)">REQUIRED</span>)</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">add_subdirectory</span>(cuda)</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">INCLUDE_DIRECTORIES</span>(<span style="color:rgb(0,0,128)">${</span><span style="color:rgb(192,144,80)">CMAKE_SOURCE_DIR</span><span style="color:rgb(0,0,128)">}</span>/cuda)</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">INCLUDE_DIRECTORIES</span>(<span style="color:rgb(0,0,128)">${</span><span style="color:rgb(192,144,80)">CMAKE_SOURCE_DIR</span><span style="color:rgb(0,0,128)">}</span>/cuda/lib)</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">LINK_DIRECTORIES</span>(<span style="color:rgb(0,0,128)">${</span><span style="color:rgb(192,144,80)">CMAKE_SOURCE_DIR</span><span style="color:rgb(0,0,128)">}</span>/cuda)</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">LINK_DIRECTORIES</span>(<span style="color:rgb(0,0,128)">${</span><span style="color:rgb(192,144,80)">CMAKE_SOURCE_DIR</span><span style="color:rgb(0,0,128)">}</span>/cuda/lib)</pre></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">cuda_add_executable</span>(CUDAitk<span style="color:rgb(192,192,192)"> </span><font color="#000080">${SOURCES}</font><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(192,192,192)"> </span>)</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">ADD_DEPENDENCIES</span>(CUDAitk<span style="color:rgb(192,192,192)"> </span>cudaLibName)<br></pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">target_link_libraries</span>(<span style="color:rgb(192,192,192)"> </span>CUDAitk<span style="color:rgb(192,192,192)"> </span>cudaLibName .... )</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">---------------------------------------------</pre></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre></div><div>Best,</div><div>José</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 21, 2017 at 6:49 PM, D'Isidoro Fabio <span dir="ltr"><<a href="mailto:fisidoro@ethz.ch" target="_blank">fisidoro@ethz.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="DE-CH" link="#0563C1" vlink="#954F72">
<div class="m_6599501555081478619WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hallo,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I have a .cu CUDA main code which makes use of itk to read and write images.
<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">How can I create a new ITK project with Cmake that include CUDA? I could not find any tutorial/description on it. Since I am not familiar with Cmake, I would need an understandable and detailed description.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">The most basic CmakeLists.txt I could find does not work:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">------------------------------<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">project(CUDAitk)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">find_package(ITK REQUIRED)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">include(${ITK_USE_FILE})<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">find_package(CUDA REQUIRED)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">CUDA_INCLUDE_DIRECTORIES(${<wbr>ITK_INCLUDE_DIRS})<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">cuda_add_executable(CUDAitk CUDAitk.cu)<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">target_link_libraries(CUDAitk ${ITK_LIBRARIES})<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">------------------------------<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">The compling errors I get are like:<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black">error C2244: 'itk::FixedArray<TValue,<wbr>VLength>::FixedArray': unable to match function definition to an existing declaration<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black">CMake Error at CUDAitk_generated_CUDAitk.cu.<wbr>obj.Debug.cmake:267 (message):<u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black"> Error generating file<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:black"> C:/Users/Fabio/Documents/<wbr>CUDAitk_cpp2/bin/CMakeFiles/<wbr>CUDAitk.dir//Debug/CUDAitk_<wbr>generated_CUDAitk.cu.obj</span><span lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Any help is highly appreciated.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Thank you!<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p><span class="HOEnZb"><font color="#888888">
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Fabio<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
</font></span></div>
</div>
<br>______________________________<wbr>_______<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_<wbr>FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br></div>