JuliaLabs / Cassette.jl

Overdub Your Julia Code
Other
371 stars 35 forks source link

Is there a way to bail out of overdubbing? #180

Closed marius311 closed 3 years ago

marius311 commented 3 years ago

I'd love to use Cassette to do some nifty things with my code but just a no-op overdub already makes it run 10x slower (probably stuff related to https://github.com/jrevels/Cassette.jl/issues/91). My gut feeling (could well be wrong) is that if I could bail out of overdubbing before I get to the very bottom of my call tree, I can still do everything I want with the high-level function calls but not take the overhead. Is there any mechanism to do this, or would it even work? I'm thinking something like prehook could return a boolean of whether to actually overdub the expression, and if it was false, it would just call the original function.

vchuravy commented 3 years ago

Since Cassette is the land of endless possibilty variants of that are indeed possible. You can write a bespoke pass that inserts Expr(:nooverdub, ...) around the arguments to call.

https://github.com/JuliaGPU/KernelAbstractions.jl/blob/17469f21826970e4ff14a938e16159c2fb1df524/src/compiler/pass.jl#L66

Now what condition you want to have for that is up to you and depends on what you need to do.

marius311 commented 3 years ago

Thanks, that's interesting. Another option I've found is basically what AutoPreallocation.jl does, just define a no-op overdub at the point you want to stop: https://github.com/oxinabox/AutoPreallocation.jl/blob/1013ac618749ac3bd3534162cb6c176e4c6d19bf/src/inference_fixes.jl#L3-L22