{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Futhark.Representation.Kernels.Sizes
( SizeClass (..)
, KernelPath
, Count(..)
, NumGroups, GroupSize, NumThreads
)
where
import Data.Traversable
import Futhark.Util.Pretty
import Language.Futhark.Core (Name)
import Futhark.Util.IntegralExp (IntegralExp)
import Futhark.Representation.AST.Attributes.Names (FreeIn)
type KernelPath = [(Name, Bool)]
data SizeClass = SizeThreshold KernelPath
| SizeGroup
| SizeNumGroups
| SizeTile
| SizeLocalMemory
deriving (Eq, Ord, Show)
instance Pretty SizeClass where
ppr (SizeThreshold path) = text $ "threshold (" ++ unwords (map pStep path) ++ ")"
where pStep (v, True) = pretty v
pStep (v, False) = '!' : pretty v
ppr SizeGroup = text "group_size"
ppr SizeNumGroups = text "num_groups"
ppr SizeTile = text "tile_size"
ppr SizeLocalMemory = text "local_memory"
newtype Count u e = Count { unCount :: e }
deriving (Eq, Ord, Show, Num, IntegralExp, FreeIn, Pretty)
instance Functor (Count u) where
fmap = fmapDefault
instance Foldable (Count u) where
foldMap = foldMapDefault
instance Traversable (Count u) where
traverse f (Count x) = Count <$> f x
data NumGroups
data GroupSize
data NumThreads