Compile cuda into ros code in TEGRA

asked 2018-10-03 11:26:06 -0600

billyDong gravatar image

updated 2018-10-03 13:12:10 -0600

gvdhoorn gravatar image

I've an 'old' Tegra jetson TK1 with ubuntu 16.04 (arm architecture) ros kinetic and CUDA 6.5.

I've a ros node with cuda code that worked fine on two different computers with different Nvidia boards. But now I'm trying to use it on Tegra and the ros cpp librarys are not working. Here is the terminal output of the errors:

here is part of the .cu code

#include <numeric>
#include <stdlib.h>
#include <stdio.h>
#include <cuda_runtime.h>
#include "Novo_Teste.hpp"
#include <iostream> //Este tambem repete no .cpp
#include <math.h>


//Includes do .cpp
#include <ros/ros.h>
#include <ros/package.h>
#include <image_transport/image_transport.h>
#include <compressed_image_transport/compressed_subscriber.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/highgui/highgui.hpp>

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/opencv.hpp>
#include <string>


#include <vector>

#include <sstream>

#include <fstream>

#include "fbn_lbp/imagedescriptor.h"
#include "fbn_lbp/lbp_pattern.h"
#include "train_and_test.h"
/*************************************************************/

//Declaration from .cu

#define CHECK(call)                                                     \
{                                                                       \
const cudaError_t error = call;                                         \
if (error != cudaSuccess)                                               \
{                                                                       \
printf("Error: %s:%d, ", __FILE__, __LINE__);                           \
printf("code:%d, reason: %s\n", error, cudaGetErrorString(error));      \
exit(-10*error);                                                        \
}                                                                       \
}

I just posted the headers because that's where the problems start. in the includes of ROS.

Could someone help me to solve this?

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(v_detector)

find_package(catkin REQUIRED COMPONENTS
    roscpp
    rospy
    std_msgs
    image_transport
    compressed_image_transport
    image_geometry
    cv_bridge
    rosbag
    geometry_msgs
    tf
)

find_package(OpenCV REQUIRED)
include_directories(  ${OpenCV_INCLUDE_DIRS} )

find_package(Boost REQUIRED COMPONENTS system thread filesystem  )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

find_package( CUDA REQUIRED )
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${CUDA_INCLUDE_DIRS}
)


catkin_package()


SET(CUDA_NVCC_FLAGS "-arch=sm_32" CACHE STRING "nvcc flags" FORCE)
SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)
SET(LIB_TYPE STATIC)
CUDA_ADD_LIBRARY(TestLib ${LIB_TYPE} src/Novo_Teste.cu)      # THE ERROR OCCURS IN THIS LINE !

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" )

#include_directories(
 # ${catkin_INCLUDE_DIRS}
#  ${CUDA_INCLUDE_DIRS}

#)

link_directories(${CUDA_LIBRARY_DIRS})

cuda_compile(NOVO_TESTE_CU_O src/Novo_Teste.cu)

set(FBN_SVM src/fbn_libsvm/fbn_svm.cpp  src/lrf_to_camera.cpp src/fbn_libsvm/fbn_svm-predict.cpp src/fbn_libsvm/fbn_svm-scale.cpp  src/fbn_libsvm/fbn_svm-train.cpp )
set(FBN_LBP src/fbn_lbp/lbp_pattern.cpp src/fbn_lbp/imagedescriptor.cpp)

## Declare a C++ and cuda executable
## cuda_add_executable( hello_exec ${LINE_PROFILER_CU_O} )
add_executable(V_detector_node src/main.cpp ${FBN_SVM})
target_link_libraries(V_detector_node   ${catkin_LIBRARIES} ${OpenCV_LIBS} ${cuda_LIBRARIES})


add_executable(must_detector_hLBP_plus_Colour_4_classes_V16_ground_truth src/detector_hLBP_plus_Colour_4_classes_V16_ground_truth.cpp src/train_and_test.cpp  ${FBN_SVM} ${FBN_LBP} ${NOVO_TESTE_CU_O})
target_link_libraries(must_detector_hLBP_plus_Colour_4_classes_V16_ground_truth   ${catkin_LIBRARIES} ${OpenCV_LIBS} ${cuda_LIBRARIES} TestLib /home/catkin_ws/src/V_detector/src/Novo_Teste.hpp)

Compilation output:

[ 45%] Building NVCC (Device) object V_detector/CMakeFiles/TestLib.dir/src/TestLib_generated_Novo_Teste.cu.o
-- Removing /home/ubuntu/catkin_ws/build/V_detector/CMakeFiles/TestLib.dir/src/./TestLib_generated_Novo_Teste.cu.o
/usr/bin/cmake -E remove /home/ubuntu/catkin_ws/build/V_detector/CMakeFiles/TestLib.dir/src/./TestLib_generated_Novo_Teste.cu.o
-- Generating dependency file: /home/ubuntu/catkin_ws/build/V_detector/CMakeFiles/TestLib.dir/src/TestLib_generated_Novo_Teste.cu.o.NVCC-depend
/usr/local/cuda-6.5/bin/nvcc -M -D__CUDACC__ /home/ubuntu/catkin_ws/src/V_detector/src/Novo_Teste.cu -o /home/ubuntu/catkin_ws/build/V_detector/CMakeFiles/TestLib.dir/src/TestLib_generated_Novo_Teste.cu.o.NVCC-depend -ccbin /usr/bin/cc -m32 -DROS_BUILD_SHARED_LIBS=1 -DROS_PACKAGE_NAME=\"V_detector\" -DROSCONSOLE_BACKEND_LOG4CXX -Xcompiler ,\"-g\" -arch=sm_32 -DNVCC -I/usr/local/cuda-6.5/include -I ...
(more)
edit retag flag offensive close merge delete

Comments

I just posted the headers because that's where the problems start. in the includes of ROS.

it's actually more likely that the problem is somewhere else and it first surfaces in the error message that refers to /opt/ros/kinetic/include/ros/service_client.h.

gvdhoorn gravatar imagegvdhoorn ( 2018-10-03 13:14:45 -0600 )edit

@gvdhoorn it works perfectly with cuda 9.1 either using ros kinetic or ros melodic in an x86_64 arch.

Here I must use cuda 6.5 (the latest compatible version) and ubuntu 16.04 with ARM arch. the problem begins by adding the ROS header in file "novo_teste.cu"

billyDong gravatar imagebillyDong ( 2018-10-22 13:27:34 -0600 )edit