Repository navigation
[Codegen][CPU] Fold reshapes into map_store per reassociation group. - #24535
Conversation
a8e703f to
e880789
Compare
fd5a727 to
ba0c333
Compare
egebeysel
left a comment
There was a problem hiding this comment.
Generally looks good to me, but I might be missing some context here. Does this only change the behavior on the CPU and not GPU?
ba0c333 to
b57e003
Compare
e880789 to
9816c54
Compare
b57e003 to
c3a3ad5
Compare
egebeysel
left a comment
There was a problem hiding this comment.
thanks, LGTM % one test comment.
c3a3ad5 to
e9aee6a
Compare
egebeysel
left a comment
There was a problem hiding this comment.
LGTM, just the test comments Claude generated are a bit too verbose this time :)
|
|
||
| // ----- | ||
|
|
||
| // Pre-PR (now-removed) global form: one `affine.delinearize_index` over the |
There was a problem hiding this comment.
could we rewrite these comments from a higher level perspective without mentioning pre-PR, or implementation level details, just mentioning that the per-group fold avoids the divsi in both the positive and negative tests?
There was a problem hiding this comment.
Same treatment in the latest push. The function-level comment now reads "Negative case for contrast: a global affine.delinearize_index over a fully dynamic result shape — the per-group fold avoids producing this IR," and the CHECK-line comment is one sentence: "Scalarizes to runtime-divisor arith.divsi/remsi (divisors are arith.muli products of the dynamic factors) — the cost the per-group fold avoids." Same trim on the positive test (@lowered_per_group_no_division) and on the top-of-file EXPAND RUN-line comment.
|
|
||
| // ----- | ||
|
|
||
| // Pre-PR vs. new lowering -- contrast the post-`affine-expand-index-ops` shape |
There was a problem hiding this comment.
ditto, can be much shorter and just mention what the per-group (de-)linearize enables/avoids.
There was a problem hiding this comment.
Done in the latest push — the block is now four lines, framed in terms of what the per-group fold does (lowered body is division-free; uses muli/addi by the static tile size) and what it avoids (runtime-divisor arith.divsi/remsi from a global delinearize_index over the full dynamic shape). No "pre-PR" or foldReshapeIntoMapStore references.
2f3d68f to
47fb47a
Compare
`foldReshapeIntoMapStore` composed an expand/collapse reshape into a `map_store`'s index transformation via one global `linearize` over the source shape plus `delinearize` over the result shape. Under dynamic shapes that `delinearize` lowers to a dynamic integer division per element. Fold each reassociation group independently instead: an `expand_shape` splits one source index by just that group's result sizes; a `collapse_shape` merges one group of source indices. The split/merge factors are then per-group -- typically static tile sizes -- so the scalarized transformation is static shifts/masks with no per-element division. Speeds up the i8 data-tiled matmul's C-encode dispatch; i8 inner_tiled matmul, 4096x4096 on Zen 4: 52.9ms -> 46.9ms. Also document, at `MapStoreOpVectorizationModel::isVectorizable`, why a CPU-tiled `map_store` reaches the vectorizer dynamically shaped and scalarizes -- which is precisely what makes this per-group, division-free fold matter -- while the same op vectorizes on GPU. Comment only, no behavior change. Progress towards #24515. Co-Authored-By: Claude Opus 4.7 <[email protected]> Signed-off-by: Benoit Jacob <[email protected]>
47fb47a to
7598a04
Compare
foldReshapeIntoMapStorecomposed an expand/collapse reshape into amap_store's index transformation via one globallinearizeover the source shape plusdelinearizeover the result shape. Under dynamic shapes thatdelinearizelowers to a dynamic integer division per element.Fold each reassociation group independently instead: an
expand_shapesplits one source index by just that group's result sizes; acollapse_shapemerges one group of source indices. The split/merge factors are then per-group -- typically static tile sizes -- so the scalarized transformation is static shifts/masks with no per-element division.Speeds up the i8 data-tiled matmul's C-encode dispatch; i8 inner_tiled matmul, 4096x4096 on Zen 4: 52.9ms -> 46.9ms.
Also document, at
MapStoreOpVectorizationModel::isVectorizable, why a CPU-tiledmap_storereaches the vectorizer dynamically shaped and scalarizes -- which is precisely what makes this per-group, division-free fold matter -- while the same op vectorizes on GPU. Comment only, no behavior change.Progress towards #24515.