Skip to content

Commit f07b7f7

Browse files
authored
[SWDEV-539076] Initial naive foreach autotune support (#2377)
Adds initial autotuning for foreach support required for https://ontrack-internal.amd.com/browse/SWDEV-539076 4x improvement for some kernels Before: triton_for_fused_18.kd 🔍 | 4.986 ms | 4.986 ms | 2.493 ms | 2 |   triton_for_fused_6.kd 🔍 | 0.098 ms | 0.098 ms | 0.049 ms | 2 |   triton_for_fused_7.kd 🔍 | 0.036 ms | 0.036 ms | 0.018 ms | 2 |   After: triton_for_fused_18.kd 🔍 | 1.273 ms | 1.273 ms | 0.636 ms | 2 |   triton_for_fused_6.kd 🔍 | 0.044 ms | 0.044 ms | 0.022 ms | 2 |   triton_for_fused_7.kd 🔍 | 0.024 ms | 0.024 ms | 0.012 ms | 2 |  
1 parent 30508ff commit f07b7f7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

torch/_inductor/codegen/triton_combo_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def jit_line(
614614
if heuristics == "foreach":
615615
heuristics_line = f"""
616616
@triton_heuristics.foreach(
617-
num_warps={self.num_warps},
617+
filename=__file__,
618618
triton_meta={triton_meta!r},
619619
inductor_meta={inductor_meta!r},
620620
)

torch/_inductor/runtime/triton_heuristics.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,20 +2213,29 @@ def user_autotune(
22132213
)
22142214

22152215

2216-
def foreach(triton_meta, num_warps, filename=None, inductor_meta=None):
2216+
def foreach(triton_meta, filename=None, inductor_meta=None):
22172217
"""
22182218
Compile a triton foreach kernel
22192219
"""
2220+
configs = []
2221+
if disable_pointwise_autotuning(inductor_meta) and not (
2222+
inductor_meta.get("max_autotune") or
2223+
inductor_meta.get("max_autotune_pointwise")
2224+
):
2225+
configs.append(triton.Config({}, num_stages=1, num_warps=8))
2226+
else:
2227+
for warps in [1, 2, 4, 8]:
2228+
configs.append(triton.Config({}, num_stages=1, num_warps=warps))
2229+
22202230
return cached_autotune(
22212231
None,
2222-
[triton.Config({}, num_stages=1, num_warps=num_warps)],
2232+
configs,
22232233
triton_meta=triton_meta,
22242234
inductor_meta=inductor_meta,
22252235
heuristic_type=HeuristicType.TEMPLATE,
22262236
filename=filename,
22272237
)
22282238

2229-
22302239
@dataclasses.dataclass
22312240
class GridExpr:
22322241
"""Generate code for grid size expressions in launcher"""

0 commit comments

Comments
 (0)