CUDA initialization: Unexpected error from cudaGetDeviceCount()

A warning appears when torch.cuda.is_available() is executed, which is:

CUDA initialization: Unexpected error from cudaGetDeviceCount(). Did you run some cuda functions before calling NumCudaDevices() that might have already set an error? Error 304: OS call failed or operation not supported on this OS.

Does anyone know how to solve this? Thanks