Skip to content
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
727dd89
flydsl implementation of a16w16 gemm, WIP
omuhamma Apr 13, 2026
aa50b0e
Code styling and unit test fixes
omuhamma Apr 20, 2026
eb82c24
UT update
omuhamma Apr 20, 2026
d8ebec7
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Apr 20, 2026
0166ffe
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Apr 28, 2026
6e04e37
code updates, best runs
Boss2002n Jul 11, 2026
a356320
Kernel updates,split k for smaller configs and unroll variable
omuhamma Jul 16, 2026
c61cee8
Update shuffle.py
omuhamma Jul 20, 2026
9095aeb
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 20, 2026
3ae9e68
Added compute bound variant + black/ruff
Boss2002n Jul 20, 2026
367e648
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 24, 2026
56f7c17
black/ruff
omuhamma Jul 24, 2026
3244365
black/ruff
omuhamma Jul 24, 2026
6560453
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 27, 2026
b453d37
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 27, 2026
3dfa6ee
new api
omuhamma Jul 27, 2026
a856bb8
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 27, 2026
48b36d0
Cleanup pt2
omuhamma Jul 29, 2026
233428d
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 30, 2026
39b1f0a
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 30, 2026
23d7598
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 30, 2026
3fa14fe
Reverting UT changes that existed for AM
omuhamma Jul 30, 2026
5f4d6de
Revert prev commit
omuhamma Jul 30, 2026
f4650e4
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 30, 2026
0cdcc43
small refactor
omuhamma Jul 30, 2026
7ab8dc3
Splitting up kernel / wrapper
omuhamma Jul 30, 2026
d8e2bdb
black/ruff
omuhamma Jul 30, 2026
4a2a743
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Jul 31, 2026
6c0fdf1
refactor with claude skill
omuhamma Jul 31, 2026
eb94193
black/ruff
omuhamma Jul 31, 2026
d46e403
kernel updates based off comments
omuhamma Aug 5, 2026
91ae387
black/ruff
omuhamma Aug 5, 2026
c0dafbc
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 5, 2026
da29bb5
Update gemm_a16w16_gfx1250.py
omuhamma Aug 7, 2026
7062dbf
oob edge cases
omuhamma Aug 7, 2026
f52a1aa
Revert "Update gemm_a16w16_gfx1250.py"
omuhamma Aug 7, 2026
cbfa910
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 7, 2026
a981b56
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 13, 2026
dcad896
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 18, 2026
5b04d43
e2e testing and fixes
omuhamma Aug 19, 2026
da64d0a
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 19, 2026
e57a7b6
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 19, 2026
069f72d
Wire flydsl_gfx1250 a16w16 dispatch into tuned_gemm solMap
omuhamma Aug 20, 2026
71db74d
Update aiter/tuned_gemm.py
omuhamma Aug 20, 2026
7338bfb
Address review nits: fx-native LDS pointer, single typed casts
omuhamma Aug 20, 2026
9917e56
Support FlyDSL >=0.3.1: version-gate raw buffer op aux argument
omuhamma Aug 20, 2026
be0a22a
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 20, 2026
449ba4f
resolving comments
omuhamma Aug 21, 2026
68bd91a
Merge branch 'main' into omuhamma/fly_a16w16
coderfeli Aug 25, 2026
cfbb2c5
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 31, 2026
a94e851
removing bad copies, and unncessary padding
omuhamma Aug 31, 2026
ceed330
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Aug 31, 2026
e659da7
config picker, refactor, kernel change to prevent copies with split k
omuhamma Sep 8, 2026
3fcfd9b
Merge branch 'main' into omuhamma/fly_a16w16
coderfeli Sep 9, 2026
c56625e
Fix ruff I001 and drop deleted is_flydsl_available import
coderfeli Sep 9, 2026
44296e3
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Sep 9, 2026
8d828df
Addressing comments
omuhamma Sep 10, 2026
8256d65
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Sep 10, 2026
8adc7ac
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Sep 10, 2026
2101f4b
CI fix
omuhamma Sep 11, 2026
f83cde9
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Sep 11, 2026
f6f0dc9
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Sep 11, 2026
eea9470
Merge branch 'main' into omuhamma/fly_a16w16
omuhamma Sep 13, 2026
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
6 changes: 3 additions & 3 deletions aiter/configs/model_configs/gptoss_bf16_tuned_gemm.csv
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ gfx1250,256,8,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0
gfx1250,256,16,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,32,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,48,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,64,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,128,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,256,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,512,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
Expand All @@ -154,7 +153,6 @@ gfx1250,256,8,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,
gfx1250,256,16,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,32,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,48,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,64,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,128,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,256,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,512,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
Expand All @@ -170,7 +168,6 @@ gfx1250,256,8,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,
gfx1250,256,16,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,32,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,48,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,64,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,128,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,256,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,512,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
Expand Down Expand Up @@ -259,3 +256,6 @@ gfx1250,96,2048,201088,2880,False,torch.bfloat16,torch.bfloat16,False,False,trit
gfx1250,96,4096,201088,2880,False,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,96,8192,201088,2880,False,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,96,16384,201088,2880,False,torch.bfloat16,torch.bfloat16,False,False,triton,0,0,0.0,auto,0.0,0.0,0.0
gfx1250,256,64,5120,2880,True,torch.bfloat16,torch.bfloat16,False,False,flydsl,0,2,6.82,flydsl_a16w16_gfx1250_t64x64x256_mw4_nw2_nb4_sk2_unroll1,0.0,276.75,4474.37
gfx1250,256,64,2880,4096,True,torch.bfloat16,torch.bfloat16,False,False,flydsl,0,4,5.82,flydsl_a16w16_gfx1250_t64x64x128_mw4_nw2_nb6_sk4_unroll1,0.0,259.44,4207.20
gfx1250,256,64,128,2880,True,torch.bfloat16,torch.bfloat16,False,False,flydsl,0,6,3.0,flydsl_a16w16_gfx1250_t16x16x256_mw1_nw1_nb3_sk6_unroll1,0.0,15.73,374.10
241 changes: 241 additions & 0 deletions aiter/ops/flydsl/gemm_a16w16_gfx1250.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2024-2026, Advanced Micro Devices, Inc. All rights reserved.

"""gfx1250 FlyDSL backend for the A16W16 GEMM: torch-facing wrapper."""

from __future__ import annotations

import functools
import re

import torch

_compile_gemm_a16w16 = None
_run_compiled = None
_ptr_arg = None
_fx = None


def _lazy_import():
global _compile_gemm_a16w16, _run_compiled, _ptr_arg, _fx
if _compile_gemm_a16w16 is not None:
return
import flydsl.expr as fx

from aiter.ops.flydsl.kernels.gemm_a16w16_kernel_gfx1250 import (
compile_gemm_a16w16,
)
from aiter.ops.flydsl.kernels.tensor_shim import _run_compiled as run_compiled
from aiter.ops.flydsl.kernels.tensor_shim import ptr_arg

_compile_gemm_a16w16 = compile_gemm_a16w16
_run_compiled = run_compiled
_ptr_arg = ptr_arg
_fx = fx


_FX_DTYPE = {}


def _p(t):
if not _FX_DTYPE:
_FX_DTYPE.update(
{
torch.bfloat16: _fx.BFloat16,
torch.float16: _fx.Float16,
torch.float32: _fx.Float32,
torch.int32: _fx.Int32,
}
)
return _ptr_arg(t, _FX_DTYPE[t.dtype])


_CFG_KEYS = (
"N",
"K",
"tile_m",
"tile_n",
"tile_k",
"m_warp",
"n_warp",
"in_dtype",
"out_dtype",
"num_buffers",
"waves_per_eu",
"activation",
"add_bias",
"physical_mk",
"physical_kn",
"kernarg_preload",
"split_k",
"sched_strategy",
"main_loop_unroll",
"variant",
)


@functools.lru_cache(maxsize=1024)
def _cached_launcher(*cfg):
return _compile_gemm_a16w16(**dict(zip(_CFG_KEYS, cfg)))


# flydsl_a16w16_gfx1250_t{tm}x{tn}x{tk}_mw{mw}_nw{nw}_nb{nb}_sk{sk}_unroll{0|1}
_KERNEL_NAME_RE = re.compile(
r"^flydsl_a16w16_gfx1250_"
r"t(?P<tile_m>\d+)x(?P<tile_n>\d+)x(?P<tile_k>\d+)_"
r"mw(?P<m_warp>\d+)_nw(?P<n_warp>\d+)_"
r"nb(?P<num_buffers>\d+)_sk(?P<split_k>\d+)_unroll(?P<main_loop_unroll>[01])$"
)


def parse_kernel_name(name: str):
"""Parse a flydsl_a16w16_gfx1250_ kernelName into its config dict, or None."""
m = _KERNEL_NAME_RE.fullmatch(name)
if m is None:
return None
cfg = {k: int(v) for k, v in m.groupdict().items()}
cfg["main_loop_unroll"] = bool(cfg["main_loop_unroll"])
return cfg


