1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
module Data.Array.Repa.Repr.HintInterleave
(I, Array (..), hintInterleave)
where
import Data.Array.Repa.Eval.Load
import Data.Array.Repa.Eval.Target
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
instance Source r1 a => Source (I r1) a where
data Array (I r1) sh a
= AInterleave !(Array r1 sh a)
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 #-}
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
-- Load -----------------------------------------------------------------------
instance (Shape sh, Load D sh e)
=> Load (I D) sh e where
loadP (AInterleave (ADelayed sh getElem)) marr
= marr `deepSeqMVec`
do traceEventIO "Repa.loadP[Interleaved]: start"
fillInterleavedP (size sh) (unsafeWriteMVec marr) (getElem . fromIndex sh)
touchMVec marr
traceEventIO "Repa.loadP[Interleaved]: end"
{-# INLINE [4] loadP #-}
-- 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
loadS (AInterleave arr) marr
= loadS arr marr
{-# INLINE loadS #-}
|