-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathutils.jl
More file actions
50 lines (43 loc) · 1.38 KB
/
utils.jl
File metadata and controls
50 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
isdebug(group) = Base.CoreLogging.current_logger_for_env(Base.CoreLogging.Debug, group, oneL0) !== nothing
# Registered callbacks invoked during memory reclamation (e.g., flushing deferred MKL
# sparse handle releases). Extensions like oneMKL can register cleanup functions here
# so they run when Level Zero reports OOM or when proactive GC fires.
const _reclaim_callbacks = Function[]
function register_reclaim_callback!(f::Function)
return push!(_reclaim_callbacks, f)
end
function _run_reclaim_callbacks()
for cb in _reclaim_callbacks
try
cb()
catch
end
end
return
end
function retry_reclaim(f, isfailed)
ret = f()
# slow path, incrementally reclaiming more memory until we succeed
if isfailed(ret)
phase = 1
while true
if phase == 1
GC.gc(false)
elseif phase == 2
GC.gc(true)
elseif phase == 3
# After GC, finalizers may have deferred resource releases (e.g., MKL
# sparse handles). Flush them now, then GC again to free the memory
# those releases made available.
_run_reclaim_callbacks()
GC.gc(true)
else
break
end
phase += 1
ret = f()
isfailed(ret) || break
end
end
ret
end