def run_gemm_a16w16_gfx1250(
x: torch.Tensor,
w: torch.Tensor,
bias: torch.Tensor | None,
dtype: torch.dtype,
kernel_name: str,
) -> torch.Tensor:
"""Dispatch entry: decode a tuned kernelName and run the kernel."""
cfg = parse_kernel_name(kernel_name)
if cfg is None:
raise ValueError(f"[FlyDSL gfx1250] unrecognised kernelName: {kernel_name!r}")
return gemm_a16w16(x, w, bias=bias, dtype=dtype, **cfg)


_SPLIT_K_MAX_TILES = 1 << 16


@functools.cache
def _split_k_counters(device, stream):
return torch.zeros(_SPLIT_K_MAX_TILES, dtype=torch.int32, device=device)


def gemm_a16w16(
x: torch.Tensor,
w: torch.Tensor,
bias: torch.Tensor | None = None,
dtype: torch.dtype = torch.float16,
y: torch.Tensor | None = None,
activation: str | None = None,
tile_m: int = 128,
tile_n: int = 128,
tile_k: int = 32,
m_warp: int = 2,
n_warp: int = 4,
num_buffers: int = 2,
waves_per_eu: int | None = None,
kernarg_preload: bool = False,
split_k: int = 1,
sched_strategy: str | None = None,
main_loop_unroll: bool = False,
variant: str = "bandwidth_bound",
):
"""Compute Y = X @ W^T + bias. Auto-detects physical layout from strides."""
_lazy_import()
_half = (torch.float16, torch.bfloat16)
assert x.dtype in _half, f"x must be fp16/bf16, got {x.dtype}"
assert w.dtype in _half, f"w must be fp16/bf16, got {w.dtype}"
assert x.shape[1] == w.shape[1], "Incompatible K dimensions"

M, K, N = x.shape[0], x.shape[1], w.shape[0]
assert (
x.stride(1) == 1 or x.stride(0) == 1 or 1 in (M, K)
), f"gemm_a16w16: x needs a unit-stride dim for TDM, got strides {tuple(x.stride())}"
assert (
w.stride(1) == 1 or w.stride(0) == 1 or 1 in (N, K)
), f"gemm_a16w16: w needs a unit-stride dim for TDM, got strides {tuple(w.stride())}"
physical_mk = x.stride(1) == 1 or K == 1
physical_kn = w.stride(1) != 1 and N > 1

in_dtype_str = "fp16" if x.dtype == torch.float16 else "bf16"
out_dtype_str = {torch.float16: "f16", torch.bfloat16: "bf16"}.get(dtype, "f32")

if y is not None:
assert (
y.shape[0] == M and y.shape[1] == N
), f"y must be ({M}, {N}), got {tuple(y.shape)}"
assert y.stride(1) == 1 or 1 in (
M,
N,
), f"gemm_a16w16: y needs unit column stride, got strides {tuple(y.stride())}"
y_buf = y
else:
y_buf = torch.empty((M, N), device=x.device, dtype=dtype)
ldy = y_buf.stride(0) if M > 1 else N
assert ldy >= N, f"gemm_a16w16: y row stride {ldy} < N {N}"

if bias is None:
bias = torch.empty(0, device=x.device, dtype=dtype)

stream = torch.cuda.current_stream(device=x.device)
sem = _split_k_counters(x.device, stream)
if split_k > 1:
tiles = ((M + tile_m - 1) // tile_m) * ((N + tile_n - 1) // tile_n)
assert (
tiles <= sem.numel()
), f"gemm_a16w16: split_k needs {tiles} tile counters, max {sem.numel()}"
m_pad = ((M + tile_m - 1) // tile_m) * tile_m
n_pad = ((N + tile_n - 1) // tile_n) * tile_n
ws = torch.empty((split_k, m_pad, n_pad), device=x.device, dtype=torch.float32)
else:
ws = y_buf

launch_fn = _cached_launcher(
N,
K,
tile_m,
tile_n,
tile_k,
m_warp,
n_warp,
in_dtype_str,
out_dtype_str,
num_buffers,
waves_per_eu,
activation,
bias.numel() > 0,
physical_mk,
physical_kn,
kernarg_preload,
split_k,
sched_strategy,
main_loop_unroll,
variant,
)

if physical_mk:
lda = x.stride(0) if M > 1 else K
else:
lda = x.stride(1) if K > 1 else M
if physical_kn:
ldb = w.stride(1) if K > 1 else N
else:
ldb = w.stride(0) if N > 1 else K
_run_compiled(
launch_fn,
_p(y_buf),
_p(x),
_p(w),
_p(bias),
_p(ws),
_p(sem),
M,
ldy,
lda,
ldb,
_fx.Stream(stream.cuda_stream),
)
return y_buf


__all__ = ["gemm_a16w16", "parse_kernel_name", "run_gemm_a16w16_gfx1250"]
Loading
Loading