# For CUDA applications export CUDA_MANAGED_FORCE_DEVICE_ALLOC=1 This is a classic "false free memory" scenario. Even if nvidia-smi reports 2GB free, you might see error -12. Why? Fragmentation.
# Find all processes using the GPU fuser -v /dev/nvidia* nvidia-smi --query-compute-apps=pid --format=csv Kill the process (replace <PID>) sudo kill -9 <PID> 3. Clear CUDA Context (Reset the GPU) If killing processes doesn't work (stale context): nvtool error -12-
# Reset the GPU (requires root) sudo nvidia-smi --gpu-reset -i 0 # Replace 0 with GPU index This will kill all processes using that GPU. 4. Reduce Memory Fragmentation Restart the CUDA driver stack (no reboot required): ) sudo kill -9 <