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 for CUDNN API Handle #88

Closed
lissahyacinth opened this issue Mar 9, 2020 · 3 comments · Fixed by #94
Closed

Memory Leak for CUDNN API Handle #88

lissahyacinth opened this issue Mar 9, 2020 · 3 comments · Fixed by #94
Labels
bug Something doesn't quite look right

Comments

@lissahyacinth
Copy link
Contributor

Issue

CUDNN is created as a lazy_static as a handle to CUDNN API (https://github.com/spearow/juice/blob/master/coaster-nn/src/frameworks/cuda/mod.rs#L15-L17)

Lazy_statics cannot be dropped, but CUDNN has a drop method that destroys the API handle, as encouraged in the CUDNN docs.
https://github.com/spearow/juice/blob/master/rcudnn/cudnn/src/cudnn.rs#L27-L32

Without this drop, we will have a minor memory leak on each GPU run.

Complications

The simplest way to resolve this issue would be to secure the lifetime of CUDNN to the CUDA backend, either with a check for CUDNN in the user environment, or assuming anyone using CUDA has CUDNN.

The current dependency chain for Juice is that Coaster-NN depends on Coaster, and so we cannot modify the initialise for CUDA in Coaster-NN, or load in Coaster-NN code into Coaster.

My initial suggestion would be to recreate CUDNN as a mutatable global (Rc may be suitable as there should never be multiple calls to CUDNN happening across threads), but this doesn't prevent the issue that we don't have any struct to tie it to without requesting users have a second backend call just to load CUDNN.

@drahnr
Copy link
Member

drahnr commented Mar 9, 2020

Two cases where this is necessary:

  1. regular exit when calling std::process::exit()
  2. on panic

  1. is more difficult, in C/C++ there are exit hooks but I am not aware of any in rust, but it would be interesting to know when drop() is called and when it is not
  2. can be covered by creating a middleware panic handler which releases the cudnn handle, this can be done in the same lazy block https://doc.rust-lang.org/std/panic/index.html

@drahnr drahnr added the bug Something doesn't quite look right label Mar 13, 2020
@drahnr
Copy link
Member

drahnr commented Mar 13, 2020

@drahnr
Copy link
Member

drahnr commented Mar 31, 2020

Solution to #71

@drahnr drahnr linked a pull request Apr 4, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something doesn't quite look right
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants