futhark-0.25.32: An optimising compiler for a functional, array-oriented language.

Safe Haskell | None
Language | GHC2021

Futhark.AD.Rev.Monad

Synopsis

- data ADM a
- data RState = RState {
  - stateAdjs :: Map VName Adj
  - stateLoopTape :: Substitutions
  - stateSubsts :: Substitutions
  - stateNameSource :: VNameSource
  }
- runADM :: MonadFreshNames m => ADM a -> m a
- data Adj
  - = AdjSparse Sparse
  - | AdjVal SubExp
  - | AdjZero Shape PrimType
- data InBounds
  - = CheckBounds (Maybe SubExp)
  - | AssumeBounds
  - | OutOfBounds
- data Sparse = Sparse {
  - sparseShape :: Shape
  - sparseType :: PrimType
  - sparseIdxVals :: [(InBounds, SubExp, SubExp)]
  }
- adjFromParam :: Param t -> Adj
- adjFromVar :: VName -> Adj
- lookupAdj :: VName -> ADM Adj
- lookupAdjVal :: VName -> ADM VName
- adjVal :: Adj -> ADM VName
- updateAdj :: VName -> VName -> ADM ()
- updateSubExpAdj :: SubExp -> VName -> ADM ()
- updateAdjSlice :: Slice SubExp -> VName -> VName -> ADM ()
- updateAdjIndex :: VName -> (InBounds, SubExp) -> SubExp -> ADM ()
- setAdj :: VName -> Adj -> ADM ()
- insAdj :: VName -> VName -> ADM ()
- adjsReps :: [Adj] -> ([SubExp], [SubExp] -> [Adj])
- copyConsumedArrsInStm :: Stm SOACS -> ADM (Substitutions, Stms SOACS)
- copyConsumedArrsInBody :: [VName] -> Body SOACS -> ADM Substitutions
- addSubstitution :: VName -> VName -> ADM ()
- returnSweepCode :: ADM a -> ADM a
- adjVName :: VName -> ADM VName
- subAD :: ADM a -> ADM a
- noAdjsFor :: Names -> ADM a -> ADM a
- subSubsts :: ADM a -> ADM a
- isActive :: VName -> ADM Bool
- tabNest :: Int -> [VName] -> ([VName] -> [VName] -> ADM [VName]) -> ADM [VName]
- oneExp :: Type -> Exp rep
- zeroExp :: Type -> Exp rep
- unitAdjOfType :: Type -> ADM Adj
- addLambda :: Type -> ADM (Lambda SOACS)
- data VjpOps = VjpOps {
  - vjpLambda :: [Adj] -> [VName] -> Lambda SOACS -> ADM (Lambda SOACS)
  - vjpStm :: Stm SOACS -> ADM () -> ADM ()
  }
- setLoopTape :: VName -> VName -> ADM ()
- lookupLoopTape :: VName -> ADM (Maybe VName)
- substLoopTape :: VName -> VName -> ADM ()
- renameLoopTape :: Substitutions -> ADM ()

# Documentation

data ADM a Source #

#### Instances

Instances details

MonadBuilder ADM Source # |

Instance details

Defined in Futhark.AD.Rev.Monad

Associated Types

type Rep ADM |
Instance details Defined in Futhark.AD.Rev.Monad type Rep ADM = SOACS

Methods

mkExpDecM :: Pat (LetDec (Rep ADM)) -> Exp (Rep ADM) -> ADM (ExpDec (Rep ADM)) Source #

mkBodyM :: Stms (Rep ADM) -> Result -> ADM (Body (Rep ADM)) Source #

mkLetNamesM :: [VName] -> Exp (Rep ADM) -> ADM (Stm (Rep ADM)) Source #

addStm :: Stm (Rep ADM) -> ADM () Source #

addStms :: Stms (Rep ADM) -> ADM () Source #

collectStms :: ADM a -> ADM (a, Stms (Rep ADM)) Source #

certifying :: Certs -> ADM a -> ADM a Source #

MonadFreshNames ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods getNameSource :: ADM VNameSource Source # putNameSource :: VNameSource -> ADM () Source #
Applicative ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods pure :: a -> ADM a Source # (<*>) :: ADM (a -> b) -> ADM a -> ADM b Source # liftA2 :: (a -> b -> c) -> ADM a -> ADM b -> ADM c Source # (*>) :: ADM a -> ADM b -> ADM b Source # (<*) :: ADM a -> ADM b -> ADM a Source #
Functor ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods fmap :: (a -> b) -> ADM a -> ADM b Source # (<$) :: a -> ADM b -> ADM a Source #
Monad ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods (>>=) :: ADM a -> (a -> ADM b) -> ADM b Source # (>>) :: ADM a -> ADM b -> ADM b Source # return :: a -> ADM a Source #
HasScope SOACS ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods lookupType :: VName -> ADM Type Source # lookupInfo :: VName -> ADM (NameInfo SOACS) Source # askScope :: ADM (Scope SOACS) Source # asksScope :: (Scope SOACS -> a) -> ADM a Source #
LocalScope SOACS ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods localScope :: Scope SOACS -> ADM a -> ADM a Source #
MonadState RState ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods get :: ADM RState Source # put :: RState -> ADM () Source # state :: (RState -> (a, RState)) -> ADM a Source #
type Rep ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad type Rep ADM = SOACS

data RState Source #

Constructors

RState |

Fields

- stateAdjs :: Map VName Adj
- stateLoopTape :: Substitutions
- stateSubsts :: Substitutions
- stateNameSource :: VNameSource

#### Instances

Instances details

MonadState RState ADM Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods get :: ADM RState Source # put :: RState -> ADM () Source # state :: (RState -> (a, RState)) -> ADM a Source #
MonadFreshNames (State RState) Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods getNameSource :: State RState VNameSource Source # putNameSource :: VNameSource -> State RState () Source #

runADM :: MonadFreshNames m => ADM a -> m a Source #

data Adj Source #

The adjoint of a variable.

Constructors

AdjSparse Sparse |
AdjVal SubExp |
AdjZero Shape PrimType |

#### Instances

Instances details

Substitute Adj Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods substituteNames :: Map VName VName -> Adj -> Adj Source #
Show Adj Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods showsPrec :: Int -> Adj -> ShowS Source # show :: Adj -> String Source # showList :: [Adj] -> ShowS Source #
Eq Adj Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods (==) :: Adj -> Adj -> Bool Source # (/=) :: Adj -> Adj -> Bool Source #
Ord Adj Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods compare :: Adj -> Adj -> Ordering Source # (<) :: Adj -> Adj -> Bool Source # (<=) :: Adj -> Adj -> Bool Source # (>) :: Adj -> Adj -> Bool Source # (>=) :: Adj -> Adj -> Bool Source # max :: Adj -> Adj -> Adj Source # min :: Adj -> Adj -> Adj Source #

data InBounds Source #

Whether `Sparse` should check bounds or assume they are correct. The latter results in simpler code.

Constructors

CheckBounds (Maybe SubExp) | If a SubExp is provided, it references a boolean that is true when in-bounds.
AssumeBounds | Assume that these are always in-bounds.
OutOfBounds | Dynamically these will always fail, so don't bother generating code for the update. This is only needed to ensure a consistent representation of sparse Jacobians.

#### Instances

Instances details

Show InBounds Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods showsPrec :: Int -> InBounds -> ShowS Source # show :: InBounds -> String Source # showList :: [InBounds] -> ShowS Source #
Eq InBounds Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods (==) :: InBounds -> InBounds -> Bool Source # (/=) :: InBounds -> InBounds -> Bool Source #
Ord InBounds Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods compare :: InBounds -> InBounds -> Ordering Source # (<) :: InBounds -> InBounds -> Bool Source # (<=) :: InBounds -> InBounds -> Bool Source # (>) :: InBounds -> InBounds -> Bool Source # (>=) :: InBounds -> InBounds -> Bool Source # max :: InBounds -> InBounds -> InBounds Source # min :: InBounds -> InBounds -> InBounds Source #

data Sparse Source #

A symbolic representation of an array that is all zeroes, except at certain indexes.

Constructors

Sparse |

Fields

- sparseShape :: Shape

  The shape of the array.

- sparseType :: PrimType

  Element type of the array.

- sparseIdxVals :: [(InBounds, SubExp, SubExp)]

  Locations and values of nonzero values. Indexes may be negative, in which case the value is ignored (unless `AssumeBounds` is used).

#### Instances

Instances details

Show Sparse Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods showsPrec :: Int -> Sparse -> ShowS Source # show :: Sparse -> String Source # showList :: [Sparse] -> ShowS Source #
Eq Sparse Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods (==) :: Sparse -> Sparse -> Bool Source # (/=) :: Sparse -> Sparse -> Bool Source #
Ord Sparse Source # |
Instance details Defined in Futhark.AD.Rev.Monad Methods compare :: Sparse -> Sparse -> Ordering Source # (<) :: Sparse -> Sparse -> Bool Source # (<=) :: Sparse -> Sparse -> Bool Source # (>) :: Sparse -> Sparse -> Bool Source # (>=) :: Sparse -> Sparse -> Bool Source # max :: Sparse -> Sparse -> Sparse Source # min :: Sparse -> Sparse -> Sparse Source #

adjFromParam :: Param t -> Adj Source #

adjFromVar :: VName -> Adj Source #

lookupAdj :: VName -> ADM Adj Source #

lookupAdjVal :: VName -> ADM VName Source #

adjVal :: Adj -> ADM VName Source #

updateAdj :: VName -> VName -> ADM () Source #

updateSubExpAdj :: SubExp -> VName -> ADM () Source #

updateAdjSlice :: Slice SubExp -> VName -> VName -> ADM () Source #

updateAdjIndex :: VName -> (InBounds, SubExp) -> SubExp -> ADM () Source #

setAdj :: VName -> Adj -> ADM () Source #

Set a specific adjoint.

insAdj :: VName -> VName -> ADM () Source #

Set an `AdjVal` adjoint. Simple wrapper around `setAdj`.

adjsReps :: [Adj] -> ([SubExp], [SubExp] -> [Adj]) Source #

Conveniently convert a list of Adjs to their representation, as well as produce a function for converting back.

copyConsumedArrsInStm :: Stm SOACS -> ADM (Substitutions, Stms SOACS) Source #

Create copies of all arrays consumed in the given statement, and return statements which include copies of the consumed arrays.

See Note [Consumption].

copyConsumedArrsInBody :: [VName] -> Body SOACS -> ADM Substitutions Source #

addSubstitution :: VName -> VName -> ADM () Source #

returnSweepCode :: ADM a -> ADM a Source #

adjVName :: VName -> ADM VName Source #

subAD :: ADM a -> ADM a Source #

Ignore any changes to adjoints made while evaluating this action.

noAdjsFor :: Names -> ADM a -> ADM a Source #

subSubsts :: ADM a -> ADM a Source #

isActive :: VName -> ADM Bool Source #

Is this primal variable active in the AD sense? FIXME: this is (obviously) much too conservative.

tabNest :: Int -> [VName] -> ([VName] -> [VName] -> ADM [VName]) -> ADM [VName] Source #

oneExp :: Type -> Exp rep Source #

zeroExp :: Type -> Exp rep Source #

unitAdjOfType :: Type -> ADM Adj Source #

addLambda :: Type -> ADM (Lambda SOACS) Source #

Construct a lambda for adding two values of the given type.

data VjpOps Source #

Constructors

VjpOps |

Fields

- vjpLambda :: [Adj] -> [VName] -> Lambda SOACS -> ADM (Lambda SOACS)
- vjpStm :: Stm SOACS -> ADM () -> ADM ()

setLoopTape :: VName -> VName -> ADM () Source #

`setLoopTape v vs` establishes `vs` as the name of the array where values of loop parameter `v` from the forward pass are stored.

lookupLoopTape :: VName -> ADM (Maybe VName) Source #

Look-up the name of the array where `v` is stored.

substLoopTape :: VName -> VName -> ADM () Source #

`substLoopTape v v'` substitutes the key `v` for `v'`. That is, if `v |-> vs` then after the substitution `v' |-> vs` (and `v` points to nothing).

renameLoopTape :: Substitutions -> ADM () Source #

Renames the keys of the loop tape. Useful for fixing the the names in the loop tape after a loop rename.