-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | An embedded language for accelerated array processing
--
-- This library defines an embedded language for regular,
-- multi-dimensional array computations with multiple backends to
-- facilitate high-performance implementations. Currently, there are two
-- backends: (1) an interpreter that serves as a reference implementation
-- of the intended semantics of the language and (2) a CUDA backend
-- generating code for CUDA-capable NVIDIA GPUs.
--
-- To use the CUDA backend, you need to have CUDA version 3.x installed.
-- The CUDA backend currently doesn't support Char and Bool
-- arrays.
--
-- Known bugs: https://github.com/mchakravarty/accelerate/issues
--
--
-- - New in 0.9.0.0: Streaming, precompilation, Repa-style indices,
-- stencils, more scans, rank-polymorphic fold, generate, block I/O &
-- many bug fixes
-- - New in 0.8.1.0: bug fixes and some performance tweaks
-- - New in 0.8.0.0: replicate, slice and foldSeg
-- supported in the CUDA backend; frontend and interpreter support for
-- stencil; bug fixes
-- - New in 0.7.1.0: the CUDA backend and a number of scalar
-- functions
--
--
-- For documentation, see the homepage and
-- https://github.com/mchakravarty/accelerate/wiki.
@package accelerate
@version 0.9.0.1
module Data.Array.Accelerate.Type
myMkTyCon :: String -> TyCon
class Typeable8 t
typeOf8 :: Typeable8 t => t a b c d e f g h -> TypeRep
typeOf7Default :: (Typeable8 t, Typeable a) => t a b c d e f g h -> TypeRep
class Typeable9 t
typeOf9 :: Typeable9 t => t a b c d e f g h i -> TypeRep
typeOf8Default :: (Typeable9 t, Typeable a) => t a b c d e f g h i -> TypeRep
data IntegralDict a
IntegralDict :: IntegralDict a
data FloatingDict a
FloatingDict :: FloatingDict a
data NonNumDict a
NonNumDict :: NonNumDict a
-- | Integral types supported in array computations.
data IntegralType a
TypeInt :: IntegralDict Int -> IntegralType Int
TypeInt8 :: IntegralDict Int8 -> IntegralType Int8
TypeInt16 :: IntegralDict Int16 -> IntegralType Int16
TypeInt32 :: IntegralDict Int32 -> IntegralType Int32
TypeInt64 :: IntegralDict Int64 -> IntegralType Int64
TypeWord :: IntegralDict Word -> IntegralType Word
TypeWord8 :: IntegralDict Word8 -> IntegralType Word8
TypeWord16 :: IntegralDict Word16 -> IntegralType Word16
TypeWord32 :: IntegralDict Word32 -> IntegralType Word32
TypeWord64 :: IntegralDict Word64 -> IntegralType Word64
TypeCShort :: IntegralDict CShort -> IntegralType CShort
TypeCUShort :: IntegralDict CUShort -> IntegralType CUShort
TypeCInt :: IntegralDict CInt -> IntegralType CInt
TypeCUInt :: IntegralDict CUInt -> IntegralType CUInt
TypeCLong :: IntegralDict CLong -> IntegralType CLong
TypeCULong :: IntegralDict CULong -> IntegralType CULong
TypeCLLong :: IntegralDict CLLong -> IntegralType CLLong
TypeCULLong :: IntegralDict CULLong -> IntegralType CULLong
-- | Floating-point types supported in array computations.
data FloatingType a
TypeFloat :: FloatingDict Float -> FloatingType Float
TypeDouble :: FloatingDict Double -> FloatingType Double
TypeCFloat :: FloatingDict CFloat -> FloatingType CFloat
TypeCDouble :: FloatingDict CDouble -> FloatingType CDouble
-- | Non-numeric types supported in array computations.
data NonNumType a
TypeBool :: NonNumDict Bool -> NonNumType Bool
TypeChar :: NonNumDict Char -> NonNumType Char
TypeCChar :: NonNumDict CChar -> NonNumType CChar
TypeCSChar :: NonNumDict CSChar -> NonNumType CSChar
TypeCUChar :: NonNumDict CUChar -> NonNumType CUChar
-- | Numeric element types implement Num & Real
data NumType a
IntegralNumType :: IntegralType a -> NumType a
FloatingNumType :: FloatingType a -> NumType a
-- | Bounded element types implement Bounded
data BoundedType a
IntegralBoundedType :: IntegralType a -> BoundedType a
NonNumBoundedType :: NonNumType a -> BoundedType a
-- | All scalar element types implement Eq, Ord & Enum
data ScalarType a
NumScalarType :: NumType a -> ScalarType a
NonNumScalarType :: NonNumType a -> ScalarType a
-- | Integral types
class (IsScalar a, IsNum a, IsBounded a) => IsIntegral a
integralType :: IsIntegral a => IntegralType a
-- | Floating types
class (Floating a, IsScalar a, IsNum a) => IsFloating a
floatingType :: IsFloating a => FloatingType a
-- | Non-numeric types
class IsNonNum a
nonNumType :: IsNonNum a => NonNumType a
-- | Numeric types
class (Num a, IsScalar a) => IsNum a
numType :: IsNum a => NumType a
-- | Bounded types
class IsBounded a
boundedType :: IsBounded a => BoundedType a
-- | All scalar type
class Typeable a => IsScalar a
scalarType :: IsScalar a => ScalarType a
integralDict :: IntegralType a -> IntegralDict a
floatingDict :: FloatingType a -> FloatingDict a
nonNumDict :: NonNumType a -> NonNumDict a
data TupleType a
UnitTuple :: TupleType ()
SingleTuple :: ScalarType a -> TupleType a
PairTuple :: TupleType a -> TupleType b -> TupleType (a, b)
-- | Boundary condition specification for stencil operations.
data Boundary a
-- | clamp coordinates to the extent of the array
Clamp :: Boundary a
-- | mirror coordinates beyond the array extent
Mirror :: Boundary a
-- | wrap coordinates around on each dimension
Wrap :: Boundary a
-- | use a constant value for outlying coordinates
Constant :: a -> Boundary a
instance Show a => Show (Boundary a)
instance Read a => Read (Boundary a)
instance IsScalar CUChar
instance IsScalar CSChar
instance IsScalar CChar
instance IsScalar Char
instance IsScalar Bool
instance IsScalar CDouble
instance IsScalar CFloat
instance IsScalar Double
instance IsScalar Float
instance IsScalar CULLong
instance IsScalar CLLong
instance IsScalar CULong
instance IsScalar CLong
instance IsScalar CUInt
instance IsScalar CInt
instance IsScalar CUShort
instance IsScalar CShort
instance IsScalar Word64
instance IsScalar Word32
instance IsScalar Word16
instance IsScalar Word8
instance IsScalar Word
instance IsScalar Int64
instance IsScalar Int32
instance IsScalar Int16
instance IsScalar Int8
instance IsScalar Int
instance IsBounded CUChar
instance IsBounded CSChar
instance IsBounded CChar
instance IsBounded Char
instance IsBounded Bool
instance IsBounded CULLong
instance IsBounded CLLong
instance IsBounded CULong
instance IsBounded CLong
instance IsBounded CUInt
instance IsBounded CInt
instance IsBounded CUShort
instance IsBounded CShort
instance IsBounded Word64
instance IsBounded Word32
instance IsBounded Word16
instance IsBounded Word8
instance IsBounded Word
instance IsBounded Int64
instance IsBounded Int32
instance IsBounded Int16
instance IsBounded Int8
instance IsBounded Int
instance IsNum CDouble
instance IsNum CFloat
instance IsNum Double
instance IsNum Float
instance IsNum CULLong
instance IsNum CLLong
instance IsNum CULong
instance IsNum CLong
instance IsNum CUInt
instance IsNum CInt
instance IsNum CUShort
instance IsNum CShort
instance IsNum Word64
instance IsNum Word32
instance IsNum Word16
instance IsNum Word8
instance IsNum Word
instance IsNum Int64
instance IsNum Int32
instance IsNum Int16
instance IsNum Int8
instance IsNum Int
instance IsNonNum CUChar
instance IsNonNum CSChar
instance IsNonNum CChar
instance IsNonNum Char
instance IsNonNum Bool
instance IsFloating CDouble
instance IsFloating CFloat
instance IsFloating Double
instance IsFloating Float
instance IsIntegral CULLong
instance IsIntegral CLLong
instance IsIntegral CULong
instance IsIntegral CLong
instance IsIntegral CUInt
instance IsIntegral CInt
instance IsIntegral CUShort
instance IsIntegral CShort
instance IsIntegral Word64
instance IsIntegral Word32
instance IsIntegral Word16
instance IsIntegral Word8
instance IsIntegral Word
instance IsIntegral Int64
instance IsIntegral Int32
instance IsIntegral Int16
instance IsIntegral Int8
instance IsIntegral Int
instance Show (ScalarType a)
instance Show (BoundedType a)
instance Show (NumType a)
instance Show (NonNumType a)
instance Show (FloatingType a)
instance Show (IntegralType a)
instance (Typeable9 s, Typeable a) => Typeable8 (s a)
instance Typeable9 (,,,,,,,,)
instance (Typeable8 s, Typeable a) => Typeable7 (s a)
instance Typeable8 (,,,,,,,)
-- | This module fixes the concrete representation of Accelerate arrays. We
-- allocate all arrays using pinned memory to enable safe direct-access
-- by non-Haskell code in multi-threaded code. In particular, we can
-- safely pass pointers to an array's payload to foreign code.
module Data.Array.Accelerate.Array.Data
class ArrayElt e where type family ArrayPtrs e
indexArrayData :: ArrayElt e => ArrayData e -> Int -> e
ptrsOfArrayData :: ArrayElt e => ArrayData e -> ArrayPtrs e
newArrayData :: ArrayElt e => Int -> ST s (MutableArrayData s e)
readArrayData :: ArrayElt e => MutableArrayData s e -> Int -> ST s e
writeArrayData :: ArrayElt e => MutableArrayData s e -> Int -> e -> ST s ()
unsafeFreezeArrayData :: ArrayElt e => MutableArrayData s e -> ST s (ArrayData e)
ptrsOfMutableArrayData :: ArrayElt e => MutableArrayData s e -> ST s (ArrayPtrs e)
arrayElt :: ArrayElt e => ArrayEltR e
-- | Immutable array representation
type ArrayData e = GArrayData (UArray Int) e
-- | Mutable array representation
type MutableArrayData s e = GArrayData (STUArray s Int) e
-- | Safe combination of creating and fast freezing of array data.
runArrayData :: ArrayElt e => (forall s. ST s (MutableArrayData s e, e)) -> (ArrayData e, e)
-- | GADT to reify the ArrayElt class.
data ArrayEltR a
ArrayEltRunit :: ArrayEltR ()
ArrayEltRint :: ArrayEltR Int
ArrayEltRint8 :: ArrayEltR Int8
ArrayEltRint16 :: ArrayEltR Int16
ArrayEltRint32 :: ArrayEltR Int32
ArrayEltRint64 :: ArrayEltR Int64
ArrayEltRword :: ArrayEltR Word
ArrayEltRword8 :: ArrayEltR Word8
ArrayEltRword16 :: ArrayEltR Word16
ArrayEltRword32 :: ArrayEltR Word32
ArrayEltRword64 :: ArrayEltR Word64
ArrayEltRfloat :: ArrayEltR Float
ArrayEltRdouble :: ArrayEltR Double
ArrayEltRbool :: ArrayEltR Bool
ArrayEltRchar :: ArrayEltR Char
ArrayEltRpair :: ArrayEltR a -> ArrayEltR b -> ArrayEltR (a, b)
fstArrayData :: ArrayData (a, b) -> ArrayData a
sndArrayData :: ArrayData (a, b) -> ArrayData b
pairArrayData :: ArrayData a -> ArrayData b -> ArrayData (a, b)
instance (ArrayElt a, ArrayElt b) => ArrayElt (a, b)
instance ArrayElt Char
instance ArrayElt Bool
instance ArrayElt Double
instance ArrayElt Float
instance ArrayElt Word64
instance ArrayElt Word32
instance ArrayElt Word16
instance ArrayElt Word8
instance ArrayElt Word
instance ArrayElt Int64
instance ArrayElt Int32
instance ArrayElt Int16
instance ArrayElt Int8
instance ArrayElt Int
instance ArrayElt ()
module Data.Array.Accelerate.Array.Representation
-- | Index representation
--
-- Class of index representations (which are nested pairs)
class (Eq sh, Slice sh) => Shape sh
dim :: Shape sh => sh -> Int
size :: Shape sh => sh -> Int
intersect :: Shape sh => sh -> sh -> sh
ignore :: Shape sh => sh
index :: Shape sh => sh -> sh -> Int
bound :: Shape sh => sh -> sh -> Boundary e -> Either e sh
iter :: Shape sh => sh -> (sh -> a) -> (a -> a -> a) -> a -> a
iter1 :: Shape sh => sh -> (sh -> a) -> (a -> a -> a) -> a
rangeToShape :: Shape sh => (sh, sh) -> sh
shapeToRange :: Shape sh => sh -> (sh, sh)
shapeToList :: Shape sh => sh -> [Int]
listToShape :: Shape sh => [Int] -> sh
-- | Slice representation
--
-- Class of slice representations (which are nested pairs)
class Slice sl where type family SliceShape sl type family CoSliceShape sl type family FullShape sl
sliceIndex :: Slice sl => sl -> SliceIndex sl (SliceShape sl) (CoSliceShape sl) (FullShape sl)
-- | Generalised array index, which may index only in a subset of the
-- dimensions of a shape.
data SliceIndex ix slice coSlice sliceDim
SliceNil :: SliceIndex () () () ()
SliceAll :: SliceIndex ix slice co dim -> SliceIndex (ix, ()) (slice, Int) co (dim, Int)
SliceFixed :: SliceIndex ix slice co dim -> SliceIndex (ix, Int) slice (co, Int) (dim, Int)
instance Show (SliceIndex ix slice coSlice sliceDim)
instance Slice sl => Slice (sl, Int)
instance Slice sl => Slice (sl, ())
instance Slice ()
instance Shape sh => Shape (sh, Int)
instance Shape ()
module Data.Array.Accelerate.Array.Sugar
-- | 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.
--
data Array sh e
Array :: EltRepr sh -> ArrayData (EltRepr e) -> Array sh e
-- | Scalars
type Scalar e = Array DIM0 e
-- | Vectors
type Vector e = Array DIM1 e
-- | Segment descriptor
type Segments = Vector Int
-- | Class that characterises the types of values that can be array
-- elements, and hence, appear in scalar Accelerate expressions.
class (Show a, Typeable a, Typeable (EltRepr a), Typeable (EltRepr' a), ArrayElt (EltRepr a), ArrayElt (EltRepr' a)) => Elt a
eltType :: Elt a => a -> TupleType (EltRepr a)
fromElt :: Elt a => a -> EltRepr a
toElt :: Elt a => EltRepr a -> a
eltType' :: Elt a => a -> TupleType (EltRepr' a)
fromElt' :: Elt a => a -> EltRepr' a
toElt' :: Elt a => EltRepr' a -> a
-- | Representation change for array element types
-- ----------------------------------------------
--
-- Type representation mapping
--
-- We represent tuples by using '()' and '(,)' as type-level nil and snoc
-- to construct snoc-lists of types.
liftToElt :: (Elt a, Elt b) => (EltRepr a -> EltRepr b) -> (a -> b)
liftToElt2 :: (Elt a, Elt b, Elt c) => (EltRepr a -> EltRepr b -> EltRepr c) -> (a -> b -> c)
sinkFromElt :: (Elt a, Elt b) => (a -> b) -> (EltRepr a -> EltRepr b)
sinkFromElt2 :: (Elt a, Elt b, Elt c) => (a -> b -> c) -> (EltRepr a -> EltRepr b -> EltRepr c)
type DIM0 = Z
type DIM1 = DIM0 :. Int
type DIM2 = DIM1 :. Int
type DIM3 = DIM2 :. Int
type DIM4 = DIM3 :. Int
type DIM5 = DIM4 :. Int
type DIM6 = DIM5 :. Int
type DIM7 = DIM6 :. Int
type DIM8 = DIM7 :. Int
type DIM9 = DIM8 :. Int
-- | Surface types representing array indices and slices
-- ----------------------------------------------------
--
-- Array indices are snoc type lists
--
-- For example, the type of a rank-2 array index is 'Z :.Int :. Int'.
--
-- Rank-0 index
data Z
Z :: Z
-- | Increase an index rank by one dimension
data (:.) tail head
(:.) :: tail -> head -> :. tail head
-- | Marker for entire dimensions in slice descriptors
data All
All :: All
-- | Marker for arbitrary shapes in slice descriptors
data Any sh
Any :: Any sh
-- | Shapes and indices of multi-dimensional arrays
class (Elt sh, Elt (Any sh), Shape (EltRepr sh)) => Shape sh where dim = dim . fromElt size = size . fromElt ignore = toElt ignore index sh ix = index (fromElt sh) (fromElt ix) bound sh ix bndy = case bound (fromElt sh) (fromElt ix) bndy of { Left v -> Left v Right ix' -> Right $ toElt ix' } iter sh f c r = iter (fromElt sh) (f . toElt) c r rangeToShape (low, high) = toElt (rangeToShape (fromElt low, fromElt high)) shapeToRange ix = let (low, high) = shapeToRange (fromElt ix) in (toElt low, toElt high) shapeToList = shapeToList . fromElt listToShape = toElt . listToShape
dim :: Shape sh => sh -> Int
size :: Shape sh => sh -> Int
ignore :: Shape sh => sh
index :: Shape sh => sh -> sh -> Int
bound :: Shape sh => sh -> sh -> Boundary a -> Either a sh
iter :: Shape sh => sh -> (sh -> a) -> (a -> a -> a) -> a -> a
rangeToShape :: Shape sh => (sh, sh) -> sh
shapeToRange :: Shape sh => sh -> (sh, sh)
shapeToList :: Shape sh => sh -> [Int]
listToShape :: Shape sh => [Int] -> sh
sliceAnyIndex :: Shape sh => sh -> SliceIndex (EltRepr (Any sh)) (EltRepr sh) () (EltRepr sh)
-- | Slices -aka generalised indices- as n-tuples and mappings of slice
-- indicies to slices, co-slices, and slice dimensions
class (Elt sl, Shape (SliceShape sl), Shape (CoSliceShape sl), Shape (FullShape sl)) => Slice sl where type family SliceShape sl :: * type family CoSliceShape sl :: * type family FullShape sl :: *
sliceIndex :: Slice sl => sl -> SliceIndex (EltRepr sl) (EltRepr (SliceShape sl)) (EltRepr (CoSliceShape sl)) (EltRepr (FullShape sl))
-- | Yield an array's shape
shape :: Shape sh => Array sh e -> sh
-- | Array indexing
(!) :: Array sh e -> sh -> e
-- | Create an array from its representation function
newArray :: (Shape sh, Elt e) => sh -> (sh -> e) -> Array sh e
-- | Creates a new, uninitialized Accelerate array.
allocateArray :: (Shape sh, Elt e) => sh -> Array sh e
-- | Convert an IArray to an accelerated array.
fromIArray :: (EltRepr ix ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => a ix e -> Array sh e
-- | Convert an accelerated array to an IArray
toIArray :: (EltRepr ix ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => Array sh e -> a ix e
-- | Convert a list (with elements in row-major order) to an accelerated
-- array.
fromList :: (Shape sh, Elt e) => sh -> [e] -> Array sh e
-- | Convert an accelerated array to a list in row-major order.
toList :: Array sh e -> [e]
instance Typeable Z
instance Typeable2 :.
instance Typeable All
instance Typeable1 Any
instance Typeable2 Array
instance Show Z
instance (Show tail, Show head) => Show (tail :. head)
instance Show All
instance Show (Any sh)
instance Show (Array sh e)
instance Shape sh => Slice (Any sh)
instance Slice sl => Slice (sl :. Int)
instance Slice sl => Slice (sl :. All)
instance Slice Z
instance Shape sh => Shape (sh :. Int)
instance Shape Z
instance (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)
instance (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)
instance (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => Elt (a, b, c, d, e, f, g)
instance (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => Elt (a, b, c, d, e, f)
instance (Elt a, Elt b, Elt c, Elt d, Elt e) => Elt (a, b, c, d, e)
instance (Elt a, Elt b, Elt c, Elt d) => Elt (a, b, c, d)
instance (Elt a, Elt b, Elt c) => Elt (a, b, c)
instance (Elt a, Elt b) => Elt (a, b)
instance Elt Char
instance Elt Bool
instance Elt Double
instance Elt Float
instance Elt Word64
instance Elt Word32
instance Elt Word16
instance Elt Word8
instance Elt Word
instance Elt Int64
instance Elt Int32
instance Elt Int16
instance Elt Int8
instance Elt Int
instance Shape sh => Elt (Any (sh :. Int))
instance Elt (Any Z)
instance Elt All
instance (Elt t, Elt h) => Elt (t :. h)
instance Elt Z
instance Elt ()
-- | Our representation of tuples are heterogenous snoc lists, which are
-- typed by type lists, where '()' and '(,)' are type-level nil and snoc,
-- respectively. The components may only be drawn from types that can be
-- used as array elements.
module Data.Array.Accelerate.Tuple
-- | We represent tuples as heterogenous lists, typed by a type list.
data Tuple c t
NilTup :: Tuple c ()
SnocTup :: Tuple c s -> c t -> Tuple c (s, t)
-- | Type-safe projection indicies for tuples.
--
-- NB: We index tuples by starting to count from the *right*!
data TupleIdx t e
ZeroTupIdx :: TupleIdx (t, s) s
SuccTupIdx :: TupleIdx t e -> TupleIdx (t, s) e
-- | Conversion between surface n-tuples and our tuple representation.
class IsTuple tup where type family TupleRepr tup
fromTuple :: IsTuple tup => tup -> TupleRepr tup
toTuple :: IsTuple tup => TupleRepr tup -> tup
instance IsTuple (a, b, c, d, e, f, g, h, i)
instance IsTuple (a, b, c, d, e, f, g, h)
instance IsTuple (a, b, c, d, e, f, g)
instance IsTuple (a, b, c, d, e, f)
instance IsTuple (a, b, c, d, e)
instance IsTuple (a, b, c, d)
instance IsTuple (a, b, c)
instance IsTuple (a, b)
instance IsTuple ()
-- | Scalar versus collective operations
--
-- The embedded array processing language is a two-level language. It
-- combines a language of scalar expressions and functions with a
-- language of collective array operations. Scalar expressions are used
-- to compute arguments for collective operations and scalar functions
-- are used to parametrise higher-order, collective array operations. The
-- two-level structure, in particular, ensures that collective operations
-- cannot be parametrised with collective operations; hence, we are
-- following a flat data-parallel model. The collective operations
-- manipulate multi-dimensional arrays whose shape is explicitly tracked
-- in their types. In fact, collective operations cannot produce any
-- values other than multi-dimensional arrays; when they yield a scalar,
-- this is in the form of a 0-dimensional, singleton array. Similarly,
-- scalar expression can -as their name indicates- only produce tuples of
-- scalar, but not arrays.
--
-- There are, however, two expression forms that take arrays as
-- arguments. As a result scalar and array expressions are recursively
-- dependent. As we cannot and don't want to compute arrays in the middle
-- of scalar computations, array computations will always be hoisted out
-- of scalar expressions. So that this is always possible, these array
-- expressions may not contain any free scalar variables. To express that
-- condition in the type structure, we use separate environments for
-- scalar and array variables.
--
-- Programs
--
-- Collective array programs comprise closed expressions of array
-- operations. There is no explicit sharing in the initial AST form, but
-- sharing is introduced subsequently by common subexpression elimination
-- and floating of array computations.
--
-- Functions
--
-- The array expression language is first-order and only provides limited
-- control structures to ensure that it can be efficiently executed on
-- compute-acceleration hardware, such as GPUs. To restrict functions to
-- first-order, we separate function abstraction from the main expression
-- type. Functions are represented using de Bruijn indices.
--
-- Parametric and ad-hoc polymorphism
--
-- The array language features paramatric polymophism (e.g., pairing and
-- projections) as well as ad-hoc polymorphism (e.g., arithmetic
-- operations). All ad-hoc polymorphic constructs include reified
-- dictionaries (c.f., module Types). Reified dictionaries also
-- ensure that constants (constructor Const) are representable on
-- compute acceleration hardware.
--
-- The AST contains both reified dictionaries and type class constraints.
-- Type classes are used for array-related functionality that is
-- uniformly available for all supported types. In contrast, reified
-- dictionaries are used for functionality that is only available for
-- certain types, such as arithmetic operations.
module Data.Array.Accelerate.AST
data Idx env t
ZeroIdx :: Idx (env, t) t
SuccIdx :: Idx env t -> Idx (env, s) t
data Val env
Empty :: Val ()
Push :: Val env -> t -> Val (env, t)
prj :: Idx env t -> Val env -> t
idxToInt :: Idx env t -> Int
-- | Tuples of arrays (of type 'Array dim e'). This characterises the
-- domain of results of Accelerate array computations.
class (Delayable arrs, Typeable arrs) => Arrays arrs
arrays :: Arrays arrs => ArraysR arrs
-- | GADT reifying the Arrays class.
data ArraysR arrs
ArraysRunit :: ArraysR ()
ArraysRarray :: ArraysR (Array sh e)
ArraysRpair :: ArraysR arrs1 -> ArraysR arrs2 -> ArraysR (arrs1, arrs2)
-- | Function abstraction over parametrised array computations
data PreOpenAfun acc aenv t
Abody :: acc aenv t -> PreOpenAfun acc aenv t
Alam :: PreOpenAfun acc (aenv, as) t -> PreOpenAfun acc aenv (as -> t)
type OpenAfun = PreOpenAfun OpenAcc
-- | Parametrised array-computation function without free array variables
type PreAfun acc = PreOpenAfun acc ()
-- | Vanilla array-computation function without free array variables
type Afun = OpenAfun ()
-- | Collective array computations parametrised over array variables
-- represented with de Bruijn indices.
--
--
-- - Scalar functions and expressions embedded in well-formed array
-- computations cannot contain free scalar variable indices. The latter
-- cannot be bound in array computations, and hence, cannot appear in any
-- well-formed program.
-- - The let-form is used to represent the sharing discovered by common
-- subexpression elimination as well as to control evaluation order. (We
-- need to hoist array expressions out of scalar expressions - they occur
-- in scalar indexing and in determining an arrays shape.)
--
--
-- The data type is parameterised over the surface types (not the
-- representation type).
--
-- We use a non-recursive variant parametrised over the recursive
-- closure, to facilitate attribute calculation in the backend.
data PreOpenAcc acc aenv a
Let :: acc aenv bndArrs -> acc (aenv, bndArrs) bodyArrs -> PreOpenAcc acc aenv bodyArrs
Let2 :: acc aenv (bndArrs1, bndArrs2) -> acc ((aenv, bndArrs1), bndArrs2) bodyArrs -> PreOpenAcc acc aenv bodyArrs
PairArrays :: acc aenv (Array sh1 e1) -> acc aenv (Array sh2 e2) -> PreOpenAcc acc aenv (Array sh1 e1, Array sh2 e2)
Avar :: Idx aenv arrs -> PreOpenAcc acc aenv arrs
Apply :: PreAfun acc (arrs1 -> arrs2) -> acc aenv arrs1 -> PreOpenAcc acc aenv arrs2
Acond :: PreExp acc aenv Bool -> acc aenv arrs -> acc aenv arrs -> PreOpenAcc acc aenv arrs
Use :: Array dim e -> PreOpenAcc acc aenv (Array dim e)
Unit :: PreExp acc aenv e -> PreOpenAcc acc aenv (Scalar e)
Reshape :: PreExp acc aenv sh -> acc aenv (Array sh' e) -> PreOpenAcc acc aenv (Array sh e)
Generate :: PreExp acc aenv sh -> PreFun acc aenv (sh -> e) -> PreOpenAcc acc aenv (Array sh e)
Replicate :: SliceIndex (EltRepr slix) (EltRepr sl) co' (EltRepr sh) -> PreExp acc aenv slix -> acc aenv (Array sl e) -> PreOpenAcc acc aenv (Array sh e)
Index :: SliceIndex (EltRepr slix) (EltRepr sl) co' (EltRepr sh) -> acc aenv (Array sh e) -> PreExp acc aenv slix -> PreOpenAcc acc aenv (Array sl e)
Map :: PreFun acc aenv (e -> e') -> acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e')
ZipWith :: PreFun acc aenv (e1 -> e2 -> e3) -> acc aenv (Array sh e1) -> acc aenv (Array sh e2) -> PreOpenAcc acc aenv (Array sh e3)
Fold :: PreFun acc aenv (e -> e -> e) -> PreExp acc aenv e -> acc aenv (Array (sh :. Int) e) -> PreOpenAcc acc aenv (Array sh e)
Fold1 :: PreFun acc aenv (e -> e -> e) -> acc aenv (Array (sh :. Int) e) -> PreOpenAcc acc aenv (Array sh e)
FoldSeg :: PreFun acc aenv (e -> e -> e) -> PreExp acc aenv e -> acc aenv (Array (sh :. Int) e) -> acc aenv Segments -> PreOpenAcc acc aenv (Array (sh :. Int) e)
Fold1Seg :: PreFun acc aenv (e -> e -> e) -> acc aenv (Array (sh :. Int) e) -> acc aenv Segments -> PreOpenAcc acc aenv (Array (sh :. Int) e)
Scanl :: PreFun acc aenv (e -> e -> e) -> PreExp acc aenv e -> acc aenv (Vector e) -> PreOpenAcc acc aenv (Vector e)
Scanl' :: PreFun acc aenv (e -> e -> e) -> PreExp acc aenv e -> acc aenv (Vector e) -> PreOpenAcc acc aenv (Vector e, Scalar e)
Scanl1 :: PreFun acc aenv (e -> e -> e) -> acc aenv (Vector e) -> PreOpenAcc acc aenv (Vector e)
Scanr :: PreFun acc aenv (e -> e -> e) -> PreExp acc aenv e -> acc aenv (Vector e) -> PreOpenAcc acc aenv (Vector e)
Scanr' :: PreFun acc aenv (e -> e -> e) -> PreExp acc aenv e -> acc aenv (Vector e) -> PreOpenAcc acc aenv (Vector e, Scalar e)
Scanr1 :: PreFun acc aenv (e -> e -> e) -> acc aenv (Vector e) -> PreOpenAcc acc aenv (Vector e)
Permute :: PreFun acc aenv (e -> e -> e) -> acc aenv (Array sh' e) -> PreFun acc aenv (sh -> sh') -> acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh' e)
Backpermute :: PreExp acc aenv sh' -> PreFun acc aenv (sh' -> sh) -> acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh' e)
Stencil :: PreFun acc aenv (stencil -> e') -> Boundary (EltRepr e) -> acc aenv (Array sh e) -> PreOpenAcc acc aenv (Array sh e')
Stencil2 :: PreFun acc aenv (stencil1 -> stencil2 -> e') -> Boundary (EltRepr e1) -> acc aenv (Array sh e1) -> Boundary (EltRepr e2) -> acc aenv (Array sh e2) -> PreOpenAcc acc aenv (Array sh e')
newtype OpenAcc aenv t
OpenAcc :: (PreOpenAcc OpenAcc aenv t) -> OpenAcc aenv t
-- | Closed array expression aka an array program
type Acc = OpenAcc ()
-- | Operations on stencils.
class (Shape sh, Elt e, IsTuple stencil) => Stencil sh e stencil
stencil :: Stencil sh e stencil => StencilR sh e stencil
stencilAccess :: Stencil sh e stencil => (sh -> e) -> sh -> stencil
-- | GADT reifying the Stencil class.
data StencilR sh e pat
StencilRunit3 :: StencilR DIM1 e (e, e, e)
StencilRunit5 :: StencilR DIM1 e (e, e, e, e, e)
StencilRunit7 :: StencilR DIM1 e (e, e, e, e, e, e, e)
StencilRunit9 :: StencilR DIM1 e (e, e, e, e, e, e, e, e, e)
StencilRtup3 :: StencilR sh e pat1 -> StencilR sh e pat2 -> StencilR sh e pat3 -> StencilR (sh :. Int) e (pat1, pat2, pat3)
StencilRtup5 :: StencilR sh e pat1 -> StencilR sh e pat2 -> StencilR sh e pat3 -> StencilR sh e pat4 -> StencilR sh e pat5 -> StencilR (sh :. Int) e (pat1, pat2, pat3, pat4, pat5)
StencilRtup7 :: StencilR sh e pat1 -> StencilR sh e pat2 -> StencilR sh e pat3 -> StencilR sh e pat4 -> StencilR sh e pat5 -> StencilR sh e pat6 -> StencilR sh e pat7 -> StencilR (sh :. Int) e (pat1, pat2, pat3, pat4, pat5, pat6, pat7)
StencilRtup9 :: StencilR sh e pat1 -> StencilR sh e pat2 -> StencilR sh e pat3 -> StencilR sh e pat4 -> StencilR sh e pat5 -> StencilR sh e pat6 -> StencilR sh e pat7 -> StencilR sh e pat8 -> StencilR sh e pat9 -> StencilR (sh :. Int) e (pat1, pat2, pat3, pat4, pat5, pat6, pat7, pat8, pat9)
-- | Parametrised open function abstraction
data PreOpenFun (acc :: * -> * -> *) env aenv t
Body :: PreOpenExp acc env aenv t -> PreOpenFun acc env aenv t
Lam :: PreOpenFun acc (env, EltRepr a) aenv t -> PreOpenFun acc env aenv (a -> t)
-- | Vanilla open function abstraction
type OpenFun = PreOpenFun OpenAcc
-- | Parametrised function without free scalar variables
type PreFun acc = PreOpenFun acc ()
-- | Vanilla function without free scalar variables
type Fun = OpenFun ()
-- | Parametrised open expressions using de Bruijn indices for variables
-- ranging over tuples of scalars and arrays of tuples. All code, except
-- Cond, is evaluated eagerly. N-tuples are represented as nested pairs.
--
-- The data type is parametrised over the surface types (not the
-- representation type).
data PreOpenExp (acc :: * -> * -> *) env aenv t
Var :: Idx env (EltRepr t) -> PreOpenExp acc env aenv t
Const :: EltRepr t -> PreOpenExp acc env aenv t
Tuple :: Tuple (PreOpenExp acc env aenv) (TupleRepr t) -> PreOpenExp acc env aenv t
Prj :: TupleIdx (TupleRepr t) e -> PreOpenExp acc env aenv t -> PreOpenExp acc env aenv e
IndexNil :: PreOpenExp acc env aenv Z
IndexCons :: PreOpenExp acc env aenv sl -> PreOpenExp acc env aenv a -> PreOpenExp acc env aenv (sl :. a)
IndexHead :: PreOpenExp acc env aenv (sl :. a) -> PreOpenExp acc env aenv a
IndexTail :: PreOpenExp acc env aenv (sl :. a) -> PreOpenExp acc env aenv sl
IndexAny :: PreOpenExp acc env aenv (Any sh)
Cond :: PreOpenExp acc env aenv Bool -> PreOpenExp acc env aenv t -> PreOpenExp acc env aenv t -> PreOpenExp acc env aenv t
PrimConst :: PrimConst t -> PreOpenExp acc env aenv t
PrimApp :: PrimFun (a -> r) -> PreOpenExp acc env aenv a -> PreOpenExp acc env aenv r
IndexScalar :: acc aenv (Array dim t) -> PreOpenExp acc env aenv dim -> PreOpenExp acc env aenv t
Shape :: acc aenv (Array dim e) -> PreOpenExp acc env aenv dim
Size :: acc aenv (Array dim e) -> PreOpenExp acc env aenv Int
-- | Vanilla open expression
type OpenExp = PreOpenExp OpenAcc
-- | Parametrised expression without free scalar variables
type PreExp acc = PreOpenExp acc ()
-- | Vanilla expression without free scalar variables
type Exp = OpenExp ()
-- | Primitive GPU constants
data PrimConst ty
PrimMinBound :: BoundedType a -> PrimConst a
PrimMaxBound :: BoundedType a -> PrimConst a
PrimPi :: FloatingType a -> PrimConst a
-- | Primitive scalar operations
data PrimFun sig
PrimAdd :: NumType a -> PrimFun ((a, a) -> a)
PrimSub :: NumType a -> PrimFun ((a, a) -> a)
PrimMul :: NumType a -> PrimFun ((a, a) -> a)
PrimNeg :: NumType a -> PrimFun (a -> a)
PrimAbs :: NumType a -> PrimFun (a -> a)
PrimSig :: NumType a -> PrimFun (a -> a)
PrimQuot :: IntegralType a -> PrimFun ((a, a) -> a)
PrimRem :: IntegralType a -> PrimFun ((a, a) -> a)
PrimIDiv :: IntegralType a -> PrimFun ((a, a) -> a)
PrimMod :: IntegralType a -> PrimFun ((a, a) -> a)
PrimBAnd :: IntegralType a -> PrimFun ((a, a) -> a)
PrimBOr :: IntegralType a -> PrimFun ((a, a) -> a)
PrimBXor :: IntegralType a -> PrimFun ((a, a) -> a)
PrimBNot :: IntegralType a -> PrimFun (a -> a)
PrimBShiftL :: IntegralType a -> PrimFun ((a, Int) -> a)
PrimBShiftR :: IntegralType a -> PrimFun ((a, Int) -> a)
PrimBRotateL :: IntegralType a -> PrimFun ((a, Int) -> a)
PrimBRotateR :: IntegralType a -> PrimFun ((a, Int) -> a)
PrimFDiv :: FloatingType a -> PrimFun ((a, a) -> a)
PrimRecip :: FloatingType a -> PrimFun (a -> a)
PrimSin :: FloatingType a -> PrimFun (a -> a)
PrimCos :: FloatingType a -> PrimFun (a -> a)
PrimTan :: FloatingType a -> PrimFun (a -> a)
PrimAsin :: FloatingType a -> PrimFun (a -> a)
PrimAcos :: FloatingType a -> PrimFun (a -> a)
PrimAtan :: FloatingType a -> PrimFun (a -> a)
PrimAsinh :: FloatingType a -> PrimFun (a -> a)
PrimAcosh :: FloatingType a -> PrimFun (a -> a)
PrimAtanh :: FloatingType a -> PrimFun (a -> a)
PrimExpFloating :: FloatingType a -> PrimFun (a -> a)
PrimSqrt :: FloatingType a -> PrimFun (a -> a)
PrimLog :: FloatingType a -> PrimFun (a -> a)
PrimFPow :: FloatingType a -> PrimFun ((a, a) -> a)
PrimLogBase :: FloatingType a -> PrimFun ((a, a) -> a)
PrimAtan2 :: FloatingType a -> PrimFun ((a, a) -> a)
PrimTruncate :: FloatingType a -> IntegralType b -> PrimFun (a -> b)
PrimRound :: FloatingType a -> IntegralType b -> PrimFun (a -> b)
PrimFloor :: FloatingType a -> IntegralType b -> PrimFun (a -> b)
PrimCeiling :: FloatingType a -> IntegralType b -> PrimFun (a -> b)
PrimLt :: ScalarType a -> PrimFun ((a, a) -> Bool)
PrimGt :: ScalarType a -> PrimFun ((a, a) -> Bool)
PrimLtEq :: ScalarType a -> PrimFun ((a, a) -> Bool)
PrimGtEq :: ScalarType a -> PrimFun ((a, a) -> Bool)
PrimEq :: ScalarType a -> PrimFun ((a, a) -> Bool)
PrimNEq :: ScalarType a -> PrimFun ((a, a) -> Bool)
PrimMax :: ScalarType a -> PrimFun ((a, a) -> a)
PrimMin :: ScalarType a -> PrimFun ((a, a) -> a)
PrimLAnd :: PrimFun ((Bool, Bool) -> Bool)
PrimLOr :: PrimFun ((Bool, Bool) -> Bool)
PrimLNot :: PrimFun (Bool -> Bool)
PrimOrd :: PrimFun (Char -> Int)
PrimChr :: PrimFun (Int -> Char)
PrimBoolToInt :: PrimFun (Bool -> Int)
PrimFromIntegral :: IntegralType a -> NumType b -> PrimFun (a -> b)
instance Typeable2 OpenAcc
instance Typeable1 Val
instance (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)
instance (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)
instance (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)
instance (Stencil (sh :. Int) a row1, Stencil (sh :. Int) a row2, Stencil (sh :. Int) a row3) => Stencil ((sh :. Int) :. Int) a (row1, row2, row3)
instance Elt e => Stencil DIM1 e (e, e, e, e, e, e, e, e, e)
instance Elt e => Stencil DIM1 e (e, e, e, e, e, e, e)
instance Elt e => Stencil DIM1 e (e, e, e, e, e)
instance Elt e => Stencil DIM1 e (e, e, e)
instance (Arrays arrs1, Arrays arrs2) => Arrays (arrs1, arrs2)
instance (Shape sh, Elt e) => Arrays (Array sh e)
instance Arrays ()
module Data.Array.Accelerate.Analysis.Shape
type AccDim acc = forall aenv sh e. acc aenv (Array sh e) -> Int
type AccDim2 acc = forall aenv sh1 e1 sh2 e2. acc aenv (Array sh1 e1, Array sh2 e2) -> (Int, Int)
-- | Reify the dimensionality of the result type of an array computation
accDim :: AccDim OpenAcc
-- | Reify the dimensionality of the results of a computation that yields
-- two arrays
accDim2 :: AccDim2 OpenAcc
-- | Reify dimensionality of a computation parameterised over a recursive
-- closure
preAccDim :: AccDim acc -> PreOpenAcc acc aenv (Array sh e) -> Int
preAccDim2 :: AccDim acc -> AccDim2 acc -> PreOpenAcc acc aenv (Array sh1 e1, Array sh2 e2) -> (Int, Int)
-- | The Accelerate AST does not explicitly store much type information.
-- Most of it is only indirectly through type class constraints
-- -especially, Elt constraints- available. This module provides
-- functions that reify that type information in the form of a
-- TupleType value. This is, for example, needed to emit type
-- information in a backend.
module Data.Array.Accelerate.Analysis.Type
-- | Determine the type of an expressions
-- -------------------------------------
type AccType acc = forall aenv sh e. acc aenv (Array sh e) -> TupleType (EltRepr e)
type AccType2 acc = forall aenv sh1 e1 sh2 e2. acc aenv (Array sh1 e1, Array sh2 e2) -> (TupleType (EltRepr e1), TupleType (EltRepr e2))
-- | Determine an array type ------------------------
--
-- Reify the element type of an array.
arrayType :: Array sh e -> TupleType (EltRepr e)
-- | Reify the element type of the result of an array computation.
accType :: AccType OpenAcc
-- | Reify the element types of the results of an array computation that
-- yields two arrays.
accType2 :: AccType2 OpenAcc
-- | Reify the result type of a scalar expression.
expType :: OpenExp aenv env t -> TupleType (EltRepr t)
-- | Size of a tuple type, in bytes
sizeOf :: TupleType a -> Int
-- | Reify the element type of the result of an array computation using the
-- array computation AST before tying the knot.
preAccType :: AccType acc -> PreOpenAcc acc aenv (Array sh e) -> TupleType (EltRepr e)
-- | Reify the element types of the results of an array computation that
-- yields two arrays using the array computation AST before tying the
-- knot.
preAccType2 :: AccType acc -> AccType2 acc -> PreOpenAcc acc aenv (Array sh1 e1, Array sh2 e2) -> (TupleType (EltRepr e1), TupleType (EltRepr e2))
-- | Reify the result types of of a scalar expression using the expression
-- AST before tying the knot.
preExpType :: AccType acc -> PreOpenExp acc aenv env t -> TupleType (EltRepr t)
module Data.Array.Accelerate.Pretty
instance Show (OpenExp env aenv t)
instance Show (OpenFun env aenv f)
instance Show (OpenAcc aenv a)
-- | This modules defines the AST of the user-visible embedded language
-- using more convenient higher-order abstract syntax (instead of de
-- Bruijn indices). Moreover, it defines smart constructors to construct
-- programs.
module Data.Array.Accelerate.Smart
-- | Array-valued collective computations
newtype Acc a
Acc :: (PreAcc Acc a) -> Acc a
-- | Array-valued collective computations without a recursive knot
--
-- Note [Pipe and sharing recovery] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The
-- Pipe constructor is special. It is the only form that contains
-- functions over array computations and these functions are fixed to be
-- over vanilla Acc types. This enables us to perform sharing
-- recovery independently from the context for them.
data PreAcc acc a
Atag :: Int -> PreAcc acc as
Pipe :: (Acc as -> Acc bs) -> (Acc bs -> Acc cs) -> acc as -> PreAcc acc cs
Acond :: PreExp acc Bool -> acc as -> acc as -> PreAcc acc as
FstArray :: acc (Array sh1 e1, Array sh2 e2) -> PreAcc acc (Array sh1 e1)
SndArray :: acc (Array sh1 e1, Array sh2 e2) -> PreAcc acc (Array sh2 e2)
PairArrays :: acc (Array sh1 e1) -> acc (Array sh2 e2) -> PreAcc acc (Array sh1 e1, Array sh2 e2)
Use :: Array sh e -> PreAcc acc (Array sh e)
Unit :: PreExp acc e -> PreAcc acc (Scalar e)
Generate :: PreExp acc sh -> (Exp sh -> PreExp acc e) -> PreAcc acc (Array sh e)
Reshape :: PreExp acc sh -> acc (Array sh' e) -> PreAcc acc (Array sh e)
Replicate :: PreExp acc slix -> acc (Array (SliceShape slix) e) -> PreAcc acc (Array (FullShape slix) e)
Index :: acc (Array (FullShape slix) e) -> PreExp acc slix -> PreAcc acc (Array (SliceShape slix) e)
Map :: (Exp e -> PreExp acc e') -> acc (Array sh e) -> PreAcc acc (Array sh e')
ZipWith :: (Exp e1 -> Exp e2 -> PreExp acc e3) -> acc (Array sh e1) -> acc (Array sh e2) -> PreAcc acc (Array sh e3)
Fold :: (Exp e -> Exp e -> PreExp acc e) -> PreExp acc e -> acc (Array (sh :. Int) e) -> PreAcc acc (Array sh e)
Fold1 :: (Exp e -> Exp e -> PreExp acc e) -> acc (Array (sh :. Int) e) -> PreAcc acc (Array sh e)
FoldSeg :: (Exp e -> Exp e -> PreExp acc e) -> PreExp acc e -> acc (Array (sh :. Int) e) -> acc Segments -> PreAcc acc (Array (sh :. Int) e)
Fold1Seg :: (Exp e -> Exp e -> PreExp acc e) -> acc (Array (sh :. Int) e) -> acc Segments -> PreAcc acc (Array (sh :. Int) e)
Scanl :: (Exp e -> Exp e -> PreExp acc e) -> PreExp acc e -> acc (Vector e) -> PreAcc acc (Vector e)
Scanl' :: (Exp e -> Exp e -> PreExp acc e) -> PreExp acc e -> acc (Vector e) -> PreAcc acc (Vector e, Scalar e)
Scanl1 :: (Exp e -> Exp e -> PreExp acc e) -> acc (Vector e) -> PreAcc acc (Vector e)
Scanr :: (Exp e -> Exp e -> PreExp acc e) -> PreExp acc e -> acc (Vector e) -> PreAcc acc (Vector e)
Scanr' :: (Exp e -> Exp e -> PreExp acc e) -> PreExp acc e -> acc (Vector e) -> PreAcc acc (Vector e, Scalar e)
Scanr1 :: (Exp e -> Exp e -> PreExp acc e) -> acc (Vector e) -> PreAcc acc (Vector e)
Permute :: (Exp e -> Exp e -> PreExp acc e) -> acc (Array sh' e) -> (Exp sh -> PreExp acc sh') -> acc (Array sh e) -> PreAcc acc (Array sh' e)
Backpermute :: PreExp acc sh' -> (Exp sh' -> PreExp acc sh) -> acc (Array sh e) -> PreAcc acc (Array sh' e)
Stencil :: (stencil -> PreExp acc b) -> Boundary a -> acc (Array sh a) -> PreAcc acc (Array sh b)
Stencil2 :: (stencil1 -> stencil2 -> PreExp acc c) -> Boundary a -> acc (Array sh a) -> Boundary b -> acc (Array sh b) -> PreAcc acc (Array sh c)
-- | Scalar expressions for plain array computations.
type Exp t = PreExp Acc t
-- | Scalar expressions to parametrise collective array operations,
-- themselves parameterised over the type of collective array operations.
data PreExp acc t
Tag :: Int -> PreExp acc t
Const :: t -> PreExp acc t
Tuple :: Tuple (PreExp acc) (TupleRepr t) -> PreExp acc t
Prj :: TupleIdx (TupleRepr t) e -> PreExp acc t -> PreExp acc e
IndexNil :: PreExp acc Z
IndexCons :: PreExp acc sl -> PreExp acc a -> PreExp acc (sl :. a)
IndexHead :: PreExp acc (sl :. a) -> PreExp acc a
IndexTail :: PreExp acc (sl :. a) -> PreExp acc sl
IndexAny :: PreExp acc (Any sh)
Cond :: PreExp acc Bool -> PreExp acc t -> PreExp acc t -> PreExp acc t
PrimConst :: PrimConst t -> PreExp acc t
PrimApp :: PrimFun (a -> r) -> PreExp acc a -> PreExp acc r
IndexScalar :: acc (Array sh t) -> PreExp acc sh -> PreExp acc t
Shape :: acc (Array sh e) -> PreExp acc sh
Size :: acc (Array sh e) -> PreExp acc Int
-- | Boundary condition specification for stencil operations.
data Boundary a
-- | clamp coordinates to the extent of the array
Clamp :: Boundary a
-- | mirror coordinates beyond the array extent
Mirror :: Boundary a
-- | wrap coordinates around on each dimension
Wrap :: Boundary a
-- | use a constant value for outlying coordinates
Constant :: a -> Boundary a
-- | Smart constructors for stencil reification
-- -------------------------------------------
class (Elt (StencilRepr sh stencil), Stencil sh a (StencilRepr sh stencil)) => Stencil sh a stencil where type family StencilRepr sh stencil :: *
stencilPrj :: Stencil sh a stencil => sh -> a -> Exp (StencilRepr sh stencil) -> stencil
-- | Conversion from HOAS to de Bruijn computation AST -
--
-- Convert a closed array expression to de Bruijn form while also
-- incorporating sharing information.
convertAcc :: Arrays arrs => Acc arrs -> Acc arrs
-- | Convert a unary function over array computations
convertAccFun1 :: (Arrays a, Arrays b) => (Acc a -> Acc b) -> Afun (a -> b)
pair :: (Shape sh1, Shape sh2, Elt e1, Elt e2) => Acc (Array sh1 e1) -> Acc (Array sh2 e2) -> Acc (Array sh1 e1, Array sh2 e2)
unpair :: (Shape sh1, Shape sh2, Elt e1, Elt e2) => Acc (Array sh1 e1, Array sh2 e2) -> (Acc (Array sh1 e1), Acc (Array sh2 e2))
-- | Constant scalar expression
constant :: Elt t => t -> Exp t
tup2 :: (Elt a, Elt b) => (Exp a, Exp b) -> Exp (a, b)
tup3 :: (Elt a, Elt b, Elt c) => (Exp a, Exp b, Exp c) -> Exp (a, b, c)
tup4 :: (Elt a, Elt b, Elt c, Elt d) => (Exp a, Exp b, Exp c, Exp d) -> Exp (a, b, c, d)
tup5 :: (Elt a, Elt b, Elt c, Elt d, Elt e) => (Exp a, Exp b, Exp c, Exp d, Exp e) -> Exp (a, b, c, d, e)
tup6 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f) -> Exp (a, b, c, d, e, f)
tup7 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g) -> Exp (a, b, c, d, e, f, g)
tup8 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h) => (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h) -> Exp (a, b, c, d, e, f, g, h)
tup9 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i) => (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h, Exp i) -> Exp (a, b, c, d, e, f, g, h, i)
untup2 :: (Elt a, Elt b) => Exp (a, b) -> (Exp a, Exp b)
untup3 :: (Elt a, Elt b, Elt c) => Exp (a, b, c) -> (Exp a, Exp b, Exp c)
untup4 :: (Elt a, Elt b, Elt c, Elt d) => Exp (a, b, c, d) -> (Exp a, Exp b, Exp c, Exp d)
untup5 :: (Elt a, Elt b, Elt c, Elt d, Elt e) => Exp (a, b, c, d, e) -> (Exp a, Exp b, Exp c, Exp d, Exp e)
untup6 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => Exp (a, b, c, d, e, f) -> (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f)
untup7 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => Exp (a, b, c, d, e, f, g) -> (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g)
untup8 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h) => Exp (a, b, c, d, e, f, g, h) -> (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h)
untup9 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i) => Exp (a, b, c, d, e, f, g, h, i) -> (Exp a, Exp b, Exp c, Exp d, Exp e, Exp f, Exp g, Exp h, Exp i)
mkMinBound :: (Elt t, IsBounded t) => Exp t
mkMaxBound :: (Elt t, IsBounded t) => Exp t
mkPi :: (Elt r, IsFloating r) => Exp r
mkSin :: (Elt t, IsFloating t) => Exp t -> Exp t
mkCos :: (Elt t, IsFloating t) => Exp t -> Exp t
mkTan :: (Elt t, IsFloating t) => Exp t -> Exp t
mkAsin :: (Elt t, IsFloating t) => Exp t -> Exp t
mkAcos :: (Elt t, IsFloating t) => Exp t -> Exp t
mkAtan :: (Elt t, IsFloating t) => Exp t -> Exp t
mkAsinh :: (Elt t, IsFloating t) => Exp t -> Exp t
mkAcosh :: (Elt t, IsFloating t) => Exp t -> Exp t
mkAtanh :: (Elt t, IsFloating t) => Exp t -> Exp t
mkExpFloating :: (Elt t, IsFloating t) => Exp t -> Exp t
mkSqrt :: (Elt t, IsFloating t) => Exp t -> Exp t
mkLog :: (Elt t, IsFloating t) => Exp t -> Exp t
mkFPow :: (Elt t, IsFloating t) => Exp t -> Exp t -> Exp t
mkLogBase :: (Elt t, IsFloating t) => Exp t -> Exp t -> Exp t
mkTruncate :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
mkRound :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
mkFloor :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
mkCeiling :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
mkAtan2 :: (Elt t, IsFloating t) => Exp t -> Exp t -> Exp t
mkAdd :: (Elt t, IsNum t) => Exp t -> Exp t -> Exp t
mkSub :: (Elt t, IsNum t) => Exp t -> Exp t -> Exp t
mkMul :: (Elt t, IsNum t) => Exp t -> Exp t -> Exp t
mkNeg :: (Elt t, IsNum t) => Exp t -> Exp t
mkAbs :: (Elt t, IsNum t) => Exp t -> Exp t
mkSig :: (Elt t, IsNum t) => Exp t -> Exp t
mkQuot :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkRem :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkIDiv :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkMod :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkBAnd :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkBOr :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkBXor :: (Elt t, IsIntegral t) => Exp t -> Exp t -> Exp t
mkBNot :: (Elt t, IsIntegral t) => Exp t -> Exp t
mkBShiftL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
mkBShiftR :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
mkBRotateL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
mkBRotateR :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
mkFDiv :: (Elt t, IsFloating t) => Exp t -> Exp t -> Exp t
mkRecip :: (Elt t, IsFloating t) => Exp t -> Exp t
mkLt :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
mkGt :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
mkLtEq :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
mkGtEq :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
mkEq :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
mkNEq :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
mkMax :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp t
mkMin :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp t
mkLAnd :: Exp Bool -> Exp Bool -> Exp Bool
mkLOr :: Exp Bool -> Exp Bool -> Exp Bool
mkLNot :: Exp Bool -> Exp Bool
mkBoolToInt :: Exp Bool -> Exp Int
mkFromIntegral :: (Elt a, Elt b, IsIntegral a, IsNum b) => Exp a -> Exp b
($$) :: (b -> a) -> (c -> d -> b) -> c -> d -> a
($$$) :: (b -> a) -> (c -> d -> e -> b) -> c -> d -> e -> a
($$$$) :: (b -> a) -> (c -> d -> e -> f -> b) -> c -> d -> e -> f -> a
($$$$$) :: (b -> a) -> (c -> d -> e -> f -> g -> b) -> c -> d -> e -> f -> g -> a
instance Typeable1 Acc
instance Show NodeCounts
instance (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)
instance (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)
instance (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)
instance (Stencil (sh :. Int) a row2, Stencil (sh :. Int) a row1, Stencil (sh :. Int) a row0) => Stencil ((sh :. Int) :. Int) a (row2, row1, row0)
instance Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e)
instance Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e, Exp e, Exp e)
instance Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e, Exp e, Exp e)
instance Elt e => Stencil DIM1 e (Exp e, Exp e, Exp e)
instance Show (Exp a)
instance Arrays arrs => Show (Acc arrs)
instance Eq StableSharingAcc
instance Show StableSharingAcc
instance Eq StableAccName
instance Show StableAccName
-- | This interpreter is meant to be a reference implementation of the
-- semantics of the embedded array language. The emphasis is on defining
-- the semantics clearly, not on performance.
--
-- Surface types versus representation types
--
-- As a general rule, we perform all computations on representation types
-- and we store all data as values of representation types. To guarantee
-- the type safety of the interpreter, this currently implies a lot of
-- conversions between surface and representation types. Optimising the
-- code by eliminating back and forth conversions is fine, but only where
-- it doesn't negatively affects clarity — after all, the main purpose of
-- the interpreter is to serve as an executable specification.
module Data.Array.Accelerate.Interpreter
-- | Tuples of arrays (of type 'Array dim e'). This characterises the
-- domain of results of Accelerate array computations.
class (Delayable arrs, Typeable arrs) => Arrays arrs
-- | Run a complete embedded array program using the reference interpreter.
run :: Arrays a => Acc a -> a
-- | Stream a lazily read list of input arrays through the given program,
-- collecting results as we go
stream :: (Arrays a, Arrays b) => (Acc a -> Acc b) -> [a] -> [b]
-- | 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 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 toplevel modules. Currently, we have the following:
--
--
module Data.Array.Accelerate
-- | 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.
data Int :: *
-- | 8-bit signed integer type
data Int8 :: *
-- | 16-bit signed integer type
data Int16 :: *
-- | 32-bit signed integer type
data Int32 :: *
-- | 64-bit signed integer type
data Int64 :: *
-- | A Word is an unsigned integral type, with the same size as
-- Int.
data Word :: *
-- | 8-bit unsigned integer type
data Word8 :: *
-- | 16-bit unsigned integer type
data Word16 :: *
-- | 32-bit unsigned integer type
data Word32 :: *
-- | 64-bit unsigned integer type
data Word64 :: *
-- | Haskell type representing the C short type.
data CShort :: *
-- | Haskell type representing the C unsigned short type.
data CUShort :: *
-- | Haskell type representing the C int type.
data CInt :: *
-- | Haskell type representing the C unsigned int type.
data CUInt :: *
-- | Haskell type representing the C long type.
data CLong :: *
-- | Haskell type representing the C unsigned long type.
data CULong :: *
-- | Haskell type representing the C long long type.
data CLLong :: *
-- | Haskell type representing the C unsigned long long type.
data CULLong :: *
-- | 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 Float :: *
-- | 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 Double :: *
-- | Haskell type representing the C float type.
data CFloat :: *
-- | Haskell type representing the C double type.
data CDouble :: *
data Bool :: *
-- | 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).
data Char :: *
-- | Haskell type representing the C char type.
data CChar :: *
-- | Haskell type representing the C signed char type.
data CSChar :: *
-- | Haskell type representing the C unsigned char type.
data CUChar :: *
-- | All scalar type
class Typeable a => IsScalar a
-- | Numeric types
class (Num a, IsScalar a) => IsNum a
-- | Bounded types
class IsBounded a
-- | Integral types
class (IsScalar a, IsNum a, IsBounded a) => IsIntegral a
-- | Floating types
class (Floating a, IsScalar a, IsNum a) => IsFloating a
-- | Non-numeric types
class IsNonNum a
-- | Tuples of arrays (of type 'Array dim e'). This characterises the
-- domain of results of Accelerate array computations.
class (Delayable arrs, Typeable arrs) => Arrays arrs
-- | 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.
--
data Array sh e
-- | Scalars
type Scalar e = Array DIM0 e
-- | Vectors
type Vector e = Array DIM1 e
-- | Segment descriptor
type Segments = Vector Int
-- | Class that characterises the types of values that can be array
-- elements, and hence, appear in scalar Accelerate expressions.
class (Show a, Typeable a, Typeable (EltRepr a), Typeable (EltRepr' a), ArrayElt (EltRepr a), ArrayElt (EltRepr' a)) => Elt a
-- | Surface types representing array indices and slices
-- ----------------------------------------------------
--
-- Array indices are snoc type lists
--
-- For example, the type of a rank-2 array index is 'Z :.Int :. Int'.
--
-- Rank-0 index
data Z
Z :: Z
-- | Increase an index rank by one dimension
data (:.) tail head
(:.) :: tail -> head -> :. tail head
-- | Shapes and indices of multi-dimensional arrays
class (Elt sh, Elt (Any sh), Shape (EltRepr sh)) => Shape sh where dim = dim . fromElt size = size . fromElt ignore = toElt ignore index sh ix = index (fromElt sh) (fromElt ix) bound sh ix bndy = case bound (fromElt sh) (fromElt ix) bndy of { Left v -> Left v Right ix' -> Right $ toElt ix' } iter sh f c r = iter (fromElt sh) (f . toElt) c r rangeToShape (low, high) = toElt (rangeToShape (fromElt low, fromElt high)) shapeToRange ix = let (low, high) = shapeToRange (fromElt ix) in (toElt low, toElt high) shapeToList = shapeToList . fromElt listToShape = toElt . listToShape
-- | Marker for entire dimensions in slice descriptors
data All
All :: All
-- | Marker for arbitrary shapes in slice descriptors
data Any sh
Any :: Any sh
-- | Slices -aka generalised indices- as n-tuples and mappings of slice
-- indicies to slices, co-slices, and slice dimensions
class (Elt sl, Shape (SliceShape sl), Shape (CoSliceShape sl), Shape (FullShape sl)) => Slice sl where type family SliceShape sl :: * type family CoSliceShape sl :: * type family FullShape sl :: *
sliceIndex :: Slice sl => sl -> SliceIndex (EltRepr sl) (EltRepr (SliceShape sl)) (EltRepr (CoSliceShape sl)) (EltRepr (FullShape sl))
type DIM0 = Z
type DIM1 = DIM0 :. Int
type DIM2 = DIM1 :. Int
type DIM3 = DIM2 :. Int
type DIM4 = DIM3 :. Int
type DIM5 = DIM4 :. Int
type DIM6 = DIM5 :. Int
type DIM7 = DIM6 :. Int
type DIM8 = DIM7 :. Int
type DIM9 = DIM8 :. Int
arrayDim :: Shape sh => sh -> Int
-- | Array shape in plain Haskell code
arrayShape :: Shape sh => Array sh e -> sh
arraySize :: Shape sh => sh -> Int
-- | Array indexing in plain Haskell code
indexArray :: Array sh e -> sh -> e
-- | Convert an IArray to an accelerated array.
fromIArray :: (EltRepr ix ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => a ix e -> Array sh e
-- | Convert an accelerated array to an IArray
toIArray :: (EltRepr ix ~ EltRepr sh, IArray a e, Ix ix, Shape sh, Elt ix, Elt e) => Array sh e -> a ix e
-- | Convert a list (with elements in row-major order) to an accelerated
-- array.
fromList :: (Shape sh, Elt e) => sh -> [e] -> Array sh e
-- | Convert an accelerated array to a list in row-major order.
toList :: Array sh e -> [e]
-- | Array-valued collective computations
data Acc a
-- | Scalar expressions for plain array computations.
type Exp t = PreExp Acc t
-- | Boundary condition specification for stencil operations.
data Boundary a
-- | clamp coordinates to the extent of the array
Clamp :: Boundary a
-- | mirror coordinates beyond the array extent
Mirror :: Boundary a
-- | wrap coordinates around on each dimension
Wrap :: Boundary a
-- | use a constant value for outlying coordinates
Constant :: a -> Boundary a
-- | Smart constructors for stencil reification
-- -------------------------------------------
class (Elt (StencilRepr sh stencil), Stencil sh a (StencilRepr sh stencil)) => Stencil sh a stencil
type Stencil3 a = (Exp a, Exp a, Exp a)
type Stencil5 a = (Exp a, Exp a, Exp a, Exp a, Exp a)
type Stencil7 a = (Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a)
type Stencil9 a = (Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a, Exp a)
type Stencil3x3 a = (Stencil3 a, Stencil3 a, Stencil3 a)
type Stencil5x3 a = (Stencil5 a, Stencil5 a, Stencil5 a)
type Stencil3x5 a = (Stencil3 a, Stencil3 a, Stencil3 a, Stencil3 a, Stencil3 a)
type Stencil5x5 a = (Stencil5 a, Stencil5 a, Stencil5 a, Stencil5 a, Stencil5 a)
type Stencil3x3x3 a = (Stencil3x3 a, Stencil3x3 a, Stencil3x3 a)
type Stencil5x3x3 a = (Stencil5x3 a, Stencil5x3 a, Stencil5x3 a)
type Stencil3x5x3 a = (Stencil3x5 a, Stencil3x5 a, Stencil3x5 a)
type Stencil3x3x5 a = (Stencil3x3 a, Stencil3x3 a, Stencil3x3 a, Stencil3x3 a, Stencil3x3 a)
type Stencil5x5x3 a = (Stencil5x5 a, Stencil5x5 a, Stencil5x5 a)
type Stencil5x3x5 a = (Stencil5x3 a, Stencil5x3 a, Stencil5x3 a, Stencil5x3 a, Stencil5x3 a)
type Stencil3x5x5 a = (Stencil3x5 a, Stencil3x5 a, Stencil3x5 a, Stencil3x5 a, Stencil3x5 a)
type Stencil5x5x5 a = (Stencil5x5 a, Stencil5x5 a, Stencil5x5 a, Stencil5x5 a, Stencil5x5 a)
-- | Constant scalar expression
constant :: Elt t => t -> Exp t
-- | Array inlet: makes an array available for processing using the
-- Accelerate language; triggers asynchronous host->device transfer if
-- necessary.
use :: (Shape ix, Elt e) => Array ix e -> Acc (Array ix e)
-- | Scalar inlet: injects a scalar (or a tuple of scalars) into a
-- singleton array for use in the Accelerate language.
unit :: Elt e => Exp e -> Acc (Scalar e)
-- | 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.
replicate :: (Slice slix, Elt e) => Exp slix -> Acc (Array (SliceShape slix) e) -> Acc (Array (FullShape slix) e)
-- | Construct a new array by applying a function to each index.
generate :: (Shape ix, Elt a) => Exp ix -> (Exp ix -> Exp a) -> Acc (Array ix a)
-- | Extract the first component of an array pair.
fstA :: (Shape sh1, Shape sh2, Elt e1, Elt e2) => Acc (Array sh1 e1, Array sh2 e2) -> Acc (Array sh1 e1)
-- | Extract the second component of an array pair.
sndA :: (Shape sh1, Shape sh2, Elt e1, Elt e2) => Acc (Array sh1 e1, Array sh2 e2) -> Acc (Array sh2 e2)
-- | Create an array pair from two separate arrays.
pairA :: (Shape sh1, Shape sh2, Elt e1, Elt e2) => Acc (Array sh1 e1) -> Acc (Array sh2 e2) -> Acc (Array sh1 e1, Array sh2 e2)
-- | Change the shape of an array without altering its contents, where
--
--
-- precondition: size ix == size ix'
--
reshape :: (Shape ix, Shape ix', Elt e) => Exp ix -> Acc (Array ix' e) -> Acc (Array ix e)
-- | Index an array with a *generalised* array index (supplied as the
-- second argument). The result is a new array (possibly a singleton)
-- containing all dimensions in their entirety.
slice :: (Slice slix, Elt e) => Acc (Array (FullShape slix) e) -> Exp slix -> Acc (Array (SliceShape slix) e)
-- | Apply the given function elementwise to the given array.
map :: (Shape ix, Elt a, Elt b) => (Exp a -> Exp b) -> Acc (Array ix a) -> Acc (Array ix b)
-- | Apply the given binary function elementwise to the two arrays. The
-- extent of the resulting array is the intersection of the extents of
-- the two source arrays.
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)
-- | 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.
fold :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Array (ix :. Int) a) -> Acc (Array ix a)
-- | Variant of fold that requires the reduced array to be non-empty
-- and doesn't need an default value.
fold1 :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Acc (Array (ix :. Int) a) -> Acc (Array ix a)
-- | 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.
foldSeg :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Array (ix :. Int) a) -> Acc Segments -> Acc (Array (ix :. Int) a)
-- | 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.
fold1Seg :: (Shape ix, Elt a) => (Exp a -> Exp a -> Exp a) -> Acc (Array (ix :. Int) a) -> Acc Segments -> Acc (Array (ix :. Int) a)
-- | 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.
scanl :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)
-- | Variant of scanl, where the final result of the reduction is
-- returned separately. Denotationally, we have
--
--
-- scanl' f e arr = (crop 0 (len - 1) res, unit (res!len))
-- where
-- len = shape arr
-- res = scanl f e arr
--
scanl' :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> (Acc (Vector a), Acc (Scalar a))
-- | List style left-to-right scan without an intial value (aka
-- inclusive scan). Again, the first argument needs to be an
-- associative function. Denotationally, we have
--
--
-- scanl1 f e arr = crop 1 len res
-- where
-- len = shape arr
-- res = scanl f e arr
--
scanl1 :: Elt a => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc (Vector a)
-- | Right-to-left variant of scanl.
scanr :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)
-- | Right-to-left variant of 'scanl\''.
scanr' :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> (Acc (Vector a), Acc (Scalar a))
-- | Right-to-left variant of scanl1.
scanr1 :: Elt a => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc (Vector 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. Eltents that are
-- mapped to the magic value ignore by the permutation function
-- are being dropped.
permute :: (Shape ix, Shape ix', Elt a) => (Exp a -> Exp a -> Exp a) -> Acc (Array ix' a) -> (Exp ix -> Exp ix') -> Acc (Array ix a) -> Acc (Array ix' a)
-- | Backward permutation
backpermute :: (Shape ix, Shape ix', Elt a) => Exp ix' -> (Exp ix' -> Exp ix) -> Acc (Array ix a) -> Acc (Array ix' a)
-- | 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.
stencil :: (Shape ix, Elt a, Elt b, Stencil ix a stencil) => (stencil -> Exp b) -> Boundary a -> Acc (Array ix a) -> Acc (Array ix b)
-- | Map a binary stencil of an array. The extent of the resulting array is
-- the intersection of the extents of the two source arrays.
stencil2 :: (Shape ix, Elt a, Elt b, Elt c, Stencil ix a stencil1, Stencil ix b stencil2) => (stencil1 -> stencil2 -> Exp c) -> Boundary a -> Acc (Array ix a) -> Boundary b -> Acc (Array ix b) -> Acc (Array ix c)
-- | 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 subcomputations, 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.
(>->) :: (Arrays a, Arrays b, Arrays c) => (Acc a -> Acc b) -> (Acc b -> Acc c) -> (Acc a -> Acc c)
-- | An array-level if-then-else construct.
cond :: Arrays a => Exp Bool -> Acc a -> Acc a -> Acc a
-- | Infix version of cond.
(?|) :: Arrays a => Exp Bool -> (Acc a, Acc a) -> Acc a
class Lift e where type family Plain e
lift :: Lift e => e -> Exp (Plain e)
class Lift e => Unlift e
unlift :: Unlift e => Exp (Plain e) -> e
-- | Lift a unary function into Exp.
lift1 :: (Unlift e1, Lift e2) => (e1 -> e2) -> Exp (Plain e1) -> Exp (Plain e2)
-- | Lift a binary function into Exp.
lift2 :: (Unlift e1, Unlift e2, Lift e3) => (e1 -> e2 -> e3) -> Exp (Plain e1) -> Exp (Plain e2) -> Exp (Plain e3)
-- | Lift a unary function to a computation over rank-1 indices.
ilift1 :: (Exp Int -> Exp Int) -> Exp (Z :. Int) -> Exp (Z :. Int)
-- | Lift a binary function to a computation over rank-1 indices.
ilift2 :: (Exp Int -> Exp Int -> Exp Int) -> Exp (Z :. Int) -> Exp (Z :. Int) -> Exp (Z :. Int)
-- | Extract the first component of a pair.
fst :: (Elt a, Elt b) => Exp (a, b) -> Exp a
-- | Extract the second component of a pair.
snd :: (Elt a, Elt b) => Exp (a, b) -> Exp b
-- | Converts an uncurried function to a curried function.
curry :: (Elt a, Elt b) => (Exp (a, b) -> Exp c) -> Exp a -> Exp b -> Exp c
-- | Converts a curried function to a function on pairs.
uncurry :: (Elt a, Elt b) => (Exp a -> Exp b -> Exp c) -> Exp (a, b) -> Exp c
-- | The one index for a rank-0 array.
index0 :: Exp Z
-- | Turn an Int expression into a rank-1 indexing expression.
index1 :: Exp Int -> Exp (Z :. Int)
-- | Turn an Int expression into a rank-1 indexing expression.
unindex1 :: Exp (Z :. Int) -> Exp Int
-- | Conditional expression.
(?) :: Elt t => Exp Bool -> (Exp t, Exp t) -> Exp t
-- | Expression form that extracts a scalar from an array.
(!) :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp ix -> Exp e
-- | Extraction of the element in a singleton array.
the :: Elt e => Acc (Scalar e) -> Exp e
-- | Expression form that yields the shape of an array.
shape :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp ix
-- | Expression form that yields the size of an array.
size :: (Shape ix, Elt e) => Acc (Array ix e) -> Exp Int
-- | Equality lifted into Accelerate expressions.
(==*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
-- | Inequality lifted into Accelerate expressions.
(/=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
-- | Smaller-than lifted into Accelerate expressions.
(<*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
-- | Smaller-or-equal lifted into Accelerate expressions.
(<=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
-- | Greater-than lifted into Accelerate expressions.
(>*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
-- | Greater-or-equal lifted into Accelerate expressions.
(>=*) :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp Bool
-- | Determine the maximum of two scalars.
max :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp t
-- | Determine the minimum of two scalars.
min :: (Elt t, IsScalar t) => Exp t -> Exp t -> Exp t
bit :: (Elt t, IsIntegral t) => Exp Int -> Exp t
setBit, complementBit, clearBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
testBit :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp Bool
shift, shiftR, shiftL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
rotate, rotateR, rotateL :: (Elt t, IsIntegral t) => Exp t -> Exp Int -> Exp t
-- | Conversions from the RealFrac class
truncate :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
round :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
floor :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
ceiling :: (Elt a, Elt b, IsFloating a, IsIntegral b) => Exp a -> Exp b
-- | Conjunction
(&&*) :: Exp Bool -> Exp Bool -> Exp Bool
-- | Disjunction
(||*) :: Exp Bool -> Exp Bool -> Exp Bool
-- | Negation
not :: Exp Bool -> Exp Bool
-- | Convert a Boolean value to an Int, where False turns
-- into '0' and True into '1'.
boolToInt :: Exp Bool -> Exp Int
-- | General coercion from integral types
fromIntegral :: (Elt a, Elt b, IsIntegral a, IsNum b) => Exp a -> Exp b
-- | Magic value identifying elements that are ignored in a forward
-- permutation
ignore :: Shape ix => Exp ix
-- | Combine the elements of two arrays pairwise. The shape of the result
-- is the intersection of the two argument shapes.
zip :: (Shape sh, Elt a, Elt b) => Acc (Array sh a) -> Acc (Array sh b) -> Acc (Array sh (a, b))
-- | The converse of zip, but the shape of the two results is
-- identical to the shape of the argument.
unzip :: (Shape sh, Elt a, Elt b) => Acc (Array sh (a, b)) -> (Acc (Array sh a), Acc (Array sh b))
-- | Reduction of an array of arbitrary rank to a single scalar 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)
-- | Variant of foldAll that requires the reduced array to be
-- non-empty and doesn't need an default value.
fold1All :: (Shape sh, Elt a) => (Exp a -> Exp a -> Exp a) -> Acc (Array sh a) -> Acc (Scalar a)
-- | 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
--
prescanl :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)
-- | Left-to-right postscan, a variant of scanl1 with an initial
-- value. Denotationally, we have
--
--
-- postscanl f e = map (e `f`) . scanl1 f
--
postscanl :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)
-- | 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
--
prescanr :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)
-- | Right-to-left postscan, a variant of scanr1 with an initial
-- value. Denotationally, we have
--
--
-- postscanr f e = map (e `f`) . scanr1 f
--
postscanr :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc (Vector a)
-- | Segmented version of scanl.
scanlSeg :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | 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.
scanlSeg' :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> (Acc (Vector a), Acc (Vector a))
-- | Segmented version of scanl1.
scanl1Seg :: Elt a => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | Segmented version of prescanl.
prescanlSeg :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | Segmented version of postscanl.
postscanlSeg :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | Segmented version of scanr.
scanrSeg :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | Segmented version of 'scanrSeg\''.
scanrSeg' :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> (Acc (Vector a), Acc (Vector a))
-- | Segmented version of scanr1.
scanr1Seg :: Elt a => (Exp a -> Exp a -> Exp a) -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | Segmented version of prescanr.
prescanrSeg :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
-- | Segmented version of postscanr.
postscanrSeg :: Elt a => (Exp a -> Exp a -> Exp a) -> Exp a -> Acc (Vector a) -> Acc Segments -> Acc (Vector a)
class Elt e => Elem e
class Shape sh => Ix sh
class Slice sh => SliceIx sh
tuple :: Lift e => e -> Exp (Plain e)
untuple :: Unlift e => Exp (Plain e) -> e
instance Slice sh => SliceIx sh
instance Shape sh => Ix sh
instance Elt e => Elem e