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

CompilerDevTools: add proof of concept for caching runtime calls #57193

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

serenity4
Copy link
Contributor

This PR leverages new capabilities that have been implemented in #56660 to also support caching methods for runtime calls under a custom AbstractInterpreter.

In my understanding, the idea is that when executing code compiled with a custom AbstractInterpreter, only methods that can be compiled ahead of execution will be cached, because dynamic calls requiring runtime compilation will not have enough context to know which interpreter and cache to use. They will instead use the native interpreter and cache.

This sample package demonstrates a way to ensure that runtime calls go through an entry point (with_new_compiler) that provides the context required to use the right cache and interpreter for subsequent compilation.

I'd be happy to get feedback on the logic used to redirect runtime calls to with_new_compiler. Overloading optimize(::SplitCacheInterp) seemed the most convenient (right after that, the IRCode gets converted to a CodeInfo), but perhaps there might be a better place for it.

@serenity4
Copy link
Contributor Author

serenity4 commented Jan 29, 2025

Tests are currently not run in the main test suite, because of issues with invoke(f, ::CodeInstance, args...) for external interpreters on master (@Keno said he could have a look). If you want to try this out, you can build Julia with #56660 (efa917e).

@serenity4 serenity4 marked this pull request as draft January 29, 2025 11:05
@Keno
Copy link
Member

Keno commented Jan 29, 2025

Some concrete comments, but this is largely what I had in mind, yes.

@vchuravy
Copy link
Member

After many years of maintaining Cassette I distinctly dislike the approach to propagate the compiler through the IR.

That's why in #52964 I approached this from the "what if they compiler was a scoped-value" perspective.
A fundamental challenge of the override approach is the question how to handle "indirect" calls like task launches.

I could rebase #52964 if there is interest (beyond myself) in exploring that alternative approach.

@Keno
Copy link
Member

Keno commented Jan 29, 2025

This specific utility is just for testing compiler changes (and exercising the caching and foreign CodeInstance APIs) without prejudice to having, more general mechanism, for compiler switches.

@serenity4
Copy link
Contributor Author

serenity4 commented Jan 31, 2025

The bug on invoking CodeInstances was bisected to 5c88b72 (from #56880) (@Keno)

Keno pushed a commit that referenced this pull request Feb 17, 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 <[email protected]>
@Keno
Copy link
Member

Keno commented Feb 17, 2025

Should be rebasable now that #57272 is merged.

@serenity4 serenity4 marked this pull request as ready for review February 18, 2025 17:09
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