If your OS does not have an appropriate LLVM distribution available, you can
also build from source. Detailed build instructions are available on
LLVM.org. Make sure to
include the cmake build options
-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON so that the libLLVM
shared library will be built. Also ensure that the LLVM_TARGETS_TO_BUILD
option includes the NVPTX target (if not specified all targets are built).

Installing accelerate-llvm

To use accelerate-llvm it is important that the llvm-hs package is
installed against the libLLVM shared library, rather than statically
linked, so that we can use LLVM from GHCi and Template Haskell. This is the
default configuration, but you can also enforce this explicitly by adding
the following to your stack.yaml file:

Maintainer's Corner

Readme for accelerate-llvm-ptx-1.1.0.1

An LLVM backend for the Accelerate Array Language

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.

We love all kinds of contributions, so feel free to open issues for missing
features as well as report (or fix!) bugs on the issue tracker.

Docker

A docker container is provided with this package
preinstalled (via stack) at /opt/accelerate-llvm. Note that if you wish to use
the accelerate-llvm-ptx GPU backend, you will need to install the NVIDIA
docker plugin; see that page for more
information.

$ docker run -it tmcdonell/accelerate-llvm

Installing LLVM

When installing LLVM, make sure that it includes the libLLVM shared library.
If you want to use the GPU targeting accelerate-llvm-ptx backend, make sure
you install (or build) LLVM with the 'nvptx' target.

Building from source

If your OS does not have an appropriate LLVM distribution available, you can also build from source. Detailed build instructions are available on the LLVM.org website. Note that you will require at least CMake 3.4.3 and a recent C++ compiler; at least Clang 3.1, GCC 4.8, or Visual Studio 2015 (update 3).

Download and unpack the LLVM-4.0 source code. We'll refer to
the path that the source tree was unpacked to as LLVM_SRC. Only the main
LLVM source tree is required, but you can optionally add other components
such as the Clang compiler or Polly loop optimiser. See the LLVM releases
page for the complete list.

Create a temporary build directory and cd into it, for example:

$ mkdir /tmp/build
$ cd /tmp/build

Execute the following to configure the build. Here INSTALL_PREFIX is
where LLVM is to be installed, for example /usr/local or
$HOME/opt/llvm:

Installing Accelerate-LLVM

Once the dependencies are installed, we are ready to install accelerate-llvm.

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

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

Note that the version of llvm-hs
used must match the installed version of LLVM, which is currently 4.0.

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 libNVVMmay improve GPU performance compared to the code generator
built in to LLVM. One difficulty 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. The following table shows
some combinations: