Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions scripts/kernel-set-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#
# scripts/kernel-set-check.sh [--pack <model dir>] <set dir> [<set dir> ...]
#
#
# engine#2599: ALSO refuses a set that carries two ELFs with the SAME CONTENT under different names. The
# bonsai2 pack shipped prefill ELFs byte-identical to their _m16 twins, so a 128-row chunk computed 16 rows
# and every host-side check passed: the loaded file had the right NAME and the right per-tile widths, and the
# AIE image carries no readable design M (e_shnum=0, no symtab, no design string -- measured on this lane's
# packs), so nothing but a hash of the file can tell the two designs apart. A twin inside one pack is either
# a packaging accident or a design that was never widened; both are refusals, not warnings.
# Why this exists: the release candidate serves small models at 87-101 tok/s with the set that ships beside it, and a
# build of current main refused that same set with "layer ELFs: the NB 2 and 3 builds differ in size". Neither the set
# nor the kernels were wrong — the two sides came from different revisions of the private repository, one on each side of
Expand Down Expand Up @@ -219,9 +226,24 @@ if [ $# -eq 0 ]; then
exit 2
fi

# engine#2599: two ELFs with the same content under different names is a refusal. See the header for why a
# hash is the only host-side instrument that can see it.
check_twins() {
local dir=$1 dup
dup=$(find "$dir" -maxdepth 2 -name '*.elf' -type f -print0 2>/dev/null |
xargs -0 -r md5sum 2>/dev/null | sort | awk '{h=$1; $1=""; if (h==prev) print prevname " and" $0; prev=h; prevname=$0}')
if [ -n "$dup" ]; then
printf 'FAIL %s: ELFs with identical content under different names (a copied twin computes the wrong M):\n%s\n' \
"$(basename "$dir")" "$dup"
return 1
fi
return 0
}

rc=0
for dir in "$@"; do
check_set "$dir" || { rc=$?; [ "$rc" -gt 1 ] && rc=2; }
check_twins "$dir" || rc=1
done

if [ -n "$pack" ]; then
Expand Down
15 changes: 15 additions & 0 deletions tests/kernel_set_check_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ check $([ $? -eq 0 ] && echo ok || echo fail) "layer directories with a suffix:
check $(has "$tmp/out20" "3 layer-indexed" && ! has "$tmp/out20" "other" && echo ok || echo fail) \
"... all three counted as layer-indexed, none as other"

# engine#2599: two ELFs with identical content under different names must fail, and a clean set must not.
mkdir -p "$tmp/twin/good" "$tmp/twin/dup"
printf 'A' > "$tmp/twin/good/full_i8_O_K768_N768_b8.elf"
printf 'B' > "$tmp/twin/good/full_i8_O_K768_N768_b8_m16.elf"
printf 'A' > "$tmp/twin/dup/full_i8_O_K768_N768_b8.elf"
printf 'A' > "$tmp/twin/dup/full_i8_O_K768_N768_b8_m16.elf"
"$script" "$tmp/twin/good" > "$tmp/out21" 2>&1
check $([ $? -ne 0 ] || ! has "$tmp/out21" "identical content" && echo ok || echo fail) \
"distinct ELFs are not reported as twins"
"$script" "$tmp/twin/dup" > "$tmp/out22" 2>&1
check $(has "$tmp/out22" "identical content" && echo ok || echo fail) \
"two ELFs with the same content are refused"
check $(has "$tmp/out22" "full_i8_O_K768_N768_b8.elf" && has "$tmp/out22" "_m16.elf" && echo ok || echo fail) \
"... and both paths are named"

if [ "$fails" -ne 0 ]; then
printf 'kernel_set_check: %d failure(s)\n' "$fails"
exit 1
Expand Down
Loading