Skip to content

Commit

Permalink
[attention] Fix tuning and add flags (#18)
Browse files Browse the repository at this point in the history
- Fix tuning spec
- Add flag for perf
- Add a dummy generation test to attention_utils
  • Loading branch information
Groverkss authored Oct 15, 2024
1 parent 91f1260 commit 0aa226d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions attentionbench/attention_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_flops(self) -> int:
@dataclass
class TuningSpec:
wg_tiles: list[int]
reduction_tiles: list[int]
M_warp: int
N_warp: int
intrinsic: str
Expand All @@ -66,8 +67,11 @@ class TuningSpec:

def get_lowering_config(self) -> str:
return (
f"#iree_codegen.lowering_config<"
+ f"tile_sizes = [[{','.join([str(x) for x in self.wg_tiles])}]]"
f"#iree_gpu.lowering_config<"
+ "{ "
+ f"workgroup = [{', '.join(map(str, self.wg_tiles))}], "
+ f"reduction = [{', '.join(map(str, self.reduction_tiles))}]"
+ " }"
+ f">"
)

Expand Down Expand Up @@ -145,7 +149,7 @@ def generate_mlir(config: AttentionConfig, tuning: Optional[TuningSpec] = None):


def get_attention_flags() -> list[str]:
return []
return ["--iree-codegen-gpu-native-math-precision"]


def compile_attention_config(
Expand All @@ -157,7 +161,7 @@ def compile_attention_config(

# TODO: Use different tuning specs for different configs. This is just a
# general tuning config that worked well for sdxl shapes.
spec = TuningSpec([1, 128, 0, 0, 32], 4, 1, "MFMA_F32_32x32x8_F16", 2, True)
spec = TuningSpec([1, 128, 0, 0, 0], [0, 0, 0, 0, 32], 4, 1, "MFMA_F32_32x32x8_F16", 2, True)
# Generate mlir content
mlir_content = generate_mlir(config, spec)

Expand Down Expand Up @@ -196,3 +200,9 @@ def compile_attention_config(
return mlir_file, None

return mlir_file, vmfb_file

# Dummy test generation
if __name__ == "__main__":
config = AttentionConfig(20, 4096, 64, 64, 4096, "f16")
spec = TuningSpec([1, 128, 0, 0, 0], [0, 0, 0, 0, 32], 4, 1, "MFMA_F32_32x32x8_F16", 2, True)
print(generate_mlir(config, spec))

0 comments on commit 0aa226d

Please sign in to comment.