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 write C++ code. 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:
- if using
accelerate-llvm-native
for multicore CPU:libFFI
- if using
accelerate-llvm-ptx
for GPU:CUDA
; Note that not all versions of CUDA support all NVIDIA GPUs clang
(if usingaccelerate-llvm-ptx
: version 16 or higher, built with support for thenvptx
backend).accelerate-llvm
uses the command-line tool as a way to be compatible with many different LLVM versions, not to compile C code. (Accelerate passes LLVM IR toclang
.)
Below are some OS-specific instructions. If anything here is wrong or out of date, please file an issue.
To get libFFI
, run brew install libffi
. clang
is already provided with
macOS (you may need to xcode-select --install
), and CUDA is not supported on
macOS.
For clang
:
-
On Ubuntu 24.04 (noble) / Debian trixie or higher:
sudo apt install clang
. -
Otherwise, if you need only the CPU backend (
accelerate-llvm-native
):sudo apt install clang
will give you an old version ofclang
, but the CPU backend is likely to work fine. -
If you are on an older distro and need the GPU backend (
accelerate-llvm-ptx
):clang
version 16 or higher is required. Add the apt source from apt.llvm.org. The neatest way to do this is to create a file/etc/apt/sources.list.d/llvm.list
(the precise file name does not matter) and put in it, for Ubuntu (change "jammy" as appropriate):deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main
or for Debian (change "bookworm" as appropriate):
deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm main deb-src http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm main
and
sudo apt update; sudo apt install clang
. This gets you the latest version ofclang
; different sources are also available for specific versions (see apt.llvm.org).
To use the CPU backend (accelerate-llvm-native
), install libFFI
using
sudo apt install libffi-dev
.
To use the GPU backend (accelerate-llvm-ptx
), install CUDA from
here
("deb (network)" is smoother than the "deb (local)" option).
Run sudo pacman -S clang
. To use the CPU backend (accelerate-llvm-native
),
additionally run sudo pacman -S libffi
. To use the GPU backend
(accelerate-llvm-ptx
), additionally run sudo pacman -S cuda
.
We recommend WSL2 (not WSL1, WSL2!) and following the Ubuntu instructions above. The remainder of this text attemps to give you a working system on Windows native.
Install clang
; you have two options:
- Using
WinGet:
winget install LLVM.LLVM
- By downloading the installer directly (WinGet just runs the same installer)
from here (choose
"LLVM--win64.exe" from the latest release; you may need to click
"Show all 57 assets").
This will also give you
libFFI
.
Optionally, add clang
(and more) to your system path. Click to see how.
Accelerate should be able to find clang
automatically even if you do not do
this. However, for easy access to clang
and all other LLVM executables, add
C:\Program Files\LLVM\bin
to the system path as follows:
- Search for "environment variables" in the start menu
- Click "Edit the system environment variables"
- Click on "Environment Variables..."
- Double-click on the user variable called "Path"
- And add a new entry containing
C:\Program Files\LLVM\bin
.
Note that if you add an entry here manually, it is a good idea to clean it up again if you uninstall LLVM/clang. (Leaving it there is not very harmful, however.)
You may find that the LLVM/clang installer has already added the Path entry automatically (it did not for us); if so, no need to add a second entry.
——
You may additionally need the VS Build Tools, if you have not yet installed and
set up Visual Studio otherwise. You need this if clang
complains that it is
unable to find a Visual Studio installation; try running Clang from a developer command prompt
.
- If you already have the Visual Studio Installer on your system, open it and
check if you already have Visual Studio (Community) installed. Note that
this is completely unrelated to VS Code.
- If you already have VS (Community): inside the Visual Studio Installer, click on "Modify" in the VS (Community) box. This should get you a screen with "workloads" you can select.
- If you do not yet have VS (Community), install the VS Build Tools: go to https://visualstudio.microsoft.com/downloads, scroll down to "All Downloads", open "Tools for Visual Studio", and select "Build Tools for Visual Studio". If you run the installer, you should get a screen with "workloads" you can select.
- Under the Workloads tab, choose the "Desktop development with C++" workload.
If you want to save a bit of disk space (not much), keep only the following
two options selected:
- "MSVC v143 - VE 2022 C++ x64/x86 build tools (Latest)"
- "Windows 11 SDK (…)" (choose the latest option). The attentive reader may note that the wizard also offers Clang; we recommend a separate Clang install for Accelerate because the one from VS somehow doesn’t seem to work properly with Accelerate. If you find out why, please let us know.
- Install that. This takes a while.
It turns out that having both Visual Studio and the Build Tools installed results in Clang getting confused between the two (it appears that Visual Studio is 64-bit (x64) and the Build Tools are 32-bit (x86)). If Clang complains about the bit-ness of your system libraries, double-check that you haven’t installed both simultaneously.
The GPU backend (accelerate-llvm-ptx
) probably doesn't work on Windows; in
any case, it is untested.