I am trying to use the CUDA RANSAC implementation from PCL version 1.11 from here.
I have a simple example that runs without errors when I use storage type of pcl::cuda::Host, but when I try to use the GPU side (pcl::cuda::Device), it fails with error
terminate called after throwing an instance of 'thrust::system::system_error' what(): trivial_device_copy D->H failed: cudaErrorInvalidValue: invalid argument Aborted (core dumped)
How do I actually instantiate and run the CUDA GPU version of pcl::cuda::RandomSampleConsensus?
When I ran the example through the debugger, the debugger crashed but said that it got up to SampleConsensusModel1PointPlane::selectWithinDistance().
running cuda-memcheck gives:
========= Program hit cudaErrorInvalidValue (error 1) due to "invalid argument" on CUDA API call to cudaMemcpyAsync.
========= Saved host backtrace up to driver entry point at error
========= Host Frame:/lib/x86_64-linux-gnu/libcuda.so.1 [0x3343d3]
========= Host Frame:/usr/local/lib/libpcl_cuda_sample_consensus.so.1 [0xa274d]
========= Host Frame:/usr/local/lib/libpcl_cuda_sample_consensus.so.1 (_ZN3pcl4cuda25SampleConsensusModelPlaneINS0_6DeviceEE20selectWithinDistanceERN6thrust13device_vectorI6float4NS4_16device_allocatorIS6_EEEEifRSt10shared_ptrINS5_IiNS7_IiEEEEER6float3 + 0x8f) [0x3b7cf]
========= Host Frame:/usr/local/lib/libpcl_cuda_sample_consensus.so.1 (_ZN3pcl4cuda21RandomSampleConsensusINS0_6DeviceEE12computeModelEi + 0x143) [0x50723]
========= Host Frame:./cuda_random_sample_consensus [0xd220]
========= Host Frame:/lib/x86_64-linux-gnu/libc.so.6 (__libc_start_main + 0xf3) [0x270b3]
========= Host Frame:./cuda_random_sample_consensus [0xccde]
=========
========= Program hit cudaErrorInvalidValue (error 1) due to "invalid argument" on CUDA API call to cudaGetLastError.
========= Saved host backtrace up to driver entry point at error
========= Host Frame:/lib/x86_64-linux-gnu/libcuda.so.1 [0x3343d3]
========= Host Frame:/usr/local/lib/libpcl_cuda_sample_consensus.so.1 [0x8b566]
========= Host Frame:/usr/local/lib/libpcl_cuda_sample_consensus.so.1 (_ZN3pcl4cuda25SampleConsensusModelPlaneINS0_6DeviceEE20selectWithinDistanceERN6thrust13device_vectorI6float4NS4_16device_allocatorIS6_EEEEifRSt10shared_ptrINS5_IiNS7_IiEEEEER6float3 + 0xa1) [0x3b7e1]
========= Host Frame:/usr/local/lib/libpcl_cuda_sample_consensus.so.1 (_ZN3pcl4cuda21RandomSampleConsensusINS0_6DeviceEE12computeModelEi + 0x143) [0x50723]
========= Host Frame:./cuda_random_sample_consensus [0xd220]
========= Host Frame:/lib/x86_64-linux-gnu/libc.so.6 (__libc_start_main + 0xf3) [0x270b3]
========= Host Frame:./cuda_random_sample_consensus [0xccde]
=========
terminate called after throwing an instance of 'thrust::system::system_error'
what(): trivial_device_copy D->H failed: cudaErrorInvalidValue: invalid argument
========= Error: process didn't terminate successfully
========= No CUDA-MEMCHECK results found
Code that produces error:
src/main.cu
#include <iostream>
#include <pcl/cuda/sample_consensus/ransac.h>
#include <pcl/cuda/sample_consensus/sac_model_plane.h>
int main() {
pcl::cuda::PointCloudAOS<pcl::cuda::Device> ground_cloud;
ground_cloud.width = 50;
ground_cloud.height = 50;
ground_cloud.is_dense = false;
pcl::cuda::PointXYZRGB point;
for (int i = 0; i < ground_cloud.width * ground_cloud.height; i++) {
point.x = 5.;
point.y = 5.;
point.z = 5.;
point.rgb.r = 0.5;
point.rgb.g = 0.5;
point.rgb.b = 0.5;
ground_cloud.points.push_back(point);
}
pcl::cuda::SampleConsensusModelPlane<pcl::cuda::Device>::PointCloudPtr
cloudPtr(new pcl::cuda::SampleConsensusModelPlane<pcl::cuda::Device>::PointCloud (ground_cloud));
pcl::cuda::SampleConsensusModelPlane<pcl::cuda::Device>::Ptr
plane(new pcl::cuda::SampleConsensusModelPlane<pcl::cuda::Device>(cloudPtr));
pcl::cuda::RandomSampleConsensus<pcl::cuda::Device> ransac(plane);
ransac.setDistanceThreshold(0.07);
ransac.setMaxIterations(50);
bool status = ransac.computeModel();
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(random_sample_consensus)
find_package(PCL 1.2 REQUIRED)
enable_language(CUDA)
set(CMAKE_CUDA_COMPILER nvcc)
include_directories(${PCL_INCLUDE_DIRS} /usr/local/cuda/include)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (ransac src/main.cu)
target_link_libraries (ransac ${PCL_LIBRARIES})
add_compile_options(-w)
question from:
https://stackoverflow.com/questions/65912893/pcl-cuda-how-to-use-pclcudarandomsampleconsensus 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…