fix(common): robust XPU platform auto-detection
Capture xpu-smi output before grepping to avoid SIGPIPE failures under set -o pipefail when grep -q exits early.
This commit is contained in:
parent
e72e34c2f7
commit
f0d4c4753b
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user