# High-performance parallel arrays for Haskell
[![GitHub CI](https://github.com/tmcdonell/accelerate/workflows/CI/badge.svg)](https://github.com/tmcdonell/accelerate/actions)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/AccelerateHS/Lobby)
[![Stackage LTS](https://stackage.org/package/accelerate/badge/lts)](https://stackage.org/lts/package/accelerate)
[![Stackage Nightly](https://stackage.org/package/accelerate/badge/nightly)](https://stackage.org/nightly/package/accelerate)
[![Hackage](https://img.shields.io/hackage/v/accelerate.svg)](https://hackage.haskell.org/package/accelerate)
`Data.Array.Accelerate` defines an embedded language of array computations for high-performance computing in Haskell. Computations on multi-dimensional, regular arrays are expressed in the form of parameterised collective operations (such as maps, reductions, and permutations). These computations are online-compiled and executed on a range of architectures.
For more details, see our papers:
* [Accelerating Haskell Array Codes with Multicore GPUs][CKLM+11]
* [Optimising Purely Functional GPU Programs][MCKL13] ([slides][MCKL13-slides])
* [Embedding Foreign Code][CMCK14]
* [Type-safe Runtime Code Generation: Accelerate to LLVM][MCGN15] ([slides][MCGN15-slides]) ([video][MCGN15-video])
* [Streaming Irregular Arrays][CMCK17] ([video][CMCK17-video])
There are also slides from some fairly recent presentations:
* [Embedded Languages for High-Performance Computing in Haskell][Embedded]
* [GPGPU Programming in Haskell with Accelerate][YLJ13-slides] ([video][YLJ13-video]) ([workshop][YLJ13-workshop])
Chapter 6 of Simon Marlow's book [Parallel and Concurrent Programming in Haskell][Mar13] contains a tutorial introduction to Accelerate.
[Trevor's PhD thesis][Trevor-thesis] details the design and implementation of frontend optimisations and CUDA backend.
**Table of Contents**
- [An Embedded Language for Accelerated Array Computations](#an-embedded-language-for-accelerated-array-computations)
- [A simple example](#a-simple-example)
- [Availability](#availability)
- [Additional components](#additional-components)
- [Requirements](#requirements)
- [Documentation](#documentation)
- [Examples](#examples)
- [Who are we?](#who-are-we)
- [Mailing list and contacts](#mailing-list-and-contacts)
- [Citing Accelerate](#citing-accelerate)
- [What's missing?](#whats-missing)
A simple example
----------------
As a simple example, consider the computation of a dot product of two vectors of single-precision floating-point numbers:
dotp :: Acc (Vector Float) -> Acc (Vector Float) -> Acc (Scalar Float)
dotp xs ys = fold (+) 0 (zipWith (*) xs ys)
Except for the type, this code is almost the same as the corresponding Haskell code on lists of floats. The types indicate that the computation may be online-compiled for performance; for example, using `Data.Array.Accelerate.LLVM.PTX.run` it may be on-the-fly off-loaded to a GPU.
Availability
------------
Package accelerate is available from
* Hackage: [accelerate][Hackage] - install with `cabal install accelerate`
* GitHub: [AccelerateHS/accelerate][GitHub] - get the source with `git clone https://github.com/AccelerateHS/accelerate.git`. The easiest way to compile the source distributions is via the Haskell [stack](https://docs.haskellstack.org/en/stable/README/) tool.
Additional components
---------------------
The following supported add-ons are available as separate packages:
* [accelerate-llvm-native][accelerate-llvm-native]: Backend targeting multicore CPUs
* [accelerate-llvm-ptx][accelerate-llvm-ptx]: Backend targeting CUDA-enabled NVIDIA GPUs. Requires a GPU with compute capability 2.0 or greater (see the [table on Wikipedia][wiki-cc])
* [accelerate-examples][accelerate-examples]: Computational kernels and applications showcasing the use of Accelerate as well as a regression test suite (supporting function and performance testing)
* [accelerate-io][accelerate-io]: Fast conversion between Accelerate arrays and other array formats (for example, Repa and Vector)
* [accelerate-fft][accelerate-fft]: Fast Fourier transform implementation, with FFI bindings to optimised implementations
* [accelerate-blas][accelerate-blas]: BLAS and LAPACK operations, with FFI bindings to optimised implementations
* [accelerate-bignum][accelerate-bignum]: Fixed-width large integer arithmetic
* [colour-accelerate][colour-accelerate]: Colour representations in Accelerate (RGB, sRGB, HSV, and HSL)
* [gloss-accelerate][gloss-accelerate]: Generate [gloss][gloss] pictures from Accelerate
* [gloss-raster-accelerate][gloss-raster-accelerate]: Parallel rendering of raster images and animations
* [lens-accelerate][lens-accelerate]: [Lens][lens] operators for Accelerate types
* [linear-accelerate][linear-accelerate]: [Linear][linear] vector spaces in Accelerate
* [mwc-random-accelerate][mwc-random-accelerate]: Generate Accelerate arrays filled with high quality pseudorandom numbers
* [numeric-prelude-accelerate][numeric-prelude-accelerate]: Lifting the [numeric-prelude][numeric-prelude] to Accelerate
* [wigner-ville-accelerate](https://github.com/Haskell-mouse/wigner-ville-accelerate): Wigner-Ville time-frequency distribution.
Install them from Hackage with `cabal install PACKAGENAME`.
Documentation
-------------
* Haddock documentation is included and linked with the individual package releases on [Hackage][Hackage].
* Haddock documentation for in-development components can be found [here](http://tmcdonell-bot.github.io/accelerate-travis-buildbot/).
* The idea behind the HOAS (higher-order abstract syntax) to de-Bruijn conversion used in the library is [described separately][HOAS-conv].
Examples
--------
### accelerate-examples
The [accelerate-examples][accelerate-examples] package provides a range of computational kernels and a few complete applications. To install these from Hackage, issue `cabal install accelerate-examples`. The examples include:
* An implementation of [canny edge detection][wiki-canny]
* An interactive [mandelbrot set][wiki-mandelbrot] generator
* An [N-body simulation][wiki-nbody] of gravitational attraction between solid particles
* An implementation of the [PageRank][wiki-pagerank] algorithm
* A simple [ray-tracer][wiki-raytracing]
* A particle based simulation of stable fluid flows
* A cellular automata simulation
* A "password recovery" tool, for dictionary lookup of MD5 hashes
[![Mandelbrot](https://i.imgur.com/5Tbsp1j.jpg "accelerate-mandelbrot")](https://i.imgur.com/RgXRqsc.jpg)
[![Raytracer](https://i.imgur.com/7ohhKm9.jpg "accelerate-ray")](https://i.imgur.com/ZNEGEJK.jpg)
### LULESH
[LULESH-accelerate][lulesh-accelerate] is in implementation of the Livermore Unstructured Lagrangian Explicit Shock Hydrodynamics (LULESH) mini-app. [LULESH][LULESH] represents a typical hydrodynamics code such as [ALE3D][ALE3D], but is a highly simplified application, hard-coded to solve the Sedov blast problem on an unstructured hexahedron mesh.
![LULESH mesh](https://i.imgur.com/bIkODKd.jpg)
### Additional examples
Accelerate users have also built some substantial applications of their own.
Please feel free to add your own examples!
* Jonathan Fraser, [GPUVAC](https://github.com/GeneralFusion/gpuvac): An explicit advection magnetohydrodynamics simulation
* David van Balen, [Sudokus](https://github.com/dpvanbalen/Sudokus): A sudoku solver
* Trevor L. McDonell, [lol-accelerate][lol-accelerate]: A backend to the Λ ○ λ ([Lol][lol]) library for ring-based lattice cryptography
* Henning Thielemann, [patch-image](http://hackage.haskell.org/package/patch-image): Combine a collage of overlapping images
* apunktbau, [bildpunkt](https://github.com/abau/bildpunkt): A ray-marching distance field renderer
* klarh, [hasdy](https://github.com/klarh/hasdy): Molecular dynamics in Haskell using Accelerate
* Alexandros Gremm used Accelerate as part of the [2014 CSCS summer school](http://user.cscs.ch/blog/2014/cscs_usi_summer_school_2014_30_june_10_july_2014_in_serpiano_tessin/index.html) ([code](https://github.com/agremm/cscs))
Who are we?
-----------
The Accelerate team (past and present) consists of:
* Manuel M T Chakravarty ([@mchakravarty])
* Gabriele Keller ([@gckeller])
* Trevor L. McDonell ([@tmcdonell])
* Robert Clifton-Everest ([@robeverest])
* Frederik M. Madsen ([@fmma])
* Ryan R. Newton ([@rrnewton])
* Joshua Meredith ([@JoshMeredith])
* Ben Lever ([@blever])
* Sean Seefried ([@sseefried])
* Ivo Gabe de Wolff ([@ivogabe])
The maintainer and principal developer of Accelerate is Trevor L.
McDonell