hiento09 7c0b45f0c5
Fix switch thread crash nitro windows linux (#1214)
* Add fix bug #1204 on windows

* nitro gpu exit on kill

* correct bat script syntax

* Remove wait 5 second before start nitro

---------

Co-authored-by: Hien To <tominhhien97@gmail.com>
2023-12-26 17:33:20 +07:00

46 lines
1.0 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set "maxMemory=0"
set "gpuId="
rem check if nvidia-smi command exist or not
where nvidia-smi >nul 2>&1
if %errorlevel% neq 0 (
echo nvidia-smi not found, proceeding with CPU version...
cd win-cuda
goto RunCpuVersion
)
set "tempFile=%temp%\nvidia_smi_output.txt"
nvidia-smi --query-gpu=index,memory.total --format=csv,noheader,nounits > "%tempFile%"
for /f "usebackq tokens=1-2 delims=, " %%a in ("%tempFile%") do (
set /a memorySize=%%b
if !memorySize! gtr !maxMemory! (
set "maxMemory=!memorySize!"
set "gpuId=%%a"
)
)
rem Echo the selected GPU
echo Selected GPU: !gpuId!
rem Set the GPU with the highest VRAM as the visible CUDA device
set CUDA_VISIBLE_DEVICES=!gpuId!
rem Attempt to run nitro_windows_amd64_cuda.exe
cd win-cuda
nitro.exe %* > output.log
type output.log | findstr /C:"CUDA error" >nul
if %errorlevel% equ 0 ( goto :RunCpuVersion ) else ( goto :End )
:RunCpuVersion
rem Run nitro_windows_amd64.exe...
cd ..\win-cpu
nitro.exe %*
:End
endlocal