EG/run_with_nvidia.sh
2025-08-01 12:40:56 +08:00

71 lines
2.1 KiB
Bash
Executable File
Raw Permalink 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
# 使用NVIDIA GPU运行应用程序的启动脚本
# 这将强制应用程序使用NVIDIA GPU而不是集成显卡
echo "🚀 启动应用程序使用NVIDIA GPU..."
# 检查NVIDIA驱动是否可用
if ! command -v nvidia-smi &> /dev/null; then
echo "❌ 错误未找到NVIDIA驱动"
echo "请安装NVIDIA驱动"
echo "sudo apt update && sudo apt install nvidia-driver-535"
exit 1
fi
echo "📊 NVIDIA GPU状态"
nvidia-smi --query-gpu=name,driver_version,memory.total --format=csv,noheader,nounits
echo ""
echo "🔍 OpenGL信息使用NVIDIA GPU"
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep -E "(OpenGL version|OpenGL vendor|OpenGL renderer)"
# 检查OpenGL版本是否满足要求
OPENGL_VERSION=$(__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo | grep "OpenGL version" | grep -o '[0-9]\+\.[0-9]\+' | head -1)
echo "检测到OpenGL版本$OPENGL_VERSION"
if [[ $(echo "$OPENGL_VERSION >= 4.3" | bc -l) -eq 1 ]]; then
echo "✅ OpenGL版本满足RenderPipeline要求需要4.3+"
else
echo "❌ OpenGL版本不满足RenderPipeline要求需要4.3+"
echo "当前版本:$OPENGL_VERSION"
exit 1
fi
echo ""
echo "🎮 启动应用程序..."
# 设置环境变量以使用NVIDIA GPU
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
# 可选启用NVIDIA GPU性能模式和调试
export __GL_SYNC_TO_VBLANK=0
export __GL_SHADER_DISK_CACHE=1
export __GL_SHADER_DISK_CACHE_PATH=/tmp/nvidia_shader_cache
# 创建着色器缓存目录
mkdir -p /tmp/nvidia_shader_cache
# 运行Python应用程序
cd /home/gengjiayuan/EG
echo "正在启动应用程序..."
echo "如果遇到问题,请检查终端输出中的错误信息"
echo ""
/home/gengjiayuan/EG/.conda/bin/python /home/gengjiayuan/EG/main.py
EXIT_CODE=$?
echo ""
if [ $EXIT_CODE -eq 0 ]; then
echo "✅ 应用程序正常退出"
else
echo "❌ 应用程序异常退出,退出码:$EXIT_CODE"
if [ $EXIT_CODE -eq 139 ]; then
echo " 这通常表示段错误可能是GPU驱动或OpenGL问题"
fi
fi
echo "🏁 启动脚本完成"