futhark-0.25.9: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
LanguageGHC2021

Futhark.CodeGen.Backends.GenericPython

Description

A generic Python code generator which is polymorphic in the type of the operations. Concretely, we use this to handle both sequential and PyOpenCL Python code.

Synopsis

Documentation

data Constructor Source #

The class generated by the code generator must have a constructor, although it can be vacuous.

Constructors

Constructor [String] [PyStmt] 

emptyConstructor :: Constructor Source #

A constructor that takes no arguments and does nothing.

compilePrimExp :: Monad m => (v -> m PyExp) -> PrimExp v -> m PyExp Source #

Tell me how to compile a v, and I'll Compile any PrimExp v for you.

compileCode :: Code op -> CompilerM op s () Source #

compilePrimType :: PrimType -> String Source #

The ctypes type corresponding to a PrimType.

compilePrimTypeExt :: PrimType -> Signedness -> String Source #

The ctypes type corresponding to a PrimType, taking sign into account.

compilePrimToNp :: PrimType -> String Source #

The Numpy type corresponding to a PrimType.

compilePrimToExtNp :: PrimType -> Signedness -> String Source #

The Numpy type corresponding to a PrimType, taking sign into account.

fromStorage :: PrimType -> PyExp -> PyExp Source #

Convert from storage to scalar representation for the given type.

toStorage :: PrimType -> PyExp -> PyExp Source #

Convert from scalar to storage representation for the given type.

data Operations op s Source #

Constructors

Operations 

Fields

type DoLMADCopy op s = PrimType -> [Count Elements PyExp] -> PyExp -> (Count Elements PyExp, [Count Elements PyExp]) -> PyExp -> (Count Elements PyExp, [Count Elements PyExp]) -> CompilerM op s () Source #

Perform an LMADCopy. It is expected that these functions are each specialised on which spaces they operate on, so that is not part of their arguments.

defaultOperations :: Operations op s Source #

A set of operations that fail for every operation involving non-default memory spaces. Uses plain pointers and malloc for memory management.

newtype CompilerM op s a Source #

Constructors

CompilerM (RWS (CompilerEnv op s) [PyStmt] (CompilerState s) a) 

Instances

Instances details
MonadState (CompilerState s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

get :: CompilerM op s (CompilerState s) #

put :: CompilerState s -> CompilerM op s () #

state :: (CompilerState s -> (a, CompilerState s)) -> CompilerM op s a #

MonadWriter [PyStmt] (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

writer :: (a, [PyStmt]) -> CompilerM op s a #

tell :: [PyStmt] -> CompilerM op s () #

listen :: CompilerM op s a -> CompilerM op s (a, [PyStmt]) #

pass :: CompilerM op s (a, [PyStmt] -> [PyStmt]) -> CompilerM op s a #

Applicative (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

pure :: a -> CompilerM op s a #

(<*>) :: CompilerM op s (a -> b) -> CompilerM op s a -> CompilerM op s b #

liftA2 :: (a -> b -> c) -> CompilerM op s a -> CompilerM op s b -> CompilerM op s c #

(*>) :: CompilerM op s a -> CompilerM op s b -> CompilerM op s b #

(<*) :: CompilerM op s a -> CompilerM op s b -> CompilerM op s a #

Functor (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

fmap :: (a -> b) -> CompilerM op s a -> CompilerM op s b #

(<$) :: a -> CompilerM op s b -> CompilerM op s a #

Monad (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

(>>=) :: CompilerM op s a -> (a -> CompilerM op s b) -> CompilerM op s b #

(>>) :: CompilerM op s a -> CompilerM op s b -> CompilerM op s b #

return :: a -> CompilerM op s a #

MonadFreshNames (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

MonadReader (CompilerEnv op s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

ask :: CompilerM op s (CompilerEnv op s) #

local :: (CompilerEnv op s -> CompilerEnv op s) -> CompilerM op s a -> CompilerM op s a #

reader :: (CompilerEnv op s -> a) -> CompilerM op s a #

type OpCompiler op s = op -> CompilerM op s () Source #

A substitute expression compiler, tried before the main compilation function.

type WriteScalar op s = PyExp -> PyExp -> PrimType -> SpaceId -> PyExp -> CompilerM op s () Source #

Write a scalar to the given memory block with the given index and in the given memory space.

type ReadScalar op s = PyExp -> PyExp -> PrimType -> SpaceId -> CompilerM op s PyExp Source #

Read a scalar from the given memory block with the given index and in the given memory space.

type Allocate op s = PyExp -> PyExp -> SpaceId -> CompilerM op s () Source #

Allocate a memory block of the given size in the given memory space, saving a reference in the given variable name.

type Copy op s = PyExp -> PyExp -> Space -> PyExp -> PyExp -> Space -> PyExp -> PrimType -> CompilerM op s () Source #

Copy from one memory block to another.

type EntryOutput op s = VName -> SpaceId -> PrimType -> Signedness -> [DimSize] -> CompilerM op s PyExp Source #

Construct the Python array being returned from an entry point.

type EntryInput op s = PyExp -> SpaceId -> PrimType -> Signedness -> [DimSize] -> PyExp -> CompilerM op s () Source #

Unpack the array being passed to an entry point.

data CompilerEnv op s Source #

Constructors

CompilerEnv 

Instances

Instances details
MonadReader (CompilerEnv op s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

ask :: CompilerM op s (CompilerEnv op s) #

local :: (CompilerEnv op s -> CompilerEnv op s) -> CompilerM op s a -> CompilerM op s a #

reader :: (CompilerEnv op s -> a) -> CompilerM op s a #

data CompilerState s Source #

Instances

Instances details
MonadState (CompilerState s) (CompilerM op s) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericPython

Methods

get :: CompilerM op s (CompilerState s) #

put :: CompilerState s -> CompilerM op s () #

state :: (CompilerState s -> (a, CompilerState s)) -> CompilerM op s a #

stm :: PyStmt -> CompilerM op s () Source #

collect' :: CompilerM op s a -> CompilerM op s (a, [PyStmt]) Source #

collect :: CompilerM op s () -> CompilerM op s [PyStmt] Source #

simpleCall :: String -> [PyExp] -> PyExp Source #

A Call where the function is a variable and every argument is a simple Arg.