futhark-0.19.7: An optimising compiler for a functional, array-oriented language.
Safe HaskellNone
LanguageHaskell2010

Futhark.IR.Mem

Description

Building blocks for defining representations where every array is given information about which memory block is it based in, and how array elements map to memory block offsets.

There are two primary concepts you will need to understand:

  1. Memory blocks, which are Futhark values of type Mem (parametrized with their size). These correspond to arbitrary blocks of memory, and are created using the Alloc operation.
  2. Index functions, which describe a mapping from the index space of an array (eg. a two-dimensional space for an array of type [[int]]) to a one-dimensional offset into a memory block. Thus, index functions describe how arbitrary-dimensional arrays are mapped to the single-dimensional world of memory.

At a conceptual level, imagine that we have a two-dimensional array a of 32-bit integers, consisting of n rows of m elements each. This array could be represented in classic row-major format with an index function like the following:

  f(i,j) = i * m + j

When we want to know the location of element a[2,3], we simply call the index function as f(2,3) and obtain 2*m+3. We could also have chosen another index function, one that represents the array in column-major (or "transposed") format:

  f(i,j) = j * n + i

Index functions are not Futhark-level functions, but a special construct that the final code generator will eventually use to generate concrete access code. By modifying the index functions we can change how an array is represented in memory, which can permit memory access pattern optimisations.

Every time we bind an array, whether in a let-binding, loop merge parameter, or lambda parameter, we have an annotation specifying a memory block and an index function. In some cases, such as let-bindings for many expressions, we are free to specify an arbitrary index function and memory block - for example, we get to decide where Copy stores its result - but in other cases the type rules of the expression chooses for us. For example, Index always produces an array in the same memory block as its input, and with the same index function, except with some indices fixed.

Synopsis

Documentation

data MemOp inner Source #

Constructors

Alloc SubExp Space

Allocate a memory block. This really should not be an expression, but what are you gonna do...

Inner inner 

Instances

