CUDA not working after returning laptop from sleep

I have installed cuda 7 toolkit with newest driver, and it passed all the tests, it seems that driver is loaded, but every time when I just put my laptop to sleep, and wake it up from sleep, cuda doesn't work anymore, deviceQuery

./deviceQuery Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

cudaGetDeviceCount returned 38
-> no CUDA-capable device is detected
Result = FAIL

Solution 1:

http://forums.fast.ai/t/cuda-lib-not-working-after-suspend-on-ubuntu-16-04/3546/4

You can reload the nvidia kernel module and it will work fine:

sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm

Notice though that this won't work unless all applications using that module are closed.

Solution 2:

https://chuanwen.wordpress.com/2015/07/19/run-cuda-on-ubuntu-14-04-2/

What if cuda does not work after laptop wake up from sleep:

Put following 2 lines in your /etc/rc.local:

/usr/bin/nvidia-smi -pm ENABLED
/usr/bin/nvidia-smi -c EXCLUSIVE_PROCESS