[vtkusers] Writing CMake file for VTK+CUDA project

Reza Faieghi mfaieghi at westerneng.ca
Tue Jun 28 08:12:27 EDT 2016


Hi Chuck,

Thanks so very much for looking into my question and the detailed answer.

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:

First, upon building the solution I have got the "cmd.exe exited with code
1" error. To get around this one, I changed the build customization of the
VS project into CUDA.

Then, I had the error of "The given path's format is not supported". To fix
this, I found that the .cu file must be moved into the VS project directory.

After doing these, I have recieved the following error and could not really
figure out how to address this one.
Error 92 error LNK1104: cannot open file
'C:\Users\Reza\Desktop\cuda_vtk_testing\build\CMakeFiles\Test.dir\Debug\Test_generated_source.cu.obj'
C:\Users\Reza\Desktop\cuda_vtk_testing\build\LINK Test

It is confusing for me that the NVIDIA CUDA Samples run properly in my
computer but this code gives me these errors.

I was wondering if you could take a look into this error as well.

Regards,
Reza

On Mon, Jun 27, 2016 at 2:20 PM, Chuck Atkins <chuck.atkins at kitware.com>
wrote:

> Hi Reza,
>
>
>> find_package(CUDA REQUIRED)
>> if (CUDA_FOUND)
>>     message("CUDA found!")
>> else()
>>     message("CUDA not found, doing something alternatively")
>> endif()
>>
>
> 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).
>
>
>
>> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}
>>
>
> Rather than explicitly force the CXX flags, there's more compiler agnostic
> ways to address this:
>
>
> -std=c++11
>>
>
> 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.
>
>
>
>> -D_FORCE_INLINES
>>
>
>  Use add_definitions(-D_FORCE_INLINES).  The end effect is the same but
> it does a better job of propagating target usage requirements under the
> hood.
>
>
> CUDA_ADD_EXECUTABLE(Test source.cu)
>>
>
> 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.
>
>
>
>> I am using CUDA 7.5, VTK 7.0.0 and CMake 3.6.0. Here is the source.cu.
>> It is basically combination of VTK Hello World example (Rendering a
>> Cylinder) and vectorAdd.cu in CUDA samples and both are working separately.
>>
>
>
>
>> What are my mistakes that VS12 cannot find includes of VTK in my codes
>>
> You're missing a call to CUDA_INCLUDE_DIRECTORIES to pass them to the
> separate CUDA compiler
>
>
>
>> Generally, how do we write a CMake code when we want to combine CUDA and
>> VTK?
>>
> Putting it all together, we get:
>
> cmake_minimum_required(VERSION 3.3)
> project(Test)
>
> find_package(VTK REQUIRED)
> include(${VTK_USE_FILE})
>
> find_package(CUDA REQUIRED)
>
> add_definitions(-D_FORCE_INLINES)
>
> set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --gpu-architecture sm_20)
>
> // The following is ONLY necessary if your CDA code is actually including
> VTK
> CUDA_INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
>
> CUDA_ADD_EXECUTABLE(Test cylinder.cxx vectorAdd.cu)
> target_link_libraries(Test ${VTK_LIBRARIES})
> set_target_properties(Test PROPERTIES CXX_STANDARD 11)
>
> Hope that helps,
> - Chuck
>



-- 
PhD student in Biomedical Engineering,
Spencer Engineering Building Room 37
University of Western Ontario
London, ON, Canada, N6A 5B9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160628/c0b31f71/attachment.html>


More information about the vtkusers mailing list