AccelerateHS / AccelerateHS/accelerate
Fusion causes work duplication
- Dominant language
- Haskell
- Stars
- 1k
- Forks
- 135
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.