accelerate-0.13.0.4: An embedded language for accelerated array processing

Portabilitynon-portable (GHC extensions)
Stabilityexperimental
MaintainerManuel M T Chakravarty <chak@cse.unsw.edu.au>
Safe HaskellNone

Data.Array.Accelerate

Contents

Description

This module defines an embedded language of array computations for high-performance computing. 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.

Abstract interface:

The types representing array computations are only exported abstractly — i.e., client code can generate array computations and submit them for execution, but it cannot inspect these computations. This is to allow for more flexibility for future extensions of this library.

Code execution:

Access to the various backends is via a run function in backend-specific top level modules. Currently, we have the following:

Examples and documentation:

Synopsis

The Accelerate Array Language

Array data types

data Acc a Source

Array-valued collective computations

Instances

Typeable1 Acc 
Lift Acc (Acc a) 
(Arrays a, Arrays b) => Unlift Acc (Acc a, Acc b) 
(Lift Acc a, Lift Acc b, Arrays (Plain a), Arrays (Plain b)) => Lift Acc (a, b) 
(Shape sh, Elt e) => Lift Acc (Array sh e) 
(Arrays a, Arrays b, Arrays c) => Unlift Acc (Acc a, Acc b, Acc c) 
(Lift Acc a, Lift Acc b, Lift Acc c, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c)) => Lift Acc (a, b, c) 
(Arrays a, Arrays b, Arrays c, Arrays d) => Unlift Acc (Acc a, Acc b, Acc c, Acc d) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d)) => Lift Acc (a, b, c, d) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e)) => Lift Acc (a, b, c, d, e) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f)) => Lift Acc (a, b, c, d, e, f) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f), Arrays (Plain g)) => Lift Acc (a, b, c, d, e, f, g) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g, Arrays h) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g, Acc h) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Lift Acc h, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f), Arrays (Plain g), Arrays (Plain h)) => Lift Acc (a, b, c, d, e, f, g, h) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g, Arrays h, Arrays i) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g, Acc h, Acc i) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Lift Acc h, Lift Acc i, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f), Arrays (Plain g), Arrays (Plain h), Arrays (Plain i)) => Lift Acc (a, b, c, d, e, f, g, h, i) 
Arrays arrs => Show (Acc arrs) 
Afunction (Acc a -> f) => Show (Acc a -> f) 

class (Typeable (ArrRepr a), Typeable (ArrRepr' a), Typeable a) => Arrays a Source

Instances

Arrays () 
(Arrays b, Arrays a) => Arrays (b, a) 
(Shape sh, Elt e) => Arrays (Array sh e) 
(Arrays c, Arrays b, Arrays a) => Arrays (c, b, a) 
(Arrays d, Arrays c, Arrays b, Arrays a) => Arrays (d, c, b, a) 
(Arrays e, Arrays d, Arrays c, Arrays b, Arrays a) => Arrays (e, d, c, b, a) 
(Arrays f, Arrays e, Arrays d, Arrays c, Arrays b, Arrays a) => Arrays (f, e, d, c, b, a) 
(Arrays g, Arrays f, Arrays e, Arrays d, Arrays c, Arrays b, Arrays a) => Arrays (g, f, e, d, c, b, a) 
(Arrays h, Arrays g, Arrays f, Arrays e, Arrays d, Arrays c, Arrays b, Arrays a) => Arrays (h, g, f, e, d, c, b, a) 
(Arrays i, Arrays h, Arrays g, Arrays f, Arrays e, Arrays d, Arrays c, Arrays b, Arrays a) => Arrays (i, h, g, f, e, d, c, b, a) 

data Array sh e Source

Multi-dimensional arrays for array processing.

If device and host memory are separate, arrays will be transferred to the device when necessary (if possible asynchronously and in parallel with other tasks) and cached on the device if sufficient memory is available.

Instances

Typeable2 Array 
(Shape sh, Elt e) => Lift Acc (Array sh e) 
Show (Array sh e) 
(Shape sh, Elt e) => Arrays (Array sh e) 

type Scalar e = Array DIM0 eSource

Scalars arrays hold a single element

type Vector e = Array DIM1 eSource

Vectors are one-dimensional arrays

type Segments i = Vector iSource

Segment descriptor (vector of segment lengths).

To represent nested one-dimensional arrays, we use a flat array of data values in conjunction with a segment descriptor, which stores the lengths of the subarrays.

Array element types

class (Show a, Typeable a, Typeable (EltRepr a), Typeable (EltRepr' a), ArrayElt (EltRepr a), ArrayElt (EltRepr' a)) => Elt a Source

Accelerate supports as array elements only simple atomic types, and tuples thereof. These element types are stored efficiently in memory, unpacked as consecutive elements without pointers.

This class characterises the types of values that can be array elements, and hence, appear in scalar Accelerate expressions.

Instances

Elt Bool 
Elt Char 
Elt Double 
Elt Float 
Elt Int 
Elt Int8 
Elt Int16 
Elt Int32 
Elt Int64 
Elt Word 
Elt Word8 
Elt Word16 
Elt Word32 
Elt Word64 
Elt () 
Elt CChar 
Elt CSChar 
Elt CUChar 
Elt CShort 
Elt CUShort 
Elt CInt 
Elt CUInt 
Elt CLong 
Elt CULong 
Elt CLLong 
Elt CULLong 
Elt CFloat 
Elt CDouble 
Elt All 
Elt Z 
Shape sh => Elt (Any (:. sh Int)) 
Elt (Any Z) 
(Elt a, Elt b) => Elt (a, b) 
(Elt t, Elt h) => Elt (:. t h) 
(Elt a, Elt b, Elt c) => Elt (a, b, c) 
(Elt a, Elt b, Elt c, Elt d) => Elt (a, b, c, d) 
(Elt a, Elt b, Elt c, Elt d, Elt e) => Elt (a, b, c, d, e) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => Elt (a, b, c, d, e, f) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => Elt (a, b, c, d, e, f, g) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h) => Elt (a, b, c, d, e, f, g, h) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i) => Elt (a, b, c, d, e, f, g, h, i) 

Shapes & Indices

Array indices are snoc type lists; that is, they are backwards and the end-of-list token, Z, occurs on the left. For example, the type of a rank-2 array index is Z :. Int :. Int.

data Z Source

Rank-0 index

Constructors

Z 

Instances