Instances details
Eq inner => Eq (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

(==) :: MemOp inner -> MemOp inner -> Bool #

(/=) :: MemOp inner -> MemOp inner -> Bool #

Ord inner => Ord (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

compare :: MemOp inner -> MemOp inner -> Ordering #

(<) :: MemOp inner -> MemOp inner -> Bool #

(<=) :: MemOp inner -> MemOp inner -> Bool #

(>) :: MemOp inner -> MemOp inner -> Bool #

(>=) :: MemOp inner -> MemOp inner -> Bool #

max :: MemOp inner -> MemOp inner -> MemOp inner #

min :: MemOp inner -> MemOp inner -> MemOp inner #

Show inner => Show (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

showsPrec :: Int -> MemOp inner -> ShowS #

show :: MemOp inner -> String #

showList :: [MemOp inner] -> ShowS #

Pretty inner => Pretty (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

ppr :: MemOp inner -> Doc #

pprPrec :: Int -> MemOp inner -> Doc #

pprList :: [MemOp inner] -> Doc #

TypedOp inner => TypedOp (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

opType :: HasScope t m => MemOp inner -> m [ExtType] Source #

FreeIn inner => FreeIn (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

freeIn' :: MemOp inner -> FV Source #

Substitute inner => Substitute (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

substituteNames :: Map VName VName -> MemOp inner -> MemOp inner Source #

Rename inner => Rename (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

rename :: MemOp inner -> RenameM (MemOp inner) Source #

IsOp inner => IsOp (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

safeOp :: MemOp inner -> Bool Source #

cheapOp :: MemOp inner -> Bool Source #

CanBeAliased inner => CanBeAliased (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Associated Types

type OpWithAliases (MemOp inner) Source #

AliasedOp inner => AliasedOp (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

opAliases :: MemOp inner -> [Names] Source #

consumedInOp :: MemOp inner -> Names Source #

OpMetrics inner => OpMetrics (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

opMetrics :: MemOp inner -> MetricsM () Source #

CanBeWise inner => CanBeWise (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Associated Types

type OpWithWisdom (MemOp inner) Source #

Methods

removeOpWisdom :: OpWithWisdom (MemOp inner) -> MemOp inner Source #

IndexOp inner => IndexOp (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

indexOp :: (ASTRep rep, IndexOp (Op rep)) => SymbolTable rep -> Int -> MemOp inner -> [TPrimExp Int64 VName] -> Maybe Indexed Source #

AllocOp (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

allocOp :: SubExp -> Space -> MemOp inner Source #

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

Defined in Futhark.Pass.ExplicitAllocations

Methods

opSizeSubst :: PatternT dec -> MemOp op -> ChunkMap Source #

opIsConst :: MemOp op -> Bool Source #

CSEInOp op => CSEInOp (MemOp op) Source # 
Instance details

Defined in Futhark.Optimise.CSE

Methods

cseInOp :: MemOp op -> CSEM rep (MemOp op)

type OpWithAliases (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

type OpWithAliases (MemOp inner) = MemOp (OpWithAliases inner)
type OpWithWisdom (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

type OpWithWisdom (MemOp inner) = MemOp (OpWithWisdom inner)

data MemInfo d u ret Source #

A summary of the memory information for every let-bound identifier, function parameter, and return value. Parameterisered over uniqueness, dimension, and auxiliary array information.

Constructors

MemPrim PrimType

A primitive value.

MemMem Space

A memory block.

MemArray PrimType (ShapeBase d) u ret

The array is stored in the named memory block, and with the given index function. The index function maps indices in the array to element offset, not byte offsets! To translate to byte offsets, multiply the offset with the size of the array element type.

MemAcc VName Shape [Type] u

An accumulator, which is not stored anywhere.

Instances

Instances details
IsRetType FunReturns Source # 
Instance details

Defined in Futhark.IR.Mem

IsBodyType BodyReturns Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable [FunReturns] Source # 
Instance details

Defined in Futhark.IR.Mem

(Eq d, Eq u, Eq ret) => Eq (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

(==) :: MemInfo d u ret -> MemInfo d u ret -> Bool #

(/=) :: MemInfo d u ret -> MemInfo d u ret -> Bool #

(Ord d, Ord u, Ord ret) => Ord (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

compare :: MemInfo d u ret -> MemInfo d u ret -> Ordering #

(<) :: MemInfo d u ret -> MemInfo d u ret -> Bool #

(<=) :: MemInfo d u ret -> MemInfo d u ret -> Bool #

(>) :: MemInfo d u ret -> MemInfo d u ret -> Bool #

(>=) :: MemInfo d u ret -> MemInfo d u ret -> Bool #

max :: MemInfo d u ret -> MemInfo d u ret -> MemInfo d u ret #

min :: MemInfo d u ret -> MemInfo d u ret -> MemInfo d u ret #

(Show d, Show u, Show ret) => Show (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

showsPrec :: Int -> MemInfo d u ret -> ShowS #

show :: MemInfo d u ret -> String #

showList :: [MemInfo d u ret] -> ShowS #

(Pretty (ShapeBase d), Pretty (TypeBase (ShapeBase d) u), Pretty d, Pretty u, Pretty ret) => Pretty (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

ppr :: MemInfo d u ret -> Doc #

pprPrec :: Int -> MemInfo d u ret -> Doc #

pprList :: [MemInfo d u ret] -> Doc #

FixExt ret => FixExt (MemInfo ExtSize u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

fixExt :: Int -> SubExp -> MemInfo ExtSize u ret -> MemInfo ExtSize u ret Source #

FixExt ret => DeclExtTyped (MemInfo ExtSize Uniqueness ret) Source # 
Instance details

Defined in Futhark.IR.Mem

FixExt ret => ExtTyped (MemInfo ExtSize NoUniqueness ret) Source # 
Instance details

Defined in Futhark.IR.Mem

DeclTyped (MemInfo SubExp Uniqueness ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Typed (MemInfo SubExp Uniqueness ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Typed (MemInfo SubExp NoUniqueness ret) Source # 
Instance details

Defined in Futhark.IR.Mem

(FreeIn d, FreeIn ret) => FreeIn (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

freeIn' :: MemInfo d u ret -> FV Source #

(Substitute d, Substitute ret) => Substitute (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

substituteNames :: Map VName VName -> MemInfo d u ret -> MemInfo d u ret Source #

(Substitute d, Substitute ret) => Rename (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

rename :: MemInfo d u ret -> RenameM (MemInfo d u ret) Source #

(Simplifiable d, Simplifiable ret) => Simplifiable (MemInfo d u ret) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

simplify :: SimplifiableRep rep => MemInfo d u ret -> SimpleM rep (MemInfo d u ret) Source #

data MemBind Source #

Memory information for an array bound somewhere in the program.

Constructors

ArrayIn VName IxFun

Located in this memory block with this index function.

Instances

Instances details
Eq MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

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

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

Ord MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Show MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Pretty MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

ppr :: MemBind -> Doc #

pprPrec :: Int -> MemBind -> Doc #

pprList :: [MemBind] -> Doc #

FreeIn MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

freeIn' :: MemBind -> FV Source #

Substitute MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Rename MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable MemBind Source # 
Instance details

Defined in Futhark.IR.Mem

data MemReturn Source #

A description of the memory properties of an array being returned by an operation.

Constructors

ReturnsInBlock VName ExtIxFun

The array is located in a memory block that is already in scope.

ReturnsNewBlock Space Int ExtIxFun

The operation returns a new (existential) memory block.

Instances

Instances details
Eq MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Ord MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Show MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Pretty MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

ppr :: MemReturn -> Doc #

pprPrec :: Int -> MemReturn -> Doc #

pprList :: [MemReturn] -> Doc #

FixExt MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

IsRetType FunReturns Source # 
Instance details

Defined in Futhark.IR.Mem

IsBodyType BodyReturns Source # 
Instance details

Defined in Futhark.IR.Mem

FreeIn MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

freeIn' :: MemReturn -> FV Source #

Substitute MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Rename MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable MemReturn Source # 
Instance details

Defined in Futhark.IR.Mem

Simplifiable [FunReturns] Source # 
Instance details

Defined in Futhark.IR.Mem

type IxFun = IxFun (TPrimExp Int64 VName) Source #

The index function representation used for memory annotations.

type ExtIxFun = IxFun (TPrimExp Int64 (Ext VName)) Source #

An index function that may contain existential variables.

type ExpReturns = MemInfo ExtSize NoUniqueness (Maybe MemReturn) Source #

The memory return of an expression. An array is annotated with Maybe MemReturn, which can be interpreted as the expression either dictating exactly where the array is located when it is returned (if Just), or able to put it whereever the binding prefers (if Nothing).

This is necessary to capture the difference between an expression that is just an array-typed variable, in which the array being "returned" is located where it already is, and a copy expression, whose entire purpose is to store an existing array in some arbitrary location. This is a consequence of the design decision never to have implicit memory copies.

type BodyReturns = MemInfo ExtSize NoUniqueness MemReturn Source #

The return of a body, which must always indicate where returned arrays are located.

type FunReturns = MemInfo ExtSize Uniqueness MemReturn Source #

The memory return of a function, which must always indicate where returned arrays are located.

class AllocOp op where Source #

The class of ops that have memory allocation.

Methods

allocOp :: SubExp -> Space -> op Source #

Instances

Instances details
AllocOp (MemOp inner) Source # 
Instance details

Defined in Futhark.IR.Mem

Methods

allocOp :: SubExp -> Space -> MemOp inner Source #

class TypedOp (Op rep) => OpReturns rep where Source #

Minimal complete definition

Nothing

Methods

opReturns :: (Monad m, HasScope rep m) => Op rep -> m [ExpReturns] Source #

Instances

Instances details
OpReturns SeqMem Source # 
Instance details

Defined in Futhark.IR.SeqMem

OpReturns MCMem Source # 
Instance details

Defined in Futhark.IR.MCMem

Methods

opReturns :: (Monad m, HasScope MCMem m) => Op MCMem -> m [ExpReturns] Source #

OpReturns GPUMem Source # 
Instance details

Defined in Futhark.IR.GPUMem

varReturns :: (HasScope rep m, Monad m, Mem rep) => VName -> m ExpReturns Source #

expReturns :: (Monad m, LocalScope rep m, Mem rep) => Exp rep -> m [ExpReturns] Source #

The return information of an expression. This can be seen as the "return type with memory annotations" of the expression.

Type checking parts

matchBranchReturnType :: (Mem rep, Checkable rep) => [BodyReturns] -> Body (Aliases rep) -> TypeM rep () Source #

matchPatternToExp :: (Mem rep, Checkable rep) => Pattern (Aliases rep) -> Exp (Aliases rep) -> TypeM rep () Source #

matchLoopResultMem :: (Mem rep, Checkable rep) => [FParam (Aliases rep)] -> [FParam (Aliases rep)] -> [SubExp] -> TypeM rep () Source #

Module re-exports