From f36057d7edbe4e43f1768aed8aae719264667bc8 Mon Sep 17 00:00:00 2001 From: Simon Bjurek <simbj106@student.liu.se> Date: Thu, 30 Jan 2025 11:00:26 +0100 Subject: [PATCH] there is a bug that can occur when an op is scheduled before predecessors --- b_asic/scheduler.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/b_asic/scheduler.py b/b_asic/scheduler.py index a7d1b85a..b17b4842 100644 --- a/b_asic/scheduler.py +++ b/b_asic/scheduler.py @@ -181,7 +181,7 @@ class EarliestDeadlineScheduler(Scheduler): Schedule to apply the scheduling algorithm on. """ - # TODO: Take the execution time into consideration! + # TODO: Solve bug where operation (ADD) is scheduled before proceeding (MUL) -> pipelining ALAPScheduler().apply_scheduling(schedule) @@ -190,9 +190,15 @@ class EarliestDeadlineScheduler(Scheduler): input_op = cast(Input, input_op) schedule.move_operation_asap(input_op.graph_id) + # construct the set of remaining operations, excluding inputs remaining_ops = set(schedule.start_times.keys()) remaining_ops = {elem for elem in remaining_ops if not elem.startswith("in")} + # construct a dictionarry for storing how many times until a resource is available again + used_resources_ready_times = {} + + # iterate through all remaining operations and schedule them + # while not exceeding the available resources remaining_resources = self._max_resources.copy() current_time = 0 while remaining_ops: @@ -202,13 +208,23 @@ class EarliestDeadlineScheduler(Scheduler): if not best_candidate: current_time += 1 - remaining_resources = self._max_resources.copy() + + # update available operators + for operation, ready_time in used_resources_ready_times.items(): + print(ready_time, current_time) + if ready_time == current_time: + remaining_resources[operation.type_name()] += 1 + # remaining_resources = self._max_resources.copy() continue - # update remaining resources + # if the resource is constrained, update remaining resources if best_candidate.type_name() in remaining_resources: remaining_resources[best_candidate.type_name()] -= 1 + used_resources_ready_times[best_candidate] = ( + current_time + best_candidate.execution_time + ) + # schedule the best candidate to the current time remaining_ops.remove(best_candidate.graph_id) schedule.start_times[best_candidate.graph_id] = current_time @@ -222,11 +238,16 @@ class EarliestDeadlineScheduler(Scheduler): def _find_best_candidate( schedule, remaining_ops, remaining_resources, current_time ): - # precompute source end times for faster checks sfg = schedule.sfg source_end_times = defaultdict(float) + + # find the best candidate + best_candidate = None + best_deadline = float('inf') for op_id in remaining_ops: operation = sfg.find_by_id(op_id) + + # compute maximum end times of preceding operations for op_input in operation.inputs: source_op = op_input.signals[0].source.operation if not isinstance(source_op, Delay): @@ -235,11 +256,6 @@ class EarliestDeadlineScheduler(Scheduler): schedule.start_times[source_op.graph_id] + source_op.latency, ) - best_candidate = None - best_deadline = float('inf') - for op_id in remaining_ops: - operation = sfg.find_by_id(op_id) - # check resource constraints if operation.type_name() in remaining_resources: if remaining_resources[operation.type_name()] == 0: -- GitLab