Skip to content
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

Support adding CodeInstances to JIT for interpreters defining a codegen cache #57272

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

serenity4
Copy link
Contributor

@serenity4 serenity4 commented Feb 5, 2025

Implements a way to add CodeInstances compiled by external interpreters to JIT, such that they become legal targets for invoke calls.

Based on a design proposed by @Keno, the AbstractInterpreter interface is extended to support providing a codegen cache that is filled during inference for future use with add_codeinsts_to_jit!.

This allows invoke(f, ::CodeInstance, args...) to work on external interpreters, which is currently failing on master (see #57193).

@serenity4 serenity4 changed the title Add CodeInstances to JIT for interpreters defining a codegen cache Add CodeInstances to JIT for interpreters defining a codegen cache Feb 5, 2025
@serenity4 serenity4 changed the title Add CodeInstances to JIT for interpreters defining a codegen cache Support adding CodeInstances to JIT for interpreters defining a codegen cache Feb 5, 2025
@serenity4
Copy link
Contributor Author

I also believe that, instead of exposing add_codeinsts_to_jit!, we could define a more generic typeinf_ext_toplevel which would support arbitrary AbstractInterpreters and essentially call add_codeinsts_to_jit after typeinf_ext, as is already done for NativeInterpreter.

@Keno @vtjnash @aviatesk What do you think overall?

@gbaraldi
Copy link
Member

gbaraldi commented Feb 5, 2025

I'm a bit concerned about this, specifically because up to now everything that went into the JIT via the usual codepaths used the jl_create_native + JLJITAddLLVMIRModule. But this is not necessarily wrong, also @vchuravy probably has some comments on this

@gbaraldi gbaraldi requested a review from vchuravy February 5, 2025 16:15
@vtjnash
Copy link
Member

vtjnash commented Feb 6, 2025

This seems reasonable to me, based on the direction Keno has been going with invoke and these other interfaces

@serenity4
Copy link
Contributor Author

Seems like push!(::IdSet{CodeInstance}, ::CodeInstance) very rarely causes a segfault. I'm not sure what might be causing that given the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants