Skip to content

Commit b94827b

Browse files
authored
More precompile memory fixups (#1525)
* More precompile memory fixups * fix * fix * fix * cleanup
1 parent 80013c4 commit b94827b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

ext/ReactantCUDAExt.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,16 @@ end
14891489
end
14901490
y = Reactant.ConcreteRArray([2.0]; client)
14911491
Reactant.Compiler.compile_mlir(square!, (y,); optimize=false)
1492-
finalize(y)
1492+
1493+
if y isa Reactant.ConcreteIFRTArray
1494+
Reactant.XLA.free_buffer(y.data.buffer)
1495+
y.data.buffer.buffer = C_NULL
1496+
else
1497+
for dat in y.data
1498+
Reactant.XLA.free_buffer(dat.buffer)
1499+
dat.buffer.buffer = C_NULL
1500+
end
1501+
end
14931502
end
14941503
end
14951504

src/Precompile.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,27 @@ 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)
72+
if x isa ConcreteIFRTNumber
73+
XLA.free_buffer(x.data.buffer)
74+
x.data.buffer.buffer = C_NULL
75+
else
76+
for dat in x.data
77+
XLA.free_buffer(dat.buffer)
78+
dat.buffer.buffer = C_NULL
79+
end
80+
end
7381

7482
y = ConcreteRArray([2.0]; client)
7583
Reactant.compile(Base.sum, (y,); client, optimize=:all)
76-
finalize(y)
84+
if y isa ConcreteIFRTArray
85+
XLA.free_buffer(y.data.buffer)
86+
y.data.buffer.buffer = C_NULL
87+
else
88+
for dat in y.data
89+
XLA.free_buffer(dat.buffer)
90+
dat.buffer.buffer = C_NULL
91+
end
92+
end
7793
end
7894
end
7995

0 commit comments

Comments
 (0)