You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it in principle possible to have some sort of a macro that would take a function and replace its inner calls to Vector{T}(undef, n) (and similar) with @alloc(T, n)? To me this appears possible after the calls are inlined and possibly some escape analysis applied but I have a very limited understanding of the problem.
So the macro could do something like:
functionmapsum(f, x)
arr =Vector{Float64}(undef, length(x))
arr .=f.(x)
returnsum(arr)
end
transforms into
functionmapsum_bumpered(f, x)
@no_escapebegin
arr =@alloc(Float64, length(x))
arr .=f.(x)
ans =sum(arr)
endreturn ans
end
Thanks!
The text was updated successfully, but these errors were encountered:
This isn't quite the same, but there is the package https://github.com/ericphanson/AllocArrays.jl which does something similar. I must say though, the idea makes me a bit uncomfortable. Without escape analysis available at code generation time, we can't really know if it's safe to do this transformation or not.
Thank you for the answer! AllocArrays.jl looks interesting, will try it out.
I agree the approach looks unsafe but I find it would help my workflow and speed up running a bunch of parallel simulations.
It's interesting also if some approaches can be done without full escape analysis. Like considering a function safe for Bumper transformation if it only returns isbits types. Or maybe inlining and then wrapping all remaining return statements in copy_if_bumpallocated that could tell if something is bump-allocated and copy to memory when it is.
Meanwhile, feel free to close the issue if that is something not relevant for Bumper.jl atm.
Is it in principle possible to have some sort of a macro that would take a function and replace its inner calls to
Vector{T}(undef, n)
(and similar) with@alloc(T, n)
? To me this appears possible after the calls are inlined and possibly some escape analysis applied but I have a very limited understanding of the problem.So the macro could do something like:
transforms into
Thanks!
The text was updated successfully, but these errors were encountered: