Accessing point cloud stored in GPU memory with GetPtr without causing a segmentation fault


I have been reading StereoLabs example for transferring Mat stored point clouds to PCL pointclouds, and in that you use mutex and threads to access the Mat and cycle through it iterating the index of the pointer to the matrix each cycle for the 4 new pieces of data.

I have tried to emulate this example, but I continue to get segmentation faults each time, even if its as simple as GetPtr → Cout << Pointer_values.

All I want to do is access the pointcloud data stored on the GPU with pointers without causing a core dump instead of using GetValue to pull them out within a loop.

Any advice on this would be great!



Hi @TastesLikeHarry

You cannot access the GPU memory at CPU level, you must move the data from the VRAM to the RAM.

In the case that the GPU and the CPU share the same RAM you can use shadow copy and the operation is performed at almost zero cost.

1 Like

Ahah! Thank you!

So would the code look something like this:
Mat point_cloud; //Globals
Mat cpu_pc;

point_cloud.alloc(camera_config.resolution, MAT_TYPE::F32_C4, MEM::GPU);
cpu_pc.alloc(camera_config.resolution, MAT_TYPE::F32_C4, MEM::CPU);
while loop
zed.retrieveMeasure(point_cloud, MEASURE::XYZRGBA, MEM::GPU);

Do Stuff with CPU pointcloud.

Would it be point_cloud.copyTo(cpu_pc) or point_cloud.clone(cpu_pc) for your shadow copy?

Thank you :slight_smile:

or possibly point_cloud.copyTo(cpu_pc, COPY_TYPE::GPU_CPU);

Yes, it’s something similar… but if you are not using the point cloud with CUDA it’s not useful to perform this operation. You can retrieve the data directly into CPU memory letting the SDK perform the copy internally.

1 Like