Conda is a package manager provided by Anaconda or Miniconda. Currently, SINGA has conda packages (Python2.7) for Linux and MacOSX.
CPU only
conda install -c nusdbsystem singa
GPU via CUDA+cuDNN
conda install -c nusdbsystem singa-cudax.y-cudnnz
where x.y,z
is one of <8.0, 5>, <7.5, 5> and <7.5, 4>. Users need to install CUDA and cuDNN before installing SINGA. If cuDNN is not in system folders (e.g., /usr/local), export the folder of libcudnn.so to LD_LIBRARY_PATH
Only the CPU version is available,
conda config --add channels conda-forge conda install -c nusdbsystem singa
If there is no error message from
python -c "from singa import tensor"
then SINGA is installed successfully.
The following Debian packages (on architecture: amd64) are available
Download the deb file and install it via
apt-get install <path to the deb file, e.g., ./python-singa.deb>
Note that the path must include ./
if the file in inside the current folder.
The source files could be downloaded either as a tar.gz file, or as a git repo
$ git clone https://github.com/apache/incubator-singa.git $ cd incubator-singa/
The following libraries are required
The following libraries are optional
create a build
folder inside incubator-singa and go into that folder
run cmake [options] ..
by default all options are OFF except USE_PYTHON
USE_MODUELS=ON
, used if protobuf and blas are not installed a priorUSE_CUDA=ON
, used if CUDA and cuDNN is availableUSE_PYTHON=ON
, used for compiling PySINGAUSE_OPENCL=ON
, used for compiling with OpenCL supportcompile the code, e.g., make
goto python folder
run pip install .
[optional] run python setup.py bdist_wheel
to generate the wheel file
Step 4 and 5 are to install PySINGA. Details on the installation of dependent libraries and the instructions for each OS are given in the following sections.
Most of the dependent libraries could be installed from source or via package mangers like apt-get, yum, and homebrew. Please refer to FAQ for problems caused by the path setting of the dependent libraries.
The following instructions are tested on Ubuntu 14.04 and 16.04for installing dependent libraries.
# required libraries $ sudo apt-get install libprotobuf-dev libopenblas-dev protobuf-compiler # optional libraries $ sudo apt-get install python2.7-dev python-pip python-numpy $ sudo apt-get install libopencv-dev libgoogle-glog-dev liblmdb-dev
The following instructions are tested on Mac OS X Yosemite (10.11 and 10.12) for installing dependent libraries.
# required libraries $ brew tap homebrew/science $ brew install openblas $ brew install protobuf260 # optional libraries $ brew tap homebrew/python $ brew install python $ brew install opencv $ brew install -vd glog lmdb
By default, openblas is installed into /usr/local/opt/openblas. To let the compiler (and cmake) know the openblas path,
$ export CMAKE_INCLUDE_PATH=/usr/local/opt/openblas/include:$CMAKE_INCLUDE_PATH $ export CMAKE_LIBRARY_PATH=/usr/local/opt/openblas/lib:$CMAKE_LIBRARY_PATH
To let the runtime know the openblas path,
$ export LD_LIBRARY_PATH=/usr/local/opt/openblas/library:$LD_LIBRARY_PATH
If protobuf and openblas are not installed, you can compile SINGA together with them
$ In SINGA ROOT folder $ mkdir build $ cd build $ cmake -DUSE_MODULES=ON .. $ make
cmake would download OpenBlas and Protobuf (2.6.1) and compile them together with SINGA.
After compiling SINGA, you can run the unit tests by
$ ./bin/test_singa
You can see all the testing cases with testing results. If SINGA passes all tests, then you have successfully installed SINGA.
You can use ccmake ..
to configure the compilation options. If some dependent libraries are not in the system default paths, you need to export the following environment variables
export CMAKE_INCLUDE_PATH=<path to the header file folder> export CMAKE_LIBRARY_PATH=<path to the lib file folder>
swig and numpy can be install by
$ Ubuntu 14.04 and 16.04 $ sudo apt-get install python-numpy # Ubuntu 16.04 $ sudo apt-get install swig
Note that swig has to be installed from source on Ubuntu 14.04. After installing numpy, export the header path of numpy.i as
$ export CPLUS_INCLUDE_PATH=`python -c "import numpy; print numpy.get_include()"`:$CPLUS_INCLUDE_PATH
Similar to compile CPP code, PySINGA is compiled by
$ cmake -DUSE_PYTHON=ON .. $ make $ cd python $ pip install .
Developers can build the wheel file via
# under the build directory $ cd python
The generated wheel file is under “dist” directory.
Users are encouraged to install the CUDA and cuDNN for running SINGA on GPUs to get better performance.
SINGA has been tested over CUDA (7, 7.5, 8), and cuDNN (4 and 5). If cuDNN is decompressed into non-system folder, e.g. /home/bob/local/cudnn/, the following commands should be executed for cmake and the runtime to find it
$ export CMAKE_INCLUDE_PATH=/home/bob/local/cudnn/include:$CMAKE_INCLUDE_PATH $ export CMAKE_LIBRARY_PATH=/home/bob/local/cudnn/lib64:$CMAKE_LIBRARY_PATH $ export LD_LIBRARY_PATH=/home/bob/local/cudnn/lib64:$LD_LIBRARY_PATH
The cmake options for CUDA and cuDNN should be switched on
# Dependent libs are install already $ cmake -DUSE_CUDA=ON ..
SINGA uses opencl-headers and viennacl (version 1.7.1 or newer) for OpenCL support, which can be installed using via
# On Ubuntu 16.04 $ sudo apt-get install opencl-headers, libviennacl-dev # On Fedora $ sudo yum install opencl-headers, viennacl
Additionally, you will need the OpenCL Installable Client Driver (ICD) for the platforms that you want to run OpenCL on.
beignet-opencl-icd
package.Note that running OpenCL on CPUs is not currently recommended because it is slow. Memory transfer is on the order of whole seconds (1000‘s of ms on CPUs as compared to 1’s of ms on GPUs).
More information on setting up a working OpenCL environment may be found here.
If the package version of ViennaCL is not at least 1.7.1, you will need to build it from source:
Clone the repository from here, checkout the release-1.7.1
tag and build it. Remember to add its directory to PATH
and the built libraries to LD_LIBRARY_PATH
.
To build SINGA with OpenCL support, you need to pass the flag during cmake:
cmake -DUSE_OPENCL=ON ..
For the dependent library installation, please refer to Dependencies. After all the dependencies are successfully installed, just run the following commands to generate the VS solution in cmd under singa folder:
$ md build && cd build $ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF ..
The default project generated by the command is 32-bit version. You can also specify a 64-bit version project by:
$ md build && cd build $ cmake -G "Visual Studio 14 Win64" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF ..
If you get error outputs like “Could NOT find xxxxx” indicating a dependent library missing, configure your library file and include path for cmake or the system. For example, you get an error “Could NOT find CBLAS” and suppose you installed openblas header files at “d:\include” and openblas library at “d:\lib”. You should run the following command to specify your cblas parameters in cmake:
$ cmake -G "Visual Studio 14" -DUSE_CUDA=OFF -DUSE_PYTHON=OFF -DCBLAS_INCLUDE_DIR="d:\include" -DCBLAS_LIBRARIES="d:\lib\libopenblas.lib" -DProtobuf_INCLUDE_DIR=<include dir of protobuf> -DProtobuf_LIBRARIES=<path to libprotobuf.lib> -DProtobuf_PROTOC_EXECUTABLE=<path to protoc.exe> -DGLOG_INCLUDE_DIR=<include dir of glog> -DGLOG_LIBRARIES=<path to libglog.lib> ..
To find out the parameters you need to specify for some special libraries, you can run the following command:
$ cmake -LAH
If you use cmake GUI tool in windows, make sure you configure the right parameters for the singa solution by select “Advanced” box. After generating the VS project, open the “singa.sln” project file under the “build” folder and compile it as a normal VS solution. You will find the unit tests file named “test_singa” in the project binary folder. If you get errors when running test_singa.exe due to libglog.dll/libopenblas.dll missing, just copy the dll files into the same folder as test_singa.exe
Q: Error from ‘import singa’ using PySINGA installed from wheel.
A: Please check the detailed error from python -c "from singa import _singa_wrap"
. Sometimes it is caused by the dependent libraries, e.g. there are multiple versions of protobuf, missing of cudnn, numpy version mismatch. Following steps show the solutions for different cases
Check the cudnn and cuda and gcc versions, cudnn5 and cuda7.5 and gcc4.8/4.9 are preferred. if gcc is 5.0, then downgrade it. If cudnn is missing or not match with the wheel version, you can download the correct version of cudnn into ~/local/cudnn/ and
$ echo "export LD_LIBRARY_PATH=/home/<yourname>/local/cudnn/lib64:$LD_LIBRARY_PATH" >> ~/.bashrc
If it is the problem related to protobuf, then download the newest whl files which have compiled protobuf and openblas into the whl file of PySINGA. Or you can install protobuf from source into a local folder, say ~/local/; Decompress the tar file, and then
$ ./configure --prefix=/home/<yourname>local $ make && make install $ echo "export LD_LIBRARY_PATH=/home/<yourname>/local/lib:$LD_LIBRARY_PATH" >> ~/.bashrc $ source ~/.bashrc
If it cannot find other libs including python, then create virtual env using pip or conda;
If it is not caused by the above reasons, go to the folder of _singa_wrap.so
,
$ python >> import importlib >> importlib.import_module('_singa_wrap')
Check the error message. For example, if the numpy version mismatches, the error message would be, RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa Then you need to upgrade the numpy.
Q: Error from running cmake ..
, which cannot find the dependent libraries.
A: If you haven't installed the libraries, install them. If you installed the libraries in a folder that is outside of the system folder, e.g. /usr/local, you need to export the following variables
$ export CMAKE_INCLUDE_PATH=<path to your header file folder> $ export CMAKE_LIBRARY_PATH=<path to your lib file folder>
Q: Error from make
, e.g. the linking phase
A: If your libraries are in other folders than system default paths, you need to export the following varaibles
$ export LIBRARY_PATH=<path to your lib file folder> $ export LD_LIBRARY_PATH=<path to your lib file folder>
Q: Error from header files, e.g. ‘cblas.h no such file or directory exists’
A: You need to include the folder of the cblas.h into CPLUS_INCLUDE_PATH, e.g.,
$ export CPLUS_INCLUDE_PATH=/opt/OpenBLAS/include:$CPLUS_INCLUDE_PATH
Q:While compiling SINGA, I get error SSE2 instruction set not enabled
A:You can try following command:
$ make CFLAGS='-msse2' CXXFLAGS='-msse2'
Q:I get ImportError: cannot import name enum_type_wrapper
from google.protobuf.internal when I try to import .py files.
A: You need to install the python binding of protobuf, which could be installed via
$ sudo apt-get install protobuf
or from source
$ cd /PROTOBUF/SOURCE/FOLDER $ cd python $ python setup.py build $ python setup.py install
Q: When I build OpenBLAS from source, I am told that I need a Fortran compiler.
A: You can compile OpenBLAS by
$ make ONLY_CBLAS=1
or install it using
$ sudo apt-get install libopenblas-dev
Q: When I build protocol buffer, it reports that GLIBC++_3.4.20 not found in /usr/lib64/libstdc++.so.6.
A: This means the linker found libstdc++.so.6 but that library belongs to an older version of GCC than was used to compile and link the program. The program depends on code defined in the newer libstdc++ that belongs to the newer version of GCC, so the linker must be told how to find the newer libstdc++ shared library. The simplest way to fix this is to find the correct libstdc++ and export it to LD_LIBRARY_PATH. For example, if GLIBC++_3.4.20 is listed in the output of the following command,
$ strings /usr/local/lib64/libstdc++.so.6|grep GLIBC++
then you just set your environment variable as
$ export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
Q: When I build glog, it reports that “src/logging_unittest.cc:83:20: error: ‘gflags’ is not a namespace-name”
A: It maybe that you have installed gflags with a different namespace such as “google”. so glog can't find ‘gflags’ namespace. Because it is not necessary to have gflags to build glog. So you can change the configure.ac file to ignore gflags.
1. cd to glog src directory 2. change line 125 of configure.ac to "AC_CHECK_LIB(gflags, main, ac_cv_have_libgflags=0, ac_cv_have_libgflags=0)" 3. autoreconf
After this, you can build glog again.
Q: When using virtual environment, everytime I run pip install, it would reinstall numpy. However, the numpy would not be used when I import numpy
A: It could be caused by the PYTHONPATH
which should be set to empty when you are using virtual environment to avoid the conflicts with the path of the virtual environment.
Q: When compiling PySINGA from source, there is a compilation error due to the missing of <numpy/objectarray.h>
A: Please install numpy and export the path of numpy header files as
$ export CPLUS_INCLUDE_PATH=`python -c "import numpy; print numpy.get_include()"`:$CPLUS_INCLUDE_PATH
Q: When I run PySINGA in Mac OS X, I got the error “Fatal Python error: PyThreadState_Get: no current thread Abort trap: 6”
A: This error happens typically when you have multiple version of Python on your system and you installed SINGA via pip (this problem is resolved for installation via conda), e.g, the one comes with the OS and the one installed by Homebrew. The Python linked by PySINGA must be the same as the Python interpreter. You can check your interpreter by which python
and check the Python linked by PySINGA via otool -L <path to _singa_wrap.so>
. To fix this error, compile SINGA with the correct version of Python. In particular, if you build PySINGA from source, you need to specify the paths when invoking cmake
$ cmake -DPYTHON_LIBRARY=`python-config --prefix`/lib/libpython2.7.dylib -DPYTHON_INCLUDE_DIR=`python-config --prefix`/include/python2.7/ ..
If installed PySINGA from binary packages, e.g. debian or wheel, then you need to change the python interpreter, e.g., reset the $PATH to put the correct path of Python at the front position.