0
$\begingroup$

Rosanswers logo

Hi,

I am trying to integrate CUDA in my ros package (which is not catkinized) and have some problems. I believe, that I have to use cuda_add_library and cuda_add_executable in my CMakeLists.txt and after that target_link_libraries. If I do that, for some reason I get linking errors because the libraries have not been linked, it says it doesn't know about ros::spin for instance. If instead, I use rosbuild_add_library and rosbuild_add_executable, there is some CUDA related linking issue. I append the important bits of the CMakeLists file. If I compile without CUDA support, everything works. I would be grateful for any help.

if(SUPPORT_CUDA)
    find_package(CUDA QUIET REQUIRED)
    include_directories(${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc)
    add_definitions(-DCUDA_BUILD -DBT_USE_DOUBLE_PRECISION)
    list(APPEND  SOURCES bar.cu)
else()
    MESSAGE(STATUS "cuda not found")
endif()

if(SUPPORT_CUDA)
    cuda_add_library(${PROJECT_NAME} SHARED ${SOURCES})
    cuda_add_executable(main ${PROJECT_SOURCE_DIR}/src/main.cpp)  
else()
    rosbuild_add_library(${PROJECT_NAME} SHARED ${SOURCES})
    rosbuild_add_executable(main ${PROJECT_SOURCE_DIR}/src/main.cpp)
ENDIF()

target_link_libraries(${PROJECT_NAME} ${EXTERNAL_LIBS})
target_link_libraries(main ${PROJECT_NAME}) 

Originally posted by Oier on ROS Answers with karma: 145 on 2013-05-31

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You can start by looking at parallel_quickstep package that has CUDA enabled

You can also check out this wiki page.

Both of these packages are incredibly out-of-date, but should provide good guidelines on how to compile your project

Make sure to note the FindCUDA.cmake file in both of these packages as it contains all of the CUDA variables needed to get your project up and running

Also, you may want to look into cuda_compile instead of cuda_add_library. I know this resolved some linking issues for me


Originally posted by mortonjt with karma: 217 on 2013-05-31

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by reza64 on 2014-04-08:
I am new in using cuda in ROS package, the first link was not informative for me, the second link is not working! I have test diff solution but non of them couldn't solve my problem. May you please help me to find a step by step tutorial?

Comment by dwyer2bp on 2015-07-02:
'wiki' page is dead. parallel_quickstep link is not dead, but it's link to the github repo is dead

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.