diff --git a/accelerate.cabal b/accelerate.cabal index b3e1eca87..2a237c37e 100644 --- a/accelerate.cabal +++ b/accelerate.cabal @@ -355,8 +355,6 @@ library , hashable >= 1.1 , hashtables >= 1.2.3 , hedgehog >= 0.5 - -- , highs-lp >= 0.0 - -- , linear-programming >= 0.0.0.1 , microlens >= 0.4 , microlens-th >= 0.4 , microlens-mtl >= 0.2 diff --git a/src/Data/Array/Accelerate/AST.hs b/src/Data/Array/Accelerate/AST.hs index 0db692bf7..f78c67fd6 100644 --- a/src/Data/Array/Accelerate/AST.hs +++ b/src/Data/Array/Accelerate/AST.hs @@ -185,7 +185,7 @@ type Afun = OpenAfun () -- Vanilla open array computations -- -newtype OpenAcc aenv t = OpenAcc (PreOpenAcc OpenAcc aenv t) +newtype OpenAcc aenv t = OpenAcc { runOpenAcc :: PreOpenAcc OpenAcc aenv t } -- | Closed array expression aka an array program -- @@ -632,7 +632,7 @@ rnfPreOpenAcc rnfA pacc = rnfB = rnfBoundary rnfM :: Message a -> () - rnfM (Message f g msg) = f `seq` rnfMaybe (\x -> x `seq` ()) g `seq` rnf msg + rnfM (Message f g msg) = f `seq` rnfMaybe (`seq` ()) g `seq` rnf msg in case pacc of Alet lhs bnd body -> rnfALeftHandSide lhs `seq` rnfA bnd `seq` rnfA body diff --git a/src/Data/Array/Accelerate/AST/Schedule/Sequential.hs b/src/Data/Array/Accelerate/AST/Schedule/Sequential.hs index b10939c36..7747bb80c 100644 --- a/src/Data/Array/Accelerate/AST/Schedule/Sequential.hs +++ b/src/Data/Array/Accelerate/AST/Schedule/Sequential.hs @@ -1,10 +1,7 @@ -{-# LANGUAGE EmptyCase #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_HADDOCK hide #-} @@ -33,15 +30,14 @@ import Data.Array.Accelerate.Type import Data.Array.Accelerate.Representation.Array import Data.Array.Accelerate.Representation.Shape import Data.Array.Accelerate.Representation.Type -import Data.Array.Accelerate.AST.Var import Data.Array.Accelerate.AST.LeftHandSide import qualified Data.Array.Accelerate.AST.Operation as Operation -import Data.Array.Accelerate.AST.Partitioned hiding (PreOpenAcc(..), PreOperationAfun(..), PartitionedAcc, PartitionedAfun) +import Data.Array.Accelerate.AST.Partitioned hiding (PreOpenAcc(..), PartitionedAcc, PartitionedAfun) import qualified Data.Array.Accelerate.AST.Partitioned as Partition import Data.Array.Accelerate.AST.Kernel import Data.Array.Accelerate.AST.Schedule import Data.Array.Accelerate.AST.Schedule.Uniform ( SArg(..), SArgs ) -import Data.Array.Accelerate.Trafo.Schedule.Uniform ( compileKernel', CompiledKernel(..), rnfSArg, rnfSArgs ) +import Data.Array.Accelerate.Trafo.Schedule.Uniform ( compileKernel', CompiledKernel(..), rnfSArgs ) import Data.Array.Accelerate.AST.Execute import Control.Concurrent.MVar import Data.Typeable ( (:~:)(..) ) diff --git a/src/Data/Array/Accelerate/Backend.hs b/src/Data/Array/Accelerate/Backend.hs index b0f5c684f..76ef524d3 100644 --- a/src/Data/Array/Accelerate/Backend.hs +++ b/src/Data/Array/Accelerate/Backend.hs @@ -1,16 +1,12 @@ {-# LANGUAGE AllowAmbiguousTypes #-} -{-# LANGUAGE BangPatterns #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE MagicHash #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} -- | -- Module : Data.Array.Accelerate.Backend @@ -51,7 +47,7 @@ module Data.Array.Accelerate.Backend ( Pretty.PrettyOp(..), Execute(..), Operation.NFData'(..), - Operation.ShrinkArg(..), runWithObj, runNWithObj, runNBench, Benchmarking(..) + Operation.ShrinkArg(..), runWithObj, runNWithObj, runNBench, Benchmarking ) where import qualified Data.Array.Accelerate.Smart as Smart @@ -77,7 +73,6 @@ import Data.Type.Equality import System.IO.Unsafe (unsafePerformIO) import qualified Data.Array.Accelerate.AST.Operation as Operation import qualified Data.Array.Accelerate.Trafo.Partitioning.ILP.Graph as Graph -import Data.Array.Accelerate.Eval (EvalOp) import Data.Array.Accelerate.Trafo.Partitioning.ILP.Solve (Objective) import Data.Array.Accelerate.Trafo.Partitioning.ILP (Benchmarking) diff --git a/src/Data/Array/Accelerate/Interpreter.hs b/src/Data/Array/Accelerate/Interpreter.hs index 9007a58c4..8cbe283a5 100644 --- a/src/Data/Array/Accelerate/Interpreter.hs +++ b/src/Data/Array/Accelerate/Interpreter.hs @@ -46,8 +46,7 @@ module Data.Array.Accelerate.Interpreter ( ) where import Prelude hiding (take, (!!), sum, Either(..) ) -import Data.Array.Accelerate.AST.Partitioned hiding (Empty) -import Data.Array.Accelerate.AST.Operation +import Data.Array.Accelerate.AST.Partitioned import Data.Array.Accelerate.AST.Kernel import Data.Array.Accelerate.Trafo.Desugar import qualified Data.Array.Accelerate.Debug.Internal as Debug @@ -82,7 +81,7 @@ import Lens.Micro ((.~), (&)) import Data.Array.Accelerate.Array.Buffer import Data.Array.Accelerate.Pretty.Partitioned () import Data.Array.Accelerate.AST.Idx -import Data.Array.Accelerate.AST.LeftHandSide (LeftHandSide (LeftHandSideWildcard, LeftHandSideUnit)) +import Data.Array.Accelerate.AST.LeftHandSide (LeftHandSide (LeftHandSideUnit)) import Data.Array.Accelerate.AST.Schedule import Control.Concurrent (forkIO) @@ -97,7 +96,6 @@ import qualified Data.Map as M import Control.Monad (when) import Data.Array.Accelerate.Trafo.Var (DeclareVars(DeclareVars), declareVars) import Data.Array.Accelerate.Trafo.Operation.Substitution (alet, aletUnique, weaken, LHS (LHS), mkLHS) -import Control.DeepSeq (rnf) import Data.Map (Map) import System.IO.Unsafe (unsafePerformIO) @@ -105,8 +103,6 @@ import Data.Array.Accelerate.Eval import qualified Data.Array.Accelerate.AST.Partitioned as P import Data.Functor.Identity import Data.Array.Accelerate.Trafo.LiveVars -import qualified Debug.Trace -import Data.Maybe (fromJust) data Interpreter instance Backend Interpreter where @@ -114,6 +110,7 @@ instance Backend Interpreter where type Kernel Interpreter = InterpretKernel +(!?!) :: (Ord a1, Show a1, Show a2) => Map a1 a2 -> a1 -> a2 map !?! key = case map M.!? key of Just x -> x Nothing -> error ("error: map "<> show map <> "does not contain key " <> show key) @@ -128,7 +125,7 @@ instance Eq (BackendClusterArg2 InterpretOp env arg) where BCA f x == BCA g y = map f [1..100] == map g [1..100] && x == y instance Show (BackendClusterArg2 InterpretOp env arg) where - show (BCA f a) = "bca" + show (BCA _ _) = "bca" instance StaticClusterAnalysis InterpretOp where data BackendClusterArg2 InterpretOp env arg = BCA (Int -> Int) Int -- backpermute function and iteration size @@ -714,7 +711,7 @@ doNTimes n f linearIndexToSh :: ShapeR sh -> sh -> Int -> sh linearIndexToSh ShapeRz () 0 = () linearIndexToSh ShapeRz () _ = error "non-zero index in unit array" -linearIndexToSh (ShapeRsnoc shr) (sh, outer) i = let +linearIndexToSh (ShapeRsnoc shr) (sh, _) i = let innerSize = arrsize shr sh outerIndex = i `div` innerSize innerIndex = linearIndexToSh shr sh (i `mod` innerSize) @@ -722,7 +719,7 @@ linearIndexToSh (ShapeRsnoc shr) (sh, outer) i = let shToLinearIndex :: ShapeR sh -> sh -> sh -> Int shToLinearIndex ShapeRz () () = 0 -shToLinearIndex (ShapeRsnoc shr) (sh, x) (sh', y) = let +shToLinearIndex (ShapeRsnoc shr) (sh, _) (sh', y) = let innerSize = arrsize shr sh innerIndex = shToLinearIndex shr sh sh' in y*innerSize+innerIndex diff --git a/src/Data/Array/Accelerate/Pretty.hs b/src/Data/Array/Accelerate/Pretty.hs index fc4a6545d..560c53d15 100644 --- a/src/Data/Array/Accelerate/Pretty.hs +++ b/src/Data/Array/Accelerate/Pretty.hs @@ -4,8 +4,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeApplications #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_HADDOCK hide #-} @@ -32,20 +30,15 @@ module Data.Array.Accelerate.Pretty ( -- ** Graphviz Graph, - PrettyGraph(..), Detail(..), + PrettyGraph, Detail, graphDelayedAcc, graphDelayedAfun, ) where import Data.Array.Accelerate.AST hiding ( Acc, Exp ) import Data.Array.Accelerate.Debug.Internal.Flags -import Data.Array.Accelerate.Error import Data.Array.Accelerate.Pretty.Graphviz import Data.Array.Accelerate.Pretty.Print hiding ( Keyword(..) ) -import Data.Array.Accelerate.Pretty.Exp hiding ( Keyword(..) ) -import Data.Array.Accelerate.Smart ( Acc, Exp ) -import Data.Array.Accelerate.Sugar.Array -import Data.Array.Accelerate.Sugar.Elt -- import Data.Array.Accelerate.Trafo.Delayed import Data.Maybe @@ -58,7 +51,6 @@ import System.IO.Unsafe import qualified Data.Text.Lazy as T import qualified System.Console.ANSI as Term import qualified System.Console.Terminal.Size as Term -import Data.Array.Accelerate.AST.Operation (OperationAcc, OperationAfun) #if ACCELERATE_DEBUG import Control.DeepSeq @@ -87,13 +79,6 @@ instance PrettyEnv aenv => Show (OpenAcc aenv a) where instance PrettyEnv aenv => Show (OpenAfun aenv f) where show = renderForTerminal . prettyPreOpenAfun configPlain prettyOpenAcc (prettyEnv (pretty 'a')) -instance PrettyEnv aenv => Show (OperationAcc op aenv a) where - -- show = let config = if shouldPrintHash then configWithHash else configPlain - -- in renderForTerminal . prettyDelayedOpenAcc config context0 (prettyEnv (pretty 'a')) - -instance PrettyEnv aenv => Show (OperationAfun op aenv f) where - -- show = let config = if shouldPrintHash then configWithHash else configPlain - -- in renderForTerminal . prettyPreOpenAfun config prettyDelayedOpenAcc (prettyEnv (pretty 'a')) instance (PrettyEnv env, PrettyEnv aenv) => Show (OpenExp env aenv e) where show = renderForTerminal . prettyOpenExp context0 (prettyEnv (pretty 'x')) (prettyEnv (pretty 'a')) @@ -122,8 +107,6 @@ terminalSupportsANSI :: Bool terminalSupportsANSI = unsafePerformIO $ Term.hSupportsANSI stdout {-# NOINLINE terminalLayoutOptions #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeApplications #-} terminalLayoutOptions :: LayoutOptions terminalLayoutOptions = unsafePerformIO diff --git a/src/Data/Array/Accelerate/Pretty/Operation.hs b/src/Data/Array/Accelerate/Pretty/Operation.hs index 38d4bfa77..4f9323934 100644 --- a/src/Data/Array/Accelerate/Pretty/Operation.hs +++ b/src/Data/Array/Accelerate/Pretty/Operation.hs @@ -4,11 +4,8 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} + -- | -- Module : Data.Array.Accelerate.Pretty.Operation -- Copyright : [2008..2020] The Accelerate Team @@ -40,7 +37,7 @@ import Data.Array.Accelerate.Representation.Elt import Data.Array.Accelerate.Representation.Type import Data.Array.Accelerate.Type -import Data.Text.Prettyprint.Doc +import Prettyprinter import Data.String import Prelude hiding (exp) diff --git a/src/Data/Array/Accelerate/Pretty/Print.hs b/src/Data/Array/Accelerate/Pretty/Print.hs index 32f41906f..e01247952 100644 --- a/src/Data/Array/Accelerate/Pretty/Print.hs +++ b/src/Data/Array/Accelerate/Pretty/Print.hs @@ -2,12 +2,8 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} -- | -- Module : Data.Array.Accelerate.Pretty.Print @@ -96,7 +92,7 @@ ansiKeyword Execute = color Blue ansiKeyword Modifier = colorDull Blue -- Configuration for the pretty-printing functions -data PrettyConfig acc +newtype PrettyConfig acc = PrettyConfig { confOperator :: forall aenv arrs. PreOpenAcc acc aenv arrs -> String @@ -126,7 +122,7 @@ prettyPreOpenAfun -> Val aenv -> PreOpenAfun acc aenv f -> Adoc -prettyPreOpenAfun config prettyAcc aenv0 = next (pretty '\\') aenv0 +prettyPreOpenAfun config prettyAcc = next (pretty '\\') where next :: Adoc -> Val aenv' -> PreOpenAfun acc aenv' f' -> Adoc next vs aenv (Abody body) = diff --git a/src/Data/Array/Accelerate/Trafo.hs b/src/Data/Array/Accelerate/Trafo.hs index e2e37d7b9..56a4e0d8b 100644 --- a/src/Data/Array/Accelerate/Trafo.hs +++ b/src/Data/Array/Accelerate/Trafo.hs @@ -67,111 +67,38 @@ import Data.Text.Lazy.Builder import qualified Data.Array.Accelerate.AST.Operation as Operation import qualified Data.Array.Accelerate.Trafo.Partitioning.ILP.Graph as Graph import Data.Array.Accelerate.Pretty.Print (configPlain, Val (Empty)) -import qualified Debug.Trace -import Data.Text.Lazy (unpack) -import Formatting -import System.IO.Unsafe -import Data.Array.Accelerate.Debug.Internal.Flags hiding ( when ) -import Data.Array.Accelerate.Debug.Internal.Timed import Data.Array.Accelerate.Trafo.Partitioning.ILP.Solve (Objective(..)) import Data.Array.Accelerate.Trafo.NewNewFusion (Benchmarking) +import Data.Array.Accelerate.Trafo.Partitioning.ILP (FusionType(..), defaultObjective) +import Control.Monad.Trans.Writer (runWriter, Writer, writer) +import Control.Monad ((>=>)) +import Data.Array.Accelerate.Pretty.Exp (context0) -defaultObjective = IntermediateArrays -- TODO: so much duplication here, and I keep worrying that there are differences hiding in one of them. -- need to abstract a bit! test - :: forall sched kernel f. (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + :: forall sched kernel f. (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) => f -> String -test = testWithObjective @sched @kernel @f defaultObjective +test = snd . convertAfunFullOptions @sched @kernel defaultOptions defaultObjective Pretty.renderForTerminal -- TODO: simplifications commented out, because they REMOVE PERMUTE testWithObjective - :: forall sched kernel f. (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + :: forall sched kernel f. (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) => Objective -> f -> String -testWithObjective obj f - = "OriginalAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyPreOpenAfun configPlain prettyOpenAcc Empty original) - ++ "\n\nDesugared OperationAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun desugared) - ++ "\n\nSimplified OperationAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun operation) - ++ "\n\nPartitionedAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun partitioned) - ++ "\nSLV'd PartitionedAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun slvpartitioned) - ++ "\n\nSchedule:\n" - ++ Pretty.renderForTerminal (Pretty.prettySchedule schedule) - where - operation - = - Operation.simplifyFun $ - Operation.stronglyLiveVariablesFun $ - Operation.simplifyFun $ - desugared - desugared = - desugarAfun @(KernelOperation kernel) - $ original - original = - LetSplit.convertAfun - $ Sharing.convertAfunWith defaultOptions f - - partitioned = - Operation.simplifyFun $ - NewNewFusion.convertAfun obj operation - - slvpartitioned = - Operation.simplifyFun $ - Operation.stronglyLiveVariablesFun partitioned - - schedule = convertScheduleFun @sched @kernel slvpartitioned +testWithObjective obj = snd . convertAfunFullOptions @sched @kernel defaultOptions (Fusion obj) Pretty.renderForTerminal testBench - :: forall sched kernel f. (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + :: forall sched kernel f. (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) => Benchmarking -> f -> String -testBench bench f - = "OriginalAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyPreOpenAfun configPlain prettyOpenAcc Empty original) - ++ "\n\nDesugared OperationAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun desugared) - ++ "\n\nSimplified OperationAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun operation) - ++ "\n\nPartitionedAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun partitioned) - ++ "\nSLV'd PartitionedAcc:\n" - ++ Pretty.renderForTerminal (Pretty.prettyAfun slvpartitioned) - ++ "\n\nSchedule:\n" - ++ Pretty.renderForTerminal (Pretty.prettySchedule schedule) - where - operation - = - Operation.simplifyFun $ - Operation.stronglyLiveVariablesFun $ - Operation.simplifyFun $ - desugared - desugared = - desugarAfun @(KernelOperation kernel) - $ original - original = - LetSplit.convertAfun - $ Sharing.convertAfunWith defaultOptions f - - partitioned = - Operation.simplifyFun $ - NewNewFusion.convertAccBenchF bench operation - - slvpartitioned = - Operation.simplifyFun $ - Operation.stronglyLiveVariablesFun partitioned - - schedule = convertScheduleFun @sched @kernel slvpartitioned +testBench bench = snd . convertAfunFullOptions @sched @kernel defaultOptions (Benchmarking bench) Pretty.renderForTerminal @@ -184,43 +111,26 @@ testBench bench f -- convertAcc :: forall sched kernel arrs. - (DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + (DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Pretty.PrettySchedule sched, Pretty.PrettyKernel kernel) => Acc arrs -> sched kernel () (ScheduleOutput sched (DesugaredArrays (ArraysR arrs)) -> ()) convertAcc = convertAccWith defaultOptions convertAccWith :: forall sched kernel arrs. - (DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + (DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Pretty.PrettySchedule sched, Pretty.PrettyKernel kernel) => Config -> Acc arrs -> sched kernel () (ScheduleOutput sched (DesugaredArrays (ArraysR arrs)) -> ()) -convertAccWith config - = phase' "codegen" rnfSchedule convertSchedule - . phase "partition-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) - . phase "array-fusion" (Operation.simplify . NewNewFusion.convertAccWith config defaultObjective) - . phase "operation-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) - . phase "desugar" (Operation.simplify . desugar) - . phase "array-split-lets" LetSplit.convertAcc - -- phase "vectorise-sequences" Vectorise.vectoriseSeqAcc `when` vectoriseSequences - . phase "sharing-recovery" (Sharing.convertAccWith config) - -convertAccBench +convertAccWith config = fst . convertAccFullOptions config defaultObjective (const ()) + +convertAccBench :: forall sched kernel arrs. (Pretty.PrettySchedule sched, Pretty.PrettyKernel kernel, DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) => NewNewFusion.Benchmarking -> Acc arrs -> sched kernel () (ScheduleOutput sched (DesugaredArrays (ArraysR arrs)) -> ()) -convertAccBench b - = --(\s -> Debug.Trace.trace (Pretty.renderForTerminal (Pretty.prettySchedule s)) s) . - phase' "codegen" rnfSchedule convertSchedule - . phase "partition-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) - . phase "array-fusion" (Operation.simplify . NewNewFusion.convertAccBench b) - . phase "operation-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) - . phase "desugar" (Operation.simplify . desugar) - . phase "array-split-lets" LetSplit.convertAcc - -- phase "vectorise-sequences" Vectorise.vectoriseSeqAcc `when` vectoriseSequences - . phase "sharing-recovery" (Sharing.convertAccWith defaultOptions) +convertAccBench b = fst . convertAccFullOptions defaultOptions (Benchmarking b) (const ()) convertAfunBench :: forall sched kernel f. @@ -228,33 +138,16 @@ convertAfunBench => NewNewFusion.Benchmarking -> f -> sched kernel () (Scheduled sched (DesugaredAfun (ArraysFunctionR f))) -convertAfunBench b - = --(\s -> Debug.Trace.trace (Pretty.renderForTerminal (Pretty.prettySchedule s)) s) . - phase' "codegen" rnfSchedule convertScheduleFun - . phase "partition-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) - . phase "array-fusion" (Operation.simplifyFun . NewNewFusion.convertAccBenchF b) - . phase "operation-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) - . phase "desugar" (Operation.simplifyFun . desugarAfun) - . phase "array-split-lets" LetSplit.convertAfun - -- phase "vectorise-sequences" Vectorise.vectoriseSeqAfun `when` vectoriseSequences - . phase "sharing-recovery" (Sharing.convertAfunWith defaultOptions) +convertAfunBench b = fst . convertAfunFullOptions defaultOptions (Benchmarking b) (const ()) convertAccWithObj :: forall sched kernel arrs. - (DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + (DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Pretty.PrettySchedule sched, Pretty.PrettyKernel kernel) => Objective -> Acc arrs -> sched kernel () (ScheduleOutput sched (DesugaredArrays (ArraysR arrs)) -> ()) -convertAccWithObj obj - = phase' "codegen" rnfSchedule convertSchedule - . phase "partition-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) - . phase "array-fusion" (Operation.simplify . NewNewFusion.convertAccWith defaultOptions obj) - . phase "operation-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) - . phase "desugar" (Operation.simplify . desugar) - . phase "array-split-lets" LetSplit.convertAcc - -- phase "vectorise-sequences" Vectorise.vectoriseSeqAcc `when` vectoriseSequences - . phase "sharing-recovery" (Sharing.convertAccWith defaultOptions) +convertAccWithObj obj = fst . convertAccFullOptions defaultOptions (Fusion obj) (const ()) -- | Convert a unary function over array computations, incorporating sharing @@ -273,32 +166,53 @@ convertAfunWith => Config -> f -> sched kernel () (Scheduled sched (DesugaredAfun (ArraysFunctionR f))) -convertAfunWith config - = --(\s -> Debug.Trace.trace (Pretty.renderForTerminal (Pretty.prettySchedule s)) s) . - phase' "codegen" rnfSchedule convertScheduleFun - . phase "partition-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) - . phase "array-fusion" (Operation.simplifyFun . NewNewFusion.convertAfunWith config defaultObjective) - . phase "operation-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) - . phase "desugar" (Operation.simplifyFun . desugarAfun) - . phase "array-split-lets" LetSplit.convertAfun - -- phase "vectorise-sequences" Vectorise.vectoriseSeqAfun `when` vectoriseSequences - . phase "sharing-recovery" (Sharing.convertAfunWith config) +convertAfunWith config = fst . convertAfunFullOptions config defaultObjective (const ()) convertAfunWithObj :: forall sched kernel f. - (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + (Afunction f, DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Pretty.PrettySchedule sched, Pretty.PrettyKernel kernel) => Objective -> f -> sched kernel () (Scheduled sched (DesugaredAfun (ArraysFunctionR f))) -convertAfunWithObj obj - = phase' "codegen" rnfSchedule convertScheduleFun - . phase "partition-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) - . phase "array-fusion" (Operation.simplifyFun . NewNewFusion.convertAfunWith defaultOptions obj) - . phase "operation-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) - . phase "desugar" (Operation.simplifyFun . desugarAfun) - . phase "array-split-lets" LetSplit.convertAfun - -- phase "vectorise-sequences" Vectorise.vectoriseSeqAfun `when` vectoriseSequences - . phase "sharing-recovery" (Sharing.convertAfunWith defaultOptions) +convertAfunWithObj obj = fst . convertAfunFullOptions defaultOptions (Fusion obj) (const ()) + + +convertAccFullOptions + :: forall sched kernel arrs m. + (Monoid m, DesugarAcc (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), IsSchedule sched, IsKernel kernel, Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Pretty.PrettySchedule sched, Pretty.PrettyKernel kernel) + => Config -> FusionType -> (Pretty.Adoc -> m) + -> Acc arrs -> (sched kernel () (ScheduleOutput sched (DesugaredArrays (ArraysR arrs)) -> ()), m) +convertAccFullOptions config ft pprint acc = runWriter $ + ( phase'' "sharing-recovery" (Sharing.convertAccWith config) (Pretty.prettyPreOpenAcc configPlain context0 prettyOpenAcc AST.runOpenAcc Empty . AST.runOpenAcc) + >=> phase'' "array-split-lets" LetSplit.convertAcc (Pretty.prettyPreOpenAcc configPlain context0 prettyOpenAcc AST.runOpenAcc Empty . AST.runOpenAcc) + >=> phase'' "desugar" (Operation.simplify . desugar) Pretty.prettyAcc + >=> phase'' "operation-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) Pretty.prettyAcc + >=> phase'' "array-fusion" (Operation.simplify . NewNewFusion.convertAccWith config ft) Pretty.prettyAcc + >=> phase'' "partition-live-vars" (Operation.simplify . Operation.stronglyLiveVariables) Pretty.prettyAcc + >=> (\x -> let y = phase' "codegen" rnfSchedule convertSchedule x in writer (y, pprint $ Pretty.prettySchedule y)) + ) acc + where + phase'' :: NFData b => Builder -> (a -> b) -> (b -> Pretty.Adoc) -> a -> Writer m b + phase'' name f pp a = let b = phase name f a in writer (b, pprint $ pp b) + +convertAfunFullOptions + :: forall sched kernel f m. + (Monoid m, Afunction f, DesugarAcc (KernelOperation kernel), Operation.SimplifyOperation (KernelOperation kernel), Operation.SLVOperation (KernelOperation kernel), Partitioning.MakesILP (KernelOperation kernel), Pretty.PrettyOp (KernelOperation kernel), Pretty.PrettyKernel kernel, IsSchedule sched, IsKernel kernel, Pretty.PrettySchedule sched, Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel)), Operation.NFData' (Graph.BackendClusterArg (KernelOperation kernel)), Operation.ShrinkArg (Partitioning.BackendClusterArg (KernelOperation kernel))) + => Config -> FusionType -> (Pretty.Adoc -> m) + -> f -> (sched kernel () (Scheduled sched (DesugaredAfun (ArraysFunctionR f))), m) +convertAfunFullOptions config ft pprint f = runWriter $ + ( phase'' "sharing-recovery" (Sharing.convertAfunWith config) (Pretty.prettyPreOpenAfun configPlain prettyOpenAcc Empty) + >=> phase'' "array-split-lets" LetSplit.convertAfun (Pretty.prettyPreOpenAfun configPlain prettyOpenAcc Empty) + >=> phase'' "desugar" (Operation.simplifyFun . desugarAfun) Pretty.prettyAfun + >=> phase'' "operation-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) Pretty.prettyAfun + >=> phase'' "array-fusion" (Operation.simplifyFun . NewNewFusion.convertAfunWith config ft) Pretty.prettyAfun + >=> phase'' "partition-live-vars" (Operation.simplifyFun . Operation.stronglyLiveVariablesFun) Pretty.prettyAfun + >=> (\x -> let y = phase' "codegen" rnfSchedule convertScheduleFun x in writer (y, pprint $ Pretty.prettySchedule y)) + ) f + where + phase'' :: NFData b => Builder -> (a -> b) -> (b -> Pretty.Adoc) -> a -> Writer m b + phase'' name g pp a = let b = phase name g a in writer (b, pprint $ pp b) + -- | Convert a closed scalar expression, incorporating sharing observation and @@ -318,26 +232,6 @@ convertFun = phase "exp-simplify" Rewrite.simplifyFun . phase "sharing-recovery" Sharing.convertFun -{-- --- | Convert a closed sequence computation, incorporating sharing observation and --- optimisation. --- -convertSeq :: Typeable s => Seq s -> DelayedSeq s -convertSeq = convertSeqWith phases - -convertSeqWith :: Typeable s => Phase -> Seq s -> DelayedSeq s -convertSeqWith Phase{..} s - = phase "array-fusion" (Fusion.convertSeq enableAccFusion) - -- $ phase "vectorise-sequences" Vectorise.vectoriseSeq `when` vectoriseSequences - -- $ phase "rewrite-segment-offset" Rewrite.convertSegmentsSeq `when` convertOffsetOfSegment - $ phase "sharing-recovery" (Sharing.convertSeq recoverAccSharing recoverExpSharing recoverSeqSharing floatOutAccFromExp) - $ s ---} - - --- when :: (a -> a) -> Bool -> a -> a --- when f True = f --- when _ False = id -- Debugging -- --------- diff --git a/src/Data/Array/Accelerate/Trafo/Desugar.hs b/src/Data/Array/Accelerate/Trafo/Desugar.hs index 63490c863..cb8e8b3e2 100644 --- a/src/Data/Array/Accelerate/Trafo/Desugar.hs +++ b/src/Data/Array/Accelerate/Trafo/Desugar.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE EmptyCase #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} @@ -207,7 +206,7 @@ class NFData' op => DesugarAcc (op :: Type -> Type) where -> Arg env (In (sh, Int) e) -> Arg env (Out sh e) -> OperationAcc op env () - mkFold f def input@(ArgArray _ repr@(ArrayR shr tp) _ _) output = mkDefaultFoldSequential f def input output + mkFold f def input@(ArgArray _ _ _ _) output = mkDefaultFoldSequential f def input output mkFoldSeg :: IntegralType i -> Arg env (Fun' (e -> e -> e)) @@ -217,7 +216,7 @@ class NFData' op => DesugarAcc (op :: Type -> Type) where -> Arg env (Out (sh, Int) e) -> OperationAcc op env () -- Default implementation using generate. It is sequential per segment, which is inefficient for some backends. - mkFoldSeg itp f def input segments output = mkGenerate (ArgFun $ mkDefaultFoldSegFunction itp f def input segments) output + mkFoldSeg itp f def input segments = mkGenerate (ArgFun $ mkDefaultFoldSegFunction itp f def input segments) mkScan :: Direction -> Arg env (Fun' (e -> e -> e)) @@ -1163,11 +1162,11 @@ mkIntersect shr x y mkIntersect' (ShapeRsnoc _) _ _ = error "Impossible pair" mkDefaultFoldSequential :: forall benv op sh e. DesugarAcc op => Arg benv (Fun' (e -> e -> e)) -> Maybe (Arg benv (Exp' e)) -> Arg benv (In (sh, Int) e) -> Arg benv (Out sh e) -> OperationAcc op benv () -mkDefaultFoldSequential op def argIn argOut = mkGenerate (mkDefaultFoldFunction op def argIn) argOut +mkDefaultFoldSequential op def argIn = mkGenerate (mkDefaultFoldFunction op def argIn) mkDefaultFoldFunction :: Arg benv (Fun' (e -> e -> e)) -> Maybe (Arg benv (Exp' e)) -> Arg benv (In (sh, Int) e) -> Arg benv (Fun' (sh -> e)) mkDefaultFoldFunction (ArgFun op) def (ArgArray _ (ArrayR (ShapeRsnoc shr) tp) (sh `TupRpair` n) buffers) - | DeclareVars lhsIdx k1 valueIdx <- declareVars $ shapeType shr + | DeclareVars lhsIdx _k1 valueIdx <- declareVars $ shapeType shr , DeclareVars lhsVal k2 valueVal <- declareVars tp = let initial = case def of @@ -1202,7 +1201,7 @@ mkDefaultFoldFunction (ArgFun op) def (ArgArray _ (ArrayR (ShapeRsnoc shr) tp) ( -- The default value is placed as the first value in case of a left-to-right scan, or as the -- last value for a right-to-left scan. mkDefaultScanPrepend :: Direction -> Arg benv (Exp' e) -> Arg benv (In (sh, Int) e) -> Fun benv ((sh, Int) -> e) -mkDefaultScanPrepend dir (ArgExp def) (ArgArray _ repr@(ArrayR (ShapeRsnoc shr) tp) sh input) +mkDefaultScanPrepend dir (ArgExp def) (ArgArray _ repr@(ArrayR (ShapeRsnoc shr) _) sh input) | DeclareVars lhs k value <- declareVars $ shapeType shr = let first = case dir of @@ -1223,7 +1222,7 @@ mkDefaultScanPrepend dir (ArgExp def) (ArgArray _ repr@(ArrayR (ShapeRsnoc shr) -- TODO: Is the order of arguments to 'f' correct, in both directions? mkDefaultScanFunction :: Direction -> GroundVar benv Int -> Arg benv (Fun' (e -> e -> e)) -> Arg benv (In (sh, Int) e) -> Fun benv ((sh, Int) -> e) mkDefaultScanFunction dir inc (ArgFun f) (ArgArray _ repr@(ArrayR (ShapeRsnoc shr) tp) sh input) - | DeclareVars lhs k value <- declareVars $ shapeType shr + | DeclareVars lhs _ value <- declareVars $ shapeType shr = let op = case dir of LeftToRight -> PrimSub diff --git a/src/Data/Array/Accelerate/Trafo/NewNewFusion.hs b/src/Data/Array/Accelerate/Trafo/NewNewFusion.hs index 4ade9a2c4..41389f853 100644 --- a/src/Data/Array/Accelerate/Trafo/NewNewFusion.hs +++ b/src/Data/Array/Accelerate/Trafo/NewNewFusion.hs @@ -3,16 +3,9 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE KindSignatures #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} -- | -- Module : Data.Array.Accelerate.Trafo.NewNewFusion @@ -30,8 +23,8 @@ module Data.Array.Accelerate.Trafo.NewNewFusion ( convertAcc, convertAccWith, convertAfun, convertAfunWith, - - Benchmarking(..), convertAccBench, convertAccBenchF + + Benchmarking(..) ) where @@ -43,48 +36,41 @@ import Data.Array.Accelerate.Trafo.Partitioning.ILP import Data.Array.Accelerate.Trafo.Partitioning.ILP.Graph (MakesILP) import qualified Data.Array.Accelerate.Pretty.Operation as Pretty import Data.Array.Accelerate.Trafo.Partitioning.ILP.Solve (Objective (..)) --- import Data.Array.Accelerate.Trafo.Partitioning.ILP.HiGHS (HiGHS(..)) -#ifdef ACCELERATE_DEBUG -import System.IO.Unsafe -- for debugging -#endif -convertAccBench :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Benchmarking -> OperationAcc op () a -> PartitionedAcc op () a -convertAccBench NoFusion = withSimplStats (no FusedEdges) -convertAccBench greedydir = withSimplStats (greedy greedydir FusedEdges) -convertAccBenchF :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Benchmarking -> OperationAfun op () a -> PartitionedAfun op () a -convertAccBenchF NoFusion = withSimplStats (noF FusedEdges) -convertAccBenchF greedydir = withSimplStats (greedyF greedydir FusedEdges) -- Array Fusion -- ============ -defaultSolver = - MIPSolver Gurobi +defaultSolver :: Solver +defaultSolver = + MIPSolver CBC -- | Apply the fusion transformation to a de Bruijn AST -- convertAccWith :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => Config - -> Objective + -> FusionType -> OperationAcc op () a -> PartitionedAcc op () a -convertAccWith _ = withSimplStats (ilpFusion'' defaultSolver) +convertAccWith _ (Fusion o) = withSimplStats (ilpFusion'' defaultSolver o) +convertAccWith _ (Benchmarking b) = withSimplStats (bench b FusedEdges) -convertAcc :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => Objective -> OperationAcc op () a -> PartitionedAcc op () a +convertAcc :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => FusionType -> OperationAcc op () a -> PartitionedAcc op () a convertAcc = convertAccWith defaultOptions -- | Apply the fusion transformation to a function of array arguments -- -convertAfun :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => Objective -> OperationAfun op () f -> PartitionedAfun op () f +convertAfun :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => FusionType -> OperationAfun op () f -> PartitionedAfun op () f convertAfun = convertAfunWith defaultOptions -convertAfunWith :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => Config -> Objective -> OperationAfun op () f -> PartitionedAfun op () f -convertAfunWith _ = withSimplStats (ilpFusionF'' defaultSolver) +convertAfunWith :: (HasCallStack, MakesILP op, Pretty.PrettyOp (Cluster op)) => Config -> FusionType -> OperationAfun op () f -> PartitionedAfun op () f +convertAfunWith _ (Fusion o) = withSimplStats (ilpFusionF'' defaultSolver o) +convertAfunWith _ (Benchmarking b) = withSimplStats (benchF b FusedEdges) withSimplStats :: a -> a diff --git a/src/Data/Array/Accelerate/Trafo/Operation/LiveVars.hs b/src/Data/Array/Accelerate/Trafo/Operation/LiveVars.hs index 0e0ddaa62..3abebe9a2 100644 --- a/src/Data/Array/Accelerate/Trafo/Operation/LiveVars.hs +++ b/src/Data/Array/Accelerate/Trafo/Operation/LiveVars.hs @@ -1,18 +1,14 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} {-# OPTIONS_HADDOCK hide #-} -{-# LANGUAGE InstanceSigs #-} + -- | -- Module : Data.Array.Accelerate.Trafo.Operation.LiveVars -- Copyright : [2012..2020] The Accelerate Team @@ -47,10 +43,8 @@ import Data.Array.Accelerate.Trafo.Exp.Substitution import Data.Array.Accelerate.Trafo.LiveVars import Data.Array.Accelerate.Error -import Data.List ( foldl' ) import Data.Maybe import Data.Type.Equality -import Data.Array.Accelerate.Representation.Shape (shapeType) stronglyLiveVariablesFun :: SLVOperation op => PreOpenAfun op () t -> PreOpenAfun op () t stronglyLiveVariablesFun acc = acc' ReEnvEnd diff --git a/src/Data/Array/Accelerate/Trafo/Operation/Simplify.hs b/src/Data/Array/Accelerate/Trafo/Operation/Simplify.hs index 83a955a04..158c173fe 100644 --- a/src/Data/Array/Accelerate/Trafo/Operation/Simplify.hs +++ b/src/Data/Array/Accelerate/Trafo/Operation/Simplify.hs @@ -1,14 +1,12 @@ {-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} @@ -49,7 +47,6 @@ import Data.Array.Accelerate.Trafo.Operation.Substitution import Data.Array.Accelerate.Trafo.LiveVars ( SubTupR(..), subTupR, subTupRpair, subTupPreserves ) import Data.Maybe ( mapMaybe ) import Data.List ( foldl' ) -import Data.Either ( partitionEithers ) import Control.Monad import Data.Functor.Identity diff --git a/src/Data/Array/Accelerate/Trafo/Partitioning/ILP.hs b/src/Data/Array/Accelerate/Trafo/Partitioning/ILP.hs index 79b141102..5a59c9547 100644 --- a/src/Data/Array/Accelerate/Trafo/Partitioning/ILP.hs +++ b/src/Data/Array/Accelerate/Trafo/Partitioning/ILP.hs @@ -1,6 +1,5 @@ {-# LANGUAGE MonoLocalBinds #-} {-# LANGUAGE TypeApplications #-} -{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE LambdaCase #-} @@ -29,13 +28,18 @@ import Data.Function ((&)) import qualified Data.Set as Set import Lens.Micro ((^.), (<>~)) import Data.Maybe (isJust) --- import Data.Array.Accelerate.Trafo.Partitioning.ILP.HiGHS (HiGHS(Highs)) +-- import Data.Array.Accelerate.Trafo.Partitioning.ILP.HiGHS data Benchmarking = GreedyUp | GreedyDown | NoFusion deriving (Show, Eq, Bounded, Enum) +data FusionType = Fusion Objective | Benchmarking Benchmarking + +defaultObjective :: FusionType +defaultObjective = Fusion IntermediateArrays + -- data type that should probably be in the options -data Solver = MIPSolver MIPSolver -- | HiGHS +newtype Solver = MIPSolver MIPSolver data MIPSolver = CBC | Gurobi | CPLEX | GLPSOL | LPSOLVE | SCIP ilpFusion'' :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Solver -> Objective -> OperationAcc op () a -> PartitionedAcc op () a @@ -46,7 +50,6 @@ ilpFusion'' (MIPSolver s) = case s of GLPSOL -> ilpFusion (MIP glpsol) LPSOLVE -> ilpFusion (MIP lpSolve) SCIP -> ilpFusion (MIP scip) --- ilpFusion'' HiGHS = ilpFusion Highs ilpFusionF'' :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Solver -> Objective -> OperationAfun op () a -> PartitionedAfun op () a @@ -57,25 +60,7 @@ ilpFusionF'' (MIPSolver s) = case s of GLPSOL -> ilpFusionF (MIP glpsol) LPSOLVE -> ilpFusionF (MIP lpSolve) SCIP -> ilpFusionF (MIP scip) --- ilpFusionF'' HiGHS = ilpFusionF Highs - -cbcFusion, gurobiFusion, cplexFusion, glpsolFusion, lpSolveFusion, scipFusion - :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Objective -> OperationAcc op () a -> PartitionedAcc op () a -cbcFusion = ilpFusion (MIP cbc) -gurobiFusion = ilpFusion (MIP gurobiCl) -cplexFusion = ilpFusion (MIP cplex) -glpsolFusion = ilpFusion (MIP glpsol) -lpSolveFusion = ilpFusion (MIP lpSolve) -scipFusion = ilpFusion (MIP scip) - -cbcFusionF, gurobiFusionF, cplexFusionF, glpsolFusionF, lpSolveFusionF, scipFusionF - :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Objective -> OperationAfun op () a -> PartitionedAfun op () a -cbcFusionF = ilpFusionF (MIP cbc) -gurobiFusionF = ilpFusionF (MIP gurobiCl) -cplexFusionF = ilpFusionF (MIP cplex) -glpsolFusionF = ilpFusionF (MIP glpsol) -lpSolveFusionF = ilpFusionF (MIP lpSolve) -scipFusionF = ilpFusionF (MIP scip) + ilpFusion :: (MakesILP op, ILPSolver s op, Pretty.PrettyOp (Cluster op)) => s -> Objective -> OperationAcc op () a -> PartitionedAcc op () a ilpFusion = ilpFusion' makeFullGraph (reconstruct False) @@ -149,7 +134,8 @@ greedyFusion' k1 k2 s b obj acc = fusedAcc | otherwise = let i:->j = (graph^.fusibleEdges) Set.\\ (graph^.infusibleEdges)&Set.elemAt (case b of GreedyUp -> n - GreedyDown -> nedges - n - 1) + GreedyDown -> nedges - n - 1 + _ -> error "nope") info'' = info&constr<>~(fused i j .==. int 0) in go (n+1) $ if check info'' then info'' else info check :: Information op -> Bool @@ -168,6 +154,12 @@ greedyFusion' k1 k2 s b obj acc = fusedAcc Nothing -> error "Accelerate: No ILP solution found" Just y -> y +bench :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Benchmarking -> Objective -> OperationAcc op () a -> PartitionedAcc op () a +bench NoFusion = no +bench b = greedy b +benchF :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Benchmarking -> Objective -> OperationAfun op () a -> PartitionedAfun op () a +benchF NoFusion = noF +benchF b = greedyF b greedy :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Benchmarking -> Objective -> OperationAcc op () a -> PartitionedAcc op () a greedy = greedyFusion (MIP gurobiCl) no :: (MakesILP op, Pretty.PrettyOp (Cluster op)) => Objective -> OperationAcc op () a -> PartitionedAcc op () a diff --git a/src/Data/Array/Accelerate/Trafo/Partitioning/ILP/Solve.hs b/src/Data/Array/Accelerate/Trafo/Partitioning/ILP/Solve.hs index 9bcecc267..d569fc986 100644 --- a/src/Data/Array/Accelerate/Trafo/Partitioning/ILP/Solve.hs +++ b/src/Data/Array/Accelerate/Trafo/Partitioning/ILP/Solve.hs @@ -1,9 +1,7 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE BangPatterns #-} + module Data.Array.Accelerate.Trafo.Partitioning.ILP.Solve where diff --git a/src/Data/Array/Accelerate/Trafo/Schedule/Uniform.hs b/src/Data/Array/Accelerate/Trafo/Schedule/Uniform.hs index aa8ccd01f..694021dc7 100644 --- a/src/Data/Array/Accelerate/Trafo/Schedule/Uniform.hs +++ b/src/Data/Array/Accelerate/Trafo/Schedule/Uniform.hs @@ -1,22 +1,16 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} -{-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-} -{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -fno-warn-orphans #-} {-# OPTIONS_HADDOCK hide #-} + -- | -- Module : Data.Array.Accelerate.Trafo.Schedule.Uniform -- Copyright : [2012..2020] The Accelerate Team diff --git a/src/Data/Array/Accelerate/Trafo/Sharing.hs b/src/Data/Array/Accelerate/Trafo/Sharing.hs index fbd6b1d04..d1d968124 100644 --- a/src/Data/Array/Accelerate/Trafo/Sharing.hs +++ b/src/Data/Array/Accelerate/Trafo/Sharing.hs @@ -1,6 +1,4 @@ {-# LANGUAGE AllowAmbiguousTypes #-} -{-# LANGUAGE BangPatterns #-} -{-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} @@ -10,7 +8,6 @@ {-# LANGUAGE PatternGuards #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} diff --git a/stack.yaml b/stack.yaml index bb460eacc..54ab4e876 100644 --- a/stack.yaml +++ b/stack.yaml @@ -16,9 +16,6 @@ extra-deps: commit: 4295aa21a24a30926b55770c55ac00f749fb8a39 subdirs: - MIP -# - highs-lp-0.0 -# - comfort-array-0.5.5 -# - linear-programming-0.0.1