Add hoist_invariants() directive for semiring reductions - #9190
Open
alexreinking wants to merge 7 commits into
Open
Add hoist_invariants() directive for semiring reductions#9190alexreinking wants to merge 7 commits into
alexreinking wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## alexreinking/change-type #9190 +/- ##
============================================================
+ Coverage 70.25% 70.37% +0.11%
============================================================
Files 258 258
Lines 79605 79714 +109
Branches 19111 19141 +30
============================================================
+ Hits 55926 56097 +171
+ Misses 17939 17914 -25
+ Partials 5740 5703 -37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
alexreinking
marked this pull request as draft
July 6, 2026 14:22
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
2 times, most recently
from
July 20, 2026 15:28
9e244ff to
328fd0a
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
3 times, most recently
from
July 29, 2026 19:07
f2cbdc3 to
f271649
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
July 29, 2026 19:33
f271649 to
9660010
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
July 29, 2026 19:59
9660010 to
12834ac
Compare
4 tasks
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
July 30, 2026 12:45
12834ac to
d049c0c
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
July 30, 2026 13:35
d049c0c to
460d780
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
2 times, most recently
from
July 30, 2026 15:20
8f48f71 to
25be6cb
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
3 times, most recently
from
July 30, 2026 16:57
a26996d to
9787945
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
July 30, 2026 18:03
9787945 to
33e3729
Compare
abadams
reviewed
Jul 30, 2026
Member
|
Please add a test that turns a gaussian blur implemented as this: f(x, y) += kernel(r.x) * kernel(r.y) * input(x + r.x, y + r.y) into a separable implementation |
Member
|
Also it would be good to demo turning a one-step downsample into two-stage separable downsample (basically the same as the blur example but there's a stride) - it can be a lot faster to separate a downsample into a first stage that just downsamples in y, followed by a second that just downsamples in x. |
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
2 times, most recently
from
July 30, 2026 20:11
1c5f111 to
97c1c65
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
July 31, 2026 15:49
97c1c65 to
b237059
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
2 times, most recently
from
July 31, 2026 21:30
7f7fd7c to
cf8298e
Compare
alexreinking
marked this pull request as ready for review
August 1, 2026 03:18
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
August 4, 2026 19:39
cf8298e to
c6aed7f
Compare
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
August 4, 2026 21:37
c6aed7f to
7d6e34b
Compare
Introduce Stage::hoist_invariants(), which applies a semiring distributive law to hoist loop-invariant factors out of associative reductions. The returned intermediate accumulates the factor-free reduction over the original RDom, while the write-back applies the factor once. Support +/*, min/+, max/+, or/&&, and and/|| laws, including factors nested within associative chains. Add reusable binary-operator helpers, the Python binding, and correctness tests.
Add a quantized (int8 x int8 -> f32) mat-vec performance test targeting ARM's SDOT instruction, scheduled by composing eager_inline(), hoist_invariants(), rfactor(), and change_type(). eager_inline() folds the Wt and VecDq producers into Acc's update so their scale factors -- WtScale(i) and VecScale -- surface as explicit leaves that hoist_invariants() can then lift out of the reduction as the invariant product WtScale(i) * VecScale. rfactor() splits the now scale-free reduction by block, and change_type(Int(32)) retypes the innermost per-block dot product so CodeGen_ARM matches it to SDOT. The generated assembly contains sdot instructions, the Hoisted/PlainRfactor numerical cross-check passes, and the composed schedule is several times faster than the non-hoisting variant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: GPT 5.6 Sol <noreply@openai.com>
alexreinking
force-pushed
the
alexreinking/rfactor-hoisting
branch
from
August 4, 2026 22:13
7d6e34b to
c8dc9c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a scheduling directive similar to
rfactorthat hoists invariant factors according to a detected distributive (semiring) law into the write-back part of the accumulation step. This enables writing straightforward quantized kernels in the algorithm language and factoring them into efficient kernels.This is meant to work towards optimizing quantized mat-mul and mat-vec kernels (especially those from GGML).
Checklist