Ask Your Question
2

how to catkin_make cuda code

asked 2014-05-07 14:27:33 -0600

moyashi gravatar image

Hi, everyone.
I'd like to know how to write CMakesLists.txt for cuda code.
Are there any good references for it ??

Code is as the following, very simple.


// hello.cu
#include <cuda.h>
#include <cuda_runtime.h>

__global__ kernel()
{
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "hello");
  ros::NodeHandle nh;

  kernel<<<1, 1>>>()
  ROS_INFO_STREAM("Hello, world.");

  return 0;
}
 

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-05-08 01:24:46 -0600

Wolf gravatar image

in your CMakeLists.txt:

    find_package( CUDA REQUIRED 

 # set CUDA_NVCC_FLAGS as you would do with CXX/C FLAGS                        
  set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DMY_DEF=1")
  set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMY_DEF=1" )
  set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMY_DEF=1" )

 # only necessary if you wish to create a lib
  set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF)
  set(BUILD_SHARED_LIBS ON)

# cuda compile GPU_CODE for executable
  cuda_compile(  HELLO_CU_O src/hello.cu )

## create an executable
## can add other (none CUDA) cpp files here
  cuda_add_executable( hello_exec ${LINE_PROFILER_CU_O} )
  target_link_libraries( hello_exec ${catkin_LIBRARIES} )
  add_dependencies( hello_lib ${PROJECT_NAME}_generate_messages_cpp  ${LINE_PROFILER_CU_O} )

## if message headers needed 
  add_dependencies( hello_lib ${PROJECT_NAME}_generate_messages_cpp )

### or create a lib 
  cuda_add_library( ${PROJECT_NAME} src/lib_cuda_code.cu src/libe_none_cuda_code.cpp )
  target_link_libraries( ${PROJECT_NAME} ${catkin_LIBRARIES}  )

## if message headers needed 
  add_dependencies( ${PROJECT_NAME} ${PROJECT_NAME}_generate_messages_cpp )
edit flag offensive delete link more

Comments

The question is: if i want to add a ros.h this code don't work.. because i can't to include the ros.h in the compilation of hello.cu

barovehicles gravatar imagebarovehicles ( 2018-03-18 11:32:28 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2014-05-07 14:27:33 -0600

Seen: 3,349 times

Last updated: May 08 '14