AccelerateHS / AccelerateHS/accelerate
Fusion causes work duplication
- Langage dominant
- Haskell
- Étoiles
- 1k
- Forks
- 135
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
``` Haskell
work_dup :: Acc (Vector Int) -> Acc (Vector Int)
work_dup xs = A.generate (index1 (A.size xs * 4)) g
where
g ix = ys A.! index1 (unindex1 ix `div` 4)
ys = A.map f xs
f x = A.iterate x (\i -> i * i) x -- An operation with high cost
```
After fusion, the above becomes this:
``` Haskell
\a0 -> generate
(Z :. 4 * (shapeSize ((shape a0))))
(\x0 -> let x1 = a0!(Z :. div (indexHead x0,4))
in #0 (while (\x2 -> (#1 x2) <* x1)
(\x2 -> (1 + (#1 x2)
,let x3 = #0 x2
in x3 * x3))
(0,x1)))
```
By fusing the map into the generate here, `f` is being executed 4 times as often as it would have been without the fusion. In general, I'm not sure we should be fusing producers into generates as there is no guarantee that the array being indexed is not being indexed at the same index multiple times.
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.