LLVM backend for Accelerate
See the codeThis 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 some external library dependencies that you will need to install as well:
accelerate-llvm-native for multicore CPU:
libFFIaccelerate-llvm-ptx for GPU:
CUDA;
Note that not all versions of CUDA support all NVIDIA GPUsclang (if using accelerate-llvm-ptx: version
16 or higher, built with support for the nvptx 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 to clang.)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 of clang, 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 of clang; 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:
winget install LLVM.LLVMlibFFI.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:
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.
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.
Haskell
99.5%
LLVM backend for Accelerate
See the codeThis 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 some external library dependencies that you will need to install as well:
accelerate-llvm-native for multicore CPU:
libFFIaccelerate-llvm-ptx for GPU:
CUDA;
Note that not all versions of CUDA support all NVIDIA GPUsclang (if using accelerate-llvm-ptx: version
16 or higher, built with support for the nvptx 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 to clang.)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 of clang, 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 of clang; 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:
winget install LLVM.LLVMlibFFI.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:
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.
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.
Haskell
99.5%