openphotogrammetry / meshroomcl

MeshroomCL: An OpenCL implementation of photogrammetry with the Meshroom interface
Other
163 stars 8 forks source link

Suspected memory leak with `meshroomCL_colmap` #25

Closed expenses closed 2 years ago

expenses commented 2 years ago

Hi. I'm having a problem where MultiviewStereoCL manages to process about 50 views before hitting GpuMatCL<T>::GpuMatCL failed in clCreateBuffer with error code=-4. I am on a (perhaps strange) system with 8gb of CPU memory and 16gb of GPUmemory. When processing the views, the memory usage goes up over time from about 1GB for the first couple to 4GB+ later on:

mem

This smells like a memory leak to me, unless the algorithm needs data from all previous runs in order to do the processing which seems unlikely.

revisionarian commented 2 years ago

Hi @expenses, thanks a lot for posting your MeshroomCL bug report. The issue is similar to one reported last week, #23. In that case, I thought the user might be exceeding their VRAM, but the information you have provided suggests it is more likely hitting a RAM limitation.

The MultiviewStereoCL algorithm uses a LRU data cache, to which image and depth map data are continually added. Multiview stereo algorithms often cache data to share across the processing of different views, since neighboring views will likely need to access the same image and depth data. So, I think that the increasing memory usage that you are observing is just the cache gradually filling up, rather than a memory leak. Unfortunately, we made the size of the data cache very large (over 8 GB), so this is causing you to run out of memory.

When we release the next version of MeshroomCL (hopefully soon!), we will reduce the size of the data cache so that it will work better on your computer. In the meantime, you can decrease the memory requirements of the MultiviewStereoCL node by reducing the "Max Image Size" parameter from the default of 3200 to something lower (changing it to 1600 would reduce the memory usage by 4x, for example).

Thanks again for raising this issue. Let us know if you have any more problems or ideas!

revisionarian commented 2 years ago

Hi @expenses, we have released a new version of MeshroomCL (version 0.8.1) that addresses the memory issue you were observing with the MultiviewStereoCL node. In MeshroomCL 0.8.1, the default size of the multiview stereo data cache is much smaller, and we've added an attribute in the MultiviewStereoCL node to allow the user to specify the cache size if desired. This new version should work much better on your 8 GB RAM system.

However, with only 8 GB of RAM, I am worried that you might encounter similar problems with the TexturingCL node later in the pipeline (if you are trying to make phototextured models). The TexturingCL node also requires a lot of RAM for its processing on larger datasets. If you run into memory problems on the TexturingCL node, you can try the following workarounds:

1) Rescale your images by 50% before importing them into MeshroomCL, and/or 2) Insert a "MeshDecimate" node in the pipeline immediately before the TexturingCL node, and aggressively decimate the mesh down to a smaller number of vertices.

Both of these techniques will reduce the amount of RAM required for processing in the TexturingCL node. We'll better address this in an upcoming version of MeshroomCL in early January.

expenses commented 2 years ago

Hey, yeah that seems to have solved the problem. Thanks!