repa-3.4.1.4: High performance, regular, shape polymorphic parallel arrays.

Safe HaskellNone
LanguageHaskell98

Data.Array.Repa.Eval

Contents

Description

Low level interface to parallel array filling operators.

Synopsis

Element types

class Elt a where #

Element types that can be used with the blockwise filling functions.

This class is mainly used to define the touch method. This is used internally in the imeplementation of Repa to prevent let-binding from being floated inappropriately by the GHC simplifier. Doing a seq sometimes isn't enough, because the GHC simplifier can erase these, and still move around the bindings.

Minimal complete definition

Nothing

Methods

touch :: a -> IO () #

Place a demand on a value at a particular point in an IO computation.

touch :: (Generic a, GElt (Rep a)) => a -> IO () #

Place a demand on a value at a particular point in an IO computation.

zero :: a #

Generic zero value, helpful for debugging.

zero :: (Generic a, GElt (Rep a)) => a #

Generic zero value, helpful for debugging.

one :: a #

Generic one value, helpful for debugging.

one :: (Generic a, GElt (Rep a)) => a #

Generic one value, helpful for debugging.

Instances
Elt Bool # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Bool -> IO () #

zero :: Bool #

one :: Bool #

Elt Double # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Double -> IO () #

zero :: Double #

one :: Double #

Elt Float # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Float -> IO () #

zero :: Float #

one :: Float #

Elt Int # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Int -> IO () #

zero :: Int #

one :: Int #

Elt Int8 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Int8 -> IO () #

zero :: Int8 #

one :: Int8 #

Elt Int16 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Int16 -> IO () #

zero :: Int16 #

one :: Int16 #

Elt Int32 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Int32 -> IO () #

zero :: Int32 #

one :: Int32 #

Elt Int64 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Int64 -> IO () #

zero :: Int64 #

one :: Int64 #

Elt Word # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Word -> IO () #

zero :: Word #

one :: Word #

Elt Word8 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Word8 -> IO () #

zero :: Word8 #

one :: Word8 #

Elt Word16 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Word16 -> IO () #

zero :: Word16 #

one :: Word16 #

Elt Word32 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Word32 -> IO () #

zero :: Word32 #

one :: Word32 #

Elt Word64 # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: Word64 -> IO () #

zero :: Word64 #

one :: Word64 #

(Elt a, Elt b) => Elt (a, b) # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: (a, b) -> IO () #

zero :: (a, b) #

one :: (a, b) #

(Elt a, Elt b, Elt c) => Elt (a, b, c) # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: (a, b, c) -> IO () #

zero :: (a, b, c) #

one :: (a, b, c) #

(Elt a, Elt b, Elt c, Elt d) => Elt (a, b, c, d) # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: (a, b, c, d) -> IO () #

zero :: (a, b, c, d) #

one :: (a, b, c, d) #

(Elt a, Elt b, Elt c, Elt d, Elt e) => Elt (a, b, c, d, e) # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: (a, b, c, d, e) -> IO () #

zero :: (a, b, c, d, e) #

one :: (a, b, c, d, e) #

(Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => Elt (a, b, c, d, e, f) # 
Instance details

Defined in Data.Array.Repa.Eval.Elt

Methods

touch :: (a, b, c, d, e, f) -> IO () #

zero :: (a, b, c, d, e, f) #

one :: (a, b, c, d, e, f) #

Parallel array filling

class Target r e where #

Class of manifest array representations that can be constructed in parallel.

Associated Types

data MVec r e #

Mutable version of the representation.

Methods

newMVec :: Int -> IO (MVec r e) #

Allocate a new mutable array of the given size.

unsafeWriteMVec :: MVec r e -> Int -> e -> IO () #

Write an element into the mutable array.

unsafeFreezeMVec :: sh -> MVec r e -> IO (Array r sh e) #

Freeze the mutable array into an immutable Repa array.

deepSeqMVec :: MVec r e -> a -> a #

Ensure the strucure of a mutable array is fully evaluated.

touchMVec :: MVec r e -> IO () #

Ensure the array is still live at this point. Needed when the mutable array is a ForeignPtr with a finalizer.

Instances
Storable e => Target F e #

Filling foreign buffers.

Instance details

Defined in Data.Array.Repa.Repr.ForeignPtr

Associated Types

data MVec F e :: Type #

Methods

newMVec :: Int -> IO (MVec F e) #

unsafeWriteMVec :: MVec F e -> Int -> e -> IO () #

unsafeFreezeMVec :: sh -> MVec F e -> IO (Array F sh e) #

deepSeqMVec :: MVec F e -> a -> a #

touchMVec :: MVec F e -> IO () #

Target V e #

Filling of boxed vector arrays.

Instance details

Defined in Data.Array.Repa.Repr.Vector

Associated Types

data MVec V e :: Type #

Methods

newMVec :: Int -> IO (MVec V e) #

unsafeWriteMVec :: MVec V e -> Int -> e -> IO () #

unsafeFreezeMVec :: sh -> MVec V e -> IO (Array V sh e) #

deepSeqMVec :: MVec V e -> a -> a #

touchMVec :: MVec V e -> IO () #

Unbox e => Target U e #

Filling of unboxed vector arrays.

Instance details

Defined in Data.Array.Repa.Repr.Unboxed

Associated Types

data MVec U e :: Type #

Methods

newMVec :: Int -> IO (MVec U e) #

unsafeWriteMVec :: MVec U e -> Int -> e -> IO () #

unsafeFreezeMVec :: sh -> MVec U e -> IO (Array U sh e) #

deepSeqMVec :: MVec U e -> a -> a #

touchMVec :: MVec U e -> IO () #

class (Source r1 e, Shape sh) => Load r1 sh e where #

Compute all elements defined by an array and write them to a manifest target representation.

Note that instances require that the source array to have a delayed representation such as D or C. If you want to use a pre-existing manifest array as the source then delay it first.

Methods

loadS :: Target r2 e => Array r1 sh e -> MVec r2 e -> IO () #

Fill an entire array sequentially.

loadP :: Target r2 e => Array r1 sh e -> MVec r2 e -> IO () #

Fill an entire array in parallel.

Instances
Shape sh => Load D sh e #

Compute all elements in an array.

Instance details

Defined in Data.Array.Repa.Repr.Delayed

Methods

loadS :: Target r2 e => Array D sh e -> MVec r2 e -> IO () #

loadP :: Target r2 e => Array D sh e -> MVec r2 e -> IO () #

Shape sh => Load X sh e # 
Instance details

Defined in Data.Array.Repa.Repr.Undefined

Methods

loadS :: Target r2 e => Array X sh e -> MVec r2 e -> IO () #

loadP :: Target r2 e => Array X sh e -> MVec r2 e -> IO () #

Elt e => Load C DIM2 e #

Compute all elements in an rank-2 array.

Instance details

Defined in Data.Array.Repa.Repr.Cursored

Methods

loadS :: Target r2 e => Array C DIM2 e -> MVec r2 e -> IO () #

loadP :: Target r2 e => Array C DIM2 e -> MVec r2 e -> IO () #

(Shape sh, Load r1 sh e) => Load (S r1) sh e # 
Instance details

Defined in Data.Array.Repa.Repr.HintSmall

Methods

loadS :: Target r2 e => Array (S r1) sh e -> MVec r2 e -> IO () #

loadP :: Target r2 e => Array (S r1) sh e -> MVec r2 e -> IO () #

(Shape sh, Load D sh e) => Load (I D) sh e # 
Instance details

Defined in Data.Array.Repa.Repr.HintInterleave

Methods

loadS :: Target r2 e => Array (I D) sh e -> MVec r2 e -> IO () #

loadP :: Target r2 e => Array (I D) sh e -> MVec r2 e -> IO () #

(LoadRange r1 sh e, Load r2 sh e) => Load (P r1 r2) sh e # 
Instance details

Defined in Data.Array.Repa.Repr.Partitioned

Methods

loadS :: Target r20 e => Array (P r1 r2) sh e -> MVec r20 e -> IO () #

loadP :: Target r20 e => Array (P r1 r2) sh e -> MVec r20 e -> IO () #

class (Source r1 e, Shape sh) => LoadRange r1 sh e where #

Compute a range of elements defined by an array and write them to a fillable representation.

Methods

loadRangeS :: Target r2 e => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () #

Fill a range of an array sequentially.

loadRangeP :: Target r2 e => Array r1 sh e -> MVec r2 e -> sh -> sh -> IO () #

Fill a range of an array in parallel.

Instances
Elt e => LoadRange D DIM2 e #

Compute a range of elements in a rank-2 array.

Instance details

Defined in Data.Array.Repa.Repr.Delayed

Methods

loadRangeS :: Target r2 e => Array D DIM2 e -> MVec r2 e -> DIM2 -> DIM2 -> IO () #

loadRangeP :: Target r2 e => Array D DIM2 e -> MVec r2 e -> DIM2 -> DIM2 -> IO () #

Elt e => LoadRange C DIM2 e #

Compute a range of elements in a rank-2 array.

Instance details

Defined in Data.Array.Repa.Repr.Cursored

Methods

loadRangeS :: Target r2 e => Array C DIM2 e -> MVec r2 e -> DIM2 -> DIM2 -> IO () #

loadRangeP :: Target r2 e => Array C DIM2 e -> MVec r2 e -> DIM2 -> DIM2 -> IO () #

(Shape sh, LoadRange r1 sh e) => LoadRange (S r1) sh e # 
Instance details

Defined in Data.Array.Repa.Repr.HintSmall

Methods

loadRangeS :: Target r2 e => Array (S r1) sh e -> MVec r2 e -> sh -> sh -> IO () #

loadRangeP :: Target r2 e => Array (S r1) sh e -> MVec r2 e -> sh -> sh -> IO () #

fromList :: (Shape sh, Target r e) => sh -> [e] -> Array r sh e #

O(n). Construct a manifest array from a list.

Converting between representations

computeS :: (Load r1 sh e, Target r2 e) => Array r1 sh e -> Array r2 sh e #

Sequential computation of array elements.

computeP :: (Load r1 sh e, Target r2 e, Source r2 e, Monad m) => Array r1 sh e -> m (Array r2 sh e) #

Parallel computation of array elements.

  • The source array must have a delayed representation like D, C or P, and the result a manifest representation like U or F.
  • If you want to copy data between manifest representations then use copyP instead.
  • If you want to convert a manifest array back to a delayed representation then use delay instead.

suspendedComputeP :: (Load r1 sh e, Target r2 e) => Array r1 sh e -> Array r2 sh e #

Suspended parallel computation of array elements.

This version creates a thunk that will evaluate the array on demand. If you force it when another parallel computation is already running then you will get a runtime warning and evaluation will be sequential. Use deepSeqArray and now to ensure that each array is evaluated before proceeding to the next one.

If unsure then just use the monadic version computeP. This one ensures that each array is fully evaluated before continuing.

copyS :: (Source r1 e, Load D sh e, Target r2 e) => Array r1 sh e -> Array r2 sh e #

Sequential copying of arrays.

copyP :: (Source r1 e, Source r2 e, Load D sh e, Target r2 e, Monad m) => Array r1 sh e -> m (Array r2 sh e) #

Parallel copying of arrays.

  • This is a wrapper that delays an array before calling computeP.
  • You can use it to copy manifest arrays between representations.

suspendedCopyP :: (Source r1 e, Load D sh e, Target r2 e) => Array r1 sh e -> Array r2 sh e #

Suspended parallel copy of array elements.

now :: (Shape sh, Source r e, Monad m) => Array r sh e -> m (Array r sh e) #

Monadic version of deepSeqArray.

Forces an suspended array computation to be completed at this point in a monadic computation.

 do  let arr2 = suspendedComputeP arr1
     ...
     arr3 <- now $ arr2
     ...

Chunked filling

fillLinearS #

Arguments

:: Int

Number of elements.

-> (Int -> a -> IO ())

Update function to write into result buffer.

-> (Int -> a)

Fn to get the value at a given index.

-> IO () 

Fill something sequentially.

  • The array is filled linearly from start to finish.

fillChunkedP #

Arguments

:: Int

Number of elements.

-> (Int -> a -> IO ())

Update function to write into result buffer.

-> (Int -> a)

Fn to get the value at a given index.

-> IO () 

Fill something in parallel.

  • The array is split into linear chunks, and each thread linearly fills one chunk.

fillChunkedIOP #

Arguments

:: Int

Number of elements.

-> (Int -> a -> IO ())

Update fn to write into result buffer.

-> (Int -> IO (Int -> IO a))

Create a fn to get the value at a given index. The first Int is the thread number, so you can do some per-thread initialisation.

-> IO () 

Fill something in parallel, using a separate IO action for each thread.

  • The array is split into linear chunks, and each thread linearly fills one chunk.

Interleaved filling

fillInterleavedP #

Arguments

:: Int

Number of elements.

-> (Int -> a -> IO ())

Update function to write into result buffer.

-> (Int -> a)

Fn to get the value at a given index.

-> IO () 

Fill something in parallel.

  • The array is split into linear chunks and each thread fills one chunk.

Blockwise filling

fillBlock2P #

Arguments

:: Elt a 
=> (Int -> a -> IO ())

Update function to write into result buffer.

-> (DIM2 -> a)

Function to evaluate the element at an index.

-> Int#

Width of the whole array.

-> Int#

x0 lower left corner of block to fill

-> Int#

y0

-> Int#

w0 width of block to fill.

-> Int#

h0 height of block to fill.

-> IO () 

Fill a block in a rank-2 array in parallel.

  • Blockwise filling can be more cache-efficient than linear filling for rank-2 arrays.
  • Coordinates given are of the filled edges of the block.
  • We divide the block into columns, and give one column to each thread.
  • Each column is filled in row major order from top to bottom.

fillBlock2S #

Arguments

:: (Int -> a -> IO ())

Update function to write into result buffer.

-> (DIM2 -> a)

Fn to get the value at the given index.

-> Int#

Width of the whole array.

-> Int#

x0 lower left corner of block to fill.

-> Int#

y0

-> Int#

w0 width of block to fill

-> Int#

h0 height of block to fill

-> IO () 

Fill a block in a rank-2 array, sequentially.

  • Blockwise filling can be more cache-efficient than linear filling for rank-2 arrays.
  • The block is filled in row major order from top to bottom.

Cursored blockwise filling

fillCursoredBlock2S #

Arguments

:: Elt a 
=> (Int -> a -> IO ())

Update function to write into result buffer.

-> (DIM2 -> cursor)

Make a cursor to a particular element.

-> (DIM2 -> cursor -> cursor)

Shift the cursor by an offset.

-> (cursor -> a)

Function to evaluate an element at the given index.

-> Int#

Width of the whole array.

-> Int#

x0 lower left corner of block to fill.

-> Int#

y0

-> Int#

w0 width of block to fill

-> Int#

h0 height of block to fill

-> IO () 

Fill a block in a rank-2 array, sequentially.

  • Blockwise filling can be more cache-efficient than linear filling for rank-2 arrays.
  • Using cursor functions can help to expose inter-element indexing computations to the GHC and LLVM optimisers.
  • Coordinates given are of the filled edges of the block.
  • The block is filled in row major order from top to bottom.

fillCursoredBlock2P #

Arguments

:: Elt a 
=> (Int -> a -> IO ())

Update function to write into result buffer.

-> (DIM2 -> cursor)

Make a cursor to a particular element.

-> (DIM2 -> cursor -> cursor)

Shift the cursor by an offset.

-> (cursor -> a)

Function to evaluate the element at an index.

-> Int#

Width of the whole array.

-> Int#

x0 lower left corner of block to fill

-> Int#

y0

-> Int#

w0 width of block to fill

-> Int#

h0 height of block to fill

-> IO () 

Fill a block in a rank-2 array in parallel.

  • Blockwise filling can be more cache-efficient than linear filling for rank-2 arrays.
  • Using cursor functions can help to expose inter-element indexing computations to the GHC and LLVM optimisers.
  • Coordinates given are of the filled edges of the block.
  • We divide the block into columns, and give one column to each thread.
  • Each column is filled in row major order from top to bottom.

Chunked selection

selectChunkedS #

Arguments

:: Shape sh 
=> (sh -> a -> IO ())

Update function to write into result.

-> (sh -> Bool)

See if this predicate matches.

-> (sh -> a)

.. and apply fn to the matching index

-> sh

Extent of indices to apply to predicate.

-> IO Int

Number of elements written to destination array.

Select indices matching a predicate.

  • This primitive can be useful for writing filtering functions.

selectChunkedP #

Arguments

:: Unbox a 
=> (Int -> Bool)

See if this predicate matches.

-> (Int -> a) 
-> Int 
-> IO [IOVector a] 

Select indices matching a predicate, in parallel.

  • This primitive can be useful for writing filtering functions.
  • The array is split into linear chunks, with one chunk being given to each thread.
  • The number of elements in the result array depends on how many threads you're running the program with.