public virtual void Schedule <T>(ControlFlowGraph <T> cfg, SchedulingConstraints constraints, ISchedulingAdapter <T> scha) where T : Analysis.IInstruction { var endTimes = new Queue <long>(); long cur = long.MaxValue - 1; foreach (var bb in cfg.BasicBlocks) { if (bb.IsExitBlock) { break; } constraints.EndTime = cur; Schedule(bb.Range, scha, constraints); endTimes.Enqueue(constraints.EndTime - constraints.StartTime); } scha.ClearSchedule(); constraints.EndTime = 0; foreach (var bb in cfg.BasicBlocks) { if (bb.IsExitBlock) { break; } constraints.EndTime += endTimes.Dequeue(); Schedule(bb.Range, scha, constraints); } }
public ForceDirectedSchedulerImpl(IFDSAdapater <T> adapter, IList <T> instructions, SchedulingConstraints constraints) { Adapter = adapter; Instructions = instructions; Constraints = constraints; CheckInput(); }
public static void Schedule(IFDSAdapater <T> adapter, IEnumerable <IList <T> > blocks, SchedulingConstraints constraints, bool minimizeBuses = true, bool minimizeRegisters = false) { foreach (var block in blocks) { Schedule(adapter, block, constraints, minimizeBuses, minimizeRegisters); } }
public void Schedule <T>(IEnumerable <T> tasks, ISchedulingAdapter <T> scha, SchedulingConstraints constraints) { long curTime = constraints.StartTime; foreach (T node in tasks) { scha.CStep[node] = curTime; curTime += scha.Latency[node]; } constraints.EndTime = curTime; }
public static void Schedule(IFDSAdapater <T> adapter, IList <T> instructions, SchedulingConstraints constraints, bool minimizeBuses = true, bool minimizeRegisters = false) { var sched = new ForceDirectedSchedulerImpl <T>(adapter, instructions, constraints) { MinimizeBuses = minimizeBuses, MinimizeRegisters = minimizeRegisters }; sched.Run(); }
public void Schedule <T>(ControlFlowGraph <T> cfg, SchedulingConstraints constraints, ISchedulingAdapter <T> scha) where T : IInstruction { foreach (var bb in cfg.BasicBlocks) { if (bb.IsExitBlock) { break; } _bbsched.Schedule(bb.Range, scha, constraints); constraints.StartTime = constraints.EndTime; } }
public List <long> Schedule <T>(ISchedulingAdapter <T> a, IEnumerable <IList <T> > blocks) { long time = 0; var times = new List <long>(); var constraints = new SchedulingConstraints(); foreach (IList <T> block in blocks) { times.Add(time); constraints.StartTime = time; time = Schedule(a, block, block, constraints); } times.Add(time); return(times); }
public List <long> Schedule <T>(ISchedulingAdapter <T> a, IEnumerable <IList <T> > blocks, long endTime) { long time = endTime; var times = new List <long>(); var constraints = new SchedulingConstraints(); constraints.EndTime = endTime; foreach (IList <T> block in blocks.Reverse()) { times.Add(time); constraints.EndTime = time; long preTime = Schedule(a, block, block, constraints); time = preTime; } times.Add(time); return(times); }
public void Schedule <T>(ControlFlowGraph <T> cfg, SchedulingConstraints constraints, ISchedulingAdapter <T> scha) where T : IInstruction { foreach (var bb in cfg.BasicBlocks) { if (bb.IsExitBlock) { break; } var fdsa = new FDSAdapter <T>(scha); var asapa = new ASLAPAdapter <T>(scha, fdsa.ASAPIndex); var alapa = new ASLAPAdapter <T>(scha, fdsa.ALAPIndex); long oldStartTime = constraints.StartTime; ASAPScheduler.InstanceUnlimitedResources.Schedule(bb.Range, asapa, constraints); ALAPScheduler.InstanceUnlimitedResources.Schedule(bb.Range, alapa, constraints); constraints.StartTime = oldStartTime; ForceDirectedSchedulerImpl <T> .Schedule(fdsa, bb.Range, constraints); constraints.StartTime = constraints.EndTime; } }
public void Schedule <T>(IEnumerable <T> tasks, ISchedulingAdapter <T> scha, SchedulingConstraints constraints) { var fdsa = new FDSAdapter <T>(scha); var asapa = new ASLAPAdapter <T>(scha, fdsa.ASAPIndex); var alapa = new ASLAPAdapter <T>(scha, fdsa.ALAPIndex); ASAPScheduler.InstanceUnlimitedResources.Schedule(tasks, asapa, constraints); int maxConcurrency = tasks.GroupBy(i => asapa.CStep[i]) .Sum(grp => grp.GroupBy(j => asapa.IClass[j]).Max(g => g.Count() - 1)); long maxExtent = constraints.EndTime - constraints.StartTime + maxConcurrency; long scaledExtent = (long)Math.Ceiling((constraints.EndTime - constraints.StartTime) * constraints.SchedScale); long extent = Math.Min(maxExtent, scaledExtent); long oldStartTime = constraints.StartTime; constraints.EndTime = constraints.StartTime + extent; ALAPScheduler.InstanceUnlimitedResources.Schedule(tasks, alapa, constraints); constraints.StartTime = oldStartTime; ForceDirectedSchedulerImpl <T> .Schedule(fdsa, tasks.ToList(), constraints); }
public void Schedule <T>(IEnumerable <T> tasks, ISchedulingAdapter <T> scha, SchedulingConstraints constraints) { var nodes = tasks.ToList(); constraints.StartTime = Schedule(scha, nodes, nodes, constraints); }
public long Schedule <T>(ISchedulingAdapter <T> a, IList <T> nodes, IList <T> end, SchedulingConstraints constraints) { ASAPScheduler.CheckInput(a, nodes); long endTime = constraints.EndTime; foreach (T x in nodes) { a.CStep[x] = long.MaxValue; } var pq = new PriorityQueue <NodeSet <T> >() { Resolve = NodeSet <T> .Merge }; foreach (T x in end) { pq.Enqueue(-endTime, NodeSet <T> .From(x)); } long startTime = endTime - 1; while (!pq.IsEmpty) { var cur = pq.Dequeue(); long curTime = -cur.Key; long reqTime = long.MaxValue; var curSet = cur.Value; var order = PriorizeNodes(curSet.Nodes); foreach (T x in order) { bool ready = true; foreach (var dy in a.Succs[x]) { T y = dy.Task; if (a.CStep[y] == long.MaxValue) { // at least one successor is not yet scheduled // -> task not ready ready = false; reqTime = long.MaxValue; break; } else if (a.CStep[y] < curTime - a.Latency[x] + dy.MinDelay) { // at least one successor starts before current task could // complete -> task not ready ready = false; if (reqTime < long.MaxValue) { reqTime = Math.Min(reqTime, a.CStep[y] + a.Latency[x] - dy.MinDelay); } } } if (ready) { // Check for deadline violations in second pass foreach (var dy in a.Succs[x]) { T y = dy.Task; if (a.CStep[y] > curTime - a.Latency[x] + dy.MaxDelay) { // deadline exceeded throw new NotSchedulableException(); } } long lat = a.Latency[x]; long execTime = curTime - lat; // If some operation is combinatorial (latency == 0) and is scheduled as // last instruction, it must be moved one step back to fit inside the schedule's // time frame. if (execTime == endTime) { --execTime; } long preHint, postHint; if (!ConstrainedResources || a.TryPin(x, execTime, out preHint, out postHint)) { a.CStep[x] = execTime; long nextTime = execTime; startTime = Math.Min(startTime, execTime); // requeue predecessors foreach (var dw in a.Preds[x]) { T w = dw.Task; pq.Enqueue(-(execTime - dw.MinDelay + a.Latency[w]), NodeSet <T> .From(w)); } } else { if (preHint < 0) { throw new NotSchedulableException(); } pq.Enqueue(-(preHint + lat), NodeSet <T> .From(x)); } } else if (reqTime < long.MaxValue) { pq.Enqueue(-reqTime, NodeSet <T> .From(x)); } } } foreach (T x in nodes) { if (a.CStep[x] == long.MaxValue) { throw new NotSchedulableException(); } } return(startTime); }
public long Schedule <T>(ISchedulingAdapter <T> a, IList <T> nodes, IList <T> startNodes, SchedulingConstraints constraints) { CheckInput(a, nodes); long startTime = constraints.StartTime; foreach (T x in nodes) { a.CStep[x] = long.MinValue; } var pq = new PriorityQueue <NodeSet <T> >() { Resolve = NodeSet <T> .Merge }; foreach (T x in startNodes) { pq.Enqueue(startTime, NodeSet <T> .From(x)); } long endTime = startTime + 1; while (!pq.IsEmpty) { var cur = pq.Dequeue(); long curTime = cur.Key; var curSet = cur.Value; foreach (T x in curSet.Nodes) { bool ready = true; long reqTime = curTime; foreach (var dw in a.Preds[x]) { T w = dw.Task; if (a.CStep[w] == long.MinValue) { // at least one predecessor is not yet scheduled // -> we cannot tell whether it is ok to schedule current task. ready = false; reqTime = long.MinValue; break; } else if (a.CStep[w] + dw.MinDelay > curTime) { // at least one predecessor did not yet complete. ready = false; if (reqTime > long.MinValue) { reqTime = Math.Max(reqTime, a.CStep[w] + dw.MinDelay); } } } if (ready) { // Check for deadline violations in second pass foreach (var dw in a.Preds[x]) { T w = dw.Task; if (a.CStep[w] + dw.MaxDelay < curTime) { // deadline exceeded throw new NotSchedulableException(); } } if (a.CStep[x] == long.MinValue) { long preHint, postHint; if (!ConstrainedResources || a.TryPin(x, curTime, out preHint, out postHint)) { a.CStep[x] = curTime; long lat = a.Latency[x]; long nextTime = curTime + lat; if (lat > 0) { endTime = Math.Max(endTime, nextTime); } else { endTime = Math.Max(endTime, nextTime + 1); } // enqueue successor tasks foreach (var dy in a.Succs[x]) { T y = dy.Task; pq.Enqueue(curTime + dy.MinDelay, NodeSet <T> .From(y)); } } else { pq.Enqueue(postHint, NodeSet <T> .From(x)); } } } else if (reqTime > long.MinValue) { pq.Enqueue(reqTime, NodeSet <T> .From(x)); } } } foreach (T x in nodes) { if (a.CStep[x] == long.MinValue) { throw new NotSchedulableException(); } } return(endTime); }