LLVM backend for Accelerate
Haskell Other
Latest commit f8bd841 Feb 21, 2017 @tmcdonell tmcdonell native: scheduling tweaks

README.md

An LLVM backend for the Accelerate Array Language

Build Status

This package compiles Accelerate code to LLVM IR, and executes that code on multicore CPUs as well as NVIDIA GPUs. This avoids the need to go through nvcc or clang. For details on Accelerate, refer to the main repository. Please also file bug reports and feature requests with the issue tracker of the main repository.

Dependencies

Haskell dependencies are available from Hackage. There are several external dependencies that you will need to install as well:

  • LLVM
  • libFFI (if using the accelerate-llvm-native backend for multicore CPUs)
  • CUDA (if using the accelerate-llvm-ptx backend for NVIDIA GPUs)

Installation

You will need to install a couple of foreign libraries: libffi as well as LLVM with shared library support. If you want to use the GPU targeting accelerate-llvm-ptx backend, make sure you install (or build) LLVM with the 'nvptx' target.

Example using Homebrew on Mac OS X:

$ brew update
$ brew install libffi
$ brew install homebrew/versions/llvm35 --all-targets

For Debian/Ubuntu based Linux distributions, the LLVM.org website provides binary distribution packages. Check apt.llvm.org for instructions for adding the correct package database for your OS version, and then:

$ apt-get install libedit-dev llvm-3.5-dev

Then, installation using stack just requires you to point it to the appropriate configuration file, for example:

$ ln -s stack-7.10.yaml stack.yaml
$ stack setup
$ stack install

If installing via cabal, note that you will need to tell the llvm-general package to use the shared library version of LLVM (#84, #85) before attempting to install accelerate-llvm.

$ cabal install llvm-general -fshared-llvm
$ cabal install accelerate-llvm

Note that the version of llvm-general used must match the installed version of LLVM. The currently released version of llvm-general is for LLVM-3.5, but releases for 3.8 and 3.9 should be available soon.

libNVVM

The accelerate-llvm-ptx backend can optionally be compiled to generate GPU code using the libNVVM library, rather than LLVM's inbuilt NVPTX code generator. libNVVM is a closed-source library distributed as part of the NVIDIA CUDA toolkit, and is what the nvcc compiler itself uses internally when compiling CUDA C code.

Using libNVVM may improve GPU performance as it includes several optimisations not present in NVPTX. One difficult with using it however is that since libNVVM is also based on LLVM, and typically lags LLVM by several releases, you must install accelerate-llvm with a "compatible" version of LLVM, which will depend on the version of the CUDA toolkit you have installed.

LLVM-3.3 LLVM-3.4 LLVM-3.5 LLVM-3.8 LLVM-3.9
CUDA-7.0
CUDA-7.5
CUDA-8.0

Where ⭕ = Works, and = Does not work.

Note that accelerate-llvm itself currently requires at least LLVM-3.5. There are currently no releases of llvm-general planned for LLVM-3.6 or LLVM-3.7.

Using stack, either edit the stack.yaml and add the following section:

flags:
  accelerate-llvm-ptx:
    nvvm: true

Or install using the following option on the command line:

$ stack install accelerate-llvm-ptx --flag accelerate-llvm-ptx:nvvm

If installing via cabal:

$ cabal install accelerate-llvm-ptx -fnvvm