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

Implementation of irregular flattening #1740

Draft
wants to merge 98 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
2576b2e
wip
athas Oct 14, 2022
ec42c3a
Merge branch 'master' into flattening
athas Oct 22, 2022
f871257
More half-baked work.
athas Nov 3, 2022
23269ab
Merge branch 'master' into flattening
athas Nov 4, 2022
8c87f3e
Fix offset calculation.
athas Nov 6, 2022
eb10d91
Fix some things.
athas Nov 13, 2022
7fe28ad
Merge branch 'master' into flattening
athas Nov 16, 2022
d58ba99
Use full flattening in GPU pipelines.
athas Nov 16, 2022
138ceca
Irregular slice now works.
athas Nov 16, 2022
8e946a2
This always works.
athas Nov 16, 2022
fb21c05
Reshape and further Index fixes.
athas Nov 16, 2022
35669f9
Handle the most general case of Iota.
athas Nov 16, 2022
f2a79e4
Remove some warnings.
athas Nov 16, 2022
1682d88
More foldable.
athas Nov 16, 2022
ef35b71
Hacky initial support for flattening nested maps.
athas Nov 17, 2022
d2d7c7f
Flatten redomaps.
athas Nov 18, 2022
e9f778e
Merge branch 'master' into flattening
athas Dec 19, 2022
2496205
Merge branch 'master' into flattening
athas Jan 4, 2023
4945cd1
starting out
CKuke Jan 10, 2023
1e801d9
[WIP] `Update` flattening case
cornelius-sevald Jan 11, 2023
3fc3e0e
[WIP] Further work on `Update` flattening
cornelius-sevald Jan 13, 2023
ff6ceb3
test case
kaff3 Jan 16, 2023
c05cc91
update1 test update
CKuke Jan 16, 2023
1768e8f
Fix `Update` flattening for single dimension slice
cornelius-sevald Jan 16, 2023
31e86dd
Irregular flattening `Update` fixed dimension
cornelius-sevald Jan 16, 2023
effa353
[WIP] Unhandled multi-dim `Update` test case
cornelius-sevald Jan 16, 2023
6e35c60
Format code
cornelius-sevald Jan 16, 2023
19c0eea
Merge branch 'master' into flattening
athas Jan 18, 2023
1640e0f
Merge branch 'master' into flattening
athas Jan 18, 2023
1d303c0
Move `Update` tests to `tests/flattening/`
cornelius-sevald Jan 18, 2023
84e3e85
Fully flatten replicated `elemArr` result
cornelius-sevald Jan 18, 2023
d1caa94
More `Update` flattening tests
cornelius-sevald Jan 18, 2023
450a5d5
futhark implementation of rule
kaff3 Jan 18, 2023
ca0ddbb
Flatten `Update` fully irregular test case
cornelius-sevald Jan 18, 2023
1fe9ee8
More `Update` flattening test cases
cornelius-sevald Jan 18, 2023
e9bd637
updated futhark seg update
kaff3 Jan 19, 2023
5c7e039
Variant stride in `update_fully_irregular.fut` test
cornelius-sevald Jan 19, 2023
cf924d6
Rename variables
cornelius-sevald Jan 19, 2023
42237f2
Merge branch 'master' into flattening
athas Feb 1, 2023
e7b5536
Merge commit 'cf924d6d9777915dfd4032b2b34fd4be6dad7e92' into flattening
athas Feb 1, 2023
63cae72
Disable for now.
athas Feb 1, 2023
5b01fa1
Refactor to use readInputs.
athas Feb 1, 2023
49227a2
Refactor slightly.
athas Feb 1, 2023
8b916b3
Perhaps this makes multiple dimensions work.
athas Feb 1, 2023
211effa
Handle general Updates.
athas Feb 1, 2023
8d4ea72
Catch this error.
athas Feb 2, 2023
71da6de
Merge branch 'master' into flattening
athas Feb 17, 2023
9658a97
Handle array results.
athas Feb 17, 2023
7d264e4
Flattening of Copy.
athas Feb 17, 2023
7f53214
Merge branch 'master' into flattening
athas Feb 25, 2023
44c8439
Merge branch 'master' into flattening
athas Mar 15, 2023
f9e5bc6
Incomplete work on nested maps.
athas Mar 15, 2023
30583cd
More work on nested maps.
athas Mar 15, 2023
c63c1fa
Merge branch 'master' into flattening
athas Mar 20, 2023
fd9fc78
All these SegOps should be virtualised.
athas Mar 20, 2023
04a2baa
Merge branch 'master' into flattening
athas Mar 22, 2023
df5a916
Merge branch 'master' into flattening
athas Apr 13, 2023
1224c48
Merge branch 'master' into flattening
athas Apr 13, 2023
4674db5
More work, including nonfunctional test.
athas Apr 13, 2023
442975f
Merge branch 'master' into flattening
athas Apr 14, 2023
62f5612
Merge branch 'master' into flattening
athas Apr 15, 2023
5d6c27f
Start of work on Replicate.
athas Apr 15, 2023
29af946
Further work on replicate.
athas Apr 16, 2023
b7de81a
Merge branch 'master' into flattening
athas Apr 16, 2023
ffda3c8
More work; not really working.
athas Apr 18, 2023
3ef7442
Merge branch 'master' into flattening
athas Apr 30, 2023
7f72edd
Merge branch 'master' into flattening
athas May 17, 2023
70b904d
Merge branch 'master' into flattening
athas May 21, 2023
024e6c7
Handle free irregular arrays in nested map.
athas May 21, 2023
29dacc5
Another test.
athas May 22, 2023
2b5809b
Handle free irregular arrays in nested maps.
athas May 22, 2023
e0dc387
Merge branch 'master' into flattening
athas May 30, 2023
9c8351b
Handle distribution of free and identity results.
athas May 30, 2023
d112f20
Start function flattening (#1870)
cornelius-sevald Jun 15, 2023
c5d7c03
Merge branch 'master' into flattening
athas Jun 15, 2023
2e37824
Merge branch 'master' into flattening
athas Jul 11, 2023
03cb09e
Merge branch 'master' into flattening
athas Jul 18, 2023
cb277e0
Merge branch 'master' into flattening
athas Jul 18, 2023
76b90a8
Merge branch 'master' into flattening
athas Sep 16, 2023
d8ef766
Merge branch 'master' into flattening
athas Sep 16, 2023
acb7caf
Flattening rearranges.
athas Sep 16, 2023
d14cf71
Add failing test.
athas Sep 16, 2023
daaf815
Merge branch 'master' into flattening
athas Dec 17, 2023
4bdf0e3
Fix type annotation.
athas Dec 17, 2023
aae4bd1
Better test data.
athas Dec 17, 2023
068a16e
Fix typo.
athas Dec 17, 2023
647e4fe
This seems wrong.
athas Dec 17, 2023
8aff0d5
New formatting.
athas Dec 17, 2023
9738c47
Document nomenclature.
athas Dec 17, 2023
db81070
Use nomenclature.
athas Dec 17, 2023
eb443bb
Style fixes.
athas Dec 17, 2023
8c224e4
More nomenclature.
athas Dec 17, 2023
9871516
Revert "This seems wrong."
athas Dec 17, 2023
e7ea05c
Maybe like this.
athas Dec 17, 2023
533ada3
Merge branch 'master' into flattening
athas Dec 29, 2023
c8ba2a7
Merge branch 'master' into flattening
athas Apr 11, 2024
8fcf415
Merge branch 'master' into flattening
athas Jul 19, 2024
a711470
Merge branch 'master' into flattening
athas Nov 23, 2024
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
4 changes: 4 additions & 0 deletions futhark.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ library
Futhark.Pass.ExtractKernels.ToGPU
Futhark.Pass.ExtractMulticore
Futhark.Pass.FirstOrderTransform
Futhark.Pass.Flatten
Futhark.Pass.Flatten.Builtins
Futhark.Pass.Flatten.Distribute
Futhark.Pass.LiftAllocations
Futhark.Pass.LowerAllocations
Futhark.Pass.Simplify
Expand Down Expand Up @@ -475,6 +478,7 @@ library
, lsp-types >= 2.0.1.0
, mainland-pretty >=0.7.1
, cmark-gfm >=0.2.1
, OneTuple
, megaparsec >=9.0.0
, mtl >=2.2.1
, neat-interpolation >=0.3
Expand Down
36 changes: 36 additions & 0 deletions rewritefut/segupdate.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- Flat-Parallel Segmented Update
-- ==
-- compiled input { [1i64,2i64,3i64,1i64,2i64,1i64,2i64,3i64,4i64] [3i64,2i64,4i64] [0i64,0i64,0i64,0i64,0i64] [2i64,1i64,2i64] [0i64, 1i64, 0i64] [1i64, 1i64, 2i64] } output { [0i64,0i64,3i64,1i64,0i64,0i64,2i64,0i64,4i64] }

let sgmSumI64 [n] (flg : [n]i64) (arr : [n]i64) : [n]i64 =
let flgs_vals =
scan ( \ (f1, x1) (f2,x2) ->
let f = f1 | f2 in
if f2 != 0 then (f, x2)
else (f, x1 + x2) )
(0, 0i64) (zip flg arr)
let (_, vals) = unzip flgs_vals
in vals

let mkFlagArray [m] (aoa_shp: [m]i64) (zero: i64)
(aoa_val: [m]i64) : []i64 =
let shp_rot = map(\i -> if i==0i64 then 0i64 else aoa_shp[i-1]) (iota m)
let shp_scn = scan (+) 0i64 shp_rot
let aoa_len = shp_scn[m-1]+aoa_shp[m-1]
let shp_ind = map2 (\shp ind -> if shp==0 then -1i64 else ind) aoa_shp shp_scn
in scatter (replicate aoa_len zero) shp_ind aoa_val

let segUpdate [n][m][t] (xss_val : *[n]i64) (shp_xss : [t]i64) (vss_val : [m]i64)
(shp_vss : [t]i64) (bs : [t]i64) (ss : [t]i64): [n]i64 =
let fvss = (mkFlagArray shp_vss 0 (1...t :> [t]i64)) :> [m]i64
let II1 = sgmSumI64 fvss fvss |> map (\x -> x - 1)
let shp_xss_rot = map(\i -> if i==0i64 then 0i64 else shp_xss[i-1]) (iota t)
let bxss = scan (+) 0 shp_xss_rot
let II2 = sgmSumI64 fvss (replicate m 1) |> map (\x -> x - 1)
let iss = map (\i -> bxss[II1[i]] + bs[II1[i]] + (II2[i] * ss[II1[i]])) (iota m)
in scatter xss_val iss vss_val


let main [n][m][t] (xss_val : *[n]i64) (shp_xss : [t]i64) (vss_val : [m]i64)
(shp_vss : [t]i64) (bs : [t]i64) (ss : [t]i64): [n]i64 =
segUpdate xss_val shp_xss vss_val shp_vss bs ss
2 changes: 2 additions & 0 deletions src/Futhark/CLI/Dev.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Futhark.Pass.ExplicitAllocations.Seq qualified as Seq
import Futhark.Pass.ExtractKernels
import Futhark.Pass.ExtractMulticore
import Futhark.Pass.FirstOrderTransform
import Futhark.Pass.Flatten (flattenSOACs)
import Futhark.Pass.LiftAllocations as LiftAllocations
import Futhark.Pass.LowerAllocations as LowerAllocations
import Futhark.Pass.Simplify
Expand Down Expand Up @@ -654,6 +655,7 @@ commandLineOptions =
sinkOption [],
kernelsPassOption reduceDeviceSyncs [],
typedPassOption soacsProg GPU extractKernels [],
typedPassOption soacsProg GPU flattenSOACs [],
typedPassOption soacsProg MC extractMulticore [],
allocateOption "a",
kernelsMemPassOption doubleBufferGPU [],
Expand Down
1 change: 1 addition & 0 deletions src/Futhark/IR/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Futhark.IR.Pretty
( prettyTuple,
prettyTupleLines,
prettyString,
prettyRet,
PrettyRep (..),
)
where
Expand Down
12 changes: 6 additions & 6 deletions src/Futhark/IR/TypeCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import Futhark.Analysis.PrimExp
import Futhark.Construct (instantiateShapes)
import Futhark.IR.Aliases hiding (lookupAliases)
import Futhark.Util
import Futhark.Util.Pretty (align, docText, indent, ppTuple', pretty, (<+>), (</>))
import Futhark.Util.Pretty hiding (width)

-- | Information about an error during type checking. The 'Show'
-- instance for this type produces a human-readable description.
Expand Down Expand Up @@ -742,7 +742,7 @@ checkSubExp (Var ident) = context ("In subexp " <> prettyText ident) $ do
lookupType ident

checkCerts :: (Checkable rep) => Certs -> TypeM rep ()
checkCerts (Certs cs) = mapM_ (requireI [Prim Unit]) cs
checkCerts = mapM_ lookupType . unCerts

checkSubExpRes :: (Checkable rep) => SubExpRes -> TypeM rep Type
checkSubExpRes (SubExpRes cs se) = do
Expand Down Expand Up @@ -1023,9 +1023,9 @@ checkExp (Apply fname args rettype_annot _) = do
when (rettype_derived /= rettype_annot) $
bad . TypeError . docText $
"Expected apply result type:"
</> indent 2 (pretty $ map fst rettype_derived)
</> indent 2 (braces $ commasep $ map prettyRet rettype_derived)
</> "But annotation is:"
</> indent 2 (pretty $ map fst rettype_annot)
</> indent 2 (braces $ commasep $ map prettyRet rettype_annot)
consumeArgs paramtypes argflows
checkExp (Loop merge form loopbody) = do
let (mergepat, mergeexps) = unzip merge
Expand Down Expand Up @@ -1252,8 +1252,8 @@ checkStm ::
Stm (Aliases rep) ->
TypeM rep a ->
TypeM rep a
checkStm stm@(Let pat (StmAux (Certs cs) _ (_, dec)) e) m = do
context "When checking certificates" $ mapM_ (requireI [Prim Unit]) cs
checkStm stm@(Let pat (StmAux cs _ (_, dec)) e) m = do
context "When checking certificates" $ checkCerts cs
context "When checking expression annotation" $ checkExpDec dec
context ("When matching\n" <> message " " pat <> "\nwith\n" <> message " " e) $
matchPat pat e
Expand Down
4 changes: 4 additions & 0 deletions src/Futhark/Pass/ExtractKernels/ToGPU.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Futhark.Pass.ExtractKernels.ToGPU
segThread,
soacsLambdaToGPU,
soacsStmToGPU,
soacsExpToGPU,
scopeForGPU,
scopeForSOACs,
injectSOACS,
Expand Down Expand Up @@ -74,6 +75,9 @@ injectSOACS f =
soacsStmToGPU :: Stm SOACS -> Stm GPU
soacsStmToGPU = runIdentity . rephraseStm (injectSOACS OtherOp)

soacsExpToGPU :: Exp SOACS -> Exp GPU
soacsExpToGPU = runIdentity . rephraseExp (injectSOACS OtherOp)

soacsLambdaToGPU :: Lambda SOACS -> Lambda GPU
soacsLambdaToGPU = runIdentity . rephraseLambda (injectSOACS OtherOp)

Expand Down
Loading
Loading