torch._C._cuda_getDeviceCount() > 0 returns False

Mona_Jalal: <p>How can I fix this? I have NVIDIA GPU.</p>
<pre><code class="lang-auto">&gt;&gt;&gt; torch._C._cuda_getDeviceCount() &gt; 0
False
&gt;&gt;&gt; torch.cuda.is_available()
False
$ nvidia-smi
Fri Mar  5 17:28:31 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.39       Driver Version: 460.39       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce GTX 165...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   48C    P8     3W /  N/A |   1168MiB /  3911MiB |     17%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1163      G   /usr/lib/xorg/Xorg                133MiB |
|    0   N/A  N/A      2468      G   /usr/lib/xorg/Xorg                579MiB |
|    0   N/A  N/A      2688      G   /usr/bin/gnome-shell              166MiB |
|    0   N/A  N/A      3101      G   ...gAAAAAAAAA --shared-files      196MiB |
|    0   N/A  N/A    684945      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A    684970      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A    685042      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A    685193      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A    687287      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A    687389      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A    687497      G   /usr/lib/firefox/firefox            1MiB |
|    0   N/A  N/A   1693707      G   /opt/zoom/zoom                     50MiB |
|    0   N/A  N/A   1710209      G   /usr/lib/firefox/firefox            1MiB |
+-----------------------------------------------------------------------------+
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:08:53_PST_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293_0

&gt;&gt;&gt; torch.__version__
'1.8.0'


Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0] on Linux


$ lsb_release -a
LSB Version:	core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal

</code></pre>
<p>on the download Website, I am noticing you don’t have anything for Cuda 11.2 so what should I do in this case?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/2/c20ccaacdbd53e56f9e5d27305c9d493d513dba0.png" data-download-href="https://discuss.pytorch.org/uploads/default/c20ccaacdbd53e56f9e5d27305c9d493d513dba0" title="Screenshot from 2021-03-05 17-50-56"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/2/c20ccaacdbd53e56f9e5d27305c9d493d513dba0_2_690x277.png" alt="Screenshot from 2021-03-05 17-50-56" data-base62-sha1="rGE2bUQT9oqYMYLEW9zeshV7QeQ" width="690" height="277" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/2/c20ccaacdbd53e56f9e5d27305c9d493d513dba0_2_690x277.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/2/c20ccaacdbd53e56f9e5d27305c9d493d513dba0_2_1035x415.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/c/2/c20ccaacdbd53e56f9e5d27305c9d493d513dba0_2_1380x554.png 2x" data-dominant-color="F4D8D4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2021-03-05 17-50-56</span><span class="informations">2428×978 142 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>This is most likely related to <a href="https://discuss.pytorch.org/t/pytorch-1-8-cuda-cannot-use-gpu/113877">this</a> and <a href="https://discuss.pytorch.org/t/installing-cuda-11-1-on-ubuntu-20-04-for-nvidia-geforce-1650-ti-notebook/113872">this post</a>.<br>
Make sure your driver is successfully installed without any errors, restart the machine, and it should work.<br>
Also note, that you don’t need a local CUDA toolkit installation to execute the PyTorch binaries, as they ship with their own CUDA (cudnn, NCCL, etc.) runtimes.<br>
The local CUDA toolkit is needed, if you want to build custom CUDA extensions or PyTorch from source.</p>

Dj_Jag: <p>If I have a new driver (version 530 with cuda 12 support) - does it supports Stable Torch for Cuda 11 (or below) ?</p>

ptrblck: <p>Yes, driver 530 supports the CUDA 11 and 12 runtimes.</p>

yenming: <p>I encountered the same issue while using an A800 GPU.  My Nvidia driver version is 525.105.17, and I have CUDA 12.0 installed. I checked the cuda-toolkit-release-notes and found that CUDA 12.0.x requires driver version &gt;=525.60.13.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/0/d0e2d8051f0097b2c186124d6665500649f7a918.png" data-download-href="https://discuss.pytorch.org/uploads/default/d0e2d8051f0097b2c186124d6665500649f7a918" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/0/d0e2d8051f0097b2c186124d6665500649f7a918.png" alt="image" data-base62-sha1="tNTk7qI3pZORjrRudBNSz2PwZHa" width="690" height="188" data-dominant-color="2E2E2E"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">963×263 9.62 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I have installed <code>torch-2.0.1-cp310-cp310-manylinux1_x86_64</code> . However, when I executed the following code, I encountered an exception:</p>
<blockquote>
<p>python -c “import torch; print(torch.cuda.is_available())”</p>
</blockquote>
<blockquote>
<p>torch/cuda/<strong>init</strong>.py:107: UserWarning: CUDA initialization: Unexpected error from cudaGetDeviceCount(). Did you run some cuda functions before calling NumCudaDevices() that might have already set an error? Error 802: system not yet initialized (Triggered internally at …/c10/cuda/CUDAFunctions.cpp:109.)<br>
return torch._C._cuda_getDeviceCount() &gt; 0<br>
False</p>
</blockquote>
<p>Is there a version of PyTorch available that supports the A800 GPU and CUDA 12?</p>

ptrblck: <p>Yes, all of our PyTorch binaries support this GPU and also your error points towards a driver issue.</p>

Dj_Jag: <p>How can we fix this problems? If NVidia cannot fix there broken video driver, may be have another way to fix this bug?</p>

ptrblck: <p>I doubt the video driver is broken and the aforementioned issues are often caused by e.g. a not performed restart, while it was requested, multiple conflicting installations, etc.</p>