Skip to content

Commit b78c04b

Browse files
committed
[debugging] emit new iree flag for debugging
Depends on iree-org/iree#22216 in iree. Along with #340 this enables DWARF output with locations for Wave kernels. Signed-off-by: William G Hatch <william@hatch.uno>
1 parent f74df46 commit b78c04b

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# RUN: rm -rf %t && mkdir -p %t
2+
# RUN: python %s %t
3+
# RUN: llvm-dwarfdump --debug-line %t/*.hsaco | FileCheck %s
4+
5+
"""
6+
End-to-end test for debug information in compiled Wave kernels. This test
7+
verifies that debug locations are preserved through the entire compilation
8+
pipeline to DWARF.
9+
"""
10+
11+
import sys
12+
import wave_lang.kernel.lang as tkl
13+
import wave_lang.kernel.wave as tkw
14+
from wave_lang.support.location_config import (
15+
LocationCaptureConfig,
16+
LocationCaptureLevel,
17+
)
18+
from wave_lang.kernel.wave.compile import WaveCompileOptions, wave_compile
19+
from wave_lang.kernel.wave.utils.general_utils import run_test
20+
21+
M = tkl.sym.M
22+
N = tkl.sym.N
23+
K = tkl.sym.K
24+
BLOCK_M = tkl.sym.BLOCK_M
25+
BLOCK_N = tkl.sym.BLOCK_N
26+
BLOCK_K = tkl.sym.BLOCK_K
27+
ADDRESS_SPACE = tkl.sym.ADDRESS_SPACE
28+
29+
30+
@run_test
31+
def test_debug_dwarf():
32+
# Get the output directory from command line
33+
if len(sys.argv) > 1:
34+
output_dir = sys.argv[1]
35+
else:
36+
output_dir = "test_debug_output"
37+
38+
constraints: list[tkw.Constraint] = [
39+
tkw.WorkgroupConstraint(M, BLOCK_M, 0),
40+
tkw.WorkgroupConstraint(N, BLOCK_N, 1),
41+
tkw.TilingConstraint(K, BLOCK_K),
42+
tkw.WaveConstraint(M, BLOCK_M / 2),
43+
tkw.WaveConstraint(N, BLOCK_N / 2),
44+
tkw.HardwareConstraint(
45+
threads_per_wave=64,
46+
mma_type=tkw.MMAType.F32_16x16x16_F16,
47+
),
48+
]
49+
50+
@tkw.wave(constraints)
51+
def gemm_with_debug(
52+
a: tkl.Memory[M, K, ADDRESS_SPACE, tkl.f16],
53+
b: tkl.Memory[N, K, ADDRESS_SPACE, tkl.f16],
54+
c: tkl.Memory[M, N, tkl.AddressSpace.GLOBAL_MEMORY, tkl.f32],
55+
):
56+
c_reg = tkl.Register[M, N, tkl.f32](0.0)
57+
58+
@tkw.iterate(K, init_args=[c_reg])
59+
def repeat(acc: tkl.Register[M, N, tkl.f32]) -> tkl.Register[M, N, tkl.f32]:
60+
a_reg = tkw.read(a)
61+
b_reg = tkw.read(b)
62+
acc = tkw.mma(a_reg, b_reg, acc)
63+
return acc
64+
65+
tkw.write(repeat, c)
66+
67+
options = WaveCompileOptions(
68+
subs={
69+
M: 64,
70+
N: 128,
71+
K: 64,
72+
BLOCK_M: 32,
73+
BLOCK_N: 32,
74+
BLOCK_K: 16,
75+
ADDRESS_SPACE: tkl.AddressSpace.SHARED_MEMORY.value,
76+
},
77+
canonicalize=True,
78+
compile_to_mlir=False,
79+
# Enable debug info capture
80+
location_capture_config=LocationCaptureConfig(
81+
LocationCaptureLevel.FILE_LINE_COL
82+
),
83+
drop_debug_info_before_mlir=False,
84+
# Dump the compiled binaries so we can inspect them
85+
dump_binaries=output_dir,
86+
)
87+
88+
wave_compile(options, gemm_with_debug)
89+
90+
91+
# Check that the line table header contains our source file
92+
# CHECK: file_names[ [[FILENUM:[0-9]+]]]:
93+
# CHECK-NEXT: name: "debug_dwarf.py"
94+
95+
# Verify that the line table contains entries for the key operations in our Wave kernel.
96+
# Line 60: a_reg = tkw.read(a)
97+
# Line 61: b_reg = tkw.read(b)
98+
# Line 62: acc = tkw.mma(a_reg, b_reg, acc)
99+
# Line 65: tkw.write(repeat, c)
100+
##### Address Line Column File (other fields) Flags
101+
# CHECK-DAG: {{0x[0-9a-f]+}} 60 {{[0-9]+}} [[FILENUM]] {{.*}} is_stmt
102+
# CHECK-DAG: {{0x[0-9a-f]+}} 61 {{[0-9]+}} [[FILENUM]] {{.*}} is_stmt
103+
# CHECK-DAG: {{0x[0-9a-f]+}} 62 {{[0-9]+}} [[FILENUM]] {{.*}} is_stmt
104+
# CHECK-DAG: {{0x[0-9a-f]+}} 65 {{[0-9]+}} [[FILENUM]] {{.*}} is_stmt
105+

wave_lang/kernel/wave/utils/compile_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def compile_to_vmfb(
4848
if options.device == "hip":
4949
flags.append(f"--iree-hip-target={options.target}")
5050

51+
if not options.drop_debug_info_before_mlir:
52+
flags.append("--iree-hip-emit-debug-info")
53+
5154
if options.mlir_print_ir_after_all:
5255
flags.append("--mlir-print-ir-after-all")
5356

0 commit comments

Comments
 (0)