Fix fusion for sumPA
[packages/dph.git] / dph-lifted-vseg / Data / Array / Parallel / PArray / Sums.hs
1 {-# LANGUAGE CPP #-}
2 #include "fusion-phases.h"
3
4 module Data.Array.Parallel.PArray.Sums
5 ( sumPA_double, sumPA_l_double
6 , sumPA_int, sumPA_l_int)
7 where
8 import Data.Array.Parallel.PArray.PData
9 import qualified Data.Vector as V
10 import qualified Data.Array.Parallel.Unlifted as U
11
12
13 -- Double ---------------------------------------------------------------------
14 {-# INLINE_PA sumPA_double #-}
15 sumPA_double :: PArray Double -> Double
16 sumPA_double (PArray _ (PDouble xs))
17 = U.sum xs
18
19
20 -- | Lifted sum for Doubles
21 sumPA_l_double
22 :: Int
23 -> PData (PArray Double)
24 -> PData Double
25 {-# NOINLINE sumPA_l_double #-}
26 sumPA_l_double _ (PNested vsegd datas)
27 = {-# SCC "sumPA_l_double" #-}
28 let -- Grab all the flat source vectors.
29 !pdatas = V.map toUArrayPR datas
30
31 -- Sum up each physical segment individually.
32 !psegResults = U.fold_ss (+) 0 (U.takeSSegdOfVSegd vsegd) pdatas
33
34 -- Replicate the physical results according to the vsegids.
35 !vsegResults = U.bpermute psegResults (U.takeVSegidsOfVSegd vsegd)
36
37 in PDouble vsegResults
38
39
40
41 -- Int ------------------------------------------------------------------------
42 {-# INLINE_PA sumPA_int #-}
43 sumPA_int :: PArray Int -> Int
44 sumPA_int (PArray _ (PInt xs))
45 = U.sum xs
46
47
48 sumPA_l_int
49 :: Int
50 -> PData (PArray Int)
51 -> PData Int
52 {-# NOINLINE sumPA_l_int #-}
53 sumPA_l_int _ (PNested vsegd datas)
54 = {-# SCC "sumPA_l_int" #-}
55 let -- Grab all the flat source vectors.
56 pdatas = V.map toUArrayPR datas
57
58 -- Sum up each physical segment individually.
59 psegResults = U.fold_ss (+) 0 (U.takeSSegdOfVSegd vsegd) pdatas
60
61 -- Replicate the physical results according to the vsegids.
62 vsegResults = U.bpermute psegResults (U.takeVSegidsOfVSegd vsegd)
63
64 in PInt vsegResults