Pcl icp implementation in pytorch cpp extension

ubuntu 16.04 + anaconda 2 + pytorch 0.4.0

I’m trying to build a cpp extension for point cloud iterative closest point using the icp function in pcl-1.7 http://pointclouds.org/documentation/tutorials/iterative_closest_point.php.

The data transforming from at::tensor to pcl::Pointcloud is fine. However, as soon as I declare a new icp object, there will be a segmentation fault.

This line triggers the fault:

pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;

The setup.py file is:

            sources = ['icp_op.cpp'],
            libraries=[*pcl related libraries*],
    'build_ext': BuildExtension

I also tried to add more arguments to the CppExtension as https://github.com/strawlab/python-pcl/blob/master/setup.py. But it doesn’t help.

To repeat the bug, you can clone the related files from https://github.com/onlytailei/icp_extension.
There should be pcl and eigen in the system

sudo apt-get install libpcl-all
sudo apt-get install libeigen3-dev

Then build the extension through:

python setup install.py

Comment/Uncomment line 72 in icp_op.cpp

pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;

And rebuild the extension, you will see the difference.

python icp_test.py

Random guess: maybe PCL is stealing the ownership of a Torch Tensor, and that is causing the segfault?


The problem is that I only declare a new icp object like

pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;

As soon as you uncomment this one, the segfault happen. I’m not starting to input any point cloud to it.
In the pure cpp example, everything is fine.

Do you have the segfault if you comment out everything in https://github.com/onlytailei/icp_extension/blob/master/icp_op.cpp#L29-L65 ?

I tried. It doesn’t help.
The segfault is still coming from line 72.

Let’s move the discussion to https://github.com/pytorch/extension-cpp/issues/20