Skip to content

Commit 2bafed4

Browse files
authored
[FlyDSL] Cache compiled FlyDSL launchers on host paths (#6946)
* Cache compiled FlyDSL launchers on production host paths * Keep host-launch caching scoped to live FlyDSL paths * Preserve compiled launch safety across buffer ranks and compile-only mode * Remove extra dispatch tests and redundant table flattening * Cache remaining gfx1250 GEMM projection and MegaMoE launchers
1 parent 5af8354 commit 2bafed4

14 files changed

Lines changed: 297 additions & 165 deletions

‎aiter/ops/flydsl/batched_gemm_mxfp4.py‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from aiter.jit.utils.chip_info import get_gfx
1717

18-
from .kernels.tensor_shim import ptr_arg
18+
from .kernels.tensor_shim import _run_compiled, ptr_arg
1919

2020
SCALE_GROUP_SIZE = 32
2121
WMMA_K_GFX1250 = 128
@@ -437,12 +437,13 @@ def flydsl_batched_gemm_a8w4_v2(
437437
)
438438

439439
a_c = a.contiguous()
440-
_launch_v2(
441-
out_phys,
440+
_run_compiled(
441+
_launch_v2,
442+
out_phys.view(-1),
442443
ptr_arg(a_c),
443444
ptr_arg(w),
444-
a_scales.view(torch.int32),
445-
w_scales.view(torch.int32),
445+
a_scales.view(torch.int32).view(-1),
446+
w_scales.view(torch.int32).view(-1),
446447
M,
447448
torch.cuda.current_stream(),
448449
N,
@@ -459,5 +460,19 @@ def flydsl_batched_gemm_a8w4_v2(
459460
a_is_fp4,
460461
cluster_m,
461462
cluster_n,
463+
specialization_key=(
464+
tile_m,
465+
tile_n,
466+
tile_k,
467+
m_warp,
468+
n_warp,
469+
out_is_f16,
470+
B,
471+
layout_mbn,
472+
num_buffers,
473+
a_is_fp4,
474+
cluster_m,
475+
cluster_n,
476+
),
462477
)
463478
return out_phys.transpose(0, 1) if layout == "mbn" else out_phys

‎aiter/ops/flydsl/bpreshuffle_gemm_gfx1250.py‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,29 @@ def run_preshuffle_gemm_a8_gfx1250(
163163
gemm_out = Out if partials is None else partials
164164
out_is_f16 = 1 if out_dtype == "f16" else 0
165165

166+
gemm_spec = (
167+
tile_m,
168+
tile_n,
169+
tile_k,
170+
m_warp,
171+
n_warp,
172+
out_is_f16,
173+
nb,
174+
cluster_m,
175+
cluster_n,
176+
False, # is_mxscale
177+
SCALE_BLOCK_SIZE,
178+
split_k,
179+
False, # batched
180+
0, # preload_ks
181+
False, # a_preshuffle
182+
False, # a_scale_preshuffled
183+
False, # b_scale_32x32
184+
False, # k_tail
185+
)
166186
stream = _fx.Stream(torch.cuda.current_stream(device=XQ.device))
167-
_launch_gemm_a8w8(
187+
_run_compiled(
188+
_launch_gemm_a8w8,
168189
_ptr_arg(gemm_out),
169190
_ptr_arg(XQ),
170191
_ptr_arg(WQ),
@@ -177,18 +198,10 @@ def run_preshuffle_gemm_a8_gfx1250(
177198
0,
178199
lda,
179200
ldc,
180-
tile_m,
181-
tile_n,
182-
tile_k,
183-
m_warp,
184-
n_warp,
185-
out_is_f16,
186-
nb,
187-
cluster_m,
188-
cluster_n,
189-
False,
190-
SCALE_BLOCK_SIZE,
191-
split_k,
201+
*gemm_spec[:14],
202+
1, # batch (runtime)
203+
*gemm_spec[14:],
204+
specialization_key=gemm_spec,
192205
)
193206
if partials is not None:
194207
dense = ldc == N

‎aiter/ops/flydsl/gather_kv_b_proj_gfx1250.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def _projection_runtime():
2222
from .kernels.gather_kv_b_proj_gfx1250 import (
2323
launch_gather_kv_b_proj_8wave_gfx1250,
2424
)
25-
from .kernels.tensor_shim import ptr_arg
25+
from .kernels.tensor_shim import _run_compiled, ptr_arg
2626

27-
return launch_gather_kv_b_proj_8wave_gfx1250, ptr_arg, fx
27+
return launch_gather_kv_b_proj_8wave_gfx1250, ptr_arg, fx, _run_compiled
2828

2929

3030
def _cluster_n(m: int, n_heads: int) -> int:
@@ -45,7 +45,7 @@ def _run_projection(
4545
cluster_n: int,
4646
) -> None:
4747
"""Launch the fixed-width indexed MLA WMMA kernel."""
48-
launch_projection, ptr_arg, fx = _projection_runtime()
48+
launch_projection, ptr_arg, fx, run_compiled = _projection_runtime()
4949

5050
scale_is_ptr = activation_scale.device.type != "cpu"
5151
scale_ptr = activation_scale if scale_is_ptr else cache
@@ -62,7 +62,13 @@ def _run_projection(
6262
0.0 if scale_is_ptr else float(activation_scale),
6363
fx.Stream(torch.cuda.current_stream(device=cache.device)),
6464
)
65-
launch_projection(*args, n_heads, int(scale_is_ptr), cluster_n)
65+
projection_spec = (n_heads, int(scale_is_ptr), cluster_n)
66+
run_compiled(
67+
launch_projection,
68+
*args,
69+
*projection_spec,
70+
specialization_key=projection_spec,
71+
)
6672

6773

6874
def unsupported_reason(

‎aiter/ops/flydsl/grouped_gemm_mxfp4.py‎

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import torch
1111

1212
from .kernels.mega_moe_gfx1250.types import Stage2ScatterContext
13-
from .kernels.tensor_shim import ptr_arg
13+
from .kernels.tensor_shim import _run_compiled, ptr_arg
1414

1515
_SUPPORTED_CLUSTER_M = (1, 2, 4)
1616
_SUPPORTED_CLUSTER_N = (1, 2, 3, 4)
@@ -160,7 +160,11 @@ def flydsl_grouped_gemm_a8w4_masked(
160160
num_buffers = min(num_buffers, max(1, k_tiles))
161161
has_bias = 1 if bias is not None else 0
162162
bias_ptr = ptr_arg(bias) if bias is not None else ptr_arg(a)
163-
quant_scale_tensor = out if quant_scale is None else quant_scale.view(torch.uint8)
163+
# These tensor arguments only supply base addresses, so normalize their
164+
# ranks without specializing the compiled callable on buffer shapes.
165+
quant_scale_tensor = (
166+
out if quant_scale is None else quant_scale.view(torch.uint8)
167+
).view(-1)
164168
n_tiles = (N + tile_n - 1) // tile_n
165169
cluster_n = _select_cluster_n(n_tiles, cluster_n)
166170
cluster_m = _select_cluster_m(cluster_m, cluster_n, stage1_act)
@@ -205,16 +209,8 @@ def flydsl_grouped_gemm_a8w4_masked(
205209
f"{stage2_scatter.combine_quant_bits} needs N % {n_align} == 0 to "
206210
f"keep the scale plane cache-line aligned, got N={N}"
207211
)
208-
ep_row_map_tensor = ep_row_map if ep_row_map is not None else out
209-
launch_gemm_a8w4_tdm(
210-
out,
211-
ptr_arg(a),
212-
ptr_arg(w),
213-
a_scales.view(torch.int32),
214-
w_scales.view(torch.int32),
215-
contiguous_m,
216-
stream,
217-
N,
212+
ep_row_map_tensor = (ep_row_map if ep_row_map is not None else out).view(-1)
213+
gemm_spec = (
218214
K,
219215
tile_m,
220216
tile_n,
@@ -224,42 +220,64 @@ def flydsl_grouped_gemm_a8w4_masked(
224220
out_is_f16,
225221
num_buffers,
226222
a_is_fp4,
227-
ptr_arg(m_tile_map),
228-
n_experts,
229-
stage1_act,
230-
has_bias,
231-
bias_ptr,
232-
float(swiglu_limit),
233-
stage1_quant_out,
234-
quant_wmma_rep,
235-
quant_scale_tensor,
223+
)
224+
route_spec = (n_experts, stage1_act, has_bias)
225+
quant_spec = (stage1_quant_out, quant_wmma_rep)
226+
tdm_spec = (
236227
cluster_n,
237228
cluster_m,
238229
_select_bool_env("AITER_TDM_NEXT_STAGE_PREFETCH", next_stage_prefetch),
239230
waves_per_tensor_tdm,
240231
_select_bool_env("AITER_GROUPED_GEMM_AS_PROLOGUE", tdm_as_in_prologue),
241232
_select_tdm_b_th(tdm_b_th),
242-
enable_ep_scatter=int(enable_ep_scatter),
243-
ep_arena_handle=(int(stage2_scatter.arena_handle) if enable_ep_scatter else 0),
244-
ep_combine_input_offset=(
245-
int(stage2_scatter.combine_input_offset) if enable_ep_scatter else 0
246-
),
247-
ep_slot_stride_bytes=(
248-
int(stage2_scatter.slot_stride_bytes) if enable_ep_scatter else 0
249-
),
250-
ep_destination_stride=int(ep_destination_stride),
251-
ep_world_size=int(stage2_scatter.world_size) if enable_ep_scatter else 0,
252-
ep_quant_bits=(
253-
int(stage2_scatter.combine_quant_bits) if enable_ep_scatter else 0
233+
)
234+
ep_spec = (
235+
int(enable_ep_scatter),
236+
int(stage2_scatter.arena_handle) if enable_ep_scatter else 0,
237+
int(stage2_scatter.combine_input_offset) if enable_ep_scatter else 0,
238+
int(stage2_scatter.slot_stride_bytes) if enable_ep_scatter else 0,
239+
int(ep_destination_stride),
240+
int(stage2_scatter.world_size) if enable_ep_scatter else 0,
241+
int(stage2_scatter.combine_quant_bits) if enable_ep_scatter else 0,
242+
)
243+
layout_spec = (
244+
int(row_major_ascale),
245+
int(a_row_stride_bytes),
246+
int(a_scale_row_stride_bytes),
247+
int(lds_soa_load_interleave),
248+
persistent_workers,
249+
rolled_drain,
250+
)
251+
_run_compiled(
252+
launch_gemm_a8w4_tdm,
253+
out.view(-1),
254+
ptr_arg(a),
255+
ptr_arg(w),
256+
a_scales.view(torch.int32).view(-1),
257+
w_scales.view(torch.int32).view(-1),
258+
contiguous_m,
259+
stream,
260+
N,
261+
*gemm_spec,
262+
ptr_arg(m_tile_map),
263+
*route_spec,
264+
bias_ptr,
265+
float(swiglu_limit),
266+
*quant_spec,
267+
quant_scale_tensor,
268+
*tdm_spec,
269+
*ep_spec,
270+
ep_row_map_tensor,
271+
float(situ_beta),
272+
float(situ_linear_beta),
273+
*layout_spec,
274+
specialization_key=(
275+
gemm_spec,
276+
route_spec,
277+
quant_spec,
278+
tdm_spec,
279+
ep_spec,
280+
layout_spec,
254281
),
255-
arg_ep_row_map=ep_row_map_tensor,
256-
f32_situ_beta=float(situ_beta),
257-
f32_situ_linear_beta=float(situ_linear_beta),
258-
row_major_ascale=int(row_major_ascale),
259-
a_row_stride_bytes=int(a_row_stride_bytes),
260-
a_scale_row_stride_bytes=int(a_scale_row_stride_bytes),
261-
lds_soa_load_interleave=int(lds_soa_load_interleave),
262-
persistent_workers=persistent_workers,
263-
rolled_drain=rolled_drain,
264282
)
265283
return out

0 commit comments

Comments
 (0)