diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.4k stars 167 forks source link

Fusion regression in sequential backend #1733

Closed Munksgaard closed 2 years ago

Munksgaard commented 2 years ago

The following code used to be fusable in the sequential (CPU) backend:

let main [n] (i: i64) (ns: [n]i32) (mss: [n][n]i32): [n][n]i32 =
  let t1 = map (map (+ 1)) mss

  let k = 1
  let t0 = map (+ k) ns

  let t1[i] = t0
  in t1

Running futhark-0.21.2 dev --seq-mem foo.fut results in just a single loop, whereas the latest master produces two loops.

athas commented 2 years ago

This is unrelated to the backend; we use the same fusion algorithm in all pipelines.

athas commented 2 years ago

I actually vaguely remember that this is intentional. We changed the fusion algorithm to only perform horizontal fusion on SOACs that have overlapping inputs.

athas commented 2 years ago

Yes, fixing it is straightforward. We'd just change the filter here:

https://github.com/diku-dk/futhark/blob/8f427635cba973516a0d76285a61741b8aa5f759/src/Futhark/Optimise/Fusion.hs#L121

But is that what we want?

athas commented 2 years ago

We discussed this yesterday and decided that the new fusion strategy is superior to the old overly-aggressive one.