Futhark (programming language)
Futhark is a functional data parallel array programming language originally developed at UCPH Department of Computer Science (DIKU) as part of the HIPERFIT project.[2] It focuses on enabling data parallel programs written in a functional style to be executed with high performance on massively parallel hardware, in particular on graphics processing units (GPUs). Futhark is strongly inspired by NESL, and its implementation uses a variant of the flattening transformation, but imposes constraints on how parallelism can be expressed in order to enable more aggressive compiler optimisations. In particular, irregular nested data parallelism is not supported.[3]
Paradigm | Array, functional |
---|---|
Family | ML |
Designed by | Troels Henriksen, Cosmin Oancea, Martin Elsman |
Developer | University of Copenhagen[1] |
First appeared | 2014 |
Typing discipline | Inferred, static, strong |
OS | Cross-platform |
License | ISC |
Website | futhark-lang |
Influenced by | |
APL, Haskell, NESL, Standard ML |
Overview
Futhark is a language in the ML family, with an indentation-insensitive syntax derived from OCaml, Standard ML, and Haskell. The type system is based on Hindley-Milner with a variety of extensions, such as uniqueness types and size-dependent types. Futhark is not intended as a general-purpose programming language for writing full applications, but is instead focused on writing computational "kernels" (not necessarily the same as a GPU kernel) which are then invoked from applications written in conventional languages.[4]
Examples
Dot product
The following program computes the dot product of two vectors containing double-precision numbers.
def dotprod xs ys = f64.sum (map2 (*) xs ys))
It can also be equivalently written with explicit type annotations as follows.
def dotprod [n] (xs: [n]f64) (ys: [n]f64) : f64 = f64.sum (map2 (*) xs ys))
This makes the size-dependent types explicit: this function can only be invoked with two arrays of the same size, and the type checker will reject any program where this cannot be statically determined.
Matrix multiplication
The following program performs matrix multiplication, using the definition of dot product above.
def matmul [n][m][p] (A: [n][m]f64) (B: [m][p]f64) : [n][p]f64 =
map (\A_row ->
map (\B_col -> dotprod A_row B_col)
(transpose B))
A
Note how the types enforce that the function is only invoked with matrices of compatible size. Further, this is an example of nested data parallelism.
References
- "License". futhark-lang.org. Retrieved 2023-03-26.
Developed at DIKU
- "Home". hiperfit.dk.
- Henriksen, Troels; Serup, Niels G. W.; Elsman, Martin; Henglein, Fritz; Oancea, Cosmin (2017). "Futhark: Purely Functional GPU-Programming with Nested Parallelism and In-Place Array Updates" (PDF). Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation. PLDI 2017. ACM.
- "Futhark User's Guide". futhark.readthedocs.io.