Eq Z 
Show Z 
Typeable Z 
Slice Z 
Shape Z 
Elt Z 
Unlift Exp Z 
Lift Exp Z 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt (Any Z) 

data tail :. head Source

Increase an index rank by one dimension. The :. operator is used to construct both values and types.

Constructors

tail :. head 

Instances

Typeable2 :. 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
(Elt e, Slice (Plain ix), Unlift Exp ix) => Unlift Exp (:. ix (Exp e)) 
(Elt e, Slice ix) => Unlift Exp (:. (Exp ix) (Exp e)) 
(Elt e, Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix (Exp e)) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix All) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix Int) 
Shape sh => Elt (Any (:. sh Int)) 
(Eq tail, Eq head) => Eq (:. tail head) 
(Show tail, Show head) => Show (:. tail head) 
Slice sl => Slice (:. sl Int) 
Slice sl => Slice (:. sl All) 
Shape sh => Shape (:. sh Int) 
(Elt t, Elt h) => Elt (:. t h) 
(Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row0) => Stencil (:. (:. sh Int) Int) a (row2, row1, row0) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5, Stencil (:. sh Int) a row6, Stencil (:. sh Int) a row7) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5, row6, row7) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5, Stencil (:. sh Int) a row6, Stencil (:. sh Int) a row7, Stencil (:. sh Int) a row8, Stencil (:. sh Int) a row9) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5, row6, row7, row8, row9) 

class (Elt sh, Elt (Any sh), Shape (EltRepr sh)) => Shape sh Source

Shapes and indices of multi-dimensional arrays

Instances

Shape Z 
Shape sh => Shape (:. sh Int) 

data All Source

Marker for entire dimensions in slice descriptors.

For example, when used in slices passed to replicate, the occurrences of All indicate the dimensions into which the array's existing extent will be placed, rather than the new dimensions introduced by replication.

Constructors

All 

Instances

Eq All 
Show All 
Typeable All 
Elt All 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix All) 
Slice sl => Slice (:. sl All) 

data Any sh Source

Marker for arbitrary shapes in slice descriptors. Such arbitrary shapes may include an unknown number of dimensions.

Any can be used in the leftmost position of a slice instead of Z, for example (Any :. _ :. _). In the following definition Any is used to match against whatever shape the type variable sh takes:

 repN :: (Shape sh, Elt e) => Int -> Acc (Array sh e) -> Acc (Array (sh:.Int) e)
 repN n a = replicate (constant $ Any :. n) a

Constructors

Any 

Instances

Typeable1 Any 
Shape sh => Lift Exp (Any sh) 
Eq (Any sh) 
Show (Any sh) 
Shape sh => Slice (Any sh) 
Shape sh => Elt (Any (:. sh Int)) 
Elt (Any Z) 

class (Elt sl, Shape (SliceShape sl), Shape (CoSliceShape sl), Shape (FullShape sl)) => Slice sl whereSource

Slices, aka generalised indices, as n-tuples and mappings of slice indices to slices, co-slices, and slice dimensions

Associated Types

type SliceShape sl :: *Source

type CoSliceShape sl :: *Source

type FullShape sl :: *Source

Methods

sliceIndex :: sl -> SliceIndex (EltRepr sl) (EltRepr (SliceShape sl)) (EltRepr (CoSliceShape sl)) (EltRepr (FullShape sl))Source

Instances

Slice Z 
Shape sh => Slice (Any sh) 
Slice sl => Slice (:. sl Int) 
Slice sl => Slice (:. sl All) 

type DIM0 = ZSource

Accessors

Indexing

(!) :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp ix -> Exp eSource

Expression form that extracts a scalar from an array

(!!) :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp Int -> Exp eSource

Expression form that extracts a scalar from an array at a linear index

the :: Elt e => Acc (Scalar e) -> Exp eSource

Extraction of the element in a singleton array

Shape information

null :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp BoolSource

Test whether an array is empty

shape :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp ixSource

Expression form that yields the shape of an array

size :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp IntSource

Expression form that yields the size of an array

shapeSize :: Shape ix => Exp ix -> Exp IntSource

The total number of elements in an array of the given Shape

Extracting sub-arrays

slice :: (Slice slix, Elt e) => Acc (Array (FullShape slix) e) -> Exp slix -> Acc (Array (SliceShape slix) e)Source

Index an array with a generalised array index, supplied as the second argument. The result is a new array (possibly a singleton) containing the selected dimensions (Alls) in their entirety.

This can be used to cut out entire dimensions. The opposite of replicate. For example, if mat is a two dimensional array, the following will select a specific row and yield a one dimensional result:

 slice mat (constant (Z :. (2::Int) :. All))

A fully specified index (with no Alls) would return a single element (zero dimensional array).

init :: Elt e => Acc (Vector e) -> Acc (Vector e)Source

Yield all but the last element of the input vector. The vector must not be empty.

tail :: Elt e => Acc (Vector e) -> Acc (Vector e)Source

Yield all but the first element of the input vector. The vector must not be empty.

take :: Elt e => Exp Int -> Acc (Vector e) -> Acc (Vector e)Source

Yield the first n elements of the input vector. The vector must contain no more than n elements.

drop :: Elt e => Exp Int -> Acc (Vector e) -> Acc (Vector e)Source

Yield all but the first n elements of the input vector. The vector must contain no fewer than n elements.

slit :: Elt e => Exp Int -> Exp Int -> Acc (Vector e) -> Acc (Vector e)Source

Yield a slit (slice) from the vector. The vector must contain at least i + n elements. Denotationally, we have:

 slit i n = take n . drop i

Construction

Introduction

use :: Arrays arrays => arrays -> Acc arraysSource

Array inlet: makes an array available for processing using the Accelerate language.

Depending upon the backend used to execute array computations, this may trigger (asynchronous) data transfer.

unit :: Elt e => Exp e -> Acc (Scalar e)Source

Scalar inlet: injects a scalar (or a tuple of scalars) into a singleton array for use in the Accelerate language.

Initialisation

generate :: (Shape ix, Elt a) => Exp ix -> (Exp ix -> Exp a) -> Acc (Array ix a)Source

Construct a new array by applying a function to each index.

For example, the following will generate a one-dimensional array (Vector) of three floating point numbers:

 generate (index1 3) (\_ -> 1.2)

Or, equivalently:

 generate (constant (Z :. (3::Int))) (\_ -> 1.2)

