AccelerateHS / AccelerateHS/accelerate

Fusion causes work duplication

Đang mở
#116 6 bình luận 0 reaction 1 người được giao Được @tmcdonell nhận Xem trên GitHub
Ngôn ngữ chính
Haskell
Star
1k
Fork
135
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

``` 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.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.