The accelerate-llvm package

[ Tags: bsd3, compilers-interpreters, concurrency, data, library, parallelism ] [ Propose Tags ]

This library implements direct LLVM IR generation for the Accelerate language. For further information, refer to the main accelerate package.


Haskell dependencies are available from Hackage. The following external libraries are alse required:

Installing LLVM


Example using Homebrew on macOS:

brew install llvm-hs/homebrew-llvm/llvm-5.0

Debian & Ubuntu

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

apt-get install llvm-5.0-dev

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 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.

If using the accelerate-llvm-ptx backend, 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:

    shared-llvm: true

Or by specifying the shared-llvm flag to cabal:

cabal install llvm-hs -fshared-llvm

[Skip to Readme]


Change log
Dependencies abstract-deque (>=0.3), accelerate (==1.1.*), base (>=4.7 && <4.11), bytestring (>=0.10.4), chaselev-deque (>=0.5), containers (>=0.5), data-default-class (>=0.0.1), deepseq (>=1.3), directory (>=1.0), dlist (>=0.6), exceptions (>=0.6), fclabels (>=2.0), filepath (>=1.0), llvm-hs (>=4.1 && <5.2), llvm-hs-pure (>=4.1 && <5.2), mtl (>=2.0), mwc-random (>=0.13), template-haskell, unordered-containers (>=0.2), vector (>=0.10) [details]
License BSD3
Author Trevor L. McDonell
Maintainer Trevor L. McDonell <>
Category Compilers/Interpreters, Concurrency, Data, Parallelism
Bug tracker
Source repository head: git clone
this: git clone
Uploaded Thu Sep 21 04:18:45 UTC 2017 by TrevorMcDonell
Updated Fri Oct 13 20:22:04 UTC 2017 by TrevorMcDonell to revision 1
Distributions NixOS:, Stackage:
Downloads 233 total (55 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI


  • Control
    • Parallel
      • Control.Parallel.Meta
        • Resource
          • Control.Parallel.Meta.Resource.Backoff
          • Control.Parallel.Meta.Resource.SMP
          • Control.Parallel.Meta.Resource.Single
        • Trans
          • Control.Parallel.Meta.Trans.LBS
        • Control.Parallel.Meta.Worker
  • Data
    • Array
      • Accelerate
        • LLVM
          • Data.Array.Accelerate.LLVM.AST
          • Analysis
            • Data.Array.Accelerate.LLVM.Analysis.Match
          • Array
            • Data.Array.Accelerate.LLVM.Array.Data
          • Data.Array.Accelerate.LLVM.CodeGen
            • Data.Array.Accelerate.LLVM.CodeGen.Arithmetic
            • Data.Array.Accelerate.LLVM.CodeGen.Array
            • Data.Array.Accelerate.LLVM.CodeGen.Base
            • Data.Array.Accelerate.LLVM.CodeGen.Constant
            • Data.Array.Accelerate.LLVM.CodeGen.Downcast
            • Data.Array.Accelerate.LLVM.CodeGen.Environment
            • Data.Array.Accelerate.LLVM.CodeGen.Exp
            • Data.Array.Accelerate.LLVM.CodeGen.IR
            • Data.Array.Accelerate.LLVM.CodeGen.Intrinsic
            • Data.Array.Accelerate.LLVM.CodeGen.Loop
            • Data.Array.Accelerate.LLVM.CodeGen.Module
            • Data.Array.Accelerate.LLVM.CodeGen.Monad
            • Data.Array.Accelerate.LLVM.CodeGen.Permute
            • Data.Array.Accelerate.LLVM.CodeGen.Ptr
            • Data.Array.Accelerate.LLVM.CodeGen.Skeleton
            • Data.Array.Accelerate.LLVM.CodeGen.Stencil
            • Data.Array.Accelerate.LLVM.CodeGen.Sugar
            • Data.Array.Accelerate.LLVM.CodeGen.Type
          • Data.Array.Accelerate.LLVM.Compile
            • Data.Array.Accelerate.LLVM.Compile.Cache
          • Data.Array.Accelerate.LLVM.Embed
          • Data.Array.Accelerate.LLVM.Execute
            • Data.Array.Accelerate.LLVM.Execute.Async
            • Data.Array.Accelerate.LLVM.Execute.Environment
            • Data.Array.Accelerate.LLVM.Execute.Marshal
          • Data.Array.Accelerate.LLVM.Foreign
          • Data.Array.Accelerate.LLVM.Link
            • Data.Array.Accelerate.LLVM.Link.Cache
          • Data.Array.Accelerate.LLVM.State
          • Data.Array.Accelerate.LLVM.Target
          • Data.Array.Accelerate.LLVM.Util
    • ByteString
      • Short
        • Data.ByteString.Short.Char8
        • Data.ByteString.Short.Extra
    • IORef
      • Data.IORef.Storable
    • Range
      • Data.Range.Range
  • LLVM
    • AST
      • Type
        • LLVM.AST.Type.AddrSpace
        • LLVM.AST.Type.Constant
        • LLVM.AST.Type.Flags
        • LLVM.AST.Type.Global
        • LLVM.AST.Type.Instruction
          • LLVM.AST.Type.Instruction.Atomic
          • LLVM.AST.Type.Instruction.Compare
          • LLVM.AST.Type.Instruction.RMW
          • LLVM.AST.Type.Instruction.Volatile
        • LLVM.AST.Type.Metadata
        • LLVM.AST.Type.Name
        • LLVM.AST.Type.Operand
        • LLVM.AST.Type.Representation
        • LLVM.AST.Type.Terminator




Enable debug tracing message flags. Note that debug must be enabled in the base accelerate package as well. See the accelerate package for usage and available options.


Enable bounds checking


Enable bounds checking in unsafe operations


Enable internal consistency checks


Use a Chase-Lev deque for work stealing


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for accelerate-llvm-

[back to package description]

An LLVM backend for the Accelerate Array Language

Build Status Hackage Docker Automated build Docker 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.

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.


Haskell dependencies are available from Hackage, but there are several external library 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)


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.


