-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in remap
#134
Comments
That’s weird, however the idea with the new function signature allowing mutable outputs is that you allocate once outside of the for loop. If you check in the benches is how I’m doing. If you’re up to, would be great to provide a bench for remap using also BTW, remap is not the fastest implementation for now, it needs some optimisations as eg. the interpolation function it´s computing everytime the offset indices of the tensor from where to interpolate which could be done as a pre-step by iterating row by row with step 1. A second one, would be using simd to compute the weighted interpolation. |
I couldn't reproduce the growing memory usage issue while running for about 5 minutes. But, when testing with This is the correction_map that I used.use kornia::image::{Image, ImageSize};
use kornia::core::Tensor2;
use kornia::imgproc::interpolation::{remap, InterpolationMode, grid::meshgrid_from_fn};
fn correction_map(size: &ImageSize) -> (Tensor2<f32>, Tensor2<f32>) {
// Identity mapping
let (map_x, map_y) = meshgrid_from_fn(size.width, size.height, |x, y| {
Ok((x as f32, y as f32))
}).unwrap();
(map_x, map_y)
} Valgrind log
The leak detected by valgrind is here: kornia-rs/crates/kornia-core/src/storage.rs Lines 60 to 64 in a652662
The issue is that the memory allocated in ptr won't be freed when the Arc::new(Vec::<T>::with_capacity(len)) is freed.
|
@emilmgeorge, thanks for your investigation. It seems there’s definitely an issue with Buffer::from_custom_allocation or possibly the way I implemented it initially. I've opened a ticket to address this: kornia-rs/issues/127. It might be worthwhile to revisit the Tensor constructor API and the use of the Allocator. Here are my thoughts on the design:
|
There is some amount of memory being allocated during the
remap
function that isn't getting cleaned up.This is with the latest commit on main. So I imagine it's something to do with rayon or the new tensor implementation.
This simple program will slowly grow in memory usage:
The text was updated successfully, but these errors were encountered: