Skip to content

Conversation

serenity4
Copy link
Member

@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
Member 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
Member Author

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

@serenity4 serenity4 marked this pull request as ready for review February 11, 2025 21:20
@serenity4
Copy link
Member Author

Crash was due to a reassignment of the local ci variable being lost when split into its own function.
Tests are now passing, this PR is ready for final review & merge.

@Keno Keno merged commit 9d2e9ed into JuliaLang:master Feb 17, 2025
4 of 7 checks passed
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
…egen cache (#57272)

Implements a way to add `CodeInstance`s 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).

---------

Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
(cherry picked from commit 9d2e9ed)
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
…egen cache (#57272)

Implements a way to add `CodeInstance`s 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).

---------

Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
(cherry picked from commit 9d2e9ed)
serenity4 added a commit to serenity4/julia that referenced this pull request May 1, 2025
…egen cache (JuliaLang#57272)

Implements a way to add `CodeInstance`s 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 JuliaLang#57193).

---------

Co-authored-by: Cédric Belmant <cedric.belmant@juliahub.com>
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.

4 participants