Reputation: 842
I have an Nvidia GPU (Geforce RTX 3090) and the driver is displayed in Nvidia Control Panel. I also have installed the latest version of Cuda. However, when using the following code in Python with TensorFlow:
gpus = tf.config.list_physical_devices('GPU')
if not gpus:
print("No GPUs detected")
else:
print("GPUs detected:")
for gpu in gpus:
print(gpu)
It always shows me, that no GPU is detected. Can you tell me what I have to do in order to make Tensorflow use the GPU?
EDIT: I am using PyCharm and downloaded Python directly (so I don't use something like Anaconda).
Update: Here is the nvidia-smi output from the cmd:
U:\>nvidia-smi
Wed Jul 12 09:13:40 2023
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 531.14 Driver Version: 531.14 CUDA Version: 12.1 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3090 WDDM | 00000000:65:00.0 On | N/A |
| 0% 36C P8 13W / 350W| 2085MiB / 24576MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 3252 C+G ...m Files\Mozilla Firefox\firefox.exe N/A |
| 0 N/A N/A 4364 C+G ...h2txyewy\InputApp\TextInputHost.exe N/A |
| 0 N/A N/A 11312 C+G ...soft Office\root\Office16\EXCEL.EXE N/A |
| 0 N/A N/A 19072 C+G ...5n1h2txyewy\ShellExperienceHost.exe N/A |
| 0 N/A N/A 21476 C+G ...m Files\Mozilla Firefox\firefox.exe N/A |
| 0 N/A N/A 23832 C+G ....Search_cw5n1h2txyewy\SearchApp.exe N/A |
| 0 N/A N/A 24544 C+G ..._8wekyb3d8bbwe\Microsoft.Photos.exe N/A |
| 0 N/A N/A 25932 C+G ...x64__8wekyb3d8bbwe\ScreenSketch.exe N/A |
| 0 N/A N/A 33528 C+G ...ekyb3d8bbwe\PhoneExperienceHost.exe N/A |
| 0 N/A N/A 36580 C+G ...on 2022.3.1\jbr\bin\jcef_helper.exe N/A |
| 0 N/A N/A 42128 C+G ...cal\Microsoft\OneDrive\OneDrive.exe N/A |
+---------------------------------------------------------------------------------------+
Update: I downgraded to tensorflow 2.10 and get some new error messages:"2023-07-15 15:15:23.440924: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found 2023-07-15 15:15:23.441186: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine."
Upvotes: 2
Views: 4284
Reputation: 11
There are a few things, first of all, sometimes pycharm fails to detect installed packages. It Happens to work after restarting the pc.
Next you can check if you have the path variable for cuda setup correctly. [it should be like this][1] [1]: https://i.sstatic.net/kEVK0.png
Next if that still doesn't work, you can check the compatibility of tensorflow version with the cuda version. for reference- https://www.tensorflow.org/install/sourcehttps://www.tensorflow.org/install/source
Also check compatibility with tensorflow-gpu. if there is some problem with them, after resolving the issue, recommend restarting pycharm.
Check TensorFlow GPU Support: TensorFlow needs to be built with GPU support. You can verify this by running the following code:
import tensorflow as tf
print(tf.test.is_built_with_cuda())
these are the version i am using for tensorflow and tensorflow-gpu and my cuda version is 10.1
and whenever working on these projects, its better to be working on a venv, as different projects need different version compatibility.
Upvotes: 1
Reputation: 1835
According to this guide you should use CUDA 11.8 11.2 (with CuDNN 8.1.0) for Windows and TF 2.10. You wrote that you installed "the latest version of CUDA", which is 12.2 right now. Can you verify that? To check your installed cuda version you can try to run
from tensorflow.python.platform import build_info as build
print(build.build_info['cuda_version'])
or for a comand-line one-liner:
python3 -c "from tensorflow.python.platform import build_info as build;print(build.build_info['cuda_version'])"
But given that TensorFlow can't find your GPU, I'm not sure that works. You can also look at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
which version the subfolder name is.
The error Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll
indicates that TensorFlow looks for libraries with the version 11.
To install the right TensorFlow version, run
pip install -U "tensorflow==2.10.*"
Download CUDA 11.8 11.2 from https://developer.nvidia.com/cuda-11-2-0-download-archive
If you want to have CuDNN, download and install it according to this guide. Be careful to choose version 8.1.0!
Upvotes: 0
Reputation: 567
You can try pip install tensorflow-gpu==2.10.0
and check if it works. It should uninstall old tensorflow package and install the gpu one of version==2.10.0
Upvotes: 0
Reputation: 449
I am also faced this issue. I am using anaconda. In my case problem was i installed tensorflow instead of tensorflow-gpu. so I created new env in anaconda and then installed the tensorflow-gpu. so now it using my gpu Gtx 1060
#CREATE THE ENV
conda create --name ENVNAME -y
#ACTIVATE THE eNV
conda activate ENVNAME
#INSTALLING CUDA DRIVERS
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 -y
#INSTALLING TENSORFLOW
conda install tensorflow-gpu -y
conda install -c anaconda ipykernel -y
conda install ipykernel -y
#ADDING ENV TO JUPYTER LIST
python3 -m ipykernel install --user --name=ENVNAME
#'VERIFY GPU SUPPORT'
python3 -c "import tensorflow as tf;
print(tf.config.list_physical_devices('GPU'))"
Upvotes: 0