Finally, the following will create an array equivalent to '[1..10]':

 generate (index1 10) $ \ ix ->
          let (Z :. i) = unlift ix
          in fromIntegral i

replicate :: (Slice slix, Elt e) => Exp slix -> Acc (Array (SliceShape slix) e) -> Acc (Array (FullShape slix) e)Source

Replicate an array across one or more dimensions as specified by the generalised array index provided as the first argument.

For example, assuming arr is a vector (one-dimensional array),

 replicate (Z :.2 :.All :.3) arr

yields a three dimensional array, where arr is replicated twice across the first and three times across the third dimension.

fill :: (Shape sh, Elt e) => Exp sh -> Exp e -> Acc (Array sh e)Source

Create an array where all elements are the same value.

Enumeration

enumFromN :: (Shape sh, Elt e, IsNum e) => Exp sh -> Exp e -> Acc (Array sh e)Source

Create an array of the given shape containing the values x, x+1, etc (in row-major order).

enumFromStepNSource

Arguments

:: (Shape sh, Elt e, IsNum e) 
=> Exp sh 
-> Exp e

x: start

-> Exp e

y: step

-> Acc (Array sh e) 

Create an array of the given shape containing the values x, x+y, x+y+y etc. (in row-major order).

Composition

Flow control

(?|) :: Arrays a => Exp Bool -> (Acc a, Acc a) -> Acc aSource

Infix version of cond.

condSource

Arguments

:: Arrays a 
=> Exp Bool

if-condition

-> Acc a

then-array

-> Acc a

else-array

-> Acc a 

An array-level if-then-else construct.

Pipelining

(>->) :: (Arrays a, Arrays b, Arrays c) => (Acc a -> Acc b) -> (Acc b -> Acc c) -> Acc a -> Acc cSource

Pipelining of two array computations.

Denotationally, we have

 (acc1 >-> acc2) arrs = let tmp = acc1 arrs in acc2 tmp

Operationally, the array computations acc1 and acc2 will not share any sub-computations, neither between each other nor with the environment. This makes them truly independent stages that only communicate by way of the result of acc1 which is being fed as an argument to acc2.

Modifying Arrays

Shape manipulation

reshape :: (Shape ix, Shape ix', Elt e) => Exp ix -> Acc (Array ix' e) -> Acc (Array ix e)Source

Change the shape of an array without altering its contents. The size of the source and result arrays must be identical.

 precondition: size ix == size ix'

flatten :: (Shape ix, Elt a) => Acc (Array ix a) -> Acc (Vector a)Source

Flattens a given array of arbitrary dimension.

Permutations

permuteSource

Arguments

