public long Schedule <T>(ISchedulingAdapter <T> a, IList <T> nodes, IList <T> startNodes, long startTime) { CheckInput(a, nodes); foreach (T x in nodes) { a.CStep[x] = long.MinValue; } long curTime = startTime; foreach (T node in nodes) { var preds = a.Preds[node]; long time = curTime; if (preds.Length > 0) { time = Math.Max(time, preds.Max(p => a.CStep[p.Task] + p.MinDelay)); } if (preds.Any(p => time - a.CStep[p.Task] > p.MaxDelay)) { throw new NotSchedulableException(); } a.CStep[node] = time; curTime = time + 1; } return(curTime); }
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 long Schedule <T>(ISchedulingAdapter <T> a, IList <T> nodes, long startTime, IList <T> result) { long curTime = startTime; foreach (T node in nodes) { a.CStep[node] = curTime; result.Add(node); curTime += a.Latency[node]; } return(curTime); }
public List <long> Schedule <T>(ISchedulingAdapter <T> a, IEnumerable <IList <T> > blocks, IList <T> result) { long time = 0; var times = new List <long>(); foreach (IList <T> block in blocks) { times.Add(time); time = Schedule(a, block, time, result); } times.Add(time); return(times); }
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); }
internal static void CheckInput <T>(ISchedulingAdapter <T> a, IList <T> instructions) { Contract.Requires <ArgumentNullException>(a != null); Contract.Requires <ArgumentNullException>(instructions != null); if (instructions.Any()) { T first = instructions.First(); for (int i = 0; i < instructions.Count; i++) { T instr = instructions[i]; Debug.Assert(a.Preds[instr].All(pred => instructions.Contains(pred.Task))); Debug.Assert(a.Succs[instr].All(succ => instructions.Contains(succ.Task))); } } }
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>(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 ASLAPAdapter(ISchedulingAdapter <T> scha, IPropMap <T, long> aslapIndex) { _scha = scha; _aslapIndex = aslapIndex; }
public FDSAdapter(ISchedulingAdapter <T> scha) { _scha = scha; }
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 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 void Schedule <T>(ControlFlowGraph <T> cfg, ISchedulingConstraints <T> constraints, ISchedulingAdapter <T> scha) where T : IInstruction { var asap = new long[cfg.Instructions.Count]; var alap = new long[cfg.Instructions.Count]; var asapMap = new ArrayBackedPropMap <T, long>(asap, i => i.Index); var alapMap = new ArrayBackedPropMap <T, long>(alap, i => i.Index); foreach (var bb in cfg.BasicBlocks) { if (bb.IsExitBlock) { break; } var asapa = new ASLAPAdapter <T>(scha, asapMap); var alapa = new ASLAPAdapter <T>(scha, alapMap); ASAPScheduler.Instance.Schedule(bb.Range, asapa, constraints); asapa.ClearSchedule(); long oldStartTime = constraints.StartTime; constraints.EndTime = constraints.StartTime + (long)Math.Ceiling((constraints.EndTime - constraints.StartTime) * constraints.SchedScale); ALAPScheduler.Instance.Schedule(bb.Range, alapa, constraints); alapa.ClearSchedule(); constraints.StartTime = oldStartTime; } var sch = new MobilityALAP <T>(asapMap, alapMap); constraints.StartTime = 0; sch.Schedule(cfg, constraints, scha); }
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); }
public override void Schedule <T>(ControlFlowGraph <T> cfg, ISchedulingConstraints <T> constraints, ISchedulingAdapter <T> scha) { constraints.EndTime = 0; foreach (var bb in cfg.BasicBlocks) { if (bb.IsExitBlock) { break; } constraints.EndTime += endTimes.Dequeue(); Schedule(bb.Range, scha, constraints); } }
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>(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; } }