Files
argus/src/metric/tests/scripts/common/check-gpu.sh

60 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# GPU环境检测脚本
# 检测系统是否有NVIDIA GPU硬件
set -e
# 检测函数
check_gpu_support() {
echo "检测GPU环境..."
# 方法1: 检测GPU设备文件
if ls /dev/nvidia* &>/dev/null; then
echo "✓ 检测到NVIDIA GPU设备文件"
return 0
fi
# 方法2: 检测lspci中的NVIDIA设备(Linux)
if command -v lspci &> /dev/null; then
if lspci | grep -i nvidia &> /dev/null; then
echo "✓ 检测到NVIDIA GPU硬件"
return 0
fi
fi
# 方法3: 检测nvidia-smi
if command -v nvidia-smi &> /dev/null; then
if nvidia-smi &> /dev/null; then
echo "✓ 检测到NVIDIA GPU硬件"
return 0
fi
fi
echo "✗ 未检测到NVIDIA GPU硬件"
return 1
}
# 主函数
main() {
echo "=========================================="
echo " GPU环境检测"
echo "=========================================="
echo ""
if check_gpu_support; then
echo ""
echo "结果: GPU环境可用"
exit 0
else
echo ""
echo "结果: GPU环境不可用,将跳过GPU相关服务"
exit 1
fi
}
# 如果直接运行此脚本
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
main "$@"
fi