示例#1
0
 private static bool ScoreIsEqual(LatencyAssignerScoreCard x, LatencyAssignerScoreCard y)
 {
     if (x.TotalNumberFailingPeriod == y.TotalNumberFailingPeriod &&
         x.TotalThroughputCosts == y.TotalThroughputCosts &&
         x.TotalLatencyCosts == y.TotalLatencyCosts &&
         x.TotalRegisterCosts == y.TotalRegisterCosts &&
         x.TotalSumOfAchievedPeriods == y.TotalSumOfAchievedPeriods)
     {
         return(true);
     }
     return(false);
 }
示例#2
0
 private static bool ScoreIsBetter(LatencyAssignerScoreCard x, LatencyAssignerScoreCard y)
 {
     if (x.TotalNumberFailingPeriod < y.TotalNumberFailingPeriod ||
         (x.TotalNumberFailingPeriod == y.TotalNumberFailingPeriod &&
          (x.TotalThroughputCosts < y.TotalThroughputCosts ||
           (x.TotalThroughputCosts == y.TotalThroughputCosts &&
            (x.TotalLatencyCosts < y.TotalLatencyCosts ||
             (x.TotalLatencyCosts == y.TotalLatencyCosts &&
              (x.TotalRegisterCosts < y.TotalRegisterCosts ||
               (x.TotalRegisterCosts == y.TotalRegisterCosts &&
                (x.TotalSumOfAchievedPeriods < y.TotalSumOfAchievedPeriods ||
                 (x.TotalSumOfAchievedPeriods == y.TotalSumOfAchievedPeriods &&
                  x.TotalExecutionTime < y.TotalExecutionTime))))))))))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#3
0
 private static void CheckAgainstOthers(List <string> latencyAssigners, Dictionary <string, LatencyAssignerScoreCard> scoreCards, string latencyAssigner, LatencyAssignerScoreCard scoreCard, out bool isBest, out bool isTied)
 {
     isBest = true;
     isTied = false;
     foreach (var next in latencyAssigners)
     {
         if (next != latencyAssigner && ScoreIsBetter(scoreCards[next], scoreCard))
         {
             if (ScoreIsEqual(scoreCards[next], scoreCard))
             {
                 isTied = true;
             }
             else
             {
                 isBest = false;
             }
             break;
         }
     }
 }
示例#4
0
        public static void Main(string[] args)
        {
            var algorithms = new List <Tuple <string, ILatencyAssignment> >
            {
                new Tuple <string, ILatencyAssignment>("asap", new LatencyAssignmentAsap()),
                new Tuple <string, ILatencyAssignment>("greedy", new LatencyAssignmentGreedy()),
                // add your own latency assigner here
            };

            if (args.Length != 2)
            {
                Console.WriteLine("Error: Expecting two arguments and not " + args.Length);
                Console.WriteLine("Usage: RegisterPlacement.exe <Data Set Directory Root> <Directory For Scorecard>");
                Console.WriteLine("This program explores subdirectories of <Data Set Directory Root> to find delay graph data sets to try with register placement algorithms.");
                Console.WriteLine("Various metrics are printed into the <Directory For Scorecard>.");
                return;
            }
            if (!Directory.Exists(args[0]))
            {
                Console.WriteLine("Error: Directory does not exist: " + args[0]);
                return;
            }

            string rootDataSetDir = Path.GetFullPath(args[0]); // convert from relative to absolute

            List <DataSet> dataSets = new List <DataSet>();

            FindDataSets(rootDataSetDir, dataSets);

            if (!dataSets.Any())
            {
                Console.WriteLine("Warning: No data sets found. Make sure DelayGraph*.graphml and corresponding DelayGraphOriginalGoals*.xml files exist somewhere in this hierarchy: " + args[0]);
            }

            string scoreCardDirectoy = args[1];

            if (!Directory.Exists(scoreCardDirectoy))
            {
                Directory.CreateDirectory(scoreCardDirectoy);
            }

            var algorithmNames = algorithms.Select(kv => kv.Item1).ToList();

            foreach (var algorithmName in algorithmNames)
            {
                string filePath = GetScoreCardPath(scoreCardDirectoy, algorithmName);
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }
                using (StreamWriter stream = File.CreateText(filePath))
                {
                    stream.WriteLine("GraphPath, ThroughputCost, LatencyCost, RegisterCost, Slack, TargetPeriod, ResultingPeriod, ExecutionTime(ms)"); // column headers
                }
            }

            string dotDirectory = "DotFiles";

            if (!Directory.Exists(dotDirectory))
            {
                Directory.CreateDirectory(dotDirectory);
            }

            var overallScoreCards = new Dictionary <string, LatencyAssignerScoreCard>();
            var isBest            = new Dictionary <string, int>();
            var isBestOrTied      = new Dictionary <string, int>();
            var failedTable       = new Dictionary <string, int>();

            foreach (var algorithmName in algorithms.Select(kv => kv.Item1))
            {
                overallScoreCards[algorithmName] = new LatencyAssignerScoreCard();
                isBest[algorithmName]            = 0;
                isBestOrTied[algorithmName]      = 0;
                failedTable[algorithmName]       = 0;
            }
            int       idx = 0; // index for test cases for debugging
            Stopwatch sw  = new Stopwatch();

            foreach (DataSet dataSet in dataSets)
            {
                foreach (var graphAndGoal in dataSet.GraphsAndGoalsFilePaths)
                {
                    idx++;

                    DelayGraph.DelayGraph graph = DelayGraphGraphMlSerializer.DeserializeFromGraphMl(graphAndGoal.GraphPath);

                    XDocument doc = XDocument.Load(graphAndGoal.GoalPath);
                    XElement  clockRateElement = doc.Root.Element("TargetClockPeriodInPicoSeconds");

                    int originalTargetClockRate = int.Parse(clockRateElement.Value);

                    if (DelayGraphSolution.PruneEdges(graph))
                    {
                        Console.WriteLine("Successfully removed redundant edges in graph");
                    }

                    int minClockPeriod = DelayGraphSolution.MinClockPeriod(graph);
                    if (minClockPeriod > originalTargetClockRate)
                    {
                        originalTargetClockRate = minClockPeriod;
                    }
                    bool failed     = false;
                    var  scoreCards = new Dictionary <string, LatencyAssignerScoreCard>();
                    foreach (var tuple in algorithms)
                    {
                        string algorithmName = tuple.Item1;
                        var    algorithm     = tuple.Item2;
                        sw.Restart();
                        HashSet <DelayGraphVertex> registeredTerminals = algorithm.Execute(graph, originalTargetClockRate);
                        double milliseconds = sw.Elapsed.TotalMilliseconds;
                        sw.Stop();

                        var solutionName = Path.GetFileNameWithoutExtension(graphAndGoal.GraphPath) + "." + algorithmName;

                        DelayGraphSolution solution = new DelayGraphSolution(solutionName, graph, registeredTerminals, originalTargetClockRate);

                        // for debugging

                        var dotFileName = solutionName + ".dot";
                        var dotFilePath = Path.Combine(dotDirectory, dotFileName);
                        solution.PrintDotFile(dotFilePath);

                        bool cycle;
                        int  period = solution.EstimatePeriod(out cycle);
                        if (cycle)
                        {
                            period = int.MaxValue;
                        }

                        int slack = originalTargetClockRate - period;
                        if (slack < 0)
                        {
                            failed = true;
                            failedTable[algorithmName]++;
                        }

                        long throughputCost, latencyCost, registerCost;
                        solution.SumCosts(
                            throughputTotalCost: out throughputCost,
                            latencyTotalCost: out latencyCost,
                            registersTotalCost: out registerCost);
                        var scoreCard = new LatencyAssignerScoreCard();
                        scoreCard.RegisterResult(throughputCost, latencyCost, registerCost, period, slack, milliseconds);
                        scoreCards[algorithmName] = scoreCard;
                    }
                    TabulateAndPrintReports(algorithmNames, scoreCardDirectoy, overallScoreCards, isBest, isBestOrTied, graphAndGoal, originalTargetClockRate, failed, scoreCards);
                }
            }

            PrintSummaryReport(algorithmNames, scoreCardDirectoy, overallScoreCards, isBest, isBestOrTied, failedTable);

            Console.WriteLine("Scorecards written to: " + Path.GetFullPath(scoreCardDirectoy));
            Debug.WriteLine("Scorecards written to: " + Path.GetFullPath(scoreCardDirectoy));
        }