Skip to content

[Inductor] Improve memory locality by iterating over y dimension before x #149339

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

Closed
wants to merge 9 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions torch/_inductor/codegen/simd.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def filtered_index_map(seq, mask) -> dict[Any, int]:
val: idx for idx, val in enumerate(val for val in seq if val in mask)
}

grid_dims = ["x", "y", "z"]
grid_dims = ["z", "y", "x"]
reduction_dims = ["r0_", "r1_"]
if no_x_dim:
tensor_dims = reduction_dims
Expand Down Expand Up @@ -667,9 +667,9 @@ def getter(flat_vars: list[sympy.Expr]) -> sympy.Expr:
)
return_getters_groups.append(return_getters)

assert all(V.graph.sizevars.size_hint(s) == 1 for s in remaining), (
f"failed to set ranges {remaining} {lengths}"
)
assert all(
V.graph.sizevars.size_hint(s) == 1 for s in remaining
), f"failed to set ranges {remaining} {lengths}"

return new_ranges, return_getters_groups

Expand Down Expand Up @@ -818,12 +818,14 @@ def active_range_trees(self, reorder: bool = False) -> list[IterationRangesRoot]
trees = [
t for t in self.range_trees if not t.is_reduction or self.inside_reduction
]
if reorder and len(trees) > 1:
count = sum(t.prefix in "xyz" for t in trees)
assert "".join(t.prefix for t in trees[:count]) == "zyx"[-count:], [
t.prefix for t in trees[:count]
]
trees[:count] = reversed(trees[:count])

def tree_order(tree: IterationRangesRoot) -> int:
assert tree.tensor_dim is not None, f"Invalid tensor dim: {tree.tensor_dim}"
return tree.tensor_dim

if reorder:
trees = sorted(trees, key=tree_order)

return trees

def codegen_indexing(self, expr: sympy.Expr) -> sympy.Expr:
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy