futhark-0.9.1: An optimising compiler for a functional, array-oriented language.

Safe HaskellNone
LanguageHaskell2010

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.

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.

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
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 #

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 #

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 #

fail :: String -> 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 #

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 #

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 = VName -> 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 = VName -> 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 = VName -> 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 = VName -> PyExp -> Space -> VName -> PyExp -> Space -> PyExp -> PrimType -> CompilerM op s () Source #

Copy from one memory block to another.

type StaticArray op s = VName -> SpaceId -> PrimType -> [PrimValue] -> CompilerM op s () Source #

Create a static array of values - initialised at load time.

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 = VName -> MemSize -> 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
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
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 #

stms :: [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.