:: (Shape ix, Shape ix', Elt a) 
=> (Exp a -> Exp a -> Exp a)

combination function

-> Acc (Array ix' a)

array of default values

-> (Exp ix -> Exp ix')

permutation

-> Acc (Array ix a)

array to be permuted

-> Acc (Array ix' a) 

Forward permutation specified by an index mapping. The result array is initialised with the given defaults and any further values that are permuted into the result array are added to the current value using the given combination function.

The combination function must be associative. Elements that are mapped to the magic value ignore by the permutation function are dropped.

backpermuteSource

Arguments

:: (Shape ix, Shape ix', Elt a) 
=> Exp ix'

shape of the result array

-> (Exp ix' -> Exp ix)

permutation

-> Acc (Array ix a)

source array

-> Acc (Array ix' a) 

Backward permutation specified by an index mapping from the destination array specifying which element of the source array to read.

ignore :: Shape ix => Exp ixSource

Magic value identifying elements that are ignored in a forward permutation. Note that this currently does not work for singleton arrays.

Specialised permutations

reverse :: Elt e => Acc (Vector e) -> Acc (Vector e)Source

Reverse the elements of a vector.

transpose :: Elt e => Acc (Array DIM2 e) -> Acc (Array DIM2 e)Source

Transpose the rows and columns of a matrix.

Element-wise operations

Mapping

map :: (Shape ix, Elt a, Elt b) => (Exp a -> Exp b) -> Acc (Array ix a) -> Acc (Array ix b)Source

Apply the given function element-wise to the given array.

Zipping

zipWith :: (Shape ix, Elt a, Elt b, Elt c) => (Exp a -> Exp b -> Exp c) -> Acc (Array ix a) -> Acc (Array ix b) -> Acc (Array ix c)Source

Apply the given binary function element-wise to the two arrays. The extent of the resulting array is the intersection of the extents of the two source arrays.

zipWith3 :: (Shape sh, Elt a, Elt b, Elt c, Elt d) => (Exp a -> Exp b -> Exp c -> Exp d) -> Acc (Array sh a) -> Acc (Array sh b) -> Acc (Array sh c) -> Acc (Array sh d)Source

Zip three arrays with the given function

zipWith4 :: (Shape sh, Elt a, Elt b, Elt c, Elt d, Elt e) => (Exp a -> Exp b -> Exp c -> Exp d -> Exp e) -> Acc (Array sh a) -> Acc (Array sh b) -> Acc (Array sh c) -> Acc (Array sh d) -> Acc (Array sh e)Source

Zip four arrays with the given function

zip :: (Shape sh, Elt a, Elt b) => Acc (Array sh a) -> Acc (Array sh b) -> Acc (Array sh (a, b))Source

Combine the elements of two arrays pairwise. The shape of the result is the intersection of the two argument shapes.

zip3 :: forall sh a b c. (Shape sh, Elt a, Elt b, Elt c) => Acc (Array sh a) -> Acc (Array sh b) -> Acc (Array sh c) -> Acc (Array sh (a, b, c))Source

Take three arrays and return an array of triples, analogous to zip.

zip4 :: forall sh a b c d. (Shape sh, Elt a, Elt b, Elt c, Elt d) => Acc (Array sh a) -> Acc (Array sh b) -> Acc (Array sh c) -> Acc (Array sh d) -> Acc (Array sh (a, b, c, d))Source

Take four arrays and return an array of quadruples, analogous to zip.

Unzipping

unzip :: (Shape sh, Elt a, Elt b) => Acc (Array sh (a, b)) -> (Acc (Array sh a), Acc (Array sh b))Source

The converse of zip, but the shape of the two results is identical to the shape of the argument.

unzip3 :: (Shape sh, Elt a, Elt b, Elt c) => Acc (Array sh (a, b, c)) -> (Acc (Array sh a), Acc (Array sh b), Acc (Array sh c))Source

Take an array of triples and return three arrays, analogous to unzip.

unzip4 :: (Shape sh, Elt a, Elt b, Elt c, Elt d) => Acc (Array sh (a, b, c, d)) -> (Acc (Array sh a), Acc (Array sh b), Acc (Array sh c), Acc (Array sh d))Source

Take an array of quadruples and return four arrays, analogous to unzip.

Working with predicates

Filtering

filter :: Elt a => (Exp a -> Exp Bool) -> Acc (Vector a) -> Acc (Vector a)Source

Drop elements that do not satisfy the predicate

Scatter

scatterSource

Arguments

:: Elt e 
=> Acc (Vector Int)

map

-> Acc (Vector e)

default

-> Acc (Vector e)

input

-> Acc (Vector e)

output

Copy elements from source array to destination array according to a map. This is a forward-permute operation where a map vector encodes an input to output index mapping. Output elements for indices that are not mapped assume the default vector's value.

For example:

 default = [0, 0, 0, 0, 0, 0, 0, 0, 0]
 map     = [1, 3, 7, 2, 5, 8]
 input   = [1, 9, 6, 4, 4, 2, 5]

 output  = [0, 1, 4, 9, 0, 4, 0, 6, 2]

Note if the same index appears in the map more than once, the result is undefined. The map vector cannot be larger than the input vector.

scatterIfSource

Arguments

:: (Elt e, Elt e') 
=> Acc (Vector Int)

map

-> Acc (Vector e)

mask

-> (Exp e -> Exp Bool)

predicate

-> Acc (Vector e')

default

-> Acc (Vector e')

input

-> Acc (Vector e')

output

Conditionally copy elements from source array to destination array according to a map. This is a forward-permute operation where a map vector encodes an input to output index mapping. In addition, there is a mask vector, and an associated predicate function, that specifies whether an elements will be copied. If not copied, the output array assumes the default vector's value.

For example:

 default = [0, 0, 0, 0, 0, 0, 0, 0, 0]
 map     = [1, 3, 7, 2, 5, 8]
 mask    = [3, 4, 9, 2, 7, 5]
 pred    = (> 4)
 input   = [1, 9, 6, 4, 4, 2]

 output  = [0, 0, 0, 0, 0, 4, 0, 6, 2]

Note if the same index appears in the map more than once, the result is undefined. The map and input vector must be of the same length.

Gather

gatherSource

Arguments

:: Elt e 
=> Acc (Vector Int)

map

-> Acc (Vector e)

input

-> Acc (Vector e)

output

Copy elements from source array to destination array according to a map. This is a backpermute operation where a map vector encodes the output to input index mapping.

For example:

 input  = [1, 9, 6, 4, 4, 2, 0, 1, 2]
 map    = [1, 3, 7, 2, 5, 3]

 output = [9, 4, 1, 6, 2, 4]

gatherIfSource

Arguments

:: (Elt e, Elt e') 
=> Acc (Vector Int)

map

-> Acc (Vector e)

mask

-> (Exp e -> Exp Bool)

predicate

-> Acc (Vector e')

default

-> Acc (Vector e')

input

-> Acc (Vector e')

output

Conditionally copy elements from source array to destination array according to a map. This is a backpermute operation where a map vector encodes the output to input index mapping. In addition, there is a mask vector, and an associated predication function, that specifies whether an element will be copied. If not copied, the output array assumes the default vector's value.

For example:

 default = [6, 6, 6, 6, 6, 6]
 map     = [1, 3, 7, 2, 5, 3]
 mask    = [3, 4, 9, 2, 7, 5]
 pred    = (> 4)
 input   = [1, 9, 6, 4, 4, 2, 0, 1, 2]

 output  = [6, 6, 1, 6, 2, 4]

Folding

fold :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Array (ix :. Int) a) -> Acc (Array ix a)Source

Reduction of the innermost dimension of an array of arbitrary rank. The first argument needs to be an associative function to enable an efficient parallel implementation.

fold1 :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Acc (Array (ix :. Int) a) -> Acc (Array ix a)Source

Variant of fold that requires the reduced array to be non-empty and doesn't need an default value. The first argument needs to be an associative function to enable an efficient parallel implementation.

foldAll :: (Shape sh, Elt a) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Array sh a) -> Acc (Scalar a)Source

Reduction of an array of arbitrary rank to a single scalar value.

fold1All :: (Shape sh, Elt a) => (Exp a -> Exp a -> Exp a) -> Acc (Array sh a) -> Acc (Scalar a)Source

Variant of foldAll that requires the reduced array to be non-empty and doesn't need an default value.

Segmented reductions

foldSeg :: (Shape ix, Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Array (ix :. Int) a) -> Acc (Segments i) -> Acc (Array (ix :. Int) a)Source

Segmented reduction along the innermost dimension. Performs one individual reduction per segment of the source array. These reductions proceed in parallel.

The source array must have at least rank 1. The Segments array determines the lengths of the logical sub-arrays, each of which is folded separately.

fold1Seg :: (Shape ix, Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Acc (Array (ix :. Int) a) -> Acc (Segments i) -> Acc (Array (ix :. Int) a)Source

Variant of foldSeg that requires all segments of the reduced array to be non-empty and doesn't need a default value.

The source array must have at least rank 1. The Segments array determines the lengths of the logical sub-arrays, each of which is folded separately.

Specialised folds

all :: (Shape sh, Elt e) => (Exp e -> Exp Bool) -> Acc (Array sh e) -> Acc (Scalar Bool)Source

Check if all elements satisfy a predicate

any :: (Shape sh, Elt e) => (Exp e -> Exp Bool) -> Acc (Array sh e) -> Acc (Scalar Bool)Source

Check if any element satisfies the predicate

and :: Shape sh => Acc (Array sh Bool) -> Acc (Scalar Bool)Source

Check if all elements are True

or :: Shape sh => Acc (Array sh Bool) -> Acc (Scalar Bool)Source

Check if any element is True

sum :: (Shape sh, Elt e, IsNum e) => Acc (Array sh e) -> Acc (Scalar e)Source

Compute the sum of elements

product :: (Shape sh, Elt e, IsNum e) => Acc (Array sh e) -> Acc (Scalar e)Source

Compute the product of the elements

minimum :: (Shape sh, Elt e, IsScalar e) => Acc (Array sh e) -> Acc (Scalar e)Source

Yield the minimum element of an array. The array must not be empty.

maximum :: (Shape sh, Elt e, IsScalar e) => Acc (Array sh e) -> Acc (Scalar e)Source

Yield the maximum element of an array. The array must not be empty.

Prefix sums (scans)

scanl :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)Source

Data.List style left-to-right scan, but with the additional restriction that the first argument needs to be an associative function to enable an efficient parallel implementation. The initial value (second argument) may be arbitrary.

scanl1 :: Elt a => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc (Vector a)Source

Data.List style left-to-right scan without an initial value (aka inclusive scan). Again, the first argument needs to be an associative function. Denotationally, we have

 scanl1 f e arr = tail (scanl f e arr)

scanl' :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> (Acc (Vector a), Acc (Scalar a))Source

Variant of scanl, where the final result of the reduction is returned separately. Denotationally, we have

 scanl' f e arr = (init res, unit (res!len))
   where
     len = shape arr
     res = scanl f e arr

scanr :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)Source

Right-to-left variant of scanl.

scanr1 :: Elt a => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc (Vector a)Source

Right-to-left variant of scanl1.

scanr' :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> (Acc (Vector a), Acc (Scalar a))Source

Right-to-left variant of scanl'.

prescanl :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)Source

Left-to-right prescan (aka exclusive scan). As for scan, the first argument must be an associative function. Denotationally, we have

 prescanl f e = Prelude.fst . scanl' f e

postscanl :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)Source

Left-to-right postscan, a variant of scanl1 with an initial value. Denotationally, we have

 postscanl f e = map (e `f`) . scanl1 f

prescanr :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)Source

Right-to-left prescan (aka exclusive scan). As for scan, the first argument must be an associative function. Denotationally, we have

 prescanr f e = Prelude.fst . scanr' f e

postscanr :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)Source

Right-to-left postscan, a variant of scanr1 with an initial value. Denotationally, we have

 postscanr f e = map (e `f`) . scanr1 f

Segmented scans

scanlSeg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of scanl

scanl1Seg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of scanl1.

scanl'Seg :: forall a i. (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a, Vector a)Source

Segmented version of scanl'

The first element of the resulting tuple is a vector of scanned values. The second element is a vector of segment scan totals and has the same size as the segment vector.

prescanlSeg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of prescanl.

postscanlSeg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of postscanl.

scanrSeg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of scanr.

scanr1Seg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of scanr1.

scanr'Seg :: forall a i. (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a, Vector a)Source

Segmented version of scanr'.

prescanrSeg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of prescanr.

postscanrSeg :: (Elt a, Elt i, IsIntegral i) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Segments i) -> Acc (Vector a)Source

Segmented version of postscanr.

Stencil

stencilSource

Arguments

:: (Shape ix, Elt a, Elt b, Stencil ix a stencil) 
=> (stencil -> Exp b)

stencil function

-> Boundary a

boundary condition

-> Acc (Array ix a)

source array

-> Acc (Array ix b)

destination array

Map a stencil over an array. In contrast to map, the domain of a stencil function is an entire neighbourhood of each array element. Neighbourhoods are sub-arrays centred around a focal point. They are not necessarily rectangular, but they are symmetric in each dimension and have an extent of at least three in each dimensions — due to the symmetry requirement, the extent is necessarily odd. The focal point is the array position that is determined by the stencil.

For those array positions where the neighbourhood extends past the boundaries of the source array, a boundary condition determines the contents of the out-of-bounds neighbourhood positions.

stencil2Source

Arguments

:: (Shape ix, Elt a, Elt b, Elt c, Stencil ix a stencil1, Stencil ix b stencil2) 
=> (stencil1 -> stencil2 -> Exp c)

binary stencil function

-> Boundary a

boundary condition #1

-> Acc (Array ix a)

source array #1

-> Boundary b

boundary condition #2

-> Acc (Array ix b)

source array #2

-> Acc (Array ix c)

destination array

Map a binary stencil of an array. The extent of the resulting array is the intersection of the extents of the two source arrays.

Specification

class (Elt (StencilRepr sh stencil), Stencil sh a (StencilRepr sh stencil)) => Stencil sh a stencil Source

Instances

Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
(Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row0) => Stencil (:. (:. sh Int) Int) a (row2, row1, row0) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5, Stencil (:. sh Int) a row6, Stencil (:. sh Int) a row7) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5, row6, row7) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5, Stencil (:. sh Int) a row6, Stencil (:. sh Int) a row7, Stencil (:. sh Int) a row8, Stencil (:. sh Int) a row9) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5, row6, row7, row8, row9) 

data Boundary a Source

Boundary condition specification for stencil operations.

Constructors

Clamp

clamp coordinates to the extent of the array

Mirror

mirror coordinates beyond the array extent

Wrap

wrap coordinates around on each dimension

Constant a

use a constant value for outlying coordinates

Instances

Read a => Read (Boundary a) 
Show a => Show (Boundary a) 

Common stencil patterns

type Stencil3 a = (Exp a, Exp a, Exp a)Source

type Stencil5 a = (Exp a, Exp a, Exp a, Exp a, Exp a)Source

type Stencil7 a = (Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a)Source

type Stencil9 a = (Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a)Source

Foreign

foreignAcc :: (Arrays acc, Arrays res, Foreign ff) => ff acc res -> (Acc acc -> Acc res) -> Acc acc -> Acc resSource

Call a foreign function. The form the function takes is dependent on the backend being used. The arguments are passed as either a single array or as a tuple of arrays. In addition a pure Accelerate version of the function needs to be provided to support backends other than the one being targeted.

foreignAcc2 :: (Arrays acc, Arrays res, Foreign ff1, Foreign ff2) => ff1 acc res -> ff2 acc res -> (Acc acc -> Acc res) -> Acc acc -> Acc resSource

Call a foreign function with foreign implementations for two different backends.

foreignAcc3 :: (Arrays acc, Arrays res, Foreign ff1, Foreign ff2, Foreign ff3) => ff1 acc res -> ff2 acc res -> ff3 acc res -> (Acc acc -> Acc res) -> Acc acc -> Acc resSource

Call a foreign function with foreign implementations for three different backends.

foreignExp :: (Elt e, Elt res, Foreign ff) => ff e res -> (Exp e -> Exp res) -> Exp e -> Exp resSource

Call a foreign expression function. The form the function takes is dependent on the backend being used. The arguments are passed as either a single scalar element or as a tuple of elements. In addition a pure Accelerate version of the function needs to be provided to support backends other than the one being targeted.

foreignExp2 :: (Elt e, Elt res, Foreign ff1, Foreign ff2) => ff1 e res -> ff2 e res -> (Exp e -> Exp res) -> Exp e -> Exp resSource

Call a foreign function with foreign implementations for two different backends.

foreignExp3 :: (Elt e, Elt res, Foreign ff1, Foreign ff2, Foreign ff3) => ff1 e res -> ff2 e res -> ff3 e res -> (Exp e -> Exp res) -> Exp e -> Exp resSource

Call a foreign function with foreign implementations for three different backends.

The Accelerate Expression Language

Scalar data types

data Exp t Source

Scalar expressions for plain array computations.

Instances

Typeable1 Exp 
Unlift Exp () 
Unlift Exp Z 
Lift Exp Bool 
Lift Exp Char 
Lift Exp Double 
Lift Exp Float 
Lift Exp Int 
Lift Exp Int8 
Lift Exp Int16 
Lift Exp Int32 
Lift Exp Int64 
Lift Exp Word 
Lift Exp Word8 
Lift Exp Word16 
Lift Exp Word32 
Lift Exp Word64 
Lift Exp () 
Lift Exp Z 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Shape sh => Lift Exp (Any sh) 
Lift Exp (Exp e) 
(Elt a, Elt b) => Unlift Exp (Exp a, Exp b) 
(Elt e, Slice (Plain ix), Unlift Exp ix) => Unlift Exp (:. ix (Exp e)) 
(Elt e, Slice ix) => Unlift Exp (:. (Exp ix) (Exp e)) 
(Lift Exp a, Lift Exp b, Elt (Plain a), Elt (Plain b)) => Lift Exp (a, b) 
(Elt e, Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix (Exp e)) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix All) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix Int) 
(Elt a, Elt b, Elt c) => Unlift Exp (Exp a, Exp b, Exp c) 
(Lift Exp a, Lift Exp b, Lift Exp c, Elt (Plain a), Elt (Plain b), Elt (Plain c)) => Lift Exp (a, b, c) 
(Elt a, Elt b, Elt c, Elt d) => Unlift Exp (Exp a, Exp b, Exp c, Exp d) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d)) => Lift Exp (a, b, c, d) 
(Elt a, Elt b, Elt c, Elt d, Elt e) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e)) => Lift Exp (a, b, c, d, e) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f)) => Lift Exp (a, b, c, d, e, f) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f), Elt (Plain g)) => Lift Exp (a, b, c, d, e, f, g) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Lift Exp h, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f), Elt (Plain g), Elt (Plain h)) => Lift Exp (a, b, c, d, e, f, g, h) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h, Exp i) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Lift Exp h, Lift Exp i, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f), Elt (Plain g), Elt (Plain h), Elt (Plain i)) => Lift Exp (a, b, c, d, e, f, g, h, i) 
(Elt t, IsBounded t) => Bounded (Exp t) 
(Elt t, IsScalar t) => Enum (Exp t) 
(Elt t, IsScalar t) => Eq (Exp t) 
(Elt t, IsFloating t) => Floating (Exp t) 
(Elt t, IsFloating t) => Fractional (Exp t) 
(Elt t, IsIntegral t) => Integral (Exp t) 
(Elt t, IsNum t) => Num (Exp t) 
(Elt t, IsScalar t) => Ord (Exp t) 
(Elt t, IsNum t) => Real (Exp t) 
(Elt t, IsFloating t) => RealFloat (Exp t) 
(Elt t, IsFloating t) => RealFrac (Exp t) 
Elt e => Show (Exp e) 
(Elt t, IsNum t, IsIntegral t) => Bits (Exp t) 
Function (Exp a -> f) => Show (Exp a -> f) 

