| Futhark | |
|---|---|
| Paradigm | array,functional |
| Family | ML |
| Designed by | Troels Henriksen, Cosmin Oancea, Martin Elsman |
| Developer | University of Copenhagen[1] |
| First appeared | 2014; 11 years ago (2014) |
| Typing discipline | inferred,static,strong,Hindley–Milner,uniqueness,dependent |
| OS | cross-platform |
| License | ISC |
| Website | futhark-lang |
| Influenced by | |
| APL,Haskell,NESL,Standard ML | |
Futhark is amulti-paradigm,high-level,functional,data parallel,arrayprogramming language. It is adialect of the languageML, originally developed atUCPH 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 onmassively parallel hardware, especiallygraphics processing units (GPUs). Futhark is strongly inspired byNESL, and its implementation uses a variant of theflattening 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] It isfree and open-source software released under anISC license.
Futhark is a language in theML family, with an indentation-insensitive syntax derived fromOCaml,Standard ML, andHaskell. Thetype system is based on aHindley–Milner type system with a variety of extensions, such asuniqueness types and size-dependent types. Futhark is not intended as ageneral-purpose programming language for writing full applications, but is instead focused on writingcompute kernels (not always the same as aGPU kernel) which are then invoked from applications written in conventional languages.[4]
Futhark is named afterthe first six letters of the Runic alphabet.[5]: 2
The following program computes thedot product of two vectors containing double-precision numbers.
defdotprodxsys=f64.sum(map2(*)xsys))
It can also be equivalently written with explicit type annotations as follows.
defdotprod[n](xs:[n]f64)(ys:[n]f64):f64=f64.sum(map2(*)xsys))
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.
The following program performsmatrix multiplication, using the definition of dot product above.
defmatmul[n][m][p](A:[n][m]f64)(B:[m][p]f64):[n][p]f64=map(\A_row->map(\B_col->dotprodA_rowB_col)(transposeB))A
This shows how the types enforce that the function is only invoked with matrices of compatible size. Also, it is an example of nesteddata parallelism.
Developed atDIKU