numba-dpex icon indicating copy to clipboard operation
numba-dpex copied to clipboard

Fixed ref-counting of Python object temporaries in unboxing code

Open oleksandr-pavlyk opened this issue 1 year ago • 5 comments

Ref-count of arrayobj was not decremented after use in case dpnp.ndarray object was being processed.

Change the flow of managing lifetime of Python temporaries in unboxing code. This PR replaces use of obj in NRT structure with use of arrayobj, and shifts ref-count manipulation of obj into PyUSMNdArray_ARRAYOBJ.

  • [x] Have you provided a meaningful PR description?
  • [ ] Have you added a test, reproducer or referred to an issue with a reproducer?
  • [ ] Have you tested your changes locally for CPU and GPU devices?
  • [ ] Have you made sure that new changes do not introduce compiler warnings?
  • [ ] If this PR is a work in progress, are you filing the PR as a draft?

oleksandr-pavlyk avatar May 09 '24 14:05 oleksandr-pavlyk

Check locally with unitrace - memory leak that @adarshyoga was reporting is resolved with this PR

ZzEeKkAa avatar May 09 '24 15:05 ZzEeKkAa

@oleksandr-pavlyk there are some compile time warnings after these changes.

diptorupd avatar May 09 '24 16:05 diptorupd

The memory leak that was occurring with pairwise distance workload is resolved with this fix. Thanks, @oleksandr-pavlyk .

adarshyoga avatar May 09 '24 17:05 adarshyoga

@oleksandr-pavlyk there are some compile time warnings after these changes.

Yes, I pushed a fix for them, by casting PyUSMArrayObject * pointer to PyObject * pointer, which is always safe to do.

oleksandr-pavlyk avatar May 09 '24 17:05 oleksandr-pavlyk

Coverage Status

coverage: 86.494% (+0.01%) from 86.48% when pulling 5dcf8af4d2909c96982e28ad524f14b22ab1412c on correct-refcount-handling-fixing-memory-leak into e36c97917ec97185b52839b800b2bc2f77b79e46 on main.

coveralls avatar May 09 '24 19:05 coveralls