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

Wma/precompile and docs #176

Merged
merged 29 commits into from
May 3, 2023
Merged

Wma/precompile and docs #176

merged 29 commits into from
May 3, 2023

Conversation

willow-ahrens
Copy link
Collaborator

@willow-ahrens willow-ahrens commented Apr 26, 2023

This PR is to finalize the compilation story with Finch. Writing compilers in Julia gets tricky when we want the user to interact with the compiler.

Julia uses a "world age" to describe the set of defined functions at a point in time. Generated functions run in the same world age in which they were defined, so they can't call functions defined after the generated function. This means that if Finch uses generated functions, users can't define their own functions without redefining the generated function.

This used to be automated by the Finch.register function that just evals the generator once again. However, this is not composable when multiple packages use Finch, so we began associating different worlds with different algebras. The idea was that different users could use different algebras for different sets of functions. Unfortunately, since Finch gets called from methods like Broadcast and stuff, it quickly became too complicated to automatically figure out which algebra was appropriate top evaluate the types in a broadcast.

The new approach is to use RuntimeGeneratedFunctions, which free up the world age. This does mean that every dynamic finch call will need a dictionary lookup and a dynamic function invocation < Turns out this approach had unacceptable overhead. Instead we figured out a way to call the generator in the latest world age, and left behind a trail of breadcrumbs in case anyone wanted to invalidate finch generated functions manually (with refresh()).

If we're careful, users probably don't need to ever call refresh() if everyone designs things so that they define all relevant properties before calling each kernel.

It's a compromise, but I think it delivers as much as possible on the idea of "Jitted tensor compiler in Julia".

@willow-ahrens
Copy link
Collaborator Author

Ping https://discourse.julialang.org/t/constant-propagation-vs-generated-functions/83788 when this is finished to relay my experience.

@codecov-commenter
Copy link

codecov-commenter commented Apr 26, 2023

Codecov Report

Patch coverage: 87.50% and project coverage change: -0.53 ⚠️

Comparison is base (5d7a370) 80.04% compared to head (cb61f2d) 79.51%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #176      +/-   ##
==========================================
- Coverage   80.04%   79.51%   -0.53%     
==========================================
  Files          49       49              
  Lines        4776     4663     -113     
==========================================
- Hits         3823     3708     -115     
- Misses        953      955       +2     
Impacted Files Coverage Δ
ext/SparseArraysExt.jl 68.81% <ø> (-5.06%) ⬇️
src/base/compare.jl 100.00% <ø> (ø)
src/base/index.jl 90.00% <ø> (-0.33%) ⬇️
src/util.jl 87.78% <66.66%> (-1.46%) ⬇️
src/Finch.jl 78.26% <100.00%> (-3.23%) ⬇️
src/base/broadcast.jl 76.28% <100.00%> (-0.48%) ⬇️
src/base/copy.jl 100.00% <100.00%> (ø)
src/base/mapreduce.jl 71.01% <100.00%> (+0.42%) ⬆️
src/execute.jl 87.94% <100.00%> (-0.42%) ⬇️
src/fibers.jl 67.40% <100.00%> (-0.48%) ⬇️

... and 15 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@willow-ahrens
Copy link
Collaborator Author

willow-ahrens commented Apr 26, 2023

TODO on this before merging:

  • Change other instances of generated functions that call finch functions to also be world-age safe
  • Add docs and tests about precompiling Finch functions

@willow-ahrens
Copy link
Collaborator Author

willow-ahrens commented May 2, 2023

I wonder if anyone who develops https://github.com/NHDaly/StagedFunctions.jl/blob/master/src/StagedFunctions.jl#L116, FluxML/Zygote.jl#22, or RuntimeGeneratedFunctions has any feedback on this approach.

@willow-ahrens willow-ahrens merged commit 1a3e466 into main May 3, 2023
@willow-ahrens willow-ahrens deleted the wma/precompile-and-docs branch May 3, 2023 19:21
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.

2 participants