Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fusion across slices. #2060

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
used in all public interfaces. The OpenCL names are still supported
for backwards compatibility.

* More fusion across array slicing.

### Removed

### Changed
Expand Down
24 changes: 10 additions & 14 deletions src/Futhark/IR/SOACS/SOAC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Futhark.IR.SOACS.SOAC
isScanSOAC,
isReduceSOAC,
isMapSOAC,
scremaLambda,
ppScrema,
ppHist,
ppStream,
Expand Down Expand Up @@ -143,11 +142,16 @@ data HistOp rep = HistOp

-- | The essential parts of a 'Screma' factored out (everything
-- except the input arrays).
data ScremaForm rep
= ScremaForm
[Scan rep]
[Reduce rep]
(Lambda rep)
data ScremaForm rep = ScremaForm
{ scremaScans :: [Scan rep],
scremaReduces :: [Reduce rep],
-- | The "main" lambda of the Screma. For a map, this is
-- equivalent to 'isMapSOAC'. Note that the meaning of the return
-- value of this lambda depends crucially on exactly which Screma
-- this is. The parameters will correspond exactly to elements of
-- the input arrays, however.
scremaLambda :: Lambda rep
}
deriving (Eq, Ord, Show)

singleBinOp :: (Buildable rep) => [Lambda rep] -> Lambda rep
Expand Down Expand Up @@ -316,14 +320,6 @@ isMapSOAC (ScremaForm scans reds map_lam) = do
guard $ null reds
pure map_lam

-- | Return the "main" lambda of the Screma. For a map, this is
-- equivalent to 'isMapSOAC'. Note that the meaning of the return
-- value of this lambda depends crucially on exactly which Screma this
-- is. The parameters will correspond exactly to elements of the
-- input arrays, however.
scremaLambda :: ScremaForm rep -> Lambda rep
scremaLambda (ScremaForm _ _ map_lam) = map_lam

-- | @groupScatterResults <output specification> <results>@
--
-- Blocks the index values and result values of <results> according to the
Expand Down
3 changes: 1 addition & 2 deletions src/Futhark/Optimise/Fusion/TryFusion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,10 @@ pullIndex ::
SOAC ->
SOAC.ArrayTransforms ->
TryFusion (SOAC, SOAC.ArrayTransforms)
pullIndex (SOAC.Screma w form inps) ots
pullIndex (SOAC.Screma _ form inps) ots
| SOAC.Index cs slice@(Slice (ds@(DimSlice _ w' _) : inner_ds))
SOAC.:< ots' <-
SOAC.viewf ots,
w /= w',
Just lam <- isMapSOAC form = do
let sliceInput inp =
SOAC.addTransform
Expand Down
4 changes: 4 additions & 0 deletions tests/fusion/slicemap4.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- ==
-- structure { Screma 1 }

def main (xs: []i32) = xs |> map (+2) |> reverse |> map (*3)