Skip to content

Build Instructions for OSX

pradeep edited this page Jan 14, 2021 · 17 revisions

These are the build steps to compile ArrayFire from source on OSX. We use Homebrew to install dependencies.

Before you proceed with the build, make sure the submodules are up to date by running the following commands from the root of ArrayFire directory.

git submodule init
git submodule update

Overview:

Installing Dependencies

General Dependencies

  • Required: cmake
  • Recommended: FreeImage
  • OSX 10.9 or later
$ brew install cmake freeimage

CPU Build Dependencies

  • Required: fftw
$ brew install fftw

CUDA Build Dependencies

  • Required: >=CUDA 9.0, Boost (shared_ptr component)
  • Recommended: Latest version of CUDA (CUDA 10.0 at the time of writing)

Boost

$ brew install boost

CUDA

Refer to NVIDIA's website to install CUDA.

OpenCL Build Dependencies

In addition to the OpenCL library (installed by default on OSX), the OpenCL backend requires boost. You can install it using brew:

$ brew install boost

ArrayFire graphics dependencies

The graphics backend uses GLFW which can be installed via. brew:

$ brew tap homebrew/versions
$ brew install glfw

Building ArrayFire

Configure CMake options via ccmake .

Options Description Default
AF_BUILD_CPU Enable CPU Build ON
AF_BUILD_CUDA Enable CUDA Build OFF
AF_BUILD_OPENCL Enable OpenCL Build OFF
AF_BUILD_FORGE Build Forge Graphics Library OFF
AF_BUILD_EXAMPLES Builds Examples ON
BUILD_TESTING Builds Tests ON
CMAKE_BUILD_TYPE Build type Debug

Note that Forge graphics library doesn't need to be built to enable graphics support in ArrayFire. However, if do want to use graphics during development, please build forge too.

Commands:

$ cd /path/to/dir/arrayfire
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DAF_BUILD_CUDA=ON -DAF_BUILD_OPENCL=ON # Enables building all 3 backends
$ make -j8   # or number of threads of your choosing

Installing ArrayFire

The default installation prefix is /usr/local. Thus, 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

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/example_backend