예제 #1
0
        /// <summary>
        /// find the max latency
        /// </summary>
        /// <param name="sort">sorted list of vertices</param>
        /// <param name="graph">delay graph</param>
        /// <param name="registered">hash table of registered vertices</param>
        /// <returns>number of cycles</returns>
        internal static long FindMaxLatencyCore(IEnumerable <DelayGraphVertex> sort, DelayGraph graph, HashSet <DelayGraphVertex> registered)
        {
            long maxLatencyCost = 0;
            var  table          = new WaveFrontDictionary <long>();

            foreach (var v in sort)
            {
                var inEdges    = graph.GetForwardInEdges(v);
                var outEdges   = graph.GetForwardOutEdges(v);
                int myRefCount = outEdges.Count();

                // first, consume predecessor's wavefront data, if any
                long myCost = 0;
                foreach (var e in inEdges)
                {
                    var p = e.Source;
                    var c = table.Use(p);   // default for long is 0
                    // copy data into myData
                    myCost = Math.Max(myCost, c);
                }

                // then add v's latency cost
                myCost += GetLatencyCost(v, registered);

                // register myCost into table
                table.Define(v, myRefCount, myCost);

                // update maxLatencyCost if v has no outEdges
                if (myRefCount == 0 && maxLatencyCost < myCost)
                {
                    maxLatencyCost = myCost;
                }
            }
            return(maxLatencyCost);
        }
예제 #2
0
 /// <summary>
 /// if myData is null, create it and register it into table using table.Define() for vertex v
 /// </summary>
 /// <param name="table">the wavefront dictionary</param>
 /// <param name="v">a vertex</param>
 /// <param name="myRefCount">reference count </param>
 /// <param name="myData">original data, could be null</param>
 /// <returns></returns>
 private static Dictionary <DelayGraphVertex, long> GetOrMakeMyData(WaveFrontDictionary <Dictionary <DelayGraphVertex, long> > table,
                                                                    DelayGraphVertex v, int myRefCount, Dictionary <DelayGraphVertex, long> myData)
 {
     if (myData == null)
     {
         myData = new Dictionary <DelayGraphVertex, long>();
         table.Define(v, myRefCount, myData);
     }
     return(myData);
 }
예제 #3
0
        /// <summary>
        /// find and return the maximum cyclic throughput cost
        /// </summary>
        /// <param name="sort">topological sorted enumerable of vertices</param>
        /// <param name="graph">a delay graph</param>
        /// <param name="registered">a hash set containing registered vertices</param>
        /// <returns>a value representing maximum throughput cost of all cycles</returns>
        internal static long FindMaxThroughputCostCore(IEnumerable <DelayGraphVertex> sort, DelayGraph graph, HashSet <DelayGraphVertex> registered)
        {
            long maxCycleCost = 0;
            var  table        = new WaveFrontDictionary <Dictionary <DelayGraphVertex, long> >();

            foreach (var v in sort)
            {
                var  inEdges          = graph.GetForwardInEdges(v);
                var  outEdges         = graph.GetForwardOutEdges(v);
                var  feedbackInEdges  = graph.GetFeedbackInEdges(v);
                var  feedbackOutEdges = graph.GetFeedbackOutEdges(v);
                int  myRefCount       = outEdges.Count();
                long cost             = GetThroughputCost(v, registered);

                Dictionary <DelayGraphVertex, long> myData = null;
                // first, consume predecessor's wavefront data, if any
                foreach (var e in inEdges)
                {
                    var p    = e.Source;
                    var data = table.Use(p);
                    if (data == null)
                    {
                        continue;
                    }
                    // copy data into myData
                    myData = GetOrMakeMyData(table, v, myRefCount, myData);

                    UpdateMaxData(myData, data);
                }

                if (cost > 0 && myData != null)
                {
                    // incr all costs in myData by cost
                    foreach (var p in myData.Keys.ToList())
                    {
                        myData[p] += cost;
                    }
                }

                if (feedbackInEdges.Any())
                {
                    // v is start of cycle - enter v into myData
                    myData    = GetOrMakeMyData(table, v, myRefCount, myData);
                    myData[v] = cost;
                }

                if (myData == null)
                {
                    continue;
                }

                // update max cycle cost
                foreach (var e in feedbackOutEdges)
                {
                    var  p = e.Target;
                    long cycleCost;
                    if (myData.TryGetValue(p, out cycleCost) &&
                        cycleCost > maxCycleCost)
                    {
                        maxCycleCost = cycleCost;
                    }
                }
            }

            return(maxCycleCost);
        }