diku-dk / futhark

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

Support for Unsafe UpdateAcc #2127

Closed sortraev closed 7 months ago

sortraev commented 8 months ago

Adds support for unsafe UpdateAcc ops, to omit boundary checks on the accumulator in cases where the indices are known (or assumed) to always be within bounds. The initial motivation was to use WithAcc to read block/register tiles from global to shared memory in the (WIP) tensor contraction tiling, wherein I would like to handle boundaries manually (if at all).

In most places, I simply took inspiration from the existing Update cases.

TODOs: 1) In those places in the compiler where UpdateAcc ops are passed along, I simply pass on the existing Safety information. I cannot discern whether there may be cases where an optimization or transformation enables or necessitates changing the Safety, so I hope someone will look into this before merging. 2) In those places in e.g. AD where new UpdateAccs are created, I used Safe safety to preserve behavior, but it may or may not be beneficial to substitute Unsafe in certain places. 3) I am not familiar with Megaparsec, so I simply copy+pasted the current rule for UpdateAcc in IR.Parse (and IR.Pretty).

athas commented 8 months ago

Regarding point (1), since you only ever create Safe UpdateAccs, propagation should maintain the current behaviour, which is therefore correct.

Using Unsafe where appropriate in AD can be done later.

athas commented 7 months ago

Is this still WIP or can it be merged?

sortraev commented 7 months ago

As far as I'm concerned, it is ready to merge, yes!