{-# LANGUAGE CPP #-}
{-# OPTIONS_HADDOCK hide #-}
module Data.Array.Accelerate.Trafo (
convertAcc, convertAccWith,
Afunction, ArraysFunctionR,
convertAfun, convertAfunWith,
Function, EltFunctionR,
convertExp, convertFun,
) where
import Data.Array.Accelerate.Sugar.Array ( ArraysR )
import Data.Array.Accelerate.Sugar.Elt ( EltR )
import Data.Array.Accelerate.Smart
import Data.Array.Accelerate.Trafo.Config
import Data.Array.Accelerate.Trafo.Delayed
import Data.Array.Accelerate.Trafo.Sharing ( Afunction, ArraysFunctionR, Function, EltFunctionR )
import qualified Data.Array.Accelerate.AST as AST
import qualified Data.Array.Accelerate.Trafo.Fusion as Fusion
import qualified Data.Array.Accelerate.Trafo.LetSplit as LetSplit
import qualified Data.Array.Accelerate.Trafo.Simplify as Rewrite
import qualified Data.Array.Accelerate.Trafo.Sharing as Sharing
import Control.DeepSeq
#ifdef ACCELERATE_DEBUG
import Text.Printf
import System.IO.Unsafe
import Data.Array.Accelerate.Debug.Flags hiding ( when )
import Data.Array.Accelerate.Debug.Timed
#endif
convertAcc :: Acc arrs -> DelayedAcc (ArraysR arrs)
convertAcc :: Acc arrs -> DelayedAcc (ArraysR arrs)
convertAcc = Config -> Acc arrs -> DelayedAcc (ArraysR arrs)
forall arrs. Config -> Acc arrs -> DelayedAcc (ArraysR arrs)
convertAccWith Config
defaultOptions
convertAccWith :: Config -> Acc arrs -> DelayedAcc (ArraysR arrs)
convertAccWith :: Config -> Acc arrs -> DelayedAcc (ArraysR arrs)
convertAccWith Config
config
= String
-> (Acc (ArraysR arrs) -> DelayedAcc (ArraysR arrs))
-> Acc (ArraysR arrs)
-> DelayedAcc (ArraysR arrs)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"array-fusion" (Config -> Acc (ArraysR arrs) -> DelayedAcc (ArraysR arrs)
forall arrs. HasCallStack => Config -> Acc arrs -> DelayedAcc arrs
Fusion.convertAccWith Config
config)
(Acc (ArraysR arrs) -> DelayedAcc (ArraysR arrs))
-> (Acc arrs -> Acc (ArraysR arrs))
-> Acc arrs
-> DelayedAcc (ArraysR arrs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> (Acc (ArraysR arrs) -> Acc (ArraysR arrs))
-> Acc (ArraysR arrs)
-> Acc (ArraysR arrs)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"array-split-lets" Acc (ArraysR arrs) -> Acc (ArraysR arrs)
forall aenv a. OpenAcc aenv a -> OpenAcc aenv a
LetSplit.convertAcc
(Acc (ArraysR arrs) -> Acc (ArraysR arrs))
-> (Acc arrs -> Acc (ArraysR arrs))
-> Acc arrs
-> Acc (ArraysR arrs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> (Acc arrs -> Acc (ArraysR arrs))
-> Acc arrs
-> Acc (ArraysR arrs)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"sharing-recovery" (Config -> Acc arrs -> Acc (ArraysR arrs)
forall arrs.
HasCallStack =>
Config -> Acc arrs -> Acc (ArraysR arrs)
Sharing.convertAccWith Config
config)
convertAfun :: Afunction f => f -> DelayedAfun (ArraysFunctionR f)
convertAfun :: f -> DelayedAfun (ArraysFunctionR f)
convertAfun = Config -> f -> DelayedAfun (ArraysFunctionR f)
forall f.
Afunction f =>
Config -> f -> DelayedAfun (ArraysFunctionR f)
convertAfunWith Config
defaultOptions
convertAfunWith :: Afunction f => Config -> f -> DelayedAfun (ArraysFunctionR f)
convertAfunWith :: Config -> f -> DelayedAfun (ArraysFunctionR f)
convertAfunWith Config
config
= String
-> (Afun (ArraysFunctionR f) -> DelayedAfun (ArraysFunctionR f))
-> Afun (ArraysFunctionR f)
-> DelayedAfun (ArraysFunctionR f)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"array-fusion" (Config
-> Afun (ArraysFunctionR f) -> DelayedAfun (ArraysFunctionR f)
forall f. HasCallStack => Config -> Afun f -> DelayedAfun f
Fusion.convertAfunWith Config
config)
(Afun (ArraysFunctionR f) -> DelayedAfun (ArraysFunctionR f))
-> (f -> Afun (ArraysFunctionR f))
-> f
-> DelayedAfun (ArraysFunctionR f)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> (Afun (ArraysFunctionR f) -> Afun (ArraysFunctionR f))
-> Afun (ArraysFunctionR f)
-> Afun (ArraysFunctionR f)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"array-split-lets" Afun (ArraysFunctionR f) -> Afun (ArraysFunctionR f)
forall aenv f.
PreOpenAfun OpenAcc aenv f -> PreOpenAfun OpenAcc aenv f
LetSplit.convertAfun
(Afun (ArraysFunctionR f) -> Afun (ArraysFunctionR f))
-> (f -> Afun (ArraysFunctionR f)) -> f -> Afun (ArraysFunctionR f)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> (f -> Afun (ArraysFunctionR f)) -> f -> Afun (ArraysFunctionR f)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"sharing-recovery" (Config -> f -> Afun (ArraysFunctionR f)
forall f.
(HasCallStack, Afunction f) =>
Config -> f -> Afun (ArraysFunctionR f)
Sharing.convertAfunWith Config
config)
convertExp :: Exp e -> AST.Exp () (EltR e)
convertExp :: Exp e -> Exp () (EltR e)
convertExp
= String
-> (Exp () (EltR e) -> Exp () (EltR e))
-> Exp () (EltR e)
-> Exp () (EltR e)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"exp-simplify" Exp () (EltR e) -> Exp () (EltR e)
forall aenv t. HasCallStack => Exp aenv t -> Exp aenv t
Rewrite.simplifyExp
(Exp () (EltR e) -> Exp () (EltR e))
-> (Exp e -> Exp () (EltR e)) -> Exp e -> Exp () (EltR e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> (Exp e -> Exp () (EltR e)) -> Exp e -> Exp () (EltR e)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"sharing-recovery" Exp e -> Exp () (EltR e)
forall e. HasCallStack => Exp e -> Exp () (EltR e)
Sharing.convertExp
convertFun :: Function f => f -> AST.Fun () (EltFunctionR f)
convertFun :: f -> Fun () (EltFunctionR f)
convertFun
= String
-> (Fun () (EltFunctionR f) -> Fun () (EltFunctionR f))
-> Fun () (EltFunctionR f)
-> Fun () (EltFunctionR f)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"exp-simplify" Fun () (EltFunctionR f) -> Fun () (EltFunctionR f)
forall aenv f. HasCallStack => Fun aenv f -> Fun aenv f
Rewrite.simplifyFun
(Fun () (EltFunctionR f) -> Fun () (EltFunctionR f))
-> (f -> Fun () (EltFunctionR f)) -> f -> Fun () (EltFunctionR f)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String
-> (f -> Fun () (EltFunctionR f)) -> f -> Fun () (EltFunctionR f)
forall b a. NFData b => String -> (a -> b) -> a -> b
phase String
"sharing-recovery" f -> Fun () (EltFunctionR f)
forall f.
(HasCallStack, Function f) =>
f -> Fun () (EltFunctionR f)
Sharing.convertFun
phase :: NFData b => String -> (a -> b) -> a -> b
#ifdef ACCELERATE_DEBUG
phase n f x = unsafePerformIO $ do
enabled <- getFlag dump_phases
if enabled
then timed dump_phases (\wall cpu -> printf "phase %s: %s" n (elapsed wall cpu)) (return $!! f x)
else return (f x)
#else
phase :: String -> (a -> b) -> a -> b
phase String
_ a -> b
f = a -> b
f
#endif