Pcl icp implementation in pytorch cpp extension

Environments:
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:

setup(
    name='icp_cpp',
    version='1.0',
    ext_modules=[
        CppExtension(
            name='icp_cpp',
            sources = ['icp_op.cpp'],
            library_dirs=['/usr/lib/x86_64-linux-gnu'],
            libraries=[*pcl related libraries*],
            include_dirs=["/usr/include/pcl-1.7/",
                          "/usr/include/eigen3"])],
    cmdclass={
    'build_ext': BuildExtension
})

I also tried to add more arguments to the CppExtension as python-pcl/setup.py at master · strawlab/python-pcl · GitHub. 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?

Thanks!

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