diff --git a/scripts/common/platform.sh b/scripts/common/platform.sh index 26823a6..b20f88f 100755 --- a/scripts/common/platform.sh +++ b/scripts/common/platform.sh @@ -9,7 +9,15 @@ ROOT_DIR="$(cd "${_PLATFORM_DIR}/../.." && pwd)" # Auto-detect platform if not set. if [[ -z "${PLATFORM:-}" ]]; then - if lspci 2>/dev/null | grep -qiE "XPU|Kunlun"; then + # Capture xpu-smi output first; piping it directly can trigger SIGPIPE under + # pipefail when grep -q exits early. + _XPU_SMI_OUT="" + if command -v xpu-smi >/dev/null 2>&1; then + _XPU_SMI_OUT=$(xpu-smi 2>/dev/null || true) + fi + if [[ -n "$_XPU_SMI_OUT" ]] && grep -qiE "P800|Kunlun" <<< "$_XPU_SMI_OUT"; then + PLATFORM="kunlun_p800" + elif lspci 2>/dev/null | grep -qiE "XPU|Kunlun"; then PLATFORM="kunlun_p800" elif command -v nvidia-smi >/dev/null 2>&1; then PLATFORM="nvidia_h200" @@ -17,6 +25,7 @@ if [[ -z "${PLATFORM:-}" ]]; then echo "ERROR: Could not auto-detect PLATFORM. Set PLATFORM env var explicitly." >&2 exit 1 fi + unset _XPU_SMI_OUT echo "Auto-detected platform: ${PLATFORM}" fi