-
Notifications
You must be signed in to change notification settings - Fork 65
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
Something invalidating Enzyme.__init__
causes a heavy package load time penalty
#776
Comments
This should now be resolved by #881 |
I am not sure that fixed all instances. Need to confirm with an actual profile |
I just want to point out that this is still happening and causes ~18s load time increase to any package that recursively ends up getting Enzyme as a dependency. |
hm @KristofferC do you have any information regarding what could be causing this? |
|
is there a tool or something to profile what methods/invalidations are the source? |
One would usually use SnoopCompile. I can try (later) to see if I can find what actually ends up invalidating it. |
I will note that the Enzyme Blas init loader presently is expected to have a long load time and I'm not sure of how to fix that. Specifically here: Enzyme.jl/src/compiler/validation.jl Line 67 in 9829494
We need the runtime address of blas and julia runtime libraries to be able to identify what function is being ccall'ed (in IR it is an integer). This is definitionally runtime information so it couldn't be preserved. If you have ideas for a design that avoid the expense, I'm all ears. If it's somewhere else causing the issue definitely interested in what's causing it so we can fix it. |
But:
is some sort of MWE. Will narrow it down more. |
Okej, Tracker committed the mortal sin of defining
Anyway, as a question, is there anyway this work can be moved from |
It seems to me that that |
From some testing, it seems the Lines 2425 to 2454 in 019258a
|
Okay if that init takes longer to compile I am a bit more unclear how to resolve it. So some context, this code interfaces between Enzyme proper (aka Enzyme_jll) and Enzyme.jl to registister all of the julia specific handling. As a result this actually is most of Enzyme.jl's code, so this is highly desirable to be precompiled. this is done by taking many functions in Julia code, making a cfunction of it, then passing the Julia cfunction runtime pointer into Enzyme_jll. While the actual call to pass the pointer (and the pointer itself) are runtime specific values, the actual compilation of those cfunctions on those specified types is fixed, and should be in theory able to be precompiled (but I presume not in practice here). Those cfunctions are wrapped in a macro (see here: Enzyme.jl/src/rules/llvmrules.jl Line 1030 in 019258a
Regardless, I'm not sure what the state of julia internals for precompilation are here, but that's what I can see from our end. |
Running the KristofferC@4246ddb#diff-21145f7299f4174cfb41f7c0c845a0ee798fc065bae0a352171552dc4b810508R1033 However, I have no idea what impact this has on runtime performance so that would have to be investigated. Might not be a good idea at all. |
Yeah disabling optimizations seems like a bad idea.
Is there any other way we can cut down on load time here?
…On Mon, Nov 20, 2023 at 3:29 AM Kristoffer Carlsson < ***@***.***> wrote:
Running the register_llvm_rules() in a module where optimizations are
turned off more or less fixes the bad behavior:
***@***.***
#diff-21145f7299f4174cfb41f7c0c845a0ee798fc065bae0a352171552dc4b810508R1033
<KristofferC@4246ddb#diff-21145f7299f4174cfb41f7c0c845a0ee798fc065bae0a352171552dc4b810508R1033>
However, I have no idea what impact this has on runtime performance so
that would have to be investigated. Might not be a good idea at all.
—
Reply to this email directly, view it on GitHub
<#776 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJTUXDWSHKOS7FYUK3RHJDYFMWGZAVCNFSM6AAAAAAXJ25G6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJYG43TMOJXGE>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
I guess these are the possibilities:
|
I think disabling optimizations for the registration functions should be fine. |
That's what I was worried about as well. I think the compilation time was in fact partly due to inferring the callbacks so my change making things faster probably means the callbacks also stopped getting inferred... |
When loading OmniPackage.jl(https://github.com/JuliaComputing/OmniPackage.jl/) a big part of its load time (around 10s) is spent compiling and running the
__init__
method in Enzyme, profile available at https://kristofferc.github.io/tracy-traces/omnipackage/.Ideally, Enzyme would somehow protect itself against this, by either making the code in
__init__
less vulnerable to invalidations or some other way (maybe using a frozen world age).cc @vchuravy
The text was updated successfully, but these errors were encountered: