How to install TensorFlow GPU on UBUNTU 18.04 | by Sushrut Ashtikar | Towards Data Science

The rate of progress in the field of artificial intelligence is one of the most hotly contested aspects of the ongoing boom in teaching computers and robots how to see the world, make sense of it, and eventually perform complex tasks both in the physical realm and the virtual one. And just how fast the industry is moving, and to what end, is typically measured not just by actual product advancements and research milestones, but also by the prognostications and voiced concerns of AI leaders, futurists, academics, economists, and policymakers. AI is going to change the world — but how and when are still open questions.
Most of the users who already train their machine learning models on their desktops/laptops having Nvidia GPU compromise with CPU due to difficulties in installation of GPU version of TENSORFLOW. After having a bit of research in installation process i’m writing the procedure that i have tried on my laptop having nvidia 930MX.
Why TensorFlow?TensorFlow is an end-to-end open source platform for machine learning. It has a comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML powered applications.
The very first step is to check whether you have installed nvidia drivers.You can check that by typing below command in terminal.
nvidia-smi
If your system have detected nvidia drivers then u will see some similar output like mine.
If you have not installed the graphics driver i recommend to install drivers from official website and then recheck by entering the above command.
Optional, if you are not able to find the graphics driver for your gpu then you can try below process.
Goto Software & Updates ->Additional Drivers -> There you can find your driver. Select driver — Using NVIDIA driver metapackage then click on Apply changes.
As you can check that there is a system default option for driver installation, but you can see i have manually installed my graphics drivers. I would highly recommend to install gpu drivers manually.
BonusIf you are trying to install drivers from .run file then you may face conflicts with the “nouveau kernal driver” , don’t force install in this case. First add the driver to blacklist. This is compulsory as it will stop the kernel from using your gpu resource.To blacklist the nouveau run below command.echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
After this , runsudo update-initramfs -u
to update initframsThen try installing the drivers again.
CUDA® is a parallel computing platform and programming model developed by NVIDIA for general computing on graphical processing units (GPUs). With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.
In GPU-accelerated applications, the sequential part of the workload runs on the CPU — which is optimized for single-threaded performance — while the compute intensive portion of the application runs on thousands of GPU cores in parallel. When using CUDA, developers program in popular languages such as C, C++, Fortran, Python and MATLAB and express parallelism through extensions in the form of a few basic keywords.
Visit official nvidia website for downloading cuda for your os.
Select appropriate version of Operating System,Distribution, Version and select Installer type to deb (local)
You will need to download cuda deb file (1.6GB) and follow the installation steps mentioned as you can see above.
The NVIDIA CUDA® Deep Neural Network library (cuDNN) is a GPU-accelerated library of primitives for deep neural networks. cuDNN provides highly tuned implementations for standard routines such as forward and backward convolution, pooling, normalization, and activation layers.
Deep learning researchers and framework developers worldwide rely on cuDNN for high-performance GPU acceleration. It allows them to focus on training neural networks and developing software applications rather than spending time on low-level GPU performance tuning. cuDNN accelerates widely used deep learning frameworks, including Caffe,Caffe2, Chainer, Keras,MATLAB, MxNet, TensorFlow, and PyTorch. For access to NVIDIA optimized deep learning framework containers, that has cuDNN integrated into the frameworks, visit NVIDIA GPU CLOUD to learn more and get started.
Goto https://developer.nvidia.com/cudnn and download (Login and agreement required).
After login and accepting agreement.
Select appropriate cuDNN developer library (deb file)based on the version of CUDA you installed in previous step.
run the following steps to install the cuDNN library.
sudo dpkg -i </path/to/cudnn_file.deb>If you get cupti dependencies error while installation, then install the cupti dependency with below command:sudo apt-get install libcupti-devecho ‘export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH’ >> ~/.bashrc
pip install --upgrade tensorflow-gpu
Verify TensorFlow installation: Please execute the following Python snipped to verify your TensorFlow installation:
python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())
After execution of above command you will recieve output similar to my output as mentioned below.
2019-04-17 23:10:19.343549: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA2019-04-17 23:10:19.377027: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2400000000 Hz2019-04-17 23:10:19.377323: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x56231cab6c90 executing computations on platform Host. Devices:2019-04-17 23:10:19.377360: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>2019-04-17 23:10:19.427725: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero2019-04-17 23:10:19.428532: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x56231cbb9310 executing computations on platform CUDA. Devices:2019-04-17 23:10:19.428551: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): GeForce 930MX, Compute Capability 5.02019-04-17 23:10:19.428797: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties: name: GeForce 930MX major: 5 minor: 0 memoryClockRate(GHz): 1.0195pciBusID: 0000:01:00.0totalMemory: 1.96GiB freeMemory: 1.50GiB2019-04-17 23:10:19.428833: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 02019-04-17 23:10:19.429703: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:2019-04-17 23:10:19.429717: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990]      0 2019-04-17 23:10:19.429744: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0:   N 2019-04-17 23:10:19.429924: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/device:GPU:0 with 1307 MB memory) -> physical GPU (device: 0, name: GeForce 930MX, pci bus id: 0000:01:00.0, compute capability: 5.0)[name: "/device:CPU:0"device_type: "CPU"memory_limit: 268435456locality {}incarnation: 7335559256733264271, name: "/device:XLA_CPU:0"device_type: "XLA_CPU"memory_limit: 17179869184locality {}incarnation: 5312720144392370303physical_device_desc: "device: XLA_CPU device", name: "/device:XLA_GPU:0"device_type: "XLA_GPU"memory_limit: 17179869184locality {}incarnation: 4529346810094966789physical_device_desc: "device: XLA_GPU device", name: "/device:GPU:0"device_type: "GPU"memory_limit: 1370750976locality {  bus_id: 1  links {  }}incarnation: 2845160405845590596physical_device_desc: "device: 0, name: GeForce 930MX, pci bus id: 0000:01:00.0, compute capability: 5.0"]
I really hope this guide helps you to install TensorFlow GPU on your machine containing nvidia graphics card. Please let me know if you are finding any difficulties in the installation process.