Skip to content

Allow hoisting invariant factors in rfactor#9190

Open
alexreinking wants to merge 9 commits into
mainfrom
alexreinking/rfactor-hoisting
Open

Allow hoisting invariant factors in rfactor#9190
alexreinking wants to merge 9 commits into
mainfrom
alexreinking/rfactor-hoisting

Conversation

@alexreinking

Copy link
Copy Markdown
Member

This PR adds a mode to rfactor that 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.

On my system (Apple M3 Max, 1 core), the schedule in test/performance/tiled_matmul_arm_neon.cpp outcompetes existing schedules:

Quantized mat-vec (int8 x int8 -> f32, SDOT)
Time with non-hoisting rfactor:  0.0871 ms
Time with hoisted rfactor:       0.0122 ms (7.13x vs non-hoisting)

The difference in performance is in mostly due to hoisted rfactor's ability to target SDOT instructions.

Breaking changes

No breaking changes. The mode is 100% opt-in.

Just like rfactor, it is possible to write equivalent algorithms that can be scheduled equally well. However, doing so is relatively finicky and more complicated.

Checklist

  • Tests added or updated (not required for docs, CI config, or typo fixes)
  • Documentation updated (if public API changed)
  • Python bindings updated (if public API changed)
  • Benchmarks are included here if the change is intended to affect performance.
  • Commits include AI attribution where applicable (see Code of Conduct)

@alexreinking alexreinking added the release_notes For changes that may warrant a note in README for official releases. label Jul 4, 2026
@alexreinking alexreinking changed the title Alexreinking/rfactor hoisting Allow hoisting invariant factors in rfactor Jul 4, 2026
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 68 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@2fad88f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/IROperator.cpp 36.66% 16 Missing and 22 partials ⚠️
src/Func.cpp 84.03% 6 Missing and 13 partials ⚠️
src/Func.h 33.33% 6 Missing ⚠️
src/AssociativeOpsTable.cpp 66.66% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9190   +/-   ##
=======================================
  Coverage        ?   69.37%           
=======================================
  Files           ?      254           
  Lines           ?    78427           
  Branches        ?    18789           
=======================================
  Hits            ?    54409           
  Misses          ?    18503           
  Partials        ?     5515           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_notes For changes that may warrant a note in README for official releases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant