Skip to content

Commit d91b736

Browse files
authored
fix: force finalize the buffers after precompile (#1522)
1 parent 9add8df commit d91b736

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

ext/ReactantCUDAExt.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ end
14891489
end
14901490
y = Reactant.ConcreteRArray([2.0]; client)
14911491
Reactant.Compiler.compile_mlir(square!, (y,); optimize=false)
1492+
finalize(y)
14921493
end
14931494
end
14941495

src/Precompile.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ if Reactant_jll.is_available()
6969
@static if precompilation_supported()
7070
x = ConcreteRNumber(2.0; client)
7171
Reactant.compile(sin, (x,); client, optimize=:all)
72+
finalize(x)
7273

7374
y = ConcreteRArray([2.0]; client)
7475
Reactant.compile(Base.sum, (y,); client, optimize=:all)
76+
finalize(y)
7577
end
7678
end
7779

src/xla/Buffer.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
abstract type AbstractBuffer end
22

3+
function free_buffer end
34
function synced_buffer end
45
function buffer_on_cpu end
56
function to_host end

src/xla/IFRT/Array.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mutable struct Array <: XLA.AbstractBuffer
33

44
function Array(buffer::Ptr{Cvoid}, owned::Bool=true)
55
!owned && return new(buffer)
6-
return finalizer(free_ifrt_array, new(buffer))
6+
return finalizer(XLA.free_buffer, new(buffer))
77
end
88
end
99

@@ -158,7 +158,7 @@ function Array(
158158
return Array(client, array, ifrt_sharding)
159159
end
160160

161-
@inline function free_ifrt_array(buffer::Array)
161+
@inline function XLA.free_buffer(buffer::Array)
162162
if buffer.buffer != C_NULL
163163
@ccall MLIR.API.mlir_c.ifrt_free_array(buffer.buffer::Ptr{Cvoid})::Cvoid
164164
end

src/xla/PJRT/Buffer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mutable struct Buffer <: XLA.AbstractBuffer
22
buffer::Ptr{Cvoid}
33

44
function Buffer(buffer::Ptr{Cvoid})
5-
return finalizer(free_buffer, new(buffer))
5+
return finalizer(XLA.free_buffer, new(buffer))
66
end
77
end
88

@@ -114,7 +114,7 @@ function Base.similar(a::Buffer, S::Type, dims::Dims)
114114
return Base.similar(Buffer, S, dims; client=XLA.client(a), device=XLA.device(a))
115115
end
116116

117-
@inline function free_buffer(buffer::Buffer)
117+
@inline function XLA.free_buffer(buffer::Buffer)
118118
sbuffer = buffer.buffer
119119
if sbuffer != C_NULL
120120
@ccall MLIR.API.mlir_c.PjRtBufferFree(sbuffer::Ptr{Cvoid})::Cvoid

0 commit comments

Comments
 (0)