futhark
Safe HaskellNone
LanguageGHC2021

Futhark.Pass.ExplicitAllocations

Description

A generic transformation for adding memory allocations to a Futhark program. Specialised by specific representations in submodules.

Synopsis

Documentation

explicitAllocationsGeneric :: forall fromrep torep (inner :: Type -> Type). Allocable fromrep torep inner => Space -> (Op fromrep -> AllocM fromrep torep (Op torep)) -> (Exp torep -> AllocM fromrep torep [ExpHint]) -> Pass fromrep torep Source #

explicitAllocationsInStmsGeneric :: forall m torep fromrep (inner :: Type -> Type). (MonadFreshNames m, HasScope torep m, Allocable fromrep torep inner) => Space -> (Op fromrep -> AllocM fromrep torep (Op torep)) -> (Exp torep -> AllocM fromrep torep [ExpHint]) -> Stms fromrep -> m (Stms torep) Source #

data ExpHint Source #

Constructors

NoHint 
Hint LMAD Space 

defaultExpHints :: (ASTRep rep, HasScope rep m) => Exp rep -> m [ExpHint] Source #

scalarSpaceExpHints :: forall fromrep torep (inner :: Type -> Type). Allocable fromrep torep inner => Exp torep -> AllocM fromrep torep [ExpHint] Source #

Put small arrays of statically known size in ScalarSpace, which the CPU backends turn into ordinary C arrays of scalars rather than heap allocations. This matters most for arrays carried by a loop, where the alternative is an allocation (and a reference count update) per iteration. Only for representations where the default space is the one the host can address directly; a GPU array must stay in device memory.

askDefaultSpace :: AllocM fromrep torep Space Source #

The space in which we allocate memory if we have no other preferences or constraints.

type Allocable fromrep torep (inner :: Type -> Type) = (PrettyRep fromrep, PrettyRep torep, Mem torep inner, LetDec torep ~ LetDecMem, FParamInfo fromrep ~ DeclType, LParamInfo fromrep ~ Type, BranchType fromrep ~ ExtType, RetType fromrep ~ ExtType, BodyDec fromrep ~ (), BodyDec torep ~ (), ExpDec torep ~ (), SizeSubst (inner torep), BuilderOps torep) Source #

data AllocM fromrep torep a Source #

Monad for adding allocations to an entire program.

Instances

Instances details
ASTRep torep => HasScope torep (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

lookupType :: VName -> AllocM fromrep torep Type Source #

lookupInfo :: VName -> AllocM fromrep torep (NameInfo torep) Source #

askScope :: AllocM fromrep torep (Scope torep) Source #

asksScope :: (Scope torep -> a) -> AllocM fromrep torep a Source #

ASTRep torep => LocalScope torep (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

localScope :: Scope torep -> AllocM fromrep torep a -> AllocM fromrep torep a Source #

Allocable fromrep torep inner => MonadBuilder (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Associated Types

type Rep (AllocM fromrep torep) 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

type Rep (AllocM fromrep torep) = torep

Methods

mkExpDecM :: Pat (LetDec (Rep (AllocM fromrep torep))) -> Exp (Rep (AllocM fromrep torep)) -> AllocM fromrep torep (ExpDec (Rep (AllocM fromrep torep))) Source #

mkBodyM :: IsResult res => Stms (Rep (AllocM fromrep torep)) -> [res] -> AllocM fromrep torep (GBody (Rep (AllocM fromrep torep)) res) Source #

mkLetNamesM :: [VName] -> Exp (Rep (AllocM fromrep torep)) -> AllocM fromrep torep (Stm (Rep (AllocM fromrep torep))) Source #

addStm :: Stm (Rep (AllocM fromrep torep)) -> AllocM fromrep torep () Source #

addStms :: Stms (Rep (AllocM fromrep torep)) -> AllocM fromrep torep () Source #

collectStms :: AllocM fromrep torep a -> AllocM fromrep torep (a, Stms (Rep (AllocM fromrep torep))) Source #

certifying :: Certs -> AllocM fromrep torep a -> AllocM fromrep torep a Source #

MonadFreshNames (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

getNameSource :: AllocM fromrep torep VNameSource Source #

putNameSource :: VNameSource -> AllocM fromrep torep () Source #

Applicative (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

pure :: a -> AllocM fromrep torep a #

(<*>) :: AllocM fromrep torep (a -> b) -> AllocM fromrep torep a -> AllocM fromrep torep b #

liftA2 :: (a -> b -> c) -> AllocM fromrep torep a -> AllocM fromrep torep b -> AllocM fromrep torep c #

(*>) :: AllocM fromrep torep a -> AllocM fromrep torep b -> AllocM fromrep torep b #

(<*) :: AllocM fromrep torep a -> AllocM fromrep torep b -> AllocM fromrep torep a #

Functor (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

fmap :: (a -> b) -> AllocM fromrep torep a -> AllocM fromrep torep b #

(<$) :: a -> AllocM fromrep torep b -> AllocM fromrep torep a #

Monad (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

(>>=) :: AllocM fromrep torep a -> (a -> AllocM fromrep torep b) -> AllocM fromrep torep b #

(>>) :: AllocM fromrep torep a -> AllocM fromrep torep b -> AllocM fromrep torep b #

return :: a -> AllocM fromrep torep a #

MonadReader (AllocEnv fromrep torep) (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

ask :: AllocM fromrep torep (AllocEnv fromrep torep) #

local :: (AllocEnv fromrep torep -> AllocEnv fromrep torep) -> AllocM fromrep torep a -> AllocM fromrep torep a #

reader :: (AllocEnv fromrep torep -> a) -> AllocM fromrep torep a #

type Rep (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

type Rep (AllocM fromrep torep) = torep

data AllocEnv fromrep torep Source #

Constructors

AllocEnv 

Fields

  • allocSpace :: Space

    When allocating memory, put it in this memory space. This is primarily used to ensure that group-wide statements store their results in shared memory.

  • envConsts :: Set VName

    The set of names that are known to be constants at kernel compile time.

  • funSpace :: Name -> Space

    The memory space for function parameters. Currently we assume these are all in the same space. The result must still be in the allocSpace. This could be made more flexible.

  • allocInOp :: Op fromrep -> AllocM fromrep torep (Op torep)
     
  • envExpHints :: Exp torep -> AllocM fromrep torep [ExpHint]
     

Instances

Instances details
MonadReader (AllocEnv fromrep torep) (AllocM fromrep torep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

ask :: AllocM fromrep torep (AllocEnv fromrep torep) #

local :: (AllocEnv fromrep torep -> AllocEnv fromrep torep) -> AllocM fromrep torep a -> AllocM fromrep torep a #

reader :: (AllocEnv fromrep torep -> a) -> AllocM fromrep torep a #

class SizeSubst op where Source #

Minimal complete definition

Nothing

Methods

opIsConst :: op -> Bool Source #

Instances

Instances details
SizeSubst (HostOp rep op) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations.GPU

Methods

opIsConst :: HostOp rep op -> Bool Source #

SizeSubst (MCOp rep op) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations.MC

Methods

opIsConst :: MCOp rep op -> Bool Source #

SizeSubst (op rep) => SizeSubst (MemOp op rep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

opIsConst :: MemOp op rep -> Bool Source #

SizeSubst (NoOp rep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations

Methods

opIsConst :: NoOp rep -> Bool Source #

SizeSubst (SegOp lvl rep) Source # 
Instance details

Defined in Futhark.Pass.ExplicitAllocations.SegOp

Methods

opIsConst :: SegOp lvl rep -> Bool Source #

allocInStms :: forall fromrep torep (inner :: Type -> Type) a. Allocable fromrep torep inner => Stms fromrep -> AllocM fromrep torep a -> AllocM fromrep torep a Source #

allocInLambda :: forall fromrep torep (inner :: Type -> Type). Allocable fromrep torep inner => [LParam torep] -> Body fromrep -> AllocM fromrep torep (Lambda torep) Source #

allocInLParams :: forall fromrep torep (inner :: Type -> Type). Allocable fromrep torep inner => SubExp -> TPrimExp Int64 VName -> [LParam fromrep] -> AllocM fromrep torep [LParam torep] Source #

allocForArray :: forall fromrep torep (inner :: Type -> Type). Allocable fromrep torep inner => Type -> Space -> AllocM fromrep torep VName Source #

Allocate memory for a value of the given type.

simplifiable :: (SimplifiableRep rep, LetDec rep ~ LetDecMem, ExpDec rep ~ (), BodyDec rep ~ (), Mem (Wise rep) inner, CanBeWise inner, RephraseOp inner, IsOp inner, OpReturns inner, AliasedOp inner, IndexOp (inner (Wise rep))) => (inner (Wise rep) -> UsageTable) -> (inner (Wise rep) -> SimpleM rep (inner (Wise rep), Stms (Wise rep))) -> SimpleOps rep Source #

mkLetNamesB' :: forall m (inner :: Type -> Type). (LetDec (Rep m) ~ LetDecMem, Mem (Rep m) inner, MonadBuilder m, ExpDec (Rep m) ~ ()) => Space -> ExpDec (Rep m) -> [VName] -> Exp (Rep m) -> m (Stm (Rep m)) Source #

mkLetNamesB'' :: forall rep (inner :: Type -> Type) m. (Mem rep inner, LetDec rep ~ LetDecMem, OpReturns inner, ExpDec rep ~ (), Rep m ~ Wise rep, HasScope (Wise rep) m, MonadBuilder m, AliasedOp inner, RephraseOp (MemOp inner), CanBeWise inner, ASTConstraints (inner (Wise rep))) => Space -> [VName] -> Exp (Wise rep) -> m (Stm (Wise rep)) Source #

Module re-exports