Type classes

Element types

data Int

A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]. The exact range for a given implementation can be determined by using minBound and maxBound from the Bounded class.

Instances

Bounded Int 
Enum Int 
Eq Int 
Integral Int 
Num Int 
Ord Int 
Read Int 
Real Int 
Show Int 
Ix Int 
Typeable Int 
Generic Int 
Storable Int 
Bits Int 
Hashable Int 
Prim Int 
Lift Int 
Unbox Int 
IsScalar Int 
IsBounded Int 
IsNum Int 
IsIntegral Int 
Elt Int 
IArray UArray Int 
Vector Vector Int 
MVector MVector Int 
Lift Exp Int 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix Int) 
Shape sh => Elt (Any (:. sh Int)) 
MArray (STUArray s) Int (ST s) 
Slice sl => Slice (:. sl Int) 
Shape sh => Shape (:. sh Int) 
(Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row0) => Stencil (:. (:. sh Int) Int) a (row2, row1, row0) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5, Stencil (:. sh Int) a row6, Stencil (:. sh Int) a row7) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5, row6, row7) 
(Stencil (:. sh Int) a row1, Stencil (:. sh Int) a row2, Stencil (:. sh Int) a row3, Stencil (:. sh Int) a row4, Stencil (:. sh Int) a row5, Stencil (:. sh Int) a row6, Stencil (:. sh Int) a row7, Stencil (:. sh Int) a row8, Stencil (:. sh Int) a row9) => Stencil (:. (:. sh Int) Int) a (row1, row2, row3, row4, row5, row6, row7, row8, row9) 

