<div dir="ltr"><div class="gmail_default"><font face="verdana, sans-serif">Hi Chuck,</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">Thanks so very much for looking into my question and the detailed answer.</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">As I am new to CUDA I have the tendency to keep both CUDA and VTK in a single .cu file. But, I keep your advice in mind that ideal code should have host and device codes separated. I have written the CMake code according to your and I have ran into few problems:</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">First, upon building the solution I have got the <span style="line-height:107%">"cmd.exe exited with code 1" error. To get around this one, I changed the build customization of the VS project into CUDA.</span></font></div><div class="gmail_default"><span style="line-height:107%"><font face="verdana, sans-serif"><br></font></span></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="line-height:107%">Then, I had the error of "The </span><span style="line-height:107%">given path's format
is not supported". To fix this, I found that the .cu file must be moved into the VS project directory.</span></font></div><div class="gmail_default"><span style="line-height:107%"><font face="verdana, sans-serif"><br></font></span></div><div class="gmail_default"><span style="line-height:15.6933px"><font face="verdana, sans-serif">After doing these, I have recieved the following error and could not really figure out how to address this one.</font></span></div><div class="gmail_default"><div class="gmail_default"><span style="line-height:15.6933px"><font face="verdana, sans-serif">Error<span class="" style="white-space:pre"> </span>92<span class="" style="white-space:pre"> </span>error LNK1104: cannot open file 'C:\Users\Reza\Desktop\cuda_vtk_testing\build\CMakeFiles\Test.dir\Debug\Test_generated_source.cu.obj'<span class="" style="white-space:pre"> </span>C:\Users\Reza\Desktop\cuda_vtk_testing\build\LINK<span class="" style="white-space:pre"> </span>Test</font></span></div><div style="line-height:15.6933px"><font face="verdana, sans-serif"><br></font></div><div style="line-height:15.6933px"><font face="verdana, sans-serif">It is confusing for me that the NVIDIA CUDA Samples run properly in my computer but this code gives me these errors.</font></div><div style="line-height:15.6933px"><font face="verdana, sans-serif"><br></font></div><div style="line-height:15.6933px"><font face="verdana, sans-serif">I was wondering if you could take a look into this error as well.</font></div><div style="line-height:15.6933px"><font face="verdana, sans-serif"><br></font></div><div style="line-height:15.6933px"><font face="verdana, sans-serif">Regards,</font></div><div style="line-height:15.6933px"><font face="verdana, sans-serif">Reza</font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 27, 2016 at 2:20 PM, Chuck Atkins <span dir="ltr"><<a href="mailto:chuck.atkins@kitware.com" target="_blank">chuck.atkins@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Hi Reza,<br> <br></div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">find_package(CUDA REQUIRED)</span></font><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">if (CUDA_FOUND)</span></font></div><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"> message("CUDA found!")</span></font></div><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">else()</span></font></div><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"> message("CUDA not found, doing something alternatively")</span></font></div><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">endif()</span></font></div></div></div></blockquote><div><br></div></span><div>The if(CUDA_FOUND) is redundant since the REQUIRED argument to find_package will generate a fatal error if not found. If you want to be able to have two different configurations, one found and one not found, then just remove the REQUIRED from find_package(CUDA).<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"></span></font></div><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}</span></font></div></div></div></blockquote><div><br></div><div>Rather than explicitly force the CXX flags, there's more compiler agnostic ways to address this:<br> <br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"> -std=c++11</span></font></div></div></div></blockquote><div><br></div><div>instead of forcing the flag, let CMake do the work for you. Just set the CXX_STANDARD=11 property on the resulting target and CMake will know how to set the correct flag.<br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"> -D_FORCE_INLINES</span></font></div></div></div></blockquote><div><br></div><div> Use add_definitions(<font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">-D_FORCE_INLINES). The end effect is the same but it does a better job of propagating target usage requirements under the hood.<br></span></font></div><div> </div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"></span></font></div><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px">CUDA_ADD_EXECUTABLE(Test <a href="http://source.cu/" target="_blank">source.cu</a>)</span></font></div></div></div></blockquote><div><br></div><div>Ideally you should keep the host and device code seperate. That way the CUDA compiler is only used for actual CUDA code and your host compiler deals with the rest. <br></div><span class=""><br><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><font color="#242729" face="arial, helvetica, sans-serif"><span style="font-size:15px;line-height:19.5px"></span></font></div><div><font face="arial, helvetica, sans-serif"><span style="color:rgb(36,39,41);font-size:15px;line-height:19.5px">I am using CUDA 7.5, VTK 7.0.0 and CMake 3.6.0. Here is the <a href="http://source.cu/" target="_blank">source.cu</a>. It is basically combination of VTK Hello World example (Rendering a Cylinder) and vectorAdd.cu in CUDA samples and both are working separately.</span><font color="#242729"><span style="font-size:15px;line-height:19.5px"><br></span></font></font></div></div></div></blockquote><div><br> </div></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><font face="arial, helvetica, sans-serif"><font color="#242729"><span style="font-size:15px;line-height:19.5px"></span></font></font></div><div><div><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:15px;clear:both;color:rgb(36,39,41);line-height:19.5px"><font face="arial, helvetica, sans-serif"><font face="arial, helvetica, sans-serif">What are my mistakes that VS12 cannot find includes of VTK in my codes</font></font></p></div></div></div></div></blockquote><div>You're missing a call to CUDA_INCLUDE_DIRECTORIES to pass them to the separate CUDA compiler<br> <br></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-size:12.8px"><div><div><p style="margin:0px 0px 1em;padding:0px;border:0px none;font-size:15px;clear:both;color:rgb(36,39,41);line-height:19.5px"><font face="arial, helvetica, sans-serif">Generally, how do we write a CMake code when we want to combine CUDA and VTK?</font></p></div></div></div></div></blockquote></span>Putting it all together, we get:<br></div><br><span style="font-family:monospace,monospace">cmake_minimum_required(VERSION 3.3)<span class=""><br>project(Test)<br><br>find_package(VTK REQUIRED)<br>include(${VTK_USE_FILE})<br><br>find_package(CUDA REQUIRED)<br><br></span>add_definitions(-D_FORCE_INLINES)<span class=""><br><br>set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_20)<br><br></span>// The following is ONLY necessary if your CDA code is actually including VTK<br>CUDA_INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})<br><br>CUDA_ADD_EXECUTABLE(Test cylinder.cxx vectorAdd.cu)<br>target_link_libraries(Test ${VTK_LIBRARIES})<br>set_target_properties(Test PROPERTIES CXX_STANDARD 11)</span><br><br></div><div class="gmail_extra">Hope that helps,<br></div><div class="gmail_extra">- Chuck<br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="font-size:12.8px">PhD student in Biomedical Engineering,</div><div style="font-size:12.8px">Spencer Engineering Building Room 37</div><div style="font-size:12.8px">University of Western Ontario</div><div style="font-size:12.8px">London, ON, Canada, N6A 5B9</div></div></div>
</div>