futhark
Safe HaskellNone
LanguageGHC2021

Futhark.Pass.Flatten.General

Description

Various general utilities used in flattening.

Synopsis

Reading inputs

readNeutral :: Segments -> DistEnv -> DistInputs -> SubExp -> FlattenM SubExp Source #

Read the neutral element of a reduction or scan operator. The neutral element of an operator is unique because we assume uniform operators, so a valid program must have the same value in every segment, and we can read it from the first one. This is the case even if the neutral element is nonuniform, which is useless but allowed. The segment space may however be empty, in which case we produce a blank value instead; it is never used then, but an unconditional read would be out of bounds.

Building blocks

liftSubExpRegular :: SegLevel -> Segments -> DistInputs -> DistEnv -> Shape -> SubExp -> FlattenM VName Source #

Like liftSubExp but always returns a Regular result with the given expected shape. Reshapes the underlying data if necessary.

isRegularInputArr :: DistEnv -> DistInputs -> VName -> Bool Source #

Can this input array be lifted to a regular array? This holds unless it is represented irregularly. The uniform alternatives lift their inputs regularly (via liftSubExpRegular), which is only valid when the inputs are actually regular.

flattenIrregularRep :: SegLevel -> IrregularRep -> FlattenM IrregularRep Source #

Flatten the arrays of an IrregularRep to be entirely one-dimensional.

dataArr :: SegLevel -> Segments -> DistEnv -> DistInputs -> SubExp -> FlattenM VName Source #

Only sensible for variables of uniform type.

getIrregRep :: SegLevel -> Segments -> DistEnv -> DistInputs -> VName -> FlattenM IrregularRep Source #

Get the irregular representation of a var.

scatterIrregular :: SegLevel -> VName -> VName -> (VName, IrregularRep) -> FlattenM VName Source #

Write back the irregular results of a branch to a (partially) blank space The offsets variable is the offsets of the final result, whereas irregRep is the irregular representation of the result.

scatterRegular :: SegLevel -> VName -> (VName, VName) -> FlattenM VName Source #

Write back the regular results to a (partially) blank space

Various

replicateForDims :: Segments -> Shape -> VName -> FlattenM VName Source #

Replicate an array to insert new inner dimensions after the existing segment dimensions.

resultToResReps :: [TypeBase s o] -> [VName] -> [ResRep] Source #

This function walks through the *unlifted* result types and uses the *lifted* results to construct the corresponding res reps.

See the liftResult function for the opposite process i.e. turning ResReps into results.

irregularRepToFlatArrs :: SubExp -> IrregularRep -> FlattenM [VName] Source #

Convert an irregular representation to its flat constituents (number of data elements, segments, flags, offsets, elements), with the structure arrays reshaped to be one-dimensional of the given width. This is the form in which irregular values are passed to lifted functions and carried through loops.

distributeAndFlattenBody :: FlattenOps -> Segments -> Name -> DistEnv -> DistInputs -> [DistResult] -> Body SOACS -> FlattenM [ResRep] Source #

Distribute a body and lift the distributed statements, giving back representations of the body results.

splitInput :: SegLevel -> Segments -> DistEnv -> DistInputs -> VName -> Map VName ResRep -> VName -> FlattenM (Type, VName, ResRep) Source #

Take the elements at index is from an input v. The representation of v can be overridden through the provided mapping, which takes precedence over what the environment says.

flattenDistStm :: FlattenOps -> Segments -> DistEnv -> DistStm -> FlattenM DistEnv Source #

Flatten a single DistStm, producing an updated environment.

flattenScalarStm :: FlattenOps -> Segments -> DistEnv -> DistInputs -> [DistResult] -> Stm SOACS -> FlattenM DistEnv Source #

Flatten a single scalar statement, producing an updated environment.

distributeMapWith :: FlattenOps -> Scope rep -> Pat Type -> Segments -> [MapArray t] -> Lambda SOACS -> (Distributed, Map ResTag t) Source #

distributeMap with the settings in the given FlattenOps.

atSegLevel :: SegLevel -> FlattenOps -> FlattenOps Source #

Continue flattening at the given seg level, adjusting the irregularity handling mode to match. Intrablock code cannot use the machinery for flattening irregular arrays, as it produces SegOps whose sizes are bound inside the enclosing kernel. SequentialiseIrregularAll is requested by the user rather than implied by the level, so we keep it if provided.