Skip to content

Commit fc8f7e4

Browse files
authored
Avoid stack overflow with eary OOM reporting. (#1937)
1 parent c497a2a commit fc8f7e4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/pool.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,29 @@ handle properly.
306306
"""
307307
struct OutOfGPUMemoryError <: Exception
308308
sz::Int
309-
info::MemoryInfo
309+
info::Union{Nothing,MemoryInfo}
310310

311-
OutOfGPUMemoryError(sz::Integer=0) = new(sz, MemoryInfo())
311+
function OutOfGPUMemoryError(sz::Integer=0)
312+
info = if task_local_state() === nothing
313+
# if this error was triggered before the TLS was initialized, we should not try to
314+
# fetch memory info as those API calls will just trigger TLS initialization again.
315+
nothing
316+
else
317+
MemoryInfo()
318+
end
319+
new(sz, info)
320+
end
312321
end
313322

314323
function Base.showerror(io::IO, err::OutOfGPUMemoryError)
315324
print(io, "Out of GPU memory")
316325
if err.sz > 0
317326
print(io, " trying to allocate $(Base.format_bytes(err.sz))")
318327
end
319-
println(io)
320-
memory_status(io, err.info)
328+
if err.info !== nothing
329+
println(io)
330+
memory_status(io, err.info)
331+
end
321332
end
322333

323334
"""

0 commit comments

Comments
 (0)