-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[inductor] Enable multilayer reductions with dynamic shapes #106747
Changes from 1 commit
e065717
4e6d7f5
4474dee
af8c3e0
d9bf419
27705b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -595,6 +595,9 @@ def num_splits( | |
def _is_static(x): | ||
return isinstance(x, (int, sympy.Integer)) | ||
|
||
reduction_numel_hint = V.graph.sizevars.symbolic_hint(reduction_numel) | ||
numel_hint = V.graph.sizevars.symbolic_hint(sympy_product(ranges)) | ||
|
||
should_split = ( | ||
is_triton(device) | ||
and reduction_type | ||
|
@@ -604,9 +607,9 @@ def _is_static(x): | |
"var_unnormalized", | ||
} | ||
and config.split_reductions | ||
and all(_is_static(r) for r in ranges) | ||
and all(_is_static(r) for r in reduction_ranges) | ||
and _is_static(reduction_numel) | ||
# We don't support unbacked symints | ||
and _is_static(reduction_numel_hint) | ||
and _is_static(numel_hint) | ||
Comment on lines
+611
to
+612
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be the case that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, we probably just want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw as a further step we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Say I had an expression There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That currently happens if the symbol is marked as non-negative. When that PR is merged, we'll leverage all the other information we may as part of the value range analysis and the constraints that are put in place during tracing time. |
||
) | ||
if not should_split: | ||
return ReductionHint.DEFAULT, 1 | ||
|
@@ -689,8 +692,6 @@ def outer_reduction_splits(reduction_numel_hint, numel_hint): | |
rvals_per_thread * split_size | ||
) | ||
|
||
reduction_numel_hint = V.graph.sizevars.size_hint(reduction_numel) | ||
numel_hint = V.graph.sizevars.size_hint(sympy_product(ranges)) | ||
# easy cases | ||
if numel_hint == 1: | ||
return ReductionHint.INNER, inner_reduction_splits( | ||
|
@@ -994,24 +995,14 @@ def create_multilayer( | |
""" | ||
reduction_numel = sympy_product(reduction_ranges) | ||
|
||
# TODO(jansel): convert this to dynamic shapes | ||
# TODO(jansel): realize the reduction so we can do dynamic indexing | ||
reduction_ranges = [ | ||
sympy.Integer(V.graph.sizevars.evaluate_static_shape(s)) | ||
for s in reduction_ranges | ||
] | ||
reduction_numel = sympy.Integer( | ||
V.graph.sizevars.evaluate_static_shape(reduction_numel) | ||
need_mask = not V.graph.sizevars.is_expr_static_and_true( | ||
sympy.Eq(reduction_numel % split, 0) | ||
) | ||
|
||
if V.graph.sizevars.size_hint(reduction_numel) % split == 0: | ||
need_mask = False | ||
else: | ||
need_mask = True | ||
|
||
split = sympy.Integer(split) | ||
block_size = FloorDiv(reduction_numel + (split - 1), split) | ||
|
||
# TODO(jansel): realize the reduction so we can do dynamic indexing | ||
reindex = View.dynamic_reshape_indexer(reduction_ranges, [reduction_numel]) | ||
|
||
def wrapper_fn(index, reduction_index): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe as a follow up, add guards based on the heuristics here:
pytorch/torch/_inductor/ir.py
Line 624 in 27705b3