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

Support finalizers for MemObjects #15

Open
nshepperd opened this issue Aug 12, 2016 · 0 comments
Open

Support finalizers for MemObjects #15

nshepperd opened this issue Aug 12, 2016 · 0 comments

Comments

@nshepperd
Copy link

In the neural network framework I'm writing, explicitly freeing MemObjects isn't really practical.
I've tried storing the MemObject in an MVar and attaching a finalizer to that, but these finalizers aren't guaranteed to run promptly, and often didn't run at all, which would eventually result in running out of gpu resources (I'm actually not sure if this is a ghc bug -- what's the point of having finalizers at all if they can legally be thrown away?).

Foreign.ForeignPtr C finalizers (FinalizerPtr) are guaranteed to run promptly, but unfortunately I can't use these since the Ptr inside of MemObject isn't exposed. I've hacked it at the moment by making a local version of hopencl exporting ClMem, CMem and the MemObject constructor. But it would be nice to have some kind of official support.

Also, maybe we would consider using FinalizerPtr for the other types? Promptly released resources are always good, if less critical for things like CommandQueues and Contexts that are less frequently created and destroyed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant