Skip to content
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

[attention] Fix tuning and add flags #18

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
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
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))