From 15bd5544681d45d5bf83699c1dbcd2fe4ab57298 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 13 Oct 2026 12:25:39 +0200 Subject: [PATCH] Free resized buffers with release, not free. 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 --- src/array.jl | 2 +- test/array.jl | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/array.jl b/src/array.jl index 1a86dbb24..a0f2d520d 100644 --- a/src/array.jl +++ b/src/array.jl @@ -652,7 +652,7 @@ function Base.resize!(a::oneVector{T}, n::Integer) where {T} unsafe_copyto!(ctx, dev, ptr, pointer(a), m) end new_data = DataRef(buf) do buf - free(buf) + release(buf) end unsafe_free!(a) diff --git a/test/array.jl b/test/array.jl index 20355905f..c09cfbd69 100644 --- a/test/array.jl +++ b/test/array.jl @@ -209,6 +209,22 @@ end @test length(b) == 0 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 end # Reductions and scans come from GPUArrays (AcceleratedKernels). oneAPI used to work around