Repository navigation
[Codegen][CPU] Select inner_tiled distribution tiles with the mmt4d cost model - #25130
shuangjuliu wants to merge 5 commits into
Conversation
|
Hello @shuangjuliu 👋 Thank you for submitting a Pull Request to IREE! It looks like this is your first one. We have one ask, and you can also find some general tips below. Action required: acknowledge IREE project policiesIREE is a Linux Foundation project. All participants are expected to follow the LF Projects Code of Conduct. All contributions to IREE must follow our IREE AI Tool Use Policy. In particular:
We kindly ask you to reply to this message and confirm that you understand and accept the cited policies, particularly the AI Tool Use Policy. General guidanceOur general Contributing guide contains information and links to detailed guides on code quality, testing, commit summaries and our CI system. A common point for new PRs: if a DCO signing check fails for you, check out the section on Developer Certificate of Origin. If you have any questions, feel free to leave a comment here, or ask away on IREE Discord. Thank you, |
I understand and accept the IREE project policies, including the AI Tool Use Policy. |
|
I'm sorry I was OOO so I couldn't have time to look at it, I'll try and take a look ASAP, hopefully tomorrow :) |
|
A quick look at the results: it looks way better! Thanks for this :) If you'd like, you could go further in your exploration and dive a bit into why the remaining diffs could be, e.g. if they are because of the ever-so-slightly different distribution heuristics, instruction-level issues, code bloat in the backend (extra P.S.: Could you fix the DCO in the meanwhile? |
3ddfe1b to
7bd5d55
Compare
|
Rebase and add DCO. |
egebeysel
left a comment
There was a problem hiding this comment.
Thanks for working on this! Generally LGTM :) You could maybe make the PR description a bit more concise.
Other than that, we could handle dynamic shapes like mmt4d does, i.e. substitute kTypicalDynamicSize = 1024 for dynamic extents instead of bailing out to one tile per workgroup. We would ideally add tests for these as well.
|
Should also probably fix the linter error. One more thing, the |
…e selection The old hardcoded tile=1 created too many small workgroups and degraded multi-thread matmul performance. Reuse the mmt4d cost model to select M/N tile counts, subject to memory budget and thread utilization scoring. Fall back to tile=1 for dynamic shapes, non-MMA and multi-output ops. Vector tiling unchanged. 540x516x332 f32 RVV now uses [18,1,0] (85 workgroups vs 1530). Add RVV and x86 strategy tests. Existing configs preserved. Towards iree-org#25028 (hardware benchmarking pending). Assisted-by: Claude Code, Qwen Signed-off-by: Shuangju.Liu <[email protected]>
…ed lit tests Pin the cost model's distribution picks for the iree-org#24932 shapes (64^3, 256^3, 81x41x19, 540x516x332) with packed operands from real compiles. The RVV file sweeps --iree-llvmcpu-number-of-threads=8/4/1 (small shapes consolidate tiles as threads drop; large stays [18,1,0]; dynamic falls back to [1,1,0]); the x86 file covers the same matrix at 8 threads. Assisted-by: Claude Code, Qwen, Doubao Signed-off-by: Shuangju.Liu <[email protected]>
…d empty tiles Follow-up to cost model to add fallback to tile-of-1 for two unpriceable cases. 1. Scalable/SVE tiles: SVE intrinsics return static base-VL shape but keep dynamic VL-dependent inner extents. Budgeting from base-VL underestimates footprint, causing bad workgroup selection. Check operand layouts and fall back on dynamic inner extents. 2. Empty M/N bounds: division by zero in the underutilization term crashed iree-opt. Empty shapes now use fallback. Tests: - AArch64 SVE: add scalable inner_tiled fallback case - RVV: add batched matmul + empty-M test - x86: add SMALLTILE variant under 65536 byte budget to lock known tile selections Towards iree-org#25028. Assisted-by: Claude Code, Qwen Signed-off-by: Shuangju.Liu <[email protected]>
…4d and inner_tiled Extract the duplicated distribution cost model from mmt4d and inner_tiled into shared helpers: MatmulTileModel, evalMatmulTileCost, matmulTileFitsBudget, and selectMatmulWorkgroupTile. Both config functions now fill a MatmulTileModel and call the shared search, shrinking their cost sections by ~35 and ~65 lines. No tile selection changes. The empty-M/N division-by-zero guard moves into the shared search, so mmt4d gains the same fix inner_tiled needed. Also clang-format the file and update test comments that named the moved functions. Assisted-by: Claude Code, Deepseek Signed-off-by: Shuangju.Liu <[email protected]>
Dynamic M/N/K outer bounds now substitute 1024 elements (mmt4d's kTypicalDynamicSize) instead of falling back to one tile per workgroup; the constant moves to file scope for both call sites. A dynamic inner tile (scalable SVE) still falls back. Tests: pin the substituted picks — [5,1,0] for all-dynamic, plus focused M/N/K cases ([34,2,0], [11,4,0]/[11,8,0], [1,2,0]). A full-pipeline run confirms dynamic inner_tiled lowers to llvm.riscv.vfmacc, so the old fallback was unnecessary. Assisted-by: Claude Code, Deepseek Signed-off-by: Shuangju.Liu <[email protected]>
1241cc7 to
464b9de
Compare
|
Updated and added tests. |
egebeysel
left a comment
There was a problem hiding this comment.
Thanks for updating, LGTM. Could you add a few benchmarking numbers for dynamically compiled matmuls ran with a few different sizes and dtypes? Also, I just assumed that these benchmarks are from a Jupiter 2 board, is that true? Could you add the board name to the description as well?
setRootConfigforiree_codegen.inner_tiledhardcoded the distributiontile to 1, so each workgroup computed a single inner tile over the full K
and large matmuls became thousands of tiny workgroups (1530 for
540x516x332 f32 on RVV), losing to the mmt4d ukernel path at 4/8 threads.
Port the
getMmt4dLoweringConfigcost model: pick tile counts perworkgroup among the divisors of the static M/N iteration bounds, filtered
by the
iree-llvmcpu-matmul-tile-bytesbudget over LHS+RHS+ACC bytes andscored by traversal cost weighted by thread underutilization. Inner tile
extents come from the op's
data_tiled_mma_layoutkind. Falls back to theprevious tile-of-1 for dynamic bounds, non-MMA kinds, or multi-output ops.
Vector tiling is unchanged, so the unit-bound lowering invariants and
ukernel ordering are preserved.
The 540x516x332 f32 RVV shape now selects [18, 1, 0]: 85 workgroups.
Tests: new select_riscv_inner_tiled_lowering_strategy.mlir pins the model
output and the dynamic-bounds fallback; a large x86 case is added to
select_x86_64_lowering_strategy.mlir. Existing pinned configs unchanged;
full LLVMCPU + ukernel lit suites pass.
Towards #25028 (hardware benchmarking pending).
Assisted-by: Claude Code, Qwen
Signed-off-by: Shuangju.Liu [email protected]
small: 64³ medium: 256³ rect: 81×41×19 large: 540×516×332
Legend: 🟢 ratio < 1.0 (inner_tiled faster) | 🔴 ratio ≥ 1.0 (ukernel faster or neutral)