Skip to content
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 Fortran wrapper for the profile function calls #60

Open
tyronerees opened this issue May 27, 2021 · 0 comments
Open

Memory leak in Fortran wrapper for the profile function calls #60

tyronerees opened this issue May 27, 2021 · 0 comments

Comments

@tyronerees
Copy link
Member

As pointed out by @mjacobse in #57, there is a memory leak in the Fortran wrapper for the profile function calls:

nregions = size(regions, 1)
allocate(f_regions(nregions), stat=st)
do i = 1, nregions
f_regions(i)%nproc = regions(i)%nproc
ngpus = size(regions(i)%gpus, 1)
f_regions(i)%ngpu = ngpus
if (ngpus .gt. 0) then
allocate(gpus(ngpus), stat=st)
gpus(:) = regions(i)%gpus
f_regions(i)%gpus = c_loc(gpus(1))
nullify(gpus)
end if
end do
c_regions = c_loc(f_regions)
call c_begin(nregions, c_regions)
! TODO free data structures
end subroutine profile_begin

From PR #57:
Seems like it should not be too difficult to fix, a quick guess would be something like this:

do i = 1, nregions
   if (f_regions(i)%ngpu .gt. 0) then
      call c_f_pointer(f_regions(i)%gpus, gpus, [f_regions(i)%ngpu])
      deallocate(gpus)
   end if
end do
deallocate(f_regions)

But I was a little irritated that it was left as a "TODO", maybe I am missing something. And I'm not sure if I could test it properly, haven't used the solver with any GPU yet, let alone multiple.

Originally posted by @mjacobse in #57 (comment)

@jfowkes jfowkes added this to the New Release milestone Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants