futhark
Safe HaskellNone
LanguageGHC2021

Futhark.AD.Rev.Monad

Synopsis

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 :: IsResult res => Stms (Rep ADM) -> [res] -> ADM (GBody (Rep ADM) res) 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

Applicative ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

pure :: a -> ADM a #

(<*>) :: ADM (a -> b) -> ADM a -> ADM b #

liftA2 :: (a -> b -> c) -> ADM a -> ADM b -> ADM c #

(*>) :: ADM a -> ADM b -> ADM b #

(<*) :: ADM a -> ADM b -> ADM a #

Functor ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

fmap :: (a -> b) -> ADM a -> ADM b #

(<$) :: a -> ADM b -> ADM a #

Monad ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

(>>=) :: ADM a -> (a -> ADM b) -> ADM b #

(>>) :: ADM a -> ADM b -> ADM b #

return :: a -> ADM a #

HasScope SOACS ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

LocalScope SOACS ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

localScope :: Scope SOACS -> ADM a -> ADM a Source #

MonadReader REnv ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

ask :: ADM REnv #

local :: (REnv -> REnv) -> ADM a -> ADM a #

reader :: (REnv -> a) -> ADM a #

MonadState RState ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

get :: ADM RState #

put :: RState -> ADM () #

state :: (RState -> (a, RState)) -> ADM a #

type Rep ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

type Rep ADM = SOACS

data REnv Source #

Instances

Instances details
MonadReader REnv ADM Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

ask :: ADM REnv #

local :: (REnv -> REnv) -> ADM a -> ADM a #

reader :: (REnv -> a) -> ADM a #

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

data Adj Source #

The adjoint of a variable.

Instances

Instances details
Substitute Adj Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Show Adj Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

showsPrec :: Int -> Adj -> ShowS #

show :: Adj -> String #

showList :: [Adj] -> ShowS #

Eq Adj Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

(==) :: Adj -> Adj -> Bool #

(/=) :: Adj -> Adj -> Bool #

Ord Adj Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

compare :: Adj -> Adj -> Ordering #

(<) :: Adj -> Adj -> Bool #

(<=) :: Adj -> Adj -> Bool #

(>) :: Adj -> Adj -> Bool #

(>=) :: Adj -> Adj -> Bool #

max :: Adj -> Adj -> Adj #

min :: Adj -> Adj -> Adj #

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

Eq InBounds Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Ord InBounds Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

data Sparse Source #

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

Constructors

Sparse 

Fields

  • sparseShape :: Shape

    The full shape of the array (including any vector dimensions, which are stored in sparseVecDims).

  • sparseType :: PrimType

    Element type of the array.

  • sparseVecDims :: Int

    Number of leading dimensions that are "vector" dimensions, due to vector AD. These are not indexed by the sparse index, but are present in the values. When zero, this is the ordinary non-vector case. This is equivalent to the rank of askShape, but it is convenient to store it here as well.

  • 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

Eq Sparse Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

Methods

(==) :: Sparse -> Sparse -> Bool #

(/=) :: Sparse -> Sparse -> Bool #

Ord Sparse Source # 
Instance details

Defined in Futhark.AD.Rev.Monad

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].

subAD :: ADM a -> ADM a Source #

Ignore any changes to adjoints made while evaluating this action.

noAdjsFor :: Names -> 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 :: (MonadBuilder m, Rep m ~ SOACS) => Int -> [VName] -> ([VName] -> [VName] -> m [VName]) -> m [VName] Source #

oneExp :: Type -> Exp rep Source #

zeroExp :: Type -> Exp rep Source #

zeroArray :: MonadBuilder m => Shape -> Type -> m VName Source #

Create an array of the given shape and element type consisting of zeroes. The shape may be empty, meaning this function can (despite its name) also create non-arrays.

addLambda :: (OpC (Rep m) ~ SOAC, MonadBuilder m, Buildable (Rep m)) => TypeBase Shape NoMode -> m (Lambda (Rep m)) Source #

Construct a lambda for adding two values of the given type, Using SOACs to handle arrays.

vecOpExp :: (PrimType -> BinOp) -> VName -> VName -> ADM (Exp SOACS) Source #

Construct an expression for performing this binary operation on two variables.

data VjpOps Source #

Constructors

VjpOps 

Fields

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.

locallyNonvector Source #

Arguments

:: FreeIn e 
=> e

Something that represents all the free variables used in the action. Usually just an expression or statement.

-> ADM () 
-> ADM () 

Disable vector AD within the provided action. This results in a map that computes each adjoint explicitly, then assembles the resulting adjoint vectors. This is useful for constructs (such as scans) where vector AD is impractical or inefficient.

vecToInner :: VName -> ADM VName Source #

If we are doing vector AD, apply vecPerm to the array.

vecSlice :: Type -> [DimIndex SubExp] -> ADM (Slice SubExp) Source #

vecSlice t is indexes an adjoint of type t with is, which is written against the type of the corresponding primal value. As the vector dimensions are outermost in the adjoint, they must be skipped past.

withOperatorAccs :: [VName] -> ADM a -> ADM a Source #

Note that these accumulator certificates belong to accumulators that have a combining operator, for the duration of the action.

isOperatorAcc :: VName -> ADM Bool Source #

Does this accumulator certificate belong to an accumulator with a combining operator, rather than a scatter-like one that overwrites? See Note [Adjoints of accumulators].