pcl::io::loadPCD/PLY gives segmentation fault when compiling with nvcc/cuda

#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>

int main(int argc, char* argv[]){
  //pcl::PointCloud<pcl::PointXYZ>::Ptr s___(new pcl::PointCloud<pcl::PointXYZ>());
  pcl::PointCloud<pcl::PointXYZ> s__;
  std::vector<int> filenames = pcl::console::parse_file_extension_argument(argc,argv,".pcd");
  pcl::io::loadPCDFile(argv[filenames[0]], s__);
  return 0;

}

Either with shared pointer or PointCloud object itself, when the program hits (during runtime) "loadPCDfile" line I get the segmentation fault error!

This is while I get no error when compiling with gcc alone. Why? P.S. > I don't want to use wrappers

Ubuntu 18.04 pcl 1.11 cuda 11 gcc 7.5 eigen 3.7

and cmake is,

cmake_minimum_required(VERSION 3.20.0)


project(t LANGUAGES CXX CUDA)
find_package(Eigen3 QUIET)
find_package(PCL 1.11 REQUIRED)
find_package(CUDA)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--ptxas-options=-v;-std=c++17)
include_directories(
    ${PCL_INCLUDE_DIRS}
    ${CUDA_INCLUDE_DIRS}
    ${EIGEN3_INCLUDE_DIRS}
  )

if(NOT EIGEN3_FOUND)
  # Fallback to cmake_modules
  find_package(cmake_modules REQUIRED)
  find_package(Eigen REQUIRED)
  set(EIGEN3_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
  set(EIGEN3_LIBRARIES ${EIGEN_LIBRARIES})  # Not strictly necessary as Eigen is head only
  # Possibly map additional variables to the EIGEN3_ prefix.
else()
  set(EIGEN3_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR})
endif()

add_executable (t t.cu)

target_link_libraries(t
${CUDA_LIBRARIES}
${CUDA_CUBLAS_LIBRARIES}
${CUDA_curand_LIBRARY}
${PCL_LIBRARIES})

Then when the excutable t.out is made, I have pcd file named map.pcd then I just run

./t.out map.pcd

and there segmentation fault happens

Upvotes: 0

Views: 506

Answers (1)

I understand this was a weird question, and so unlikely to happen. But turns out it is the case with pcl::io::LoadPCD/PLY in a .cu file. I tried it for almost 10 times with the cmake provided in the question part and yet the problem persists. I found a solution with help of one of my colleagues and we are reporting this bug to pcl github. For a unknown reason you must do this for reading point cloud files pcd/ply in .cu file, very much slower but it works.

pcl::PointCloud<pcl::PointXYZ>::Ptr source(new pcl::PointCloud<pcl::PointXYZ>());
pcl::PCLPointCloud2 cloud_blob;
pcl::io::loadPCDfile("path/file.pcd", cloud_blob);
pcl::fromPCLPointCloud2(cloud_blob, *source);

Upvotes: 1

Related Questions