Skip to content

Commit

Permalink
Parallelise nested concats.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Jan 5, 2018
1 parent c5b0192 commit cbc2cea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* `futhark-bench`: Add ``--skip-compilation`` flag.

* `scatter` expressions nested in `map`s are now parallelised.

### Removed

* `futhark-dataset`: Removed `--binary-no-header` and
Expand Down
14 changes: 14 additions & 0 deletions src/Futhark/Pass/ExtractKernels.hs
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,20 @@ maybeDistributeStm bnd@(Let _ aux (BasicOp (Reshape reshape _))) acc =
map DimNew (newDims reshape)
addKernel $ oneStm $ Let outerpat aux $ BasicOp $ Reshape reshape' arr

maybeDistributeStm stm@(Let _ aux (BasicOp (Concat d _ _ w))) acc =
distributeSingleStm acc stm >>= \case
Just (kernels, _, nest, acc')
| (outer, _) <- nest,
x:xs <- map snd $ loopNestingParamsAndArrs outer ->
localScope (typeEnvFromKernelAcc acc') $ do
let d' = d + length (snd nest) + 1
outerpat = loopNestingPattern $ fst nest
addKernels kernels
addKernel $ oneStm $ Let outerpat aux $ BasicOp $ Concat d' x xs w
return acc'
_ ->
addStmToKernel stm acc

maybeDistributeStm bnd acc =
addStmToKernel bnd acc

Expand Down
9 changes: 9 additions & 0 deletions tests/distribution/segconcat0.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Nested concatenation just becomes a concatenation along an inner dimension.
-- ==
-- input { [[1,2,3],[4,5,6]] [[3,2,1],[6,5,4]] }
-- output { [[1,2,3,3,2,1],
-- [4,5,6,6,5,4]] }
-- structure distributed { Kernel 0 }

let main (xss: [][]i32) (yss: [][]i32) =
map (\(xs, ys) -> concat xs ys) (zip xss yss)
8 changes: 8 additions & 0 deletions tests/distribution/segconcat1.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Nested concatenation with more arrays.
-- ==
-- input { [[1,2],[3,4],[5,6]] [[1,2],[3,4],[5,6]] [[1,2],[3,4],[5,6]] }
-- output { [[1,2,1,2,1,2], [3,4,3,4,3,4], [5,6,5,6,5,6]] }
-- structure distributed { Kernel 0 }

let main (xss: [][]i32) (yss: [][]i32) (zss: [][]i32) =
map (\(xs, ys, zs) -> concat xs ys zs) (zip xss yss zss)

0 comments on commit cbc2cea

Please sign in to comment.