Repository navigation
Free resized buffers with release, not free - #684
Merged
Merged
Conversation
The buffer allocated by resize! was freed with a bare free(), bypassing everything release() does: decrementing the allocation counter used by the proactive-GC heuristics, synchronizing queues before freeing on the LTS stack, using the blocking free policy, and skipping empty buffers. The latter made freeing an array resized to zero length throw ZE_RESULT_ERROR_INVALID_ARGUMENT. Fixes #667
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/test/array.jl b/test/array.jl
index c09cfbd..e2b714c 100644
--- a/test/array.jl
+++ b/test/array.jl
@@ -210,21 +210,21 @@ end
resize!(b, 1)
@test length(b) == 1
- # resized buffers are released through the pool, like freshly allocated ones
- c = oneArray{Float32}(undef, 4)
- resize!(c, 0)
- oneAPI.unsafe_free!(c)
-
- GC.enable(false)
- try
- d = oneArray{Float32}(undef, 1024)
- before = oneAPI._allocated_bytes[]
- resize!(d, 1 << 20)
- oneAPI.unsafe_free!(d)
- @test oneAPI._allocated_bytes[] == before - sizeof(Float32) * 1024
- finally
- GC.enable(true)
- end
+ # resized buffers are released through the pool, like freshly allocated ones
+ c = oneArray{Float32}(undef, 4)
+ resize!(c, 0)
+ oneAPI.unsafe_free!(c)
+
+ GC.enable(false)
+ try
+ d = oneArray{Float32}(undef, 1024)
+ before = oneAPI._allocated_bytes[]
+ resize!(d, 1 << 20)
+ oneAPI.unsafe_free!(d)
+ @test oneAPI._allocated_bytes[] == before - sizeof(Float32) * 1024
+ finally
+ GC.enable(true)
+ end
end
# Reductions and scans come from GPUArrays (AcceleratedKernels). oneAPI used to work around |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #684 +/- ##
==========================================
- Coverage 81.17% 79.58% -1.59%
==========================================
Files 52 51 -1
Lines 4085 3953 -132
==========================================
- Hits 3316 3146 -170
- Misses 769 807 +38 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The buffer that
resize!allocates was freed by a finalizer callingfree(buf)instead ofrelease(buf), as the array constructor does. That bypassed the allocation accounting used by the proactive-GC heuristics, the queue synchronization on the LTS stack that keeps NEO from unmapping memory with work in flight, and the blocking free policy. It also broke arrays resized to zero length:releaseskips empty buffers, whilefreepassed the null pointer tozeMemFreeand threwZE_RESULT_ERROR_INVALID_ARGUMENT.Fixes #667