BLAS - ATLAS openBLAS and MKL installation on Ubuntu

BLAS (Basic Linear Algebra Subprograms) 

It is a specification that prescribes a set of low-level routines for performing common linear algebra operations.

There are a lot of implements of BLAS:

  • Accelerate : Apple's framework for Mac OS X and iOS, which includes tuned versions of BLAS
  • ACML : The AMD Core Math Library, supporting the AMD Athlon and Opteron CPUs under Linux and Windows.
  • ATLAS : Automatically Tuned Linear Algebra Software, an open source implementation of BLAS APIs for C and Fortran.
  • BLIS : BLAS-like Library Instantiation Software framework for rapid instantiation.
  • cuBLAS : Optimized BLAS for NVIDIA based GPU cards.
  • clBLAS : An OpenCL implemenation of BLAS.
  • Intel MKL : The Intel Math Kernel Library, supporting x86 32-bits and 64-bits. Includes optimizations for Intel Pentium, Core and Intel   Xeon CPUs and Intel Xeon Phi; support for Linux, Windows and Mac OS X.
  • etc..

MKL installation 

Step1: Go to the bellow links and register for Parallel Studio XE Cluster Edition. You will receive an email containing install and download instructions.


  $ tar zxvf parallel_studio_xe_2015_update3.tgz
  $ chmod a+x parallel_studio_xe_2015_update3 -R
  $ cd parallel_studio_xe_2015_update3
  $ sudo ./install_GUI.sh
And then enter the serial keys as follow figure

Extend default lib search path for MKL in ubuntu. Do not need to export LD_LIBRARY_PATH
Create intel_mkl.conf, and edit it.
  $ cd /etc/ld.so.conf.d
  $ sudo vi intel_mkl.conf
Paste the bellows:
  $ sudo ldconfig -v

The faster way to setup MKL:
Download MKL libraray from 
$ tar -xf intel_mkl.tar
$ sudo mv intel_mkl /opt/intel 
$ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:/opt/intel/lib/intel64:$LD_LIBRARY_PATH

ATLAS installation

  $ sudo apt-get install libatlas-base-dev

OpenBLAS installation

  $ sudo apt-get install libopenblas-dev


C/C++ gflags and glog

Install gflags and glog

$ sudo apt-get install libgflags-dev libgoogle-glog-dev

gflag Source code on GitHub: https://github.com/gflags/gflags
glog Source code on GitHub: https://github.com/google/glog

gflag sample code

// Test.cpp
#include <iostream>
#include <gflags/gflags.h> // #include <google/gflags.h>
using namespace std;

DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
DEFINE_string(languages, "english,french,german", "comma-separated list of languages to offer in the 'lang' menu");

int main(int argc, char** agrv)
    ::google::ParseCommandLineFlags(&argc, &agrv, true);
    std::cout<< "FLAGS_big_menu : " << FLAGS_big_menu << "\n";
    return 0;

$ g++ -o test Test.cpp -I /usr/include/gflags -L /usr/lib/x86_64-linux-gnu -lgflags
$ ./Test  --big_menu=false
FLAGS_big_menu : 0

gflag Defining Flags In Program

Defining a flag is easy: just use the appropriate macro for the type you want the flag to be
DEFINE_bool(big_menu, true, "Include 'advanced' options in the menu listing");
DEFINE_string(languages, "english,french,german",
                 "comma-separated list of languages to offer in the 'lang' menu");
DEFINE_bool defines a boolean flag. Here are the types supported:
DEFINE_bool: boolean
DEFINE_int32: 32-bit integer
DEFINE_int64: 64-bit integer
DEFINE_uint64: unsigned 64-bit integer
DEFINE_double: double
DEFINE_string: C++ string

gflag Setting Flags on the Command Line

app_containing_foo --languages="chinese,japanese,korean"
app_containing_foo -languages="chinese,japanese,korean"
app_containing_foo --languages "chinese,japanese,korean"
app_containing_foo -languages "chinese,japanese,korean"
For boolean flags, the possibilities are slightly different:
app_containing_foo --big_menu
app_containing_foo --nobig_menu
app_containing_foo --big_menu=true
app_containing_foo --big_menu=false

glog sample code

#include <glog/logging.h>
int main(int argc, char** argv) {
    FLAGS_alsologtostderr = 1; // It will dump to console

    LOG(INFO) << "Dump log test";
    return 0;
I0825 14:45:06.432374 22528 objectdection.cpp:15] Dump log test


If you would like to use glog for cross-platform like Android, you can use miniglog as bellows because glog didn't support Android NDK.





Integrate Caffe into ROS


Integrate Caffe into ROS to do image classification.

Please go to my Github, there are more details:


Setup Caffe from scratch


Caffe is a deep learning framework made with expression, speed, and modularity in mind. It is developed by the Berkeley Vision and Learning Center (BVLC) and by community contributors.

Installation on Ubuntu 12.04 / 14.04

Use the script to install Caffe's requirements 
$ git clone https://gist.github.com/tzutalin/b24937905a2480da1723 
$ sh b24937905a2480da1723/installCaffeDep.sh

If you would like to install Caffe's requirement manually or install CUDA depedencies, please refer to http://caffe.berkeleyvision.org/install_apt.html

Get Caffe source and compile it

Clone the source
$ git clone https://github.com/BVLC/caffe.git

After cloning, confing Makefile.config for Makefile
$ cp Makefile.config.example Makefile.config
$ vi Makefile.config
For CPU-only Caffe, uncomment CPU_ONLY := 1 in Makefile.config.

Start compiling
$ make -j 8 all ; make -j 8 test ; make -j 8 runtest ; make pycaffe ; make distribute 
My Makefile.config's screenshot is as bellow. I uncomment CPU_ONLY := 1

Run and test Caffe

Test whether caffe can run or not, use benchmarking cmd as bellos 
$ cd caffe 
$ build/tools/caffe time --model=models/bvlc_alexnet/deploy.prototxt

Run Caffe python
The search path can be manipulated from within a Python program as the variable sys.path.
$ echo PYTHONPATH=[/to/your/path]/caffe/python/:$PYTHONPATH > ~/.bashrc

Try to run classifiy_test.py
$ cd [/to/your/path]/caffe/example 
$ git clone https://gist.github.com/912d1774d96266c4e76b.git 
$ python classify_test.py

If using default python(Python 2.7.6), might need the following dependencies 
$ sudo apt-get install python-scipy python-skimage libqt4-core libqt4-gui libqt4-dev libzmq-dev ; sudo pip install -U scikit-image; sudo pip install pyzmq; sudo pip install protobuf; sudo pip install pygments 


Install Intel MKL and other BLAS for Caffe
Using Caffe with Eclipse
Manual Install Caffe
Instant way to use Caffe