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

Safe Haskell | Safe-Inferred
Language | GHC2021

Futhark.CodeGen.ImpCode.OpenCL

Description

Imperative code with an OpenCL component.

Apart from ordinary imperative code, this also carries around an OpenCL program as a string, as well as a list of kernels defined by the OpenCL program.

The imperative code has been augmented with a `LaunchKernel` operation that allows one to execute an OpenCL kernel.

Synopsis

- data Program = Program {
  - openClProgram :: Text
  - openClPrelude :: Text
  - openClMacroDefs :: [(Name, KernelConstExp)]
  - openClKernelNames :: Map KernelName KernelSafety
  - openClUsedTypes :: [PrimType]
  - openClParams :: ParamMap
  - openClFailures :: [FailureMsg]
  - hostDefinitions :: Definitions OpenCL
  }
- type KernelName = Name
- data KernelArg
  - = ValueKArg Exp PrimType
  - | MemKArg VName
- type CLCode = Code OpenCL
- data OpenCL
  - = LaunchKernel KernelSafety KernelName (Count Bytes (TExp Int64)) [KernelArg] [Exp] [BlockDim]
  - | GetSize VName Name
  - | CmpSizeLe VName Name Exp
  - | GetSizeMax VName SizeClass
- data KernelSafety
  - = SafetyNone
  - | SafetyCheap
  - | SafetyFull
- numFailureParams :: KernelSafety -> Int
- data KernelTarget
  - = TargetOpenCL
  - | TargetCUDA
  - | TargetHIP
- data FailureMsg = FailureMsg {
  - failureError :: ErrorMsg Exp
  - failureBacktrace :: String
  }
- type BlockDim = Either Exp KernelConstExp
- data KernelConst
  - = SizeConst Name SizeClass
  - | SizeMaxConst SizeClass
- type KernelConstExp = PrimExp KernelConst
- module Futhark.CodeGen.ImpCode
- module Futhark.IR.GPU.Sizes

# Documentation

data Program Source #

An program calling OpenCL kernels.

Constructors

Program |

Fields

- openClProgram :: Text
- openClPrelude :: Text

  Must be prepended to the program.

- openClMacroDefs :: [(Name, KernelConstExp)]

  Definitions to be passed as macro definitions to the kernel compiler.

- openClKernelNames :: Map KernelName KernelSafety
- openClUsedTypes :: [PrimType]

  So we can detect whether the device is capable.

- openClParams :: ParamMap

  Runtime-configurable constants.

- openClFailures :: [FailureMsg]

  Assertion failure error messages.

- hostDefinitions :: Definitions OpenCL

type KernelName = Name Source #

The name of a kernel.

data KernelArg Source #

An argument to be passed to a kernel.

Constructors

ValueKArg Exp PrimType | Pass the value of this scalar expression as argument.
MemKArg VName | Pass this pointer as argument.

#### Instances

Instances details

Show KernelArg Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.OpenCL Methods showsPrec :: Int -> KernelArg -> ShowS Source # show :: KernelArg -> String Source # showList :: [KernelArg] -> ShowS Source #

type CLCode = Code OpenCL Source #

A piece of code calling OpenCL.

data OpenCL Source #

Host-level OpenCL operation.

Constructors

LaunchKernel KernelSafety KernelName (Count Bytes (TExp Int64)) [KernelArg] [Exp] [BlockDim] |
GetSize VName Name |
CmpSizeLe VName Name Exp |
GetSizeMax VName SizeClass |

#### Instances

Instances details

Show OpenCL Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.OpenCL Methods showsPrec :: Int -> OpenCL -> ShowS Source # show :: OpenCL -> String Source # showList :: [OpenCL] -> ShowS Source #
Pretty OpenCL Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.OpenCL Methods pretty :: OpenCL -> Doc ann Source # prettyList :: [OpenCL] -> Doc ann Source #

data KernelSafety Source #

Information about bounds checks and how sensitive it is to errors. Ordered by least demanding to most.

Constructors

SafetyNone | Does not need to know if we are in a failing state, and also cannot fail.
SafetyCheap | Needs to be told if there's a global failure, and that's it, and cannot fail.
SafetyFull | Needs all parameters, may fail itself.

#### Instances

Instances details

Show KernelSafety Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.OpenCL Methods showsPrec :: Int -> KernelSafety -> ShowS Source # show :: KernelSafety -> String Source # showList :: [KernelSafety] -> ShowS Source #
Eq KernelSafety Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.OpenCL Methods (==) :: KernelSafety -> KernelSafety -> Bool Source # (/=) :: KernelSafety -> KernelSafety -> Bool Source #
Ord KernelSafety Source # |

Instance details

Defined in Futhark.CodeGen.ImpCode.OpenCL

Methods

compare :: KernelSafety -> KernelSafety -> Ordering Source #

(<) :: KernelSafety -> KernelSafety -> Bool Source #

(<=) :: KernelSafety -> KernelSafety -> Bool Source #

(>) :: KernelSafety -> KernelSafety -> Bool Source #

(>=) :: KernelSafety -> KernelSafety -> Bool Source #

max :: KernelSafety -> KernelSafety -> KernelSafety Source #

min :: KernelSafety -> KernelSafety -> KernelSafety Source #

numFailureParams :: KernelSafety -> Int Source #

How many leading failure arguments we must pass when launching a kernel with these safety characteristics.

data KernelTarget Source #

The target platform when compiling imperative code to a `Program`

Constructors

TargetOpenCL |
TargetCUDA |
TargetHIP |

#### Instances

Instances details

Eq KernelTarget Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.OpenCL Methods (==) :: KernelTarget -> KernelTarget -> Bool Source # (/=) :: KernelTarget -> KernelTarget -> Bool Source #

data FailureMsg Source #

Something that can go wrong in a kernel. Part of the machinery for reporting error messages from within kernels.

Constructors

FailureMsg |

Fields

- failureError :: ErrorMsg Exp
- failureBacktrace :: String

type BlockDim = Either Exp KernelConstExp Source #

The size of one dimension of a block.

data KernelConst Source #

A run-time constant related to kernels.

Constructors

SizeConst Name SizeClass |
SizeMaxConst SizeClass |

#### Instances

Instances details

Show KernelConst Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.GPU Methods showsPrec :: Int -> KernelConst -> ShowS Source # show :: KernelConst -> String Source # showList :: [KernelConst] -> ShowS Source #
FreeIn KernelConst Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.GPU Methods freeIn' :: KernelConst -> FV Source #
Eq KernelConst Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.GPU Methods (==) :: KernelConst -> KernelConst -> Bool Source # (/=) :: KernelConst -> KernelConst -> Bool Source #
Ord KernelConst Source # |

Instance details

Defined in Futhark.CodeGen.ImpCode.GPU

Methods

compare :: KernelConst -> KernelConst -> Ordering Source #

(<) :: KernelConst -> KernelConst -> Bool Source #

(<=) :: KernelConst -> KernelConst -> Bool Source #

(>) :: KernelConst -> KernelConst -> Bool Source #

(>=) :: KernelConst -> KernelConst -> Bool Source #

max :: KernelConst -> KernelConst -> KernelConst Source #

min :: KernelConst -> KernelConst -> KernelConst Source #

Pretty KernelConst Source # |
Instance details Defined in Futhark.CodeGen.ImpCode.GPU Methods pretty :: KernelConst -> Doc ann Source # prettyList :: [KernelConst] -> Doc ann Source #

type KernelConstExp = PrimExp KernelConst Source #

An expression whose variables are kernel constants.

module Futhark.CodeGen.ImpCode

module Futhark.IR.GPU.Sizes