-
Notifications
You must be signed in to change notification settings - Fork 1
/
free_mem.sh
executable file
·31 lines (25 loc) · 990 Bytes
/
free_mem.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
echo "Attempting to reset GPU memory..."
# Find and kill processes using the GPU
gpu_pids=$(fuser -v /dev/nvidia* 2>/dev/null | awk '{print $2}')
if [ -n "$gpu_pids" ]; then
echo "Killing the following GPU processes: $gpu_pids"
sudo kill -9 $gpu_pids
else
echo "No GPU processes found."
fi
# Unload NVIDIA kernel modules if not in use
sudo rmmod nvidia_uvm 2>/dev/null || echo "Failed to unload nvidia_uvm"
sudo rmmod nvidia_modeset 2>/dev/null || echo "Failed to unload nvidia_modeset"
sudo rmmod nvidia 2>/dev/null || echo "Failed to unload nvidia"
# Reload NVIDIA kernel modules
sudo modprobe nvidia
sudo modprobe nvidia_uvm
sudo modprobe nvidia_modeset
# Check if nvidia-persistenced service exists and restart it if available
if systemctl list-units --full -all | grep -q 'nvidia-persistenced.service'; then
sudo systemctl restart nvidia-persistenced
else
echo "nvidia-persistenced service not found."
fi
echo "GPU memory should now be freed up."