Skip to content

Build Instructions for Linux

John Melonakos edited this page Nov 6, 2023 · 55 revisions

The instructions are based on Ubuntu 14.04. Change the packages and package manager to the distro of your choice.

Overview:

Installing Dependencies

General Dependencies

  • Required: gcc (>=7.x), g++, git (>=1.8), make, cmake, boost(>=1.65, >=1.70 recommended)
  • Recommended: FreeImage (version 3), cmake-curses-gui
  • The following packages are required for the graphics to be enabled:
    • GLFW >= 3.1 (build instructions available here. 3rd party maintained packages are also available).
    • ArrayFire also requires Forge but this is a submodule and will be checkout during submodule initilization stage. AF_BUILD_FORGE cmake option has to be turned on to build graphics support.
sudo apt-get install -y build-essential git cmake libfreeimage-dev
sudo apt-get install -y cmake-curses-gui
wget <boost source url>
tar xf boost_1_70_0.tar.gz
cp -r boost_1_70_0/boost /usr/local/include

Please fetch the boost download URL from https://www.boost.org/users/download/ and replace <boost source url> with that in the above wget command.

CPU backend dependencies

  • Required: BLAS and LAPACK C++ libraries (e.g. openblas, atlas or cblas with lapacke)
  • Required: libfftw3
# Using OpenBLAS
sudo apt-get install libopenblas-dev libfftw3-dev liblapacke-dev
 # Using ATLAS
sudo apt-get install libatlas3gf-base libatlas-dev libfftw3-dev liblapacke-dev

Note: There is a known issue on Ubuntu 16.04, atlas and lapacke combination causes undefined reference errors as the version of lapacke that comes with package manager is broken. We recommend using OpenBLAS on ubuntu 16.04.

CUDA backend dependencies

  • Required: CUDA 9.0 or later
  • Recommended: Latest version of CUDA (v9.1 at the time of writing)

Installing CUDA

Download the latest CUDA toolkit. You want to download the network installer deb file for your particular Ubuntu version. Install CUDA using

$ sudo dpkg -i cuda-repo-*amd64.deb
$ sudo apt-get update
$ sudo apt-get install cuda

oneAPI backend dependencies

Required: Install the oneAPI Base Toolkit with compiler and libraries.

Once the toolkit is installed, enable necessary paths to all compilers and libraries by running the setvars.sh script. For example:

source /opt/intel/oneapi/setvars.sh

OpenCL backend dependencies

Required:

On 64-bit installs, AMDAPPSDK-3.0 installs with a broken symbolic link which can be fixed by going to $AMDAPPSDKROOT/lib/x86_64/and executing:

sudo ln -sf sdk/libOpenCL.so.1 libOpenCL.so

For all the above, ensure that you install the common opencl-headers package prior to building the OpenCL back-end:

sudo apt-get install opencl-headers

Install boost:

sudo apt-get install libboost-all-dev

Install the OpenCL ICD Loader:

sudo apt-get install ocl-icd-opencl-dev

Please note that ArrayFire also requires clBLAS, clFFT and Boost.Compute but these will automatically be checked out during the compilation stage.

ArrayFire graphics library

Required:

  • libglfw-dev (>=3.1.4)
  • libfontconfig1-dev
sudo apt-get install libglfw3-dev libfontconfig1-dev

NOTE: If your system does not have libglfw3, on Debian / Ubuntu based systems you can install it to a system directory or use the following ppa

sudo apt-add-repository ppa:keithw/glfw3
sudo apt-get update
sudo apt-get install libglfw3

For other distributions / OS you can build it from source.

Getting ArrayFire

To build ArrayFire, first clone the repository with the --recursive flag in order to grab the necessary submodules for the project:

git clone --recursive https://github.com/arrayfire/arrayfire.git

In order to build ArrayFire, you must first check out the ArrayFire source and ensure that the submodules are up to date. You can do these steps using the following commands:

Building ArrayFire

CMake Options:

Options Descrition Default
AF_BUILD_CPU Enable CPU backend ON
AF_BUILD_CUDA Enable CUDA backend ON 1
AF_BUILD_OPENCL Enable OpenCL backend ON 2
AF_BUILD_ONEAPI Enable OneAPI backend OFF
AF_BUILD_EXAMPLES Build examples ON
BUILD_TESTING Build tests ON
CMAKE_BUILD_TYPE Set build type
AF_COMPUTE_LIBRARY Set BLAS backend Intel-MKL

AF_COMPUTE_LIBRARY can take one of the following strings:

  • Intel-MKL

  • FFTW/LAPACK/BLAS Please ensure to have corresponding dependencies installed as mentioned earlier. Intel MKL can be installed using the oneAPI toolkit installation executables.

  • 1 If CUDA toolkit is found.

  • 2 If OpenCL libraries are found.

Commands:

cd /path/to/dir/arrayfire
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8   # or number of threads of your choosing

Installing ArrayFire

The default installation prefix is /usr/local. That is, includes are installed to /usr/local/include, libs are installed to /usr/local/lib, tests and examples are installed to /usr/local/arrayfire.

To change the install prefix use

cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/install/dir

Make sure your compiler is compatible with the CUDA toolkit you are going to target. If your default compiler is not compatible with nvcc, you can set the CUDA_HOST_COMPILER CMake variable to target a different compiler on the system.

For example on Arch Linux, you can install gcc7 and configure CMake with the following command:

cmake -DCMAKE_HOST_COMPILER=/usr/bin/gcc-7 ..

Then run make install (sudo is installing to system directories).

Running Tests and Examples

Run tests:

cd /path/to/dir/arrayfire/build
# Choose you preferred command
make test                      # runs all test
ctest                          # runs all test
ctest -R substring             # runs all tests that match the substring
CTEST_OUTPUT_ON_FAILURE ctest  # runs tests while printing output only if a test fails
./test/testname_backend        # runs single test with output

Run examples:

cd /path/to/dir/arrayfire/build
./examples/directory/example_backend

Packaging

The ArrayFire source code also includes support for CPack, an automatic package script from CMake. On Linux, CPack will build a self-extracting .sh installers. You can call:

For a DEB file, run the following command

cpack -G DEB

For a RPM, run the following command

cpack -G RPM

Note: For RPM, the rpm package is required.