Futhark (programming language): Difference between revisions

Content deleted Content added
Crudely fill 1 bare URL ref to website homepage, using title 'Home'
Add Overview and Examples
Line 18:
 
'''Futhark''' is a [[functional programming|functional]] [[data parallelism|data parallel]] [[array programming|array]] [[programming language]] originally developed at [[DIKU]] as part of the HIPERFIT project.<ref>{{cite web |url=http://hiperfit.dk/ |title=Home |website=hiperfit.dk}}</ref> 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 [[GPGPU|GPU]]s. Futhark is strongly inspired by [[NESL]], 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.<ref>{{cite conference |url=https://futhark-lang.org/publications/pldi17.pdf|title=Futhark: Purely Functional GPU-Programming with Nested Parallelism and In-Place Array Updates|last1=Henriksen|first1=Troels|last2=Serup|first2=Niels G. W.|last3=Elsman|first3=Martin|last4=Henglein|first4=Fritz|last5=Oancea|first5=Cosmin|date=2017|publisher=ACM|book-title=Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation|conference=PLDI 2017}}</ref>
 
== 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 type|uniqueness types]] and [[Dependent type|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 [[Compute kernel|GPU kernel]]) which are then invoked from applications written in conventional languages.<ref>{{cite web|url=https://futhark.readthedocs.io/en/latest/|title=Futhark User's Guide|website=futhark.readthedocs.io}}</ref>
 
== Examples ==
 
=== Dot product ===
 
The following program computes the dot product of two vectors containing double-precision numbers.
 
<syntaxhighlight lang="futhark">
def dotprod xs ys = f64.sum (map2 (*) xs ys))
</syntaxhighlight>
 
It can also be equivalently written with explicit type annotations as follows.
 
<syntaxhighlight lang="futhark">
def dotprod [n] (xs: [n]f64) (ys: [n]f64) : f64 = f64.sum (map2 (*) xs ys))
</syntaxhighlight>
 
This makes the size-dependent types - 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.
 
<syntaxhighlight lang="futhark">
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
</syntaxhighlight>
 
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 ==