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 109 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
109 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
3912379
Merge branch 'master' into flattening
athas Dec 4, 2024
be27284
Strangle some warnings.
athas Dec 4, 2024
f71c51e
Merge branch 'master' into flattening
athas Dec 6, 2024
41f7431
Merge branch 'master' into flattening
athas Dec 6, 2024
332c83b
Embellish comment.
athas Dec 6, 2024
76439b4
Style fixes.
athas Dec 6, 2024
25fc164
Reverse the regular dimensions here.
athas Dec 6, 2024
0ded15d
Progress.
athas Dec 11, 2024
f0782fb
Finally fix this demon.
athas Dec 11, 2024
9e5a132
Kill warnings.
athas Dec 16, 2024
cfb0cf5
Flatten concat (#2215)
athas Jan 28, 2025
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 @@ -390,6 +390,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.KernelBabysitting
Futhark.Pass.LiftAllocations
Futhark.Pass.LowerAllocations
Expand Down Expand Up @@ -491,6 +494,7 @@ library
, lsp >= 1.5.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
15 changes: 7 additions & 8 deletions src/Futhark/AD/Rev/Scan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mkScanFusedMapLam ops w scn_lam xs ys ys_adj s d = do
( buildBody_ $ do
j <- letSubExp "j" =<< toExp (pe64 w - (le64 i + 1))
y_s <- forM ys_adj $ \y_ ->
letSubExp (baseString y_ ++ "_j") =<< eIndex y_ (eSubExp j)
letSubExp (baseString y_ ++ "_j") =<< eIndex y_ [eSubExp j]
let zso = orderArgs s y_s
let ido = orderArgs s $ case_jac k sc idmat
pure $ subExpsRes $ concat $ zipWith (++) zso $ fmap concat ido
Expand All @@ -89,10 +89,10 @@ mkScanFusedMapLam ops w scn_lam xs ys ys_adj s d = do
j <- letSubExp "j" =<< toExp (pe64 w - (le64 i + 1))
j1 <- letSubExp "j1" =<< toExp (pe64 w - le64 i)
y_s <- forM ys_adj $ \y_ ->
letSubExp (baseString y_ ++ "_j") =<< eIndex y_ (eSubExp j)
letSubExp (baseString y_ ++ "_j") =<< eIndex y_ [eSubExp j]

let args =
map (`eIndex` eSubExp j) ys ++ map (`eIndex` eSubExp j1) xs
map (`eIndex` [eSubExp j]) ys ++ map (`eIndex` [eSubExp j1]) xs
lam_rs <- traverse (`eLambda` args) lams

let yso = orderArgs s $ subExpsRes y_s
Expand Down Expand Up @@ -171,7 +171,7 @@ mkScanFinalMap ops w scan_lam xs ys ds = do

dj <-
traverse
(\dd -> letExp (baseString dd ++ "_dj") =<< eIndex dd (eSubExp j))
(\dd -> letExp (baseString dd ++ "_dj") =<< eIndex dd [eSubExp j])
ds

fmap varsRes . letTupExp "scan_contribs"
Expand All @@ -182,9 +182,8 @@ mkScanFinalMap ops w scan_lam xs ys ds = do
lam <- mkScanAdjointLam ops scan_lam WrtSecond $ fmap Var dj

im1 <- letSubExp "im1" =<< toExp (le64 i - 1)
ys_im1 <- forM ys $ \y -> do
y_t <- lookupType y
letSubExp (baseString y ++ "_last") $ BasicOp $ Index y $ fullSlice y_t [DimFix im1]
ys_im1 <- forM ys $ \y ->
letSubExp (baseString y <> "_im1") =<< eIndex y [eSubExp im1]

let args = map eSubExp $ ys_im1 ++ map (Var . paramName) par_x
eLambda lam args
Expand Down Expand Up @@ -341,5 +340,5 @@ diffScanAdd _ops ys n lam' ne as = do
mkLambda [par_i] $ do
a <-
letExp "ys_bar_rev"
=<< eIndex arr (toExp (pe64 n - le64 (paramName par_i) - 1))
=<< eIndex arr [toExp (pe64 n - le64 (paramName par_i) - 1)]
pure [varRes a]
2 changes: 2 additions & 0 deletions src/Futhark/CLI/Dev.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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.KernelBabysitting
import Futhark.Pass.LiftAllocations as LiftAllocations
import Futhark.Pass.LowerAllocations as LowerAllocations
Expand Down Expand Up @@ -605,6 +606,7 @@ commandLineOptions =
kernelsPassOption sinkGPU [],
kernelsPassOption reduceDeviceSyncs [],
typedPassOption soacsProg GPU extractKernels [],
typedPassOption soacsProg GPU flattenSOACs [],
typedPassOption soacsProg MC extractMulticore [],
iplOption [],
allocateOption "a",
Expand Down
10 changes: 5 additions & 5 deletions src/Futhark/Construct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ eOutOfBounds arr is = do
foldBinOp LogOr (constant False) =<< zipWithM checkDim ws is'

-- | The array element at this index.
eIndex :: MonadBuilder m => VName -> m (Exp (Rep m)) -> m (Exp (Rep m))
eIndex arr i = do
i' <- letSubExp "i" =<< i
eIndex :: MonadBuilder m => VName -> [m (Exp (Rep m))] -> m (Exp (Rep m))
eIndex arr is = do
is' <- mapM (letSubExp "i" =<<) is
arr_t <- lookupType arr
pure $ BasicOp $ Index arr $ fullSlice arr_t [DimFix i']
pure $ BasicOp $ Index arr $ fullSlice arr_t $ map DimFix is'

-- | The last element of the given array.
eLast :: MonadBuilder m => VName -> m (Exp (Rep m))
Expand All @@ -430,7 +430,7 @@ eLast arr = do
nm1 <-
letSubExp "nm1" . BasicOp $
BinOp (Sub Int64 OverflowUndef) n (intConst Int64 1)
eIndex arr (eSubExp nm1)
eIndex arr [eSubExp nm1]

-- | Construct an unspecified value of the given type.
eBlank :: MonadBuilder m => Type -> m (Exp (Rep m))
Expand Down
6 changes: 3 additions & 3 deletions src/Futhark/IR/TypeCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,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 @@ -1276,8 +1276,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