Futhark (programming language)
{{Short description|Programming language}}
{{Infobox programming language
|name = Futhark
|paradigm = array, functional
|family = ML
|designer = Troels Henriksen, Cosmin Oancea, Martin Elsman
|developer = University of Copenhagen{{Cite web |title=License |url=https://futhark-lang.org/license.html |access-date=2023-03-26 |website=futhark-lang.org |quote=Developed at DIKU}}
|released = {{Start date and age|2014}}
|latest release version =
|latest release date =
|typing = inferred, static, strong, Hindley–Milner, uniqueness, dependent
|implementations =
|dialects =
|influenced by = APL, Haskell, NESL, Standard ML
|influenced =
|operating system = cross-platform
|license = ISC
|website = {{URL|futhark-lang.org}}
}}
Futhark is a multi-paradigm, high-level, functional, data parallel, array programming language. It is a dialect of the language ML, originally developed at UCPH Department of Computer Science (DIKU) as part of the HIPERFIT project.{{cite web |url=http://hiperfit.dk/ |title=Home |website=hiperfit.dk}} It focuses on enabling data parallel programs written in a functional style to be executed with high performance on massively parallel hardware, especially 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.{{cite conference |last1=Henriksen |first1=Troels |last2=Serup |first2=Niels G. W. |last3=Elsman |first3=Martin |last4=Henglein |first4=Fritz |last5=Oancea |first5=Cosmin |date=2017 |url=https://futhark-lang.org/publications/pldi17.pdf |title=Futhark: Purely Functional GPU-Programming with Nested Parallelism and In-Place Array Updates |publisher=ACM |book-title=Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation |conference=PLDI 2017}} It is free and open-source software released under an ISC license.
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 a Hindley–Milner type system 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 compute kernels (not always the same as a GPU kernel) which are then invoked from applications written in conventional languages.{{cite web |url=https://futhark.readthedocs.io/en/latest/ |title=Futhark User's Guide |website=futhark.readthedocs.io}}
Futhark is named after the first six letters of the Runic alphabet.{{cite thesis |last=Troels |first=Henriksen |date=November 2017 |title=Design and Implementation of the Futhark Programming Language |url=https://futhark-lang.org/publications/troels-henriksen-phd-thesis.pdf |degree=PhD |publisher=University of Copenhagen |access-date=2024-05-25}}{{rp|2}}
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
This shows how the types enforce that the function is only invoked with matrices of compatible size. Also, it is an example of nested data parallelism.
References
{{Reflist}}
{{ML programming}}
{{Parallel computing}}
Category:Programming languages
Category:High-level programming languages
Category:Array programming languages
Category:Dependently typed languages
Category:Dependently typed programming
Category:Statically typed programming languages
Category:ML programming language family
Category:Free and open source compilers