From 0341563504082b6884bc77adef179613d6f839c2 Mon Sep 17 00:00:00 2001 From: Simon Bjurek <simbj106@student.liu.se> Date: Mon, 24 Mar 2025 13:52:06 +0100 Subject: [PATCH 1/2] added optional type argument to Schedule.print_slacks() --- b_asic/schedule.py | 14 ++++++++++++-- test/unit/test_schedule.py | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/b_asic/schedule.py b/b_asic/schedule.py index 8fc13eba..1909813e 100644 --- a/b_asic/schedule.py +++ b/b_asic/schedule.py @@ -410,7 +410,7 @@ class Schedule: raise ValueError(f"No operation with graph_id {graph_id!r} in schedule") return self.backward_slack(graph_id), self.forward_slack(graph_id) - def print_slacks(self, order: int = 0) -> None: + def print_slacks(self, order: int = 0, type_name: TypeName | None = None) -> None: """ Print the slack times for all operations in the schedule. @@ -422,14 +422,24 @@ class Schedule: * 0: alphabetical on Graph ID * 1: backward slack * 2: forward slack + + type_name : TypeName, optional + If given, only the slack times for operations of this type will be printed. """ + if type_name is None: + operations = self._sfg.operations + else: + operations = [ + op for op in self._sfg.operations if isinstance(op, type_name) + ] + res: list[tuple[GraphID, int, int]] = [ ( op.graph_id, cast(int, self.backward_slack(op.graph_id)), self.forward_slack(op.graph_id), ) - for op in self._sfg.operations + for op in operations ] res.sort(key=lambda tup: tup[order]) res_str = [ diff --git a/test/unit/test_schedule.py b/test/unit/test_schedule.py index bc2071f6..0a94212e 100644 --- a/test/unit/test_schedule.py +++ b/test/unit/test_schedule.py @@ -404,6 +404,28 @@ class TestSlacks: ) assert captured.err == "" + def test_print_slacks_type_name_given(self, capsys, precedence_sfg_delays): + precedence_sfg_delays.set_latency_of_type_name(Addition.type_name(), 1) + precedence_sfg_delays.set_latency_of_type_name( + ConstantMultiplication.type_name(), 3 + ) + + schedule = Schedule(precedence_sfg_delays, scheduler=ASAPScheduler()) + schedule.print_slacks(1, type_name=ConstantMultiplication) + captured = capsys.readouterr() + assert captured.out == ( + "Graph ID | Backward | Forward\n" + "---------|----------|---------\n" + "cmul0 | 0 | 1\n" + "cmul1 | 0 | 0\n" + "cmul2 | 0 | 0\n" + "cmul3 | 4 | 0\n" + "cmul6 | 4 | 0\n" + "cmul4 | 16 | 0\n" + "cmul5 | 16 | 0\n" + ) + assert captured.err == "" + def test_slacks_errors(self, precedence_sfg_delays): precedence_sfg_delays.set_latency_of_type_name(Addition.type_name(), 1) precedence_sfg_delays.set_latency_of_type_name( -- GitLab From 5fe082849cc1a7538f8008b517221a97fc2adaea Mon Sep 17 00:00:00 2001 From: Simon Bjurek <simbj106@student.liu.se> Date: Mon, 24 Mar 2025 14:15:09 +0100 Subject: [PATCH 2/2] added latency tie-breaker for Schedule.sort_y_locations_on_start_times() --- b_asic/schedule.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/b_asic/schedule.py b/b_asic/schedule.py index 1909813e..0ce9e42f 100644 --- a/b_asic/schedule.py +++ b/b_asic/schedule.py @@ -1094,10 +1094,17 @@ class Schedule: move_y_location set_y_location """ - for i, graph_id in enumerate( - sorted(self._start_times, key=self._start_times.get) - ): + + def sort_key(graph_id): + op = self._sfg.find_by_id(graph_id) + return ( + self._start_times[op.graph_id], + -self._sfg.find_by_id(graph_id).latency, + ) + + for i, graph_id in enumerate(sorted(self._start_times, key=sort_key)): self.set_y_location(graph_id, i) + for graph_id in self._start_times: op = cast(Operation, self._sfg.find_by_id(graph_id)) # Position Outputs and Sinks adjacent to the operation generating them -- GitLab