repa 3.1.3.3 → 3.1.4.1
raw patch · 9 files changed
+229/−85 lines, 9 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Array.Repa.Repr.Hint: data S r1
- Data.Array.Repa.Repr.Hint: hintSmall :: Array r1 sh e -> Array (S r1) sh e
- Data.Array.Repa.Repr.Hint: instance (Shape sh, Fill r1 r2 sh e) => Fill (S r1) r2 sh e
- Data.Array.Repa.Repr.Hint: instance (Shape sh, FillRange r1 r2 sh e) => FillRange (S r1) r2 sh e
- Data.Array.Repa.Repr.Hint: instance Read (Array r1 sh e) => Read (Array (S r1) sh e)
- Data.Array.Repa.Repr.Hint: instance Repr r1 a => Repr (S r1) a
- Data.Array.Repa.Repr.Hint: instance Show (Array r1 sh e) => Show (Array (S r1) sh e)
+ Data.Array.Repa.Eval: fillInterleavedP :: Int -> (Int -> a -> IO ()) -> (Int -> a) -> IO ()
+ Data.Array.Repa.Repr.HintInterleave: data I r1
+ Data.Array.Repa.Repr.HintInterleave: hintInterleave :: Array r1 sh e -> Array (I r1) sh e
+ Data.Array.Repa.Repr.HintInterleave: instance (Shape sh, Fill D r2 sh e) => Fill (I D) r2 sh e
+ Data.Array.Repa.Repr.HintInterleave: instance Read (Array r1 sh e) => Read (Array (I r1) sh e)
+ Data.Array.Repa.Repr.HintInterleave: instance Repr r1 a => Repr (I r1) a
+ Data.Array.Repa.Repr.HintInterleave: instance Show (Array r1 sh e) => Show (Array (I r1) sh e)
+ Data.Array.Repa.Repr.HintSmall: data S r1
+ Data.Array.Repa.Repr.HintSmall: hintSmall :: Array r1 sh e -> Array (S r1) sh e
+ Data.Array.Repa.Repr.HintSmall: instance (Shape sh, Fill r1 r2 sh e) => Fill (S r1) r2 sh e
+ Data.Array.Repa.Repr.HintSmall: instance (Shape sh, FillRange r1 r2 sh e) => FillRange (S r1) r2 sh e
+ Data.Array.Repa.Repr.HintSmall: instance Read (Array r1 sh e) => Read (Array (S r1) sh e)
+ Data.Array.Repa.Repr.HintSmall: instance Repr r1 a => Repr (S r1) a
+ Data.Array.Repa.Repr.HintSmall: instance Show (Array r1 sh e) => Show (Array (S r1) sh e)
Files
- Data/Array/Repa.hs +9/−4
- Data/Array/Repa/Eval.hs +4/−0
- Data/Array/Repa/Eval/Interleaved.hs +56/−0
- Data/Array/Repa/Operators/Mapping.hs +1/−1
- Data/Array/Repa/Repr/Hint.hs +0/−76
- Data/Array/Repa/Repr/HintInterleave.hs +74/−0
- Data/Array/Repa/Repr/HintSmall.hs +76/−0
- Data/Array/Repa/Stencil/Dim2.hs +5/−2
- repa.cabal +4/−2
Data/Array/Repa.hs view
@@ -22,9 +22,14 @@ -- -- * `P` -- Arrays that are partitioned into several representations. ----- * `S` -- Hints that computing this array is a small amount of work that should--- not be done in parallel.+-- * `S` -- Hints that computing this array is a small amount of work,+-- so computation should be sequential rather than parallel to avoid+-- scheduling overheads. -- +-- * `I` -- Hints that computing this array will be an unbalanced workload,+-- so computation of successive elements should be interleaved between+-- the processors+-- -- * `X` -- Arrays whose elements are all undefined. -- -- Array fusion is achieved via the delayed (`D`) and cursored (`C`)@@ -164,11 +169,11 @@ import Data.Array.Repa.Repr.Unboxed import Data.Array.Repa.Repr.ByteString import Data.Array.Repa.Repr.ForeignPtr-import Data.Array.Repa.Repr.Hint+import Data.Array.Repa.Repr.HintSmall+import Data.Array.Repa.Repr.HintInterleave import Data.Array.Repa.Repr.Cursored import Data.Array.Repa.Repr.Partitioned import Data.Array.Repa.Repr.Undefined ()-import Data.Array.Repa.Repr.Hint import Data.Array.Repa.Operators.Mapping import Data.Array.Repa.Operators.Traversal import Data.Array.Repa.Operators.IndexSpace
Data/Array/Repa/Eval.hs view
@@ -21,6 +21,9 @@ , fillChunkedP , fillChunkedIOP + -- * Interleaved filling+ , fillInterleavedP+ -- * Blockwise filling , fillBlock2P , fillBlock2S@@ -36,6 +39,7 @@ import Data.Array.Repa.Eval.Elt import Data.Array.Repa.Eval.Fill import Data.Array.Repa.Eval.Chunked+import Data.Array.Repa.Eval.Interleaved import Data.Array.Repa.Eval.Cursored import Data.Array.Repa.Eval.Selection import Data.Array.Repa.Repr.Delayed
+ Data/Array/Repa/Eval/Interleaved.hs view
@@ -0,0 +1,56 @@+{-# LANGUAGE MagicHash #-}+-- | Evaluate an array in parallel in an interleaved fashion,+-- with each by having each processor computing alternate elements.+module Data.Array.Repa.Eval.Interleaved+ ( fillInterleavedP)+where+import Data.Array.Repa.Eval.Gang+import GHC.Exts+import Prelude as P+++-- | Fill something in parallel.+-- +-- * The array is split into linear chunks and each thread fills one chunk.+-- +fillInterleavedP+ :: 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 ()++{-# INLINE [0] fillInterleavedP #-}+fillInterleavedP !(I# len) write getElem+ = gangIO theGang+ $ \(I# thread) -> + let !step = threads+ !start = thread+ !count = elemsForThread thread+ in fill step start count++ where+ -- Decide now to split the work across the threads.+ !(I# threads) = gangSize theGang++ -- All threads get this many elements.+ !chunkLenBase = len `quotInt#` threads++ -- Leftover elements to divide between first few threads.+ !chunkLenSlack = len `remInt#` threads++ -- How many elements to compute with this thread.+ elemsForThread thread+ | thread <# chunkLenSlack = chunkLenBase +# 1#+ | otherwise = chunkLenBase+ {-# INLINE elemsForThread #-}++ -- Evaluate the elements of a single chunk.+ fill !step !ix0 !count0+ = go ix0 count0+ where+ go !ix !count+ | count <=# 0# = return ()+ | otherwise+ = do write (I# ix) (getElem (I# ix))+ go (ix +# step) (count -# 1#)+ {-# INLINE fill #-}
Data/Array/Repa/Operators/Mapping.hs view
@@ -15,7 +15,7 @@ import Data.Array.Repa.Repr.Cursored import Data.Array.Repa.Repr.Delayed import Data.Array.Repa.Repr.ForeignPtr-import Data.Array.Repa.Repr.Hint+import Data.Array.Repa.Repr.HintSmall import Data.Array.Repa.Repr.Partitioned import Data.Array.Repa.Repr.Unboxed import Data.Array.Repa.Repr.Undefined
− Data/Array/Repa/Repr/Hint.hs
@@ -1,76 +0,0 @@--module Data.Array.Repa.Repr.Hint- (S, Array (..), hintSmall)-where-import Data.Array.Repa.Base-import Data.Array.Repa.Eval.Fill-import Data.Array.Repa.Shape---- | Hints that evaluating this array is only a small amount of work.--- It will be evaluated sequentially in the main thread, instead of--- in parallel on the gang. This avoids the associated scheduling overhead.-data S r1--data instance Array (S r1) sh e- = ASmall !(Array r1 sh e)--deriving instance Show (Array r1 sh e) - => Show (Array (S r1) sh e)--deriving instance Read (Array r1 sh e) - => Read (Array (S r1) sh e)----- | Wrap an array with a smallness hint.-hintSmall :: Array r1 sh e -> Array (S r1) sh e-hintSmall = ASmall---instance Repr r1 a => Repr (S r1) a where- extent (ASmall arr) - = extent arr- {-# INLINE extent #-}-- index (ASmall arr) ix- = index arr ix- {-# INLINE index #-}-- unsafeIndex (ASmall arr) ix- = unsafeIndex arr ix- {-# INLINE unsafeIndex #-}-- linearIndex (ASmall arr) ix- = linearIndex arr ix- {-# INLINE linearIndex #-}-- unsafeLinearIndex (ASmall arr) ix- = unsafeLinearIndex arr ix- {-# INLINE unsafeLinearIndex #-}-- deepSeqArray (ASmall arr) x- = deepSeqArray arr x- {-# INLINE deepSeqArray #-}----- Fill ------------------------------------------------------------------------instance ( Shape sh, Fill r1 r2 sh e) - => Fill (S r1) r2 sh e where- fillP (ASmall arr) marr- = fillS arr marr- {-# INLINE fillP #-}-- fillS (ASmall arr) marr- = fillS arr marr- {-# INLINE fillS #-}----- FillRange -------------------------------------------------------------------instance ( Shape sh, FillRange r1 r2 sh e)- => FillRange (S r1) r2 sh e where- fillRangeP (ASmall arr) marr ix1 ix2- = fillRangeS arr marr ix1 ix2- {-# INLINE fillRangeP #-}-- fillRangeS (ASmall arr) marr ix1 ix2- = fillRangeS arr marr ix1 ix2- {-# INLINE fillRangeS #-}
+ Data/Array/Repa/Repr/HintInterleave.hs view
@@ -0,0 +1,74 @@++module Data.Array.Repa.Repr.HintInterleave+ (I, Array (..), hintInterleave)+where+import Data.Array.Repa.Eval.Fill+import Data.Array.Repa.Eval.Interleaved+import Data.Array.Repa.Repr.Delayed+import Data.Array.Repa.Shape+import Data.Array.Repa.Base+import Debug.Trace+++-- | Hints that computing this array will be an unbalanced workload+-- and evaluation should be interleaved between the processors.+data I r1++data instance Array (I r1) sh e+ = AInterleave !(Array r1 sh e)++deriving instance Show (Array r1 sh e) + => Show (Array (I r1) sh e)++deriving instance Read (Array r1 sh e) + => Read (Array (I r1) sh e)+++-- | Wrap an array with a unbalanced-ness hint.+hintInterleave :: Array r1 sh e -> Array (I r1) sh e+hintInterleave = AInterleave+++instance Repr r1 a => Repr (I r1) a where+ extent (AInterleave arr) + = extent arr+ {-# INLINE extent #-}++ index (AInterleave arr) ix+ = index arr ix+ {-# INLINE index #-}++ unsafeIndex (AInterleave arr) ix+ = unsafeIndex arr ix+ {-# INLINE unsafeIndex #-}++ linearIndex (AInterleave arr) ix+ = linearIndex arr ix+ {-# INLINE linearIndex #-}++ unsafeLinearIndex (AInterleave arr) ix+ = unsafeLinearIndex arr ix+ {-# INLINE unsafeLinearIndex #-}++ deepSeqArray (AInterleave arr) x+ = deepSeqArray arr x+ {-# INLINE deepSeqArray #-}+++-- Fill -----------------------------------------------------------------------+instance ( Shape sh, Fill D r2 sh e) + => Fill (I D) r2 sh e where+ fillP (AInterleave (ADelayed sh getElem)) marr+ = marr `deepSeqMArr`+ do traceEventIO "Repa.fillP[Interleaved]: start"+ fillInterleavedP (size sh) (unsafeWriteMArr marr) (getElem . fromIndex sh) + touchMArr marr+ traceEventIO "Repa.fillP[Interleaved]: end"+ {-# INLINE [4] fillP #-}++ -- The fact that the workload is unbalanced doesn't affect us when the+ -- program is run sequentially, so just use the filling method of the inner+ -- representation+ fillS (AInterleave arr) marr+ = fillS arr marr+ {-# INLINE fillS #-}
+ Data/Array/Repa/Repr/HintSmall.hs view
@@ -0,0 +1,76 @@++module Data.Array.Repa.Repr.HintSmall+ (S, Array (..), hintSmall)+where+import Data.Array.Repa.Base+import Data.Array.Repa.Eval.Fill+import Data.Array.Repa.Shape++-- | Hints that evaluating this array is only a small amount of work.+-- It will be evaluated sequentially in the main thread, instead of+-- in parallel on the gang. This avoids the associated scheduling overhead.+data S r1++data instance Array (S r1) sh e+ = ASmall !(Array r1 sh e)++deriving instance Show (Array r1 sh e) + => Show (Array (S r1) sh e)++deriving instance Read (Array r1 sh e) + => Read (Array (S r1) sh e)+++-- | Wrap an array with a smallness hint.+hintSmall :: Array r1 sh e -> Array (S r1) sh e+hintSmall = ASmall+++instance Repr r1 a => Repr (S r1) a where+ extent (ASmall arr) + = extent arr+ {-# INLINE extent #-}++ index (ASmall arr) ix+ = index arr ix+ {-# INLINE index #-}++ unsafeIndex (ASmall arr) ix+ = unsafeIndex arr ix+ {-# INLINE unsafeIndex #-}++ linearIndex (ASmall arr) ix+ = linearIndex arr ix+ {-# INLINE linearIndex #-}++ unsafeLinearIndex (ASmall arr) ix+ = unsafeLinearIndex arr ix+ {-# INLINE unsafeLinearIndex #-}++ deepSeqArray (ASmall arr) x+ = deepSeqArray arr x+ {-# INLINE deepSeqArray #-}+++-- Fill -----------------------------------------------------------------------+instance ( Shape sh, Fill r1 r2 sh e) + => Fill (S r1) r2 sh e where+ fillP (ASmall arr) marr+ = fillS arr marr+ {-# INLINE fillP #-}++ fillS (ASmall arr) marr+ = fillS arr marr+ {-# INLINE fillS #-}+++-- FillRange ------------------------------------------------------------------+instance ( Shape sh, FillRange r1 r2 sh e)+ => FillRange (S r1) r2 sh e where+ fillRangeP (ASmall arr) marr ix1 ix2+ = fillRangeS arr marr ix1 ix2+ {-# INLINE fillRangeP #-}++ fillRangeS (ASmall arr) marr ix1 ix2+ = fillRangeS arr marr ix1 ix2+ {-# INLINE fillRangeS #-}
Data/Array/Repa/Stencil/Dim2.hs view
@@ -18,10 +18,13 @@ -- * Stencil operators , PC5, mapStencil2, forStencil2) where-import Data.Array.Repa+import Data.Array.Repa.Base+import Data.Array.Repa.Index+import Data.Array.Repa.Shape+import Data.Array.Repa.Repr.Delayed import Data.Array.Repa.Repr.Cursored import Data.Array.Repa.Repr.Partitioned-import Data.Array.Repa.Repr.Hint+import Data.Array.Repa.Repr.HintSmall import Data.Array.Repa.Repr.Undefined import Data.Array.Repa.Stencil.Base import Data.Array.Repa.Stencil.Template
repa.cabal view
@@ -1,5 +1,5 @@ Name: repa-Version: 3.1.3.3+Version: 3.1.4.1 License: BSD3 License-file: LICENSE Author: The DPH Team@@ -61,7 +61,8 @@ Data.Array.Repa.Repr.Cursored Data.Array.Repa.Repr.Delayed Data.Array.Repa.Repr.ForeignPtr- Data.Array.Repa.Repr.Hint+ Data.Array.Repa.Repr.HintSmall+ Data.Array.Repa.Repr.HintInterleave Data.Array.Repa.Repr.Partitioned Data.Array.Repa.Repr.Unboxed Data.Array.Repa.Repr.Undefined@@ -79,6 +80,7 @@ Other-modules: Data.Array.Repa.Eval.Chunked Data.Array.Repa.Eval.Cursored+ Data.Array.Repa.Eval.Interleaved Data.Array.Repa.Eval.Elt Data.Array.Repa.Eval.Fill Data.Array.Repa.Eval.Reduction