umar456 · GitHub

@umar456 added this to the 3.8.1 milestone

Aug 6, 2021

@umar456

@umar456 umar456 changed the title Fix reference count if array used in JIT operations. breaks evalMultiple Fix reference count if array used in JIT operations.

Aug 10, 2021

@umar456

9prady9

@umar456

9prady9

@umar456

The Node_map_t unordered_map object uses the pointer of the nodes for the key.
This worked because you could previously because the node buffer objects tracked
the buffer object's shared pointer. This required holding an additional
reference to the buffer object when an Array was used in a JIT operation. This
did not leak memory because both the buffer and the node were deleted when the
Array object was destroyed.
This commit creates a new hash function for the node pointers which dereferences
the Node pointers and if they are buffers, it checks the buffer's pointer and
its offset to determine if its unique. This approach allows us to remove the
call_once construct from the setData member function of the buffer node.
You can now create node objects for each invocation getNode function.

@umar456

Previously when an af::array was used in a jit operation and it was backed by a
buffer, a buffer node was created and the internal shared_ptr was stored in the
Array for future use and returned when getNode was called. This increased the
reference count of the internal buffer. This reference count never decreased
because of the internal reference to the shared_ptr.
This commit changes this behavior by createing new buffer nodes for each
call the getNode. We use the new hash function to ensure the equality of
the buffer node when the jit code is generated. This avoids holding the
call_once flag in the buffer object and simplifies the management of
the buffer node objects. Additionally when a jit node goes out of scope
the reference count decrements as expected.

@9prady9

Closed

jacobkahn added a commit to jacobkahn/flashlight that referenced this pull request

Feb 28, 2023
…hlight#1080)
Summary:
See title. These changes are due to arrayfire/arrayfire#3167, which updates and improves refcounting for ArrayFire arrays.
Pull Request resolved: flashlight#1080
Test Plan: CI
Reviewed By: richjames0
Differential Revision: D43633315
Pulled By: jacobkahn
fbshipit-source-id: 8f838a42c4b724953900b8ccccde6dac23e137ec

facebook-github-bot pushed a commit to flashlight/flashlight that referenced this pull request

Mar 1, 2023
Summary:
See title. These changes are due to arrayfire/arrayfire#3167, which updates and improves refcounting for ArrayFire arrays.
Pull Request resolved: #1080
Test Plan: CI
Reviewed By: richjames0
Differential Revision: D43633315
Pulled By: jacobkahn
fbshipit-source-id: d8ed1592b1d57f3d357d40386a1c571110ad1950

Read the original on github.com ↗