data Float

Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.

data Double

Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.

data Char

The character type Char is an enumeration whose values represent Unicode (or equivalently ISO/IEC 10646) characters (see http://www.unicode.org/ for details). This set extends the ISO 8859-1 (Latin-1) character set (the first 256 characters), which is itself an extension of the ASCII character set (the first 128 characters). A character literal in Haskell has type Char.

To convert a Char to or from the corresponding Int value defined by Unicode, use toEnum and fromEnum from the Enum class respectively (or equivalently ord and chr).

Lifting and Unlifting

A value of type Int is a plain Haskell value (unlifted), whereas an Exp Int is a lifted value, that is, an integer lifted into the domain of expressions (an abstract syntax tree in disguise). Both Acc and Exp are surface types into which values may be lifted.

In general an Exp Int cannot be unlifted into an Int, because the actual number will not be available until a later stage of execution (e.g. GPU execution, when run is called). However, in some cases unlifting makes sense. For example, unlifting can convert, or unpack, an expression of tuple type into a tuple of expressions; those expressions, at runtime, will become tuple dereferences.

class Lift c e whereSource

The class of types e which can be lifted into c.

Associated Types

type Plain e Source

An associated-type (i.e. a type-level function) that strips all instances of surface type constructors c from the input type e.

For example, the tuple types (Exp Int, Int) and (Int, Exp Int) have the same "Plain" representation. That is, the following type equality holds:

Plain (Exp Int, Int) ~ (Int,Int) ~ Plain (Int, Exp Int)

Methods

lift :: e -> c (Plain e)Source

Lift the given value into a surface type c --- either Exp for scalar expressions or Acc for array computations. The value may already contain subexpressions in c.

Instances

Lift Exp Bool 
Lift Exp Char 
Lift Exp Double 
Lift Exp Float 
Lift Exp Int 
Lift Exp Int8 
Lift Exp Int16 
Lift Exp Int32 
Lift Exp Int64 
Lift Exp Word 
Lift Exp Word8 
Lift Exp Word16 
Lift Exp Word32 
Lift Exp Word64 
Lift Exp () 
Lift Exp Z 
Shape sh => Lift Exp (Any sh) 
Lift Exp (Exp e) 
Lift Acc (Acc a) 
(Lift Exp a, Lift Exp b, Elt (Plain a), Elt (Plain b)) => Lift Exp (a, b) 
(Elt e, Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix (Exp e)) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix All) 
(Slice (Plain ix), Lift Exp ix) => Lift Exp (:. ix Int) 
(Lift Acc a, Lift Acc b, Arrays (Plain a), Arrays (Plain b)) => Lift Acc (a, b) 
(Shape sh, Elt e) => Lift Acc (Array sh e) 
(Lift Exp a, Lift Exp b, Lift Exp c, Elt (Plain a), Elt (Plain b), Elt (Plain c)) => Lift Exp (a, b, c) 
(Lift Acc a, Lift Acc b, Lift Acc c, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c)) => Lift Acc (a, b, c) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d)) => Lift Exp (a, b, c, d) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d)) => Lift Acc (a, b, c, d) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e)) => Lift Exp (a, b, c, d, e) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e)) => Lift Acc (a, b, c, d, e) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f)) => Lift Exp (a, b, c, d, e, f) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f)) => Lift Acc (a, b, c, d, e, f) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f), Elt (Plain g)) => Lift Exp (a, b, c, d, e, f, g) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f), Arrays (Plain g)) => Lift Acc (a, b, c, d, e, f, g) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Lift Exp h, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f), Elt (Plain g), Elt (Plain h)) => Lift Exp (a, b, c, d, e, f, g, h) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Lift Acc h, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f), Arrays (Plain g), Arrays (Plain h)) => Lift Acc (a, b, c, d, e, f, g, h) 
(Lift Exp a, Lift Exp b, Lift Exp c, Lift Exp d, Lift Exp e, Lift Exp f, Lift Exp g, Lift Exp h, Lift Exp i, Elt (Plain a), Elt (Plain b), Elt (Plain c), Elt (Plain d), Elt (Plain e), Elt (Plain f), Elt (Plain g), Elt (Plain h), Elt (Plain i)) => Lift Exp (a, b, c, d, e, f, g, h, i) 
(Lift Acc a, Lift Acc b, Lift Acc c, Lift Acc d, Lift Acc e, Lift Acc f, Lift Acc g, Lift Acc h, Lift Acc i, Arrays (Plain a), Arrays (Plain b), Arrays (Plain c), Arrays (Plain d), Arrays (Plain e), Arrays (Plain f), Arrays (Plain g), Arrays (Plain h), Arrays (Plain i)) => Lift Acc (a, b, c, d, e, f, g, h, i) 

