2

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."

21

4 Answers 4

1
  1. There are a few things, first of all, sometimes pycharm fails to detect installed packages. It Happens to work after restarting the pc.

  2. Next you can check if you have the path variable for cuda setup correctly. [it should be like this: https://i.sstatic.net/kEVK0.png

  3. 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/source

  4. Also check compatibility with tensorflow-gpu. if there is some problem with them, after resolving the issue, recommend restarting pycharm.

  5. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0
+50

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!

20 Comments

Why do I (and everyone else) get a downvote on their answer? I'd be helpful to know if I did something wrong..
Thanks for your comment. I personally did not downvote any answer (and I think it is rude that someone downvotes without giving any explanation)
My Cuda Version is 64_112
Ah well seems I can't read my own links right. The linked guide says CUDA 11.2, not CUDA 11.8. I'll fix it in the answer. Maybe explains the downvote.. As for your version, it seems right. Sounds like CUDA 11.2. Does the error you edited in your question persists? What does it says if you type in nvcc -V in your console?
Thanks for your answer. I downloaded Cuda Toolkit 11.8 and cudnn-11.2-windows-x64-v8.1.0.77. as a zip file. When using the command nvcc -V in the Python Console of PyCharm I get "PyDev console: starting. Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32 nvcc -V Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.1\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() File "<input>", line 1, in <module> NameError: name 'nvcc' is not defined"
|
0

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'))"

enter image description here

3 Comments

Thanks for your answer. I am not using Anaconda so I don't think that I can use your suggested approach
Thanks for your comment. Just for your information: I personally did not downvote any answer (and I think it is rude that someone downvotes without giving any explanation)
who is donwvoting and why?
0

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

5 Comments

Thanks for the answer. I installed tensorflow 2.10. not via pip because this led to an error message, but via the PyCharm package manager. Unfortunately, I still get another error message and the GPU is still not found. I wrote an update on the question.
@PeterBe Its easiest if you use conda. Pip is slightly more complicated. I never tried pycharm package manager but i guess it to be more complicated than conda. It might be possible that your current environment is all messed up making things more difficult. I would recommend you create a new conda environment and follow steps mentioned by other people, then error might get easily solved. You can use miniconda if you find conda too heavy for your PC.
@Thanks YadneshD for your answer. Actually, I have very bad experience with Anaconda (for me it is one of the worst tools that I have ever used). I think it is buggy. This is why I don't want to mess around with Anaconda
Thanks for your comment. Just for your information: I personally did not downvote any answer (and I think it is rude that someone downvotes without giving any explanation)
@PeterBe Full version of conda is very heavy and even I found it messy at first. I personally prefer miniconda which is lightweight and easy to remove. Miniconda has all major functionalities of conda and is easy to use from command line.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.