A. Requirements

Torch compilation requires a number of standard packages described below:

The installation of most of these packages should be rather straightforward. For Debian based systems we use the apt-get magic:

apt-get install gcc g++
apt-get install cmake
apt-get install libreadline5-dev
apt-get install subversion
Please adapt according to your distribution.

Note: readline library is helpful for better command line interaction, but it is not required.

Note: while CMake 2.4.7 or newer will (kind of) work, we like to use CMake 2.6 which is much less buggy. CMake installation is easy and fast from the sources available on CMake website. Follow their instructions for that purpose.

We require QT 4.4 for handling graphics (beware not installing QT 4.3 or older). If it is not found at compile time, Torch will still compile but no graphics will be available. On recent Debian distribution you can install it with

apt-get install libqt4-core libqt4-gui libqt4-dev
If QT 4.4 is not available on your system you should follow our additional instructions for QT 4.4.

CBLAS installation is also recommended for speed. If not found, Torch will rely on hand-made linear algebra routines. Debian distribution provide CBLAS through the refblas package:

apt-get install refblas3-dev
Ultimate speed is achieved using the Intel MKL library. We support at the time only MKL 9, as we get weird runtime errors with MKL 10. Follow Intel instruction to unpack MKL. Then make sure the libraries relevant for your system (e.g. em64t if you are on a 64 bits distribution) are available in your LD_LIBRARY_PATH.

B. Getting Torch sources

You can download the last tarball sources and unpack it with

tar xfvz Torch5-XXX-Source.tar.gz
where XXX is the version you downloaded. This will create a directory corresponding to the name of the archive, that you should rename as torch.

However, we recommend to use the subversion repository to keep bleeding edge sources.

svn checkout https://torch5.svn.sourceforge.net/svnroot/torch5/trunk torch
This will create a torch directory. If you prefer another directory name, replace the last torch by the name you want in the above svn command.

C. Configuring Torch

We use CMake for configuring Torch. We highly recommend to create first a dedicated build directory. This eases cleaning up built objects, but also allow you to build Torch with various configurations (e.g. Release and Debug in two different build directories).

cd torch
mkdir build
cd build
cmake ..
The .. given to cmake indicates the directory where the sources are. We chose here to have a build directory inside torch, but it could be anywhere else. In that latter case, go instead in your build directory and then do:
cmake /path/to/torch/sources

CMake detects external libraries or tools necessary for Torch, and produces Makefiles such that Torch is then easily compilable on your platform. If you prefer the GUI version of CMake, you can replace cmake by ccmake in the above command lines. In particular, it is strongly encouraged to use ccmake for finer configuration of Torch.

The most common Torch configuration step you might want to perform is changing the installation path. By default, Torch will be installed in /usr/local. You will need super-user rights to perform that. If you are not root on your computer, you can instead specifying a install directory to CMake on the above cmake command:

cmake .. -DCMAKE_INSTALL_PREFIX=/my/install/path
Equivalently you can set the variable CMAKE_INSTALL_PREFIX if you use ccmake GUI. Please, see CMake documentation or at least some of our CMake hints for more details on configuration.

D. Compiling and installing

If the configuration was successful, Makefiles should have appeared in your build directory. Compile Torch with:

and then install it with:
make install
This last command might possibly be prefixed by sudo if you are installing Torch in /usr/local.

E. Running Torch

Now Torch should be installed in /usr/local or in /my/install/path if you chose to use the CMAKE_INSTALL_PREFIX when configuring with CMake. Lua executables (lua and qlua) are found in the bin sub-directory of these installation directories.

Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require 'torch'
> = torch.Tensor(5):zero()

[torch.Tensor of dimension 5]

For convenience, you might want to add to your PATH the path to lua binaries. The executable lua is a simple Lua interpreter (as provided on Lua website), while qlua has enhanced interactivity (like completion) and is able to handle graphics and QT widgets.