Skip to content

Commit

Permalink
Merge branch 'master' into automap
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Dec 19, 2024
2 parents 8a23982 + 2920151 commit 22c9b1c
Show file tree
Hide file tree
Showing 27 changed files with 255 additions and 184 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Removed

### Changed

### Fixed

## [0.25.25]

### Added

* Improvements to `futhark fmt`.

### Fixed

* Sizes that go out of scope due to use of higher order functions will
Expand All @@ -19,7 +29,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Tracing inside AD operators with the interpreter now prints values
properly.

### Changed
* Compiled and interpreted code now have same treatment of inclusive
ranges with start==end and negative step size, e.g. `1..0...1`
produces `[1]` rather than an invalid range error.

* Inconsistent handling of types in lambda lifting (#2197).

* Invalid primal results from `vjp2` in interpreter (#2199).

## [0.25.24]

Expand Down
15 changes: 10 additions & 5 deletions docs/language-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -758,17 +758,22 @@ code.

Construct a signed integer array whose first element is ``x`` and
which proceeds with a stride of ``y-x`` until reaching ``z``
(inclusive). The ``..y`` part can be elided in which case a stride of
1 is used. A run-time error occurs if ``z`` is less than ``x`` or
``y``, or if ``x`` and ``y`` are the same value.
(inclusive). The ``..y`` part can be elided in which case a stride of
``1`` is used. All components must be of the same unsigned integer
type.

A run-time error occurs if ``z`` is less than ``x`` or ``y``, or if
``x`` and ``y`` are the same value.

In the general case, the size of the array produced by a range is
unknown (see `Size types`_). In a few cases, the size is known
statically:

* ``1..2...n`` has size ``n``
* ``0..<n`` has size ``n``.

This holds only if ``n`` is a variable or constant.
* ``0..1..<n`` has size ``n``.

* ``1..2...n`` has size ``n``

.. _range_upto:

Expand Down
6 changes: 3 additions & 3 deletions src/Futhark/AD/Fwd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ zeroFromSubExp (Var v) = do
letExp "zero" $ zeroExp t

fwdSOAC :: Pat Type -> StmAux () -> SOAC SOACS -> ADM ()
fwdSOAC pat aux (Screma size xs (ScremaForm scs reds f)) = do
fwdSOAC pat aux (Screma size xs (ScremaForm f scs reds)) = do
pat' <- bundleNewPat pat
xs' <- bundleTangents xs
f' <- fwdLambda f
scs' <- mapM fwdScan scs
reds' <- mapM fwdRed reds
f' <- fwdLambda f
addStm $ Let pat' aux $ Op $ Screma size xs' $ ScremaForm scs' reds' f'
addStm $ Let pat' aux $ Op $ Screma size xs' $ ScremaForm f' scs' reds'
where
fwdScan :: Scan SOACS -> ADM (Scan SOACS)
fwdScan sc = do
Expand Down
2 changes: 1 addition & 1 deletion src/Futhark/AD/Rev/SOAC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ mapOp (Lambda [pa1, pa2] _ lam_body)
cs == mempty,
[map_stm] <- stmsToList (bodyStms lam_body),
(Let (Pat [pe]) _ (Op scrm)) <- map_stm,
(Screma _ [a1, a2] (ScremaForm [] [] map_lam)) <- scrm,
(Screma _ [a1, a2] (ScremaForm map_lam [] [])) <- scrm,
(a1 == paramName pa1 && a2 == paramName pa2) || (a1 == paramName pa2 && a2 == paramName pa1),
r == Var (patElemName pe) =
Just map_lam
Expand Down
2 changes: 1 addition & 1 deletion src/Futhark/Analysis/HORep/MapNest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fromSOAC' ::
[Ident] ->
SOAC rep ->
m (Maybe (MapNest rep))
fromSOAC' bound (SOAC.Screma w inps (SOAC.ScremaForm [] [] lam)) = do
fromSOAC' bound (SOAC.Screma w inps (SOAC.ScremaForm lam [] [])) = do
maybenest <- case ( stmsToList $ bodyStms $ lambdaBody lam,
bodyResult $ lambdaBody lam
) of
Expand Down
6 changes: 3 additions & 3 deletions src/Futhark/Analysis/HORep/SOAC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ newWidth (inp : _) _ = arraySize 0 $ inputType inp
lambda :: SOAC rep -> Lambda rep
lambda (Stream _ _ _ lam) = lam
lambda (Scatter _len _ivs _spec lam) = lam
lambda (Screma _ _ (ScremaForm _ _ lam)) = lam
lambda (Screma _ _ (ScremaForm lam _ _)) = lam
lambda (Hist _ _ _ lam) = lam

-- | Set the lambda used in the SOAC.
Expand All @@ -444,8 +444,8 @@ setLambda lam (Stream w arrs nes _) =
Stream w arrs nes lam
setLambda lam (Scatter len arrs spec _lam) =
Scatter len arrs spec lam
setLambda lam (Screma w arrs (ScremaForm scan red _)) =
Screma w arrs (ScremaForm scan red lam)
setLambda lam (Screma w arrs (ScremaForm _ scan red)) =
Screma w arrs (ScremaForm lam scan red)
setLambda lam (Hist w ops inps _) =
Hist w ops inps lam

Expand Down
37 changes: 26 additions & 11 deletions src/Futhark/Fmt/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,29 @@ instance Format PrimValue where
BoolValue False -> "false"
FloatValue v -> prettyText v

updates ::
UncheckedExp ->
(UncheckedExp, [(Fmt, Fmt)])
updates (RecordUpdate src fs ve _ _) = second (++ [(fs', ve')]) $ updates src
where
fs' = sep "." $ fmt <$> fs
ve' = fmt ve
updates (Update src is ve _) = second (++ [(is', ve')]) $ updates src
where
is' = brackets $ sep ("," <> space) $ map fmt is
ve' = fmt ve
updates e = (e, [])

fmtUpdate :: UncheckedExp -> Fmt
fmtUpdate e =
-- Special case multiple chained Updates/RecordUpdates.
let (root, us) = updates e
loc = srclocOf e
in addComments loc . localLayout loc $
fmt root <+> align (sep line (map fmtWith us))
where
fmtWith (fs', v) = "with" <+> fs' <+> "=" <+> v

instance Format UncheckedExp where
fmt (Var name _ loc) = addComments loc $ fmtQualName name
fmt (Hole _ loc) = addComments loc "???"
Expand All @@ -246,16 +269,8 @@ instance Format UncheckedExp where
fmt (Project k e _ loc) = addComments loc $ fmt e <> "." <> fmt k
fmt (Negate e loc) = addComments loc $ "-" <> fmt e
fmt (Not e loc) = addComments loc $ "!" <> fmt e
fmt (Update src idxs ve loc) =
addComments loc $
fmt src <+> "with" <+> idxs' <+> stdNest ("=" </> fmt ve)
where
idxs' = brackets $ sep ("," <> space) $ map fmt idxs
fmt (RecordUpdate src fs ve _ loc) =
addComments loc $
fmt src <+> "with" <+> fs' <+> stdNest ("=" </> fmt ve)
where
fs' = sep "." $ fmt <$> fs
fmt e@Update {} = fmtUpdate e
fmt e@RecordUpdate {} = fmtUpdate e
fmt (Assert e1 e2 _ loc) =
addComments loc $ "assert" <+> fmt e1 <+> fmt e2
fmt (Lambda params body rettype _ loc) =
Expand Down Expand Up @@ -303,7 +318,7 @@ instance Format UncheckedCase where

instance Format (AppExpBase NoInfo Name) where
fmt (BinOp (bop, _) _ (x, _) (y, _) loc) =
addComments loc $ fmt x </> fmtBinOp bop <+> fmt y
addComments loc $ align (fmt x) </> fmtBinOp bop <+> align (fmt y)
fmt (Match e cs loc) =
addComments loc $ "match" <+> fmt e </> sep line (map fmt $ toList cs)
-- need some way to omit the inital value expression, when this it's trivial
Expand Down
29 changes: 15 additions & 14 deletions src/Futhark/IR/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -727,24 +727,25 @@ pSOAC pr =
<*> p
pScremaForm =
SOAC.ScremaForm
<$> braces (pScan pr `sepBy` pComma)
<$> pLambda pr
<* pComma
<*> braces (pReduce pr `sepBy` pComma)
<*> braces (pScan pr `sepBy` pComma)
<* pComma
<*> pLambda pr
<*> braces (pReduce pr `sepBy` pComma)
pRedomapForm =
SOAC.ScremaForm mempty
<$> braces (pReduce pr `sepBy` pComma)
SOAC.ScremaForm
<$> pLambda pr
<*> pure []
<* pComma
<*> pLambda pr
<*> braces (pReduce pr `sepBy` pComma)
pScanomapForm =
SOAC.ScremaForm
<$> braces (pScan pr `sepBy` pComma)
<$> pLambda pr
<* pComma
<*> pure mempty
<*> pLambda pr
<*> braces (pScan pr `sepBy` pComma)
<*> pure []
pMapForm =
SOAC.ScremaForm mempty mempty <$> pLambda pr
SOAC.ScremaForm <$> pLambda pr <*> pure mempty <*> pure mempty
pScatter =
keyword "scatter"
*> parens
Expand Down Expand Up @@ -797,19 +798,19 @@ pSOAC pr =
pVJP =
parens $
SOAC.VJP
<$> pLambda pr
<$> braces (pSubExp `sepBy` pComma)
<* pComma
<*> braces (pSubExp `sepBy` pComma)
<* pComma
<*> braces (pSubExp `sepBy` pComma)
<*> pLambda pr
pJVP =
parens $
SOAC.JVP
<$> pLambda pr
<$> braces (pSubExp `sepBy` pComma)
<* pComma
<*> braces (pSubExp `sepBy` pComma)
<* pComma
<*> braces (pSubExp `sepBy` pComma)
<*> pLambda pr

pSizeClass :: Parser GPU.SizeClass
pSizeClass =
Expand Down
2 changes: 1 addition & 1 deletion src/Futhark/IR/SOACS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ usesAD prog = any stmUsesAD (progConsts prog) || any funUsesAD (progFuns prog)
expUsesAD (Op JVP {}) = True
expUsesAD (Op VJP {}) = True
expUsesAD (Op (Stream _ _ _ lam)) = lamUsesAD lam
expUsesAD (Op (Screma _ _ (ScremaForm scans reds lam))) =
expUsesAD (Op (Screma _ _ (ScremaForm lam scans reds))) =
lamUsesAD lam
|| any (lamUsesAD . scanLambda) scans
|| any (lamUsesAD . redLambda) reds
Expand Down
Loading

0 comments on commit 22c9b1c

Please sign in to comment.