class Lift c e => Unlift c e whereSource

A limited subset of types which can be lifted, can also be unlifted.

Methods

unlift :: c (Plain e) -> eSource

Unlift the outermost constructor through the surface type. This is only possible if the constructor is fully determined by its type - i.e., it is a singleton.

Instances

Unlift Exp () 
Unlift Exp Z 
(Elt a, Elt b) => Unlift Exp (Exp a, Exp b) 
(Elt e, Slice (Plain ix), Unlift Exp ix) => Unlift Exp (:. ix (Exp e)) 
(Elt e, Slice ix) => Unlift Exp (:. (Exp ix) (Exp e)) 
(Arrays a, Arrays b) => Unlift Acc (Acc a, Acc b) 
(Elt a, Elt b, Elt c) => Unlift Exp (Exp a, Exp b, Exp c) 
(Arrays a, Arrays b, Arrays c) => Unlift Acc (Acc a, Acc b, Acc c) 
(Elt a, Elt b, Elt c, Elt d) => Unlift Exp (Exp a, Exp b, Exp c, Exp d) 
(Arrays a, Arrays b, Arrays c, Arrays d) => Unlift Acc (Acc a, Acc b, Acc c, Acc d) 
(Elt a, Elt b, Elt c, Elt d, Elt e) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g, Arrays h) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g, Acc h) 
(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i) => Unlift Exp (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h, Exp i) 
(Arrays a, Arrays b, Arrays c, Arrays d, Arrays e, Arrays f, Arrays g, Arrays h, Arrays i) => Unlift Acc (Acc a, Acc b, Acc c, Acc d, Acc e, Acc f, Acc g, Acc h, Acc i) 

lift1 :: (Unlift Exp e1, Lift Exp e2) => (e1 -> e2) -> Exp (Plain e1) -> Exp (Plain e2)Source

Lift a unary function into Exp.

lift2 :: (Unlift Exp e1, Unlift Exp e2, Lift Exp e3) => (e1 -> e2 -> e3) -> Exp (Plain e1) -> Exp (Plain e2) -> Exp (Plain e3)Source

Lift a binary function into Exp.

ilift1 :: (Exp Int -> Exp Int) -> Exp DIM1 -> Exp DIM1Source

Lift a unary function to a computation over rank-1 indices.

ilift2 :: (Exp Int -> Exp Int -> Exp Int) -> Exp DIM1 -> Exp DIM1 -> Exp DIM1Source

Lift a binary function to a computation over rank-1 indices.

Operations

Some of the standard Haskell 98 typeclass functions need to be reimplemented because their types change. If so, function names kept the same and infix operations are suffixed by an asterisk. If not reimplemented here, the standard typeclass instances apply.

Introduction

