How to use GPU of MX150 with Tensorflow 1.8 CUDA 9.2 (Phase 3: Compilation of Tensorflow 1.8)
Reading Time: 4 minutes
In the serie, “How to use GPU with Tensorflow 1.8 and CUDA 9.2”, we are now in the third phase. This step is related to the compilation of Tensorflow 1.8 by including the library CUDA. This compilation will enable tensorflow to use the GPU core of the graphical card (384 cores). TensorFlow programs typically run significantly faster on a GPU than on a CPU. Therefore, if your system has a NVIDIA GPU and you need to run performance-critical applications, you should ultimately build and install this version. In the previous sections, we already installed the last driver of the graphical card (MX150), the library CUDNN, and CUPTI to prepare the laptop for the compilation of Tensorflow 1.8. We also check if the library is correctly installed by using the samples available in the package of CUDA.
The compilation of Tensorflow is not simple. So, I recommend to reserve around 2 hours to make this task. The compilation of the software is structured into 4 steps:
- Step 1: Download the required packages in the Ubuntu repository
- Step 2: Installation of Blazel. Blazel is an open-source build and test tool similar to Make, Maven, and Gradle.
- Step 3: Compilation of Tensorflow from the source.
- Step 4: Creation of the package whl. This package will be deployed in the phase 4.
Step 1: Download the required packages in the Ubuntu Repository
If you remember the introduction post, the objective is to use the Keras library to make a deep neural network in python. Keras is an open source neural network library written in Python. It is capable of running on top of TensorFlow, Microsoft Cognitive Toolkit or Theano. Designed to enable fast experimentation with deep neural networks, it focuses on being user-friendly, modular, and extensible. We have decided to use Tensorflow on GPU as backend of Keras.
So, the first step for this phase is the installation of the python environment which will be required for the execution of the DNN program that we will develop based on the Keras library. We will install the version 2.7 and 3 of python, numpy, python-wheel and pip on the system:
- Python is an interpreted high-level programming language for general-purpose programming. Python features a dynamic type system and automatic memory management. It supports multiple programming paradigms, including object-oriented, imperative, functional and procedural, and has a large and comprehensive standard library
- Python-wheel is Wheels are the new standard of Python distribution and are intended to replace eggs. Support is offered in pip >= 1.4 and setuptools >= 0.8. A wheel is a ZIP-format archive with a specially formatted filename and the .whl extension. It is designed to contain all the files for a PEP 376 compatible install in a way that is very close to the on-disk format.
- Python_numpy is the fundamental package for scientific computing with Python. It contains a powerful N-dimensional array object, sophisticated (broadcasting) functions, tools for integrating C/C++ and Fortran code and useful linear algebra, Fourier transform, and random number capabilities
- Python-dev is a Ubuntu package which regroups Header files, a static library and development tools for building Python modules, extending the Python interpreter or embedding Python in applications. This will be required by blazel to build the tensorflow package.
- Pip is a package management system used to install and manage software packages written in Python. Many packages can be found in the default source for packages and their dependencies. pip is a recursive acronym for “Pip Installs Packages”.
apt-get install python3-pip apt-get install python-numpy python-dev python-pip python-wheel apt-get install python3-numpy python3-dev python3-pip python3-wheel apt-get install git
Git is installed to clone the Blazel and the tensorflow source codes available on github.
Step 2: Installation of Blazel
For the compilation of Tensorflow, you need the software Blazel. Blazel is an open-source build and test tool similar to Make, Maven, and Gradle. It uses a human-readable, high-level build language. Bazel supports projects in multiple languages and builds outputs for multiple platforms. .All the documentation for this software can be found on the site : https://bazel.build/).
Blazel is not available in the Ubuntu repository, so you need to download the package from github and install it.
cd ~/ wget"https://github.com/bazelbuild/bazel/releases/download/0.14.0/bazel-0.14.0-installer-linux-x86_64.sh" chmod +x bazel-0.14.0-installer-linux-x86_64.sh ./bazel-0.14.0-installer-linux-x86_64.sh --user echo 'export PATH="$PATH:$HOME/bin"' >> ~/.bashrc ldconfig
💡 attention point : It will be better to install bazel in other directory (in the standard one or a specific directory by configuring the environment variable via the .bashrc file)
Step 3: Compilation of Tensorflow
To compile Tensorflow from the source, you firstly need to clone the directory of Tensorflow on the github thanks to the git command.
cd ~/ git clone https://github.com/tensorflow/tensorflow.git cd tensorflow git pull git checkout r1.8
Secondly, you need to prepare the compilation by configuring the different options by running the configure program.
This is at this place that we link tensorflow with Cuda 9.2 that we installed in the previous post.
Thirdly, you can make the compilation and create the wheel package that you will install in the section 4 with pip.The next step in the process to install tensorflow GPU version will be to build tensorflow using bazel. This process takes a long time (around 1h30 on the T580).
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
Finally, the creation of the wheel package of tensorflow using GPU
bazel-bin/tensorflow/tools/pip_package/build_pip_package
You will find in the directory the file with the name: tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
Conclusion:
Good ! Our initiative is almost close to the end. We have now the wheel package of Tensorflow using the GPU of the graphical card.
So, let’s start now with the Phase 4! The final post where we will learn how to run a DNN software using Keras, Tensorflow and the GPU of the card. For this, I will adapt an additional step to use a IDE “visual code” for this exercise.
Feel free to give comments or ask questions and I will try to answer you. It’s possible that I forgot a step in the explanation seeing that I made the compilation of this package in August. If you have any problem, just give me a comment and I will answer you and adapt the post.
If you find this post valuable, Rate it ! This helps me to improve it. For comments, you need to register with your LinkedIn account.
References:
When I write an article, I always give the references I used because I believe in intellectual property and I know how many times you need to write a valuable article:
- https://www.bazel.build/ where you can find more information about bazel which was used for the compilation of Tensorflow.
- https://pypi.org/project/wheel/ & https://pythonwheels.com/ where you can find more information about the wheel package.
- https://pypi.org/project/pip/ where you can find more information about the pip.
- https://www.tensorflow.org/install/install_sources where you can find the documentation for the compilation of the Tensorflow sources
Im Using windows platform with MX150 graphics card, can I use this steps to install tensorflow gpud on my laptop?