bench: fingerprint only the IR, and refuse to compare when there is none

ir_fingerprint hashed every file under the dump directory, which includes
index.tsv and naming.md. An operator that compiles no Triton kernel at all
leaves only those two, identical on both sides, so the switch-effectiveness
check reported "byte-identical ttgir" and skipped the operator with
SWITCH_NO_IR_DIFF — "the switch changed no generated code" — when the truth
was that nothing was generated. router_gemm on MUSA is exactly this case: its
kernel cannot be instantiated there (missing BLOCK_M/N/K/SPLIT_K from the
autotune path), zero .ttgir files, and the check called it a no-op switch.

Now only *.ttgir files are hashed, and a run with none returns failure so the
caller treats it as "no comparable IR" rather than "identical". The message on
that path says so, and says explicitly that it does not mean the switch is
inert.
This commit is contained in:
Aharrypotter committed 2026-09-10 16:47:39 +08:00
1 parent 551ffbbb77
commit 5236d0745f
1 file changed
+13 -6
+13 -6
View File
@@ -30,15 +30,21 @@ cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SWITCH_ALLOW_NO_IR_DIFF="${SWITCH_ALLOW_NO_IR_DIFF:-0}" SWITCH_ALLOW_NO_IR_DIFF="${SWITCH_ALLOW_NO_IR_DIFF:-0}"
# 一个 run 生成代码的指纹:ttgir 相对路径 + 内容。路径进指纹是因为"变体集合变了" # 一个 run 生成代码的指纹:只取 .ttgir 的相对路径 + 内容。
# 与"某个变体内容变了"同样算改变,而只 cat 内容会把前者洗掉。 # 路径进指纹是因为"变体集合变了"与"某个变体内容变了"同样算改变,而只 cat 内容
# 会把前者洗掉。只认 .ttgir 则是因为 dump 目录里还有 index.tsv 和 naming.md:
# 一个 kernel 都没编出来的 run 只剩这两个文件、两侧完全相同,会把"什么都没生成"
# 报成"开关没改变生成代码"——router_gemm 在 MUSA 上就是这样。
# 零 kernel 返回非零,交给调用方当作"没有可比的 IR",而不是"一致"。
ir_fingerprint() { ir_fingerprint() {
local dir="$1/ttgir" local dir="$1/ttgir"
[[ -d "$dir" ]] || return 1 [[ -d "$dir" ]] || return 1
local n
n=$(find "$dir" -name '*.ttgir' -type f 2>/dev/null | wc -l)
(( n > 0 )) || return 1
local out local out
out=$( { find "$dir" -type f | LC_ALL=C sort | while IFS= read -r f; do out=$( { find "$dir" -name '*.ttgir' -type f | LC_ALL=C sort | while IFS= read -r f; do
printf '%s printf '%s\n' "${f#"$dir"/}"; cat "$f"
' "${f#"$dir"/}"; cat "$f"
done; } | sha256sum | cut -d' ' -f1 ) done; } | sha256sum | cut -d' ' -f1 )
[[ -n "$out" ]] && printf '%s' "$out" [[ -n "$out" ]] && printf '%s' "$out"
} }
@@ -137,7 +143,8 @@ run_cell() { # round side op op_file out_dir [replay_from]
fa=$(ir_fingerprint "$out/r1_A") || fa="" fa=$(ir_fingerprint "$out/r1_A") || fa=""
fb=$(ir_fingerprint "$out/r1_B") || fb="" fb=$(ir_fingerprint "$out/r1_B") || fb=""
if [[ -z "$fa" || -z "$fb" ]]; then if [[ -z "$fa" || -z "$fb" ]]; then
echo "??? $op: 没有 ttgir 产物,跳过对比轴有效性检查" echo "??? $op: 没有编出任何 .ttgir(可能该算子没走 Triton,或本轮失败),"
echo "??? 跳过对比轴有效性检查——这不等于开关无作用"
elif [[ "$fa" == "$fb" ]]; then elif [[ "$fa" == "$fb" ]]; then
echo "!!! SWITCH_NO_IR_DIFF op=$op switch=$SWITCH" echo "!!! SWITCH_NO_IR_DIFF op=$op switch=$SWITCH"
echo "!!! 两侧 ttgir 逐字节相同:这个开关没有改变 $op 的生成代码。" echo "!!! 两侧 ttgir 逐字节相同:这个开关没有改变 $op 的生成代码。"