diff --git a/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/check_peano_stack.sh b/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/check_peano_stack.sh index 5da7a4ec5..b9397bcb8 100755 --- a/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/check_peano_stack.sh +++ b/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/check_peano_stack.sh @@ -14,39 +14,75 @@ # bound). If it fires, raise the stack size in # iron/layer_aie.py and re-check xclbins/rtp_addresses.txt, since a bigger stack # can move the RTP buffers that FLM_DLL hardcodes. +# +# Anything the check cannot work out (a missing tool or ELF, a stack_depth.py +# failure, symbols it cannot find) is an error, never a skipped core: a check +# that quietly checks nothing looks the same as one that passes. set -u +err() { echo "error: check_peano_stack.sh: $*" >&2; } + : "${PEANO_INSTALL_DIR:?check_peano_stack.sh needs PEANO_INSTALL_DIR}" OBJDUMP="${PEANO_INSTALL_DIR}/bin/llvm-objdump" NM="${PEANO_INSTALL_DIR}/bin/llvm-nm" +DEPTH="$(dirname "$0")/stack_depth.py" +for tool in "$OBJDUMP" "$NM"; do + [ -x "$tool" ] || { err "$tool not found or not executable"; exit 1; } +done +command -v python3 >/dev/null 2>&1 || { err "python3 not found"; exit 1; } +command -v awk >/dev/null 2>&1 || { err "awk not found"; exit 1; } +[ -f "$DEPTH" ] || { err "$DEPTH not found"; exit 1; } +[ $# -gt 0 ] || { err "no ELF files given"; exit 1; } rc=0 for f in "$@"; do - [ -f "$f" ] || continue + if [ ! -f "$f" ]; then + err "$f: no such ELF" + rc=1 + continue + fi base=$(basename "$f") - frames=$(python3 "$(dirname "$0")/stack_depth.py" "$OBJDUMP" "$f") + if ! frames=$(python3 "$DEPTH" "$OBJDUMP" "$f"); then + err "$base: stack_depth.py failed (see above)" + rc=1 + continue + fi + if ! [[ $frames =~ ^[0-9]+$ ]]; then + err "$base: stack_depth.py printed '${frames}', not a byte count" + rc=1 + continue + fi # A core with no SP adjustment at all uses no stack; nothing to check. - [ -n "${frames:-}" ] || continue + [ "$frames" -gt 0 ] || continue - start=$("$NM" "$f" 2>/dev/null | awk '/_sp_start_value_DM_stack/{print $1; exit}') + if ! syms=$("$NM" -n "$f" 2>&1); then + err "$base: llvm-nm failed:" + printf '%s\n' "$syms" | head -5 >&2 + rc=1 + continue + fi + start=$(awk '$NF == "_sp_start_value_DM_stack" {print $1; exit}' <<<"$syms") + if ! [[ $start =~ ^[0-9a-fA-F]+$ ]]; then + err "$base: uses ${frames} B of stack but has no _sp_start_value_DM_stack address" + rc=1 + continue + fi # llvm-nm -n sorts by address, so the first absolute symbol above the stack # start is the buffer that bounds it. Compare as integers: awk would read # "00070000" as a number but "0007c000" as a string. limit="" - if [ -n "${start:-}" ]; then - while read -r addr type _; do - [ "$type" = "N" ] || continue - if [ $((0x$addr)) -gt $((0x$start)) ]; then limit=$addr; break; fi - done < <("$NM" -n "$f" 2>/dev/null) - fi - # If the symbols this relies on are missing, warn rather than skip quietly. - if [ -z "${start:-}" ] || [ -z "$limit" ]; then - echo "warning: $base: cannot determine the stack bounds, check skipped" >&2 + while read -r addr type _; do + [ "$type" = "N" ] && [[ $addr =~ ^[0-9a-fA-F]+$ ]] || continue + if [ $((16#$addr)) -gt $((16#$start)) ]; then limit=$addr; break; fi + done <<<"$syms" + if [ -z "$limit" ]; then + err "$base: uses ${frames} B of stack but no buffer above the stack start 0x${start} bounds it" + rc=1 continue fi - region=$(( 0x$limit - 0x$start )) + region=$(( 16#$limit - 16#$start )) if [ "$frames" -gt "$region" ]; then echo "error: $base: stack frames total ${frames} B but only ${region} B of stack" >&2 echo " (stack 0x${start} grows up into the buffer at 0x${limit})" >&2 diff --git a/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/stack_depth.py b/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/stack_depth.py index 046ad22dc..45c0bba4e 100644 --- a/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/stack_depth.py +++ b/flm-dev-kit/FLM_Xclbin/Hy_MT2_1.8B/decoding/makefiles/stack_depth.py @@ -52,8 +52,11 @@ def deepest(fn, starts, frames, calls, seen=()): def main(): starts, frames, calls, indirect = parse(sys.argv[1], sys.argv[2]) + # No function in the disassembly is output this parser cannot read, not + # a core without a stack (that one prints 0): fail rather than print + # nothing, which check_peano_stack.sh would take for "nothing to check". if not frames: - return + sys.exit(f"stack_depth.py: {sys.argv[2]}: no functions in the llvm-objdump -d output") if indirect: print(sum(frames.values())) else: diff --git a/src/xclbins/Hy-MT2-1.8B-NPU2/layer.xclbin b/src/xclbins/Hy-MT2-1.8B-NPU2/layer.xclbin index 9f4f86bf4..154968153 100644 Binary files a/src/xclbins/Hy-MT2-1.8B-NPU2/layer.xclbin and b/src/xclbins/Hy-MT2-1.8B-NPU2/layer.xclbin differ