Skip to content

Commit 8615dae

Browse files
test: validate known block size through kernel launches
Replace brittle final-IR metadata matching with synchronized 512/1024-thread launches. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f2a4595 commit 8615dae

2 files changed

Lines changed: 4 additions & 24 deletions

File tree

tests/kernels/test_rmsnorm_autotune.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import json
77
import os
8-
import re
98
from pathlib import Path
109

1110
import pytest
@@ -71,8 +70,6 @@ def test_rmsnorm_direct_specializes_known_block_size(weight_dtype, weight_dtype_
7170
artifact = compiled._keepalive
7271

7372
assert "known_block_size = array<i32: 512, 1, 1>" in artifact.source_ir
74-
match = re.search(r"max_flat_workgroup_size\s*=\s*(\d+)", artifact.ir)
75-
assert match is not None and int(match.group(1)) == 512
7673
if weight_dtype == torch.float32:
7774
weight_copy_type = "!fly.copy_atom<!fly_rocdl.cdna3.buffer_copy<128>, 32>"
7875
assert artifact.source_ir.count(weight_copy_type) >= 3

tests/unit/test_kernel_known_block_size.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""Tests for known_block_size attribute on @flyc.kernel."""
22

3-
import re
4-
53
import pytest
64

75
import flydsl.compiler as flyc
@@ -129,14 +127,6 @@ def _get_source_ir(launch_fn, *args):
129127
return artifact.source_ir
130128

131129

132-
def _get_compiled_ir(launch_fn, x):
133-
"""Call the JIT function once, then return the compiled IR string."""
134-
launch_fn(x, stream=torch.cuda.current_stream())
135-
assert launch_fn._mem_cache, "expected at least one cached compilation"
136-
artifact = next(iter(launch_fn._mem_cache.values()))
137-
return artifact.ir
138-
139-
140130
# ---------------------------------------------------------------------------
141131
# Tests
142132
# ---------------------------------------------------------------------------
@@ -168,14 +158,6 @@ def test_static_numeric_dims_are_inferred(self):
168158
assert "known_block_size = array<i32: 64, 1, 1>" in source_ir
169159
assert "known_block_size = array<i32: 32, 2, 1>" in source_ir
170160

171-
def test_compiled_ir_has_max_flat_workgroup_size(self):
172-
compiled_ir = _get_compiled_ir(_launch_bs128_4_2, self.x)
173-
# The compiled IR should report max_flat_workgroup_size >= total_threads
174-
match = re.search(r"max_flat_workgroup_size\s*=\s*(\d+)", compiled_ir)
175-
assert match is not None, f"max_flat_workgroup_size not found in compiled IR:\n{compiled_ir}"
176-
max_wg = int(match.group(1))
177-
assert max_wg >= 1024, f"max_flat_workgroup_size={max_wg} < total_threads=1024"
178-
179161
def test_dynamic_block_size_omits_exact_attribute(self):
180162
source_ir = _get_source_ir(_launch_dynamic_blocks, self.x, 64, 64)
181163
# Check for the attribute syntax, not just the substring (which may
@@ -203,9 +185,10 @@ def test_reused_explicit_name_gets_unique_symbols(self):
203185
assert "gpu.func @_kn_named_block_specialization(" in source_ir
204186
assert "gpu.func @_kn_named_block_specialization_1(" in source_ir
205187

206-
def test_kernel_launches_successfully(self):
207-
"""Ensure the kernel actually launches without hipErrorLaunchFailure."""
208-
_launch_bs64(self.x, stream=torch.cuda.current_stream())
188+
@pytest.mark.parametrize("launch_fn", [_launch_bs64, _launch_bs128_4_2], ids=["64", "1024"])
189+
def test_kernel_launches_successfully(self, launch_fn):
190+
"""Exercise backend workgroup metadata, including a 1024-thread launch."""
191+
launch_fn(self.x, stream=torch.cuda.current_stream())
209192
torch.cuda.synchronize() # would raise if launch failed
210193

211194

0 commit comments

Comments
 (0)