constant :: Elt t => t -> Exp tSource

Scalar expression inlet: make a Haskell value available for processing in an Accelerate scalar expression.

Note that this embeds the value directly into the expression. Depending on the backend used to execute the computation, this might not always be desirable. For example, a backend that does external code generation may embed this constant directly into the generated code, which means new code will need to be generated and compiled every time the value changes. In such cases, consider instead lifting scalar values into (singleton) arrays so that they can be passed as an input to the computation and thus the value can change without the need to generate fresh code.

Tuples

fst :: forall f a b. Unlift f (f a, f b) => f (Plain (f a), Plain (f b)) -> f aSource

Extract the first component of a pair.

snd :: forall f a b. Unlift f (f a, f b) => f (Plain (f a), Plain (f b)) -> f bSource

Extract the second component of a pair.

curry :: Lift f (f a, f b) => (f (Plain (f a), Plain (f b)) -> f c) -> f a -> f b -> f cSource

Converts an uncurried function to a curried function.

uncurry :: Unlift f (f a, f b) => (f a -> f b -> f c) -> f (Plain (f a), Plain (f b)) -> f cSource

Converts a curried function to a function on pairs.

Conditional

(?) :: Elt t => Exp Bool -> (Exp t, Exp t) -> Exp tSource

Conditional expression. If the predicate evaluates to True, the first component of the tuple is returned, else the second.

Basic operations

(&&*) :: Exp Bool -> Exp Bool -> Exp BoolSource

Conjunction

(||*) :: Exp Bool -> Exp Bool -> Exp BoolSource

Disjunction

not :: Exp Bool -> Exp BoolSource

Negation

(==*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp BoolSource

Equality lifted into Accelerate expressions.

(/=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp BoolSource

Inequality lifted into Accelerate expressions.

(<*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp BoolSource

Smaller-than lifted into Accelerate expressions.

(<=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp BoolSource

Smaller-or-equal lifted into Accelerate expressions.

(>*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp BoolSource

Greater-than lifted into Accelerate expressions.

(>=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp BoolSource

Greater-or-equal lifted into Accelerate expressions.

max :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp tSource

Determine the maximum of two scalars.

min :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp tSource

Determine the minimum of two scalars.

Numeric functions

truncate :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp bSource

truncate x returns the integer nearest x between zero and x.

round :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp bSource

round x returns the nearest integer to x, or the even integer if x is equidistant between two integers.

floor :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp bSource

floor x returns the greatest integer not greater than x.

ceiling :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp bSource

ceiling x returns the least integer not less than x.

Bitwise functions

bit :: (Elt t, IsIntegral t) => Exp Int -> Exp tSource

bit i is a value with the ith bit set and all other bits clear

setBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

x `setBit` i is the same as x .|. bit i

clearBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

x `clearBit` i is the same as x .&. complement (bit i)

complementBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

x `complementBit` i is the same as x `xor` bit i

testBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp BoolSource

Return True if the nth bit of the argument is 1

shift :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

shift x i shifts x left by i bits if i is positive, or right by -i bits otherwise. Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

shiftL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

Shift the argument left by the specified number of bits (which must be non-negative).

shiftR :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

Shift the first argument right by the specified number of bits. The result is undefined for negative shift amounts and shift amounts greater or equal to the bitSize.

Right shifts perform sign extension on signed number types; i.e. they fill the top bits with 1 if the x is negative and with 0 otherwise.

rotate :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

rotate x i rotates x left by i bits if i is positive, or right by -i bits otherwise.

rotateL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

Rotate the argument left by the specified number of bits (which must be non-negative).

rotateR :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp tSource

Rotate the argument right by the specified number of bits (which must be non-negative).

Shape manipulation

index0 :: Exp ZSource

The one index for a rank-0 array.

index1 :: Elt i => Exp i -> Exp (Z :. i)Source

Turn an Int expression into a rank-1 indexing expression.

unindex1 :: Elt i => Exp (Z :. i) -> Exp iSource

Turn a rank-1 indexing expression into an Int expression.

index2 :: (Elt i, Slice (Z :. i)) => Exp i -> Exp i -> Exp ((Z :. i) :. i)Source

Creates a rank-2 index from two Exp Int`s

unindex2 :: forall i. (Elt i, Slice (Z :. i)) => Exp ((Z :. i) :. i) -> Exp (i, i)Source

Destructs a rank-2 index to an Exp tuple of two Int`s.

indexHead :: Slice sh => Exp (sh :. Int) -> Exp IntSource

Get the outermost dimension of a shape

indexTail :: Slice sh => Exp (sh :. Int) -> Exp shSource

Get all but the outermost element of a shape

toIndex :: Shape sh => Exp sh -> Exp sh -> Exp IntSource

Map a multi-dimensional index into a linear, row-major representation of an array. The first argument is the array shape, the second is the index.

fromIndex :: Shape sh => Exp sh -> Exp Int -> Exp shSource

Inverse of fromIndex

Conversions

boolToInt :: Exp Bool -> Exp IntSource

Convert a Boolean value to an Int, where False turns into '0' and True into '1'.

fromIntegral :: (Elt a, Elt b, IsIntegral a, IsNum b) => Exp a -> Exp bSource

General coercion from integral types

Plain arrays

Operations

arrayDim :: Shape sh => sh -> IntSource

Rank of an array

arrayShape :: Shape sh => Array sh e -> shSource

Array shape in plain Haskell code

arraySize :: Shape sh => sh -> IntSource

Total number of elements in an array of the given Shape

indexArray :: Array sh e -> sh -> eSource

Array indexing in plain Haskell code

Conversions

For additional conversion routines, see the accelerate-io package: http://hackage.haskell.org/package/accelerate-io

Lists

fromList :: (Shape sh, Elt e) => sh -> [e] -> Array sh eSource

Convert a list, with elements in row-major order, into an accelerated array.

toList :: forall sh e. Array sh e -> [e]Source

Convert an accelerated array to a list in row-major order.

IArray

fromIArray :: (EltRepr ix ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => a ix e -> Array sh eSource

Convert an IArray to an accelerated array.

While the type signature mentions Accelerate internals that are not exported, in practice satisfying the type equality is straight forward. The index type ix must be the unit type () for singleton arrays, or an Int or tuple of Int's for multidimensional arrays.

toIArray :: (EltRepr ix ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => Array sh e -> a ix eSource

Convert an accelerated array to an IArray.