Discussion:
[ITK-users] Create ITK Project with CUDA from CMake
D'Isidoro Fabio
2017-03-21 17:49:23 UTC
Permalink
Hallo,

I have a .cu CUDA main code which makes use of itk to read and write images.

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.

The most basic CmakeLists.txt I could find does not work:

------------------------------
project(CUDAitk)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

find_package(CUDA REQUIRED)

CUDA_INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIRS})

cuda_add_executable(CUDAitk CUDAitk.cu)
target_link_libraries(CUDAitk ${ITK_LIBRARIES})

------------------------------

The compling errors I get are like:

error C2244: 'itk::FixedArray<TValue,VLength>::FixedArray': unable to match function definition to an existing declaration

CMake Error at CUDAitk_generated_CUDAitk.cu.obj.Debug.cmake:267 (message):
Error generating file
C:/Users/Fabio/Documents/CUDAitk_cpp2/bin/CMakeFiles/CUDAitk.dir//Debug/CUDAitk_generated_CUDAitk.cu.obj


Any help is highly appreciated.

Thank you!

Fabio
jose alejandro matute flores
2017-03-21 22:39:38 UTC
Permalink
Hi,

I use cuda as well, I have a different directory for my cuda parts of the
application.
What I do is create a static library and link it to the application.
It might not be the best way, but it's been working so far.


-------------------cuda/CMakeLists.txt ------------------------

FIND_PACKAGE(CUDA REQUIRED)


set (CUDA_NVCC_FLAGS "-g -G -lineinfo" CACHE STRING "nvcc flags" FORCE)


SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)


SET(LIB_TYPE STATIC) #set the lib type

CUDA_ADD_LIBRARY(cudaLibName ${LIB_TYPE} visual.h visual.cu )


--------------------------------------------------



and in the main project directory


------- CMakeLists.txt---------------------


find_package(CUDA REQUIRED)

add_subdirectory(cuda)


INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda)

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda/lib)

LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda)

LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda/lib)

cuda_add_executable(CUDAitk ${SOURCES} )


ADD_DEPENDENCIES(CUDAitk cudaLibName)


target_link_libraries( CUDAitk cudaLibName .... )


---------------------------------------------


Best,
José
Post by D'Isidoro Fabio
Hallo,
I have a .cu CUDA main code which makes use of itk to read and write images.
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.
------------------------------
project(CUDAitk)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
find_package(CUDA REQUIRED)
CUDA_INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIRS})
cuda_add_executable(CUDAitk CUDAitk.cu)
target_link_libraries(CUDAitk ${ITK_LIBRARIES})
------------------------------
error C2244: 'itk::FixedArray<TValue,VLength>::FixedArray': unable to
match function definition to an existing declaration
Error generating file
C:/Users/Fabio/Documents/CUDAitk_cpp2/bin/CMakeFiles/
CUDAitk.dir//Debug/CUDAitk_generated_CUDAitk.cu.obj
Any help is highly appreciated.
Thank you!
Fabio
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
D'Isidoro Fabio
2017-03-23 17:41:15 UTC
Permalink
Thank you very much Jose,

I can’t make your example work, but I am not sure I have been doing the right things. If you can help me:

I am using Visual Studio, Windows 10. My directory looks like:

CUDAitk/
src/
CUDAitk.cu
CMakeLists.txt
CUDApart/
CUDApart.cu
CMakeLists.txt
bin/

where

----------- CUDAitk/CUDApart/CMakeLists.txt -----------

FIND_PACKAGE(CUDA REQUIRED)

set (CUDA_NVCC_FLAGS "-g -G -lineinfo" CACHE STRING "nvcc flags" FORCE)

SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)

SET(LIB_TYPE STATIC) #set the lib type
CUDA_ADD_LIBRARY(CUDAPart ${LIB_TYPE} CUDApart.h CUDApart.cu )

-----------------------------------------------------------------------

----------- src/CMakeLists.txt -----------

project(CUDAitk)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

find_package(CUDA REQUIRED)

add_subdirectory(CUDApart )

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/CUDApart)

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/CUDApart/Debug)

LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/CUDApart)

LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/CUDApart/Debug)

cuda_add_executable(CUDAitk CUDAitk.cu ${SOURCES} )

ADD_DEPENDENCIES(CUDAitk CUDApart)

target_link_libraries( CUDAitk CUDApart ${ITK_LIBRARIES} )

-----------------------------------------------------------------------

CUDAitk.cu starts with

#include "CUDApart.h"
#include "itkImage.h"


My issues are:


1) I understand I should NOT create the static library first (with Cmake) and then the main project (with another CMake run). Instead, add_subdirectory() should assure that the library is generated first with CUDAitk/CUDApart/CMakeLists.txt and then the src/CMakeLists.txt is generated after that. Is that correct?

2) However at generation, Cmake does not find the CUDApart library (I need to build the created project with Visual Studio first).

3) When I build the main project with Visual Studio (after running CMake), the itk library is not recognized (link error)

I would appreciate any feedback that could be useful to figure this whole thing out.

Thank you again!


From: jose alejandro matute flores [mailto:***@gmail.com]
Sent: Dienstag, 21. MÀrz 2017 23:40
To: D'Isidoro Fabio <***@ethz.ch>
Cc: insight-***@itk.org
Subject: Re: [ITK-users] Create ITK Project with CUDA from CMake

Hi,

I use cuda as well, I have a different directory for my cuda parts of the application.
What I do is create a static library and link it to the application.
It might not be the best way, but it's been working so far.


-------------------cuda/CMakeLists.txt ------------------------


FIND_PACKAGE(CUDA REQUIRED)



set (CUDA_NVCC_FLAGS "-g -G -lineinfo" CACHE STRING "nvcc flags" FORCE)



SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)



SET(LIB_TYPE STATIC) #set the lib type

CUDA_ADD_LIBRARY(cudaLibName ${LIB_TYPE} visual.h visual.cu<http://visual.cu> )



--------------------------------------------------





and in the main project directory



------- CMakeLists.txt---------------------





find_package(CUDA REQUIRED)



add_subdirectory(cuda)



INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda)



INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda/lib)



LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda)



LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/cuda/lib)



cuda_add_executable(CUDAitk ${SOURCES} )



ADD_DEPENDENCIES(CUDAitk cudaLibName)



target_link_libraries( CUDAitk cudaLibName .... )



---------------------------------------------


Best,
José

On Tue, Mar 21, 2017 at 6:49 PM, D'Isidoro Fabio <***@ethz.ch<mailto:***@ethz.ch>> wrote:
Hallo,

I have a .cu CUDA main code which makes use of itk to read and write images.

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.

The most basic CmakeLists.txt I could find does not work:

------------------------------
project(CUDAitk)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

find_package(CUDA REQUIRED)

CUDA_INCLUDE_DIRECTORIES(${ITK_INCLUDE_DIRS})

cuda_add_executable(CUDAitk CUDAitk.cu)
target_link_libraries(CUDAitk ${ITK_LIBRARIES})

------------------------------

The compling errors I get are like:

error C2244: 'itk::FixedArray<TValue,VLength>::FixedArray': unable to match function definition to an existing declaration

CMake Error at CUDAitk_generated_CUDAitk.cu.obj.Debug.cmake:267 (message):
Error generating file
C:/Users/Fabio/Documents/CUDAitk_cpp2/bin/CMakeFiles/CUDAitk.dir//Debug/CUDAitk_generated_CUDAitk.cu.obj


Any help is highly appreciated.

Thank you!

Fabio





_____________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users

Loading...