CMake for CUDA and RealSense SDK2.0

Hello,

I’m using Intel RealSense D415/D435 cameras along with RealSense SDK2.0 (https://github.com/IntelRealSense/librealsense). There is a part at which I want to accelerate the speed, namely, /src/proc/align.cpp.

Before adding CUDA codes to align.cpp, I simply tried to compile the SDK after changing the file name from align.cpp to align.cu as well as from align.h to align.cuh. Following relevant information described here (https://github.com/jetsonhacks/buildLibrealsense2TX), I made changes at some parts of the SDK’s CMakeLists.txt as follows:

----------------(SKIP)---------------------

option(USE_CUDA “Use CUDA for GPU acceleration” ON)
if (USE_CUDA)
add_definitions(-DUSE_CUDA)
endif()

if (USE_CUDA)
find_package(CUDA REQUIRED)
include_directories({CUDA_INCLUDE_DIRS}) SET(ALL_CUDA_LIBS {CUDA_LIBRARIES} {CUDA_cusparse_LIBRARY} {CUDA_cublas_LIBRARY})
SET(LIBS {LIBS} {ALL_CUDA_LIBS})
message(STATUS “CUDA_LIBRARIES: {CUDA_INCLUDE_DIRS} {ALL_CUDA_LIBS}”)
set(CUDA_PROPAGATE_HOST_FLAGS ON)
set(CUDA_SEPARABLE_COMPILATION OFF)
list( APPEND CUDA_NVCC_FLAGS -03 -gencode arch=compute_61,code=sm_61 ) #For using GeForce GTX 1060
endif()

----------------(SKIP)---------------------

set(REALSENSE_CPP
---------(skip)----------

src/proc/align.cpp

---------(skip)----------
)

set(REALSENSE_HPP
---------(skip)----------

src/proc/align.h

---------(skip)----------
)

----------------(SKIP)---------------------

if (USE_CUDA)
set(REALSENSE_CUDA_CUH
src/proc/align.cuh
)

set(REALSENSE_CUDA
src/proc/align.cu
)

cuda_compile(CUDA_OBJS ${REALSENSE_CUDA})
set(REALSENSE_CPP ${REALSENSE_CPP} ${CUDA_OBJS})
set(REALSENSE_HPP ${REALSENSE_HPP} ${REALSENSE_CUDA_CUH})

endif()

----------------(SKIP)---------------------
source_group(“Source Files\Processing Blocks” FILES
---------(skip)----------

src/proc/align.cpp

    src/proc/align.cu

---------(skip)----------
)

source_group(“Header Files\Processing Blocks” FILES
---------(skip)----------

src/proc/align.h

    src/proc/align.cuh

---------(skipt)----------
)

----------------(SKIP)---------------------

if (USE_CUDA)
link_directories(CUDA_LIBRARY_DIRS) target_link_libraries(realsense2 PRIVATE {LIBS})
endif()

----------------(SKIP)---------------------

CMake does not show any error. But when building libraries (e.g., realsense2.dll) on Visual Studio, I get some errors such as:

C2039 ‘HostingClass’: “global namespace” is not a member.
C2433 ‘librealsense:HostingClass’: ‘friend’ cannot be use to declare data.

In addition, I changed #include “align.h” to #include “align.cuh” in align.cu and rs.cpp – The latter two are the only parts that originally use align.h. Moreover, I checked “CUDA 9.1(.targets .props)” under Build --> Customization. Furthermore, I selected “CUDA C/C++” at the Property of align.cu and align.cuh each.

Could anyone give me some advice for solving the above issue?

Regards,

OS: Windows 10
CPU: x64
IDE: Visual Studio 2015 Community