Example using Homebrew on macOS:

$ brew install llvm-hs/homebrew-llvm/llvm-4.0


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

$ apt-get install llvm-4.0-dev

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 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).

  1. 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.

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

    $ mkdir /tmp/build
    $ cd /tmp/build
  3. 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:


    See options and variables for a list of additional build parameters you can specify.

  4. Build and install:

    $ cmake --build .
    $ cmake --build . --target install
  5. For macOS only, some additional steps are useful to work around issues related to System Integrity Protection:

    cd $INSTALL_PREFIX/lib
    ln -s libLLVM.dylib libLLVM-4.0.dylib
    install_name_tool -id $PWD/libLTO.dylib libLTO.dylib
    install_name_tool -id $PWD/libLLVM.dylib libLLVM.dylib
    install_name_tool -change '@rpath/libLLVM.dylib' $PWD/libLLVM.dylib libLTO.dylib

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.


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 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:

| | LLVM-3.3 | LLVM-3.4 | LLVM-3.5 | LLVM-3.8 | LLVM-3.9 | LLVM-4.0 | |:------------:|:--------:|:--------:|:--------:|:--------:|:--------:|:--------:| | CUDA-7.0 | ⭕ | ❌ | | | | | | CUDA-7.5 | | ⭕ | ⭕ | ❌ | | | | CUDA-8.0 | | | ⭕ | ⭕ | ❌ | ❌ |

Where ⭕ = Works, and ❌ = Does not work.

Note that the above restrictions on CUDA and LLVM version exist only if you want to use the NVVM component. Otherwise, you should be free to use any combination of CUDA and LLVM.

Also note that accelerate-llvm-ptx itself currently requires at least LLVM-3.5.

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

    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