-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explore early finalization #2443
Comments
@vchuravy noted that this may also extend the lifetime of objects, up until the inserted finalizer whereas the GC could have collected it already if there were no outstanding references. Similar issues: JuliaLang/julia#51818, JuliaLang/julia#52533 (#2197). I'm not sure this is a blocker, but it's something to keep in mind, e.g., to make sure the finalizer is inserted as aggressively as possible: a = CuArray(...)
if likely()
a = nothing
# finalizer should be inserted here
while something_long()
# ...
end
else
use(a)
end
# finalizer should not be inserted here,
# or `a` would be kept alive across the while loop The above may not match how the finalizer insertion pass currently works; I haven't properly read into it yet. |
I believe the biggest current blocker is that the finalizer inlining pass currently assumes that all operations on the target object are inlined. In other words, even simple code like the following cannot currently perform finalizer inlining: @noinline function use(a)
... # uses a, but doesn't escape it to anywhere
end
let
Base.Experimental.@force_compile
a = CuArray(...)
use(a)
end Here, using EA to analyze that |
A while back I came up with the following example for where currently the GC fails us. For me early finalization is too fragile and too dependent on inlining.
|
That is too complex, so I would prefer a simpler target if possible. CUDA might also be complex once lowered though. |
This is pretty much the simplest thing. The only complexity here is the allocation tracking so that you can immediatly tell if you are successful. You can remove the tracker...
|
Started some work at JuliaLang/julia#55954. |
Julia support early finalization insertion, JuliaLang/julia#45272, however that does not trigger here because CuArrays' finalizers taints the TLS effect. Keno suggested just untainting that using
@assume_effects
, which we should explore.If that doesn't work / In addition, @aviatesk suggested exploring integrating early finalization insertion with escape analysis, which may make this optimization even more potent.
Let's first start with the untainting and coming up with a couple of MWEs to look into.
cc @jpsamaroo
The text was updated successfully, but these errors were encountered: