Installing TensorFlow with GPU support on Windows 10 and Nvidia graphics card in 5 steps
For a successful setup of tensorflow with GPU, you need Graphics Driver, CuDnn library and CUDA Toolkit. Here are the simple 5 steps:
- Search for Nvidia Control Panel and look for nvidia version.
You can also check the specs with this command in command prompt, open cmd and type nvidia-smi
Check the CUDA version, we’ll need it later.
Go to apps and features and search for nvidia control panel and check the version.
The Graphics driver is already installed. If the CUDA Tool Kit does not appear, you need to follow the next steps.
2. Goto this link, and select the required cuda version, In my case 11.4.0
CUDA Toolkit Archive
Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the…
Click Download and Follow the prompts.
3. let’s install the CuDnn library. Goto this link
NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.
You might need to login before and select the latest file with your cuda version.
Extract the zip files in a folder.
Installations are done now. Let’s add all these to our path.
4. In System Properties> Environment Variables> User Variables> Path> Edit> select new and add the CUDA®, CUPTI, and cuDNN installation directories path. For example, if the CUDA® Toolkit is installed to
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4 and cuDNN to
C:\tools\cuda, update your
%PATH% to match:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\extras\CUPTI\lib64;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\include;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\libnvvp;
5. Install tensorflow or tensorflow-gpu in a virtual environment with this command,
pip install tensorflow-gpu
Run the following code;
import tensorflow as tffrom tensorflow.python.client import device_libprint("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))device_lib.list_local_devices()
Which should ouputs;
Moreover, The message
This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)
to use the following CPU instructions in performance-critical operations: AVX AVX2
means that in places where performance matters (eg matrix multiplication in deep neural networks), certain optimized compiler instructions will be used. i.e., it can and will take advantage of your CPU to get that extra speed out. and the installation is successful.