Loop unrolling + fusion ?

Max Bolingbroke batterseapower at hotmail.com
Thu Mar 19 04:37:43 EDT 2009

2009/3/19 Claus Reinke <claus.reinke at talk21.com>:
> If the map, filter, fold, etc can be unrolled, then the unrolled
> definitions would be fused, right? So what is missing is fine
> control ("how much to unroll this particular call to map here").

The issues is that In stream fusion the combinators like "map" are all
non-recursive and so unrolling/peeling doesn't make any sense. In
fact, their being non-recursive is almost the whole point, because it
lets GHC inline them like crazy and hence build a nice efficient fused
pipeline of combinators eventually. The recursion is introduced purely
in one place - unstream - and even then it doesn't go through unstream
but through a locally recursive wrapper (so GHC can see the structure
of the stream).

So, it might be sufficient if:
1) You changed stream fusion so unstream was directly recursive, but
added an INLINE PEEL 1 annotation to it, so if the call site doesn't
do any unrollling at least you will still be able to spot the
structure of the stream
2) You could, at the call site, add an INLINE PEEL 1 UNROLL n
annotation that took the /original/ RHS for unstream and unrolled it
however many times the user specifies (you still need a PEEL 1 so you
can spot the stream structure in the unrolled loop)

Unfortunately, this all feels quite fragile :-(


More information about the Glasgow-haskell-users mailing list