-
Notifications
You must be signed in to change notification settings - Fork 242
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
Nanobind leak warnings #758
Comments
Thanks for the small reproducer, that helps! I think part of the problem here is that Line 3700 in f5e1b7b
It needs to hold a reference, because it needs the context to free the SVM: Line 3786 in f5e1b7b
Nanobind's support for As an alternative to the complexity of shared ownership between C++ and Python, nanobind also has intrusive reference counting. Maybe that's worth a try, for all the cases where currently |
Actually, we may be dealing with what's described as the "uncollectable inter-language reference cycle" in nanobind's docs for intrusive RC. |
I feel like we should move to intrusive refcounting for context, queue, memory pools, and allocators. I'm out of time for today, but if you have time to get this started, I'd be open to looking at it. |
#759 is a start that already addresses your small reproducer. |
There still appear to be leak warnings (see e.g. https://github.com/inducer/pyopencl/actions/runs/9154012159/job/25163854069), but I can't reproduce them locally at the moment. |
Thanks for spotting that! For posterity:
We should track those down sometime. |
Could we disable these messages, e.g. by giving access to [nb::set_leak_warnings()] ?(https://nanobind.readthedocs.io/en/latest/faq.html#why-am-i-getting-errors-about-leaked-functions-and-types) |
One way to reproduce the warnings after b659cad is: $ python examples/demo-struct-reduce.py
nanobind: leaked 1 instances!
- leaked instance 0xaaaadcaedf00 of type "pyopencl._cl.Device"
nanobind: leaked 17 types!
- leaked type "pyopencl._cl.Device"
- leaked type "pyopencl._cl.SVMAllocator"
- leaked type "pyopencl._cl.SVMPointer"
- leaked type "pyopencl._cl.CommandQueue"
- leaked type "pyopencl._cl.PooledBuffer"
- leaked type "pyopencl._cl.ImmediateAllocator"
- leaked type "pyopencl._cl.AllocatorBase"
- leaked type "pyopencl._cl.Event"
- leaked type "pyopencl._cl.Buffer"
- leaked type "pyopencl._cl.Kernel"
- leaked type "pyopencl._cl.SVMPool"
- ... skipped remainder
nanobind: leaked 103 functions!
- leaked function "device_and_host_timer"
- leaked function "get_cl_header_version"
- leaked function "from_int_ptr"
- leaked function "_set_arg_multi"
- leaked function ""
- leaked function ""
- leaked function "set_arg"
- leaked function "__init__"
- leaked function "from_int_ptr"
- leaked function "get_host_array"
- leaked function "get_work_group_info"
- ... skipped remainder
nanobind: this is likely caused by a reference counting issue in the binding code. For some reason, these do not show up on my Mac, just on Linux. |
Describe the bug
At the end of execution, what appears to be SVM-related pyopencl code causes nanobind leak warnings to appear:
To Reproduce
$ cd pyopencl
$ python examples/demo_array_svm.py
(causes leak warnings)$ python examples/demo_array.py
(does not cause leak warnings)Edit:
Easiest way to reproduce:
(when not assigning to
f
, the warnings do not appear)Expected behavior
Don't show the warnings.
Environment (please complete the following information):
Additional context
Note that #755 does not address this issue.
The text was updated successfully, but these errors were encountered: