Installation of TensorFlow-GPU in System (with CUDA and CuDNN)


For Linux:

 Here is a Linux Script file to install it on a Linux OS:

#!/bin/bash

# Download CUDA Toolkit
wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux

# Install CUDA Toolkit
sudo sh cuda_10.0.130_410.48_linux --silent --toolkit --override

# Add CUDA to environment variables
echo 'export PATH="/usr/local/cuda-10.0/bin:$PATH"' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH"' >> ~/.bashrc
source ~/.bashrc

# Download cuDNN
wget https://developer.download.nvidia.com/compute/machine-learning/cudnn/secure/v7.6.5/prod/10.0_20190923/cudnn-10.0-linux-x64-v7.6.5.32.tgz

# Extract cuDNN
tar -xzvf cudnn-10.0-linux-x64-v7.6.5.32.tgz

# Copy cuDNN files to CUDA directory
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/

# Install TensorFlow GPU
pip install tensorflow-gpu

# Check if TensorFlow GPU is installed successfully
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
if [ $? -ne 0 ]; then
  echo "TensorFlow GPU installation failed. Please check CUDA and cuDNN versions and configurations."
  exit 1
fi

echo "TensorFlow GPU installation is complete!"


For Windows

Here's a batch script for installing TensorFlow GPU along with CUDA and cuDNN on a Windows machine:

@echo off

echo Installing CUDA Toolkit

REM Download CUDA Toolkit
bitsadmin /transfer download /downloadflag:overwriteexisting /priority:high https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_411.31_win10.exe C:\cuda_10.0.130_411.31_win10.exe

REM Install CUDA Toolkit
C:\cuda_10.0.130_411.31_win10.exe /silent /install /toolkit

echo Installing cuDNN

REM Download cuDNN
bitsadmin /transfer download /downloadflag:overwriteexisting /priority:high https://developer.download.nvidia.com/compute/machine-learning/cudnn/secure/v7.6.5/prod/10.0_20190923/cudnn-10.0-windows10-x64-v7.6.5.32.zip C:\cudnn-10.0-windows10-x64-v7.6.5.32.zip

REM Extract cuDNN
7z x C:\cudnn-10.0-windows10-x64-v7.6.5.32.zip -ocuda

REM Copy cuDNN files to CUDA directory
xcopy /s cuda\cuda\include\* "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include"
xcopy /s cuda\cuda\bin\cudnn64_7.dll "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin"
xcopy /s cuda\cuda\lib\x64\* "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64"

echo Installing TensorFlow GPU

REM Install TensorFlow GPU
pip install tensorflow-gpu

echo Verifying TensorFlow GPU Installation

REM Check if TensorFlow GPU is installed successfully
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
if %errorlevel% neq 0 (
  echo TensorFlow GPU installation failed. Please check CUDA and cuDNN versions and configurations.
  exit /b 1
)

echo TensorFlow GPU installation is complete!


For MacOS

Here's a bash script for installing TensorFlow GPU on MacOS with CUDA and cuDNN:

#!/bin/bash

# Install CUDA Toolkit
wget https://developer.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_mac.dmg
hdiutil mount cuda_10.2.89_mac.dmg
sudo installer -pkg /Volumes/CUDAToolkit/CUDAToolkit.pkg -target /
hdiutil unmount /Volumes/CUDAToolkit/

# Install cuDNN
wget https://developer.download.nvidia.com/compute/machine-learning/cudnn/secure/v7.6.5/prod/10.2_20190618/cudnn-10.2-osx-x64-v7.6.5.33.tgz
tar -xzvf cudnn-10.2-osx-x64-v7.6.5.33.tgz
sudo cp -R cuda/include/* /usr/local/cuda/include/
sudo cp -R cuda/lib/* /usr/local/cuda/lib/

# Install TensorFlow GPU
pip3 install tensorflow-gpu

# Verify TensorFlow GPU Installation
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
if [ $? -ne 0 ]; then
  echo "TensorFlow GPU installation failed. Please check CUDA and cuDNN versions and configurations."
  exit 1
fi

echo "TensorFlow GPU installation is complete!"





AJ Blogs

Hello everyone, My name Arth and I like to write about what I learn. Follow My Website - https://sites.google.com/view/aj-blogs/home

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page