Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make GPU available again after numba.cuda.close()?

So when I run cuda.select_device(0) and then cuda.close(). Pytorch cannot access the GPU again, I know that there is way so that PyTorch can utilize the GPU again without having to restart the kernel. But I forgot how. Does anyone else know?

from  numba import cuda as cu
import torch 


# random tensor
a=torch.rand(100,100)

#tensor can be loaded onto the gpu()
a.cuda()

device = cu.get_current_device()
device.reset()

# thows error "RuntimeError: CUDA error: invalid argument"
a.cuda()

cu.close()
# thows error "RuntimeError: CUDA error: invalid argument"
a.cuda()

torch.cuda.is_available()
#True

And then trying to run cuda-based pytorch code yields:

RuntimeError: CUDA error: invalid argument
like image 381
Janosch Avatar asked Jan 30 '20 09:01

Janosch


1 Answers

could you provide a more complete snippet, I am running

from numba import cuda
import torch 
device = cuda.get_current_device()
device.reset()
cuda.close()
torch.cuda.isavailable()

which prints True, not sure what is your issue?

like image 182
Roger Trullo Avatar answered Sep 20 '22 16:09

Roger Trullo