diff --git a/b_asic/resources.py b/b_asic/resources.py index 208c0239ff0c1cd712fc5bdaed4e3065504716d6..8ad13879df5b798f515bceb58eec11c1bbecdc10 100644 --- a/b_asic/resources.py +++ b/b_asic/resources.py @@ -550,8 +550,8 @@ class ProcessCollection: else bar_start % self._schedule_time ) bar_end = ( - bar_end - if bar_end == self._schedule_time + self.schedule_time + if bar_end and bar_end % self._schedule_time == 0 else bar_end % self._schedule_time ) if show_markers: @@ -564,8 +564,8 @@ class ProcessCollection: ) for end_time in process.read_times: end_time = ( - end_time - if end_time == self._schedule_time + self.schedule_time + if end_time and end_time % self.schedule_time == 0 else end_time % self._schedule_time ) _ax.scatter( # type: ignore @@ -583,15 +583,19 @@ class ProcessCollection: color=_WARNING_COLOR, ) elif process.execution_time == 0: - # Execution time zero, don't draw the bar - pass + # Execution time zero, draw a slim bar + _ax.broken_barh( # type: ignore + [(PAD_L + bar_start, bar_end - bar_start - PAD_L - PAD_R)], + (bar_row + 0.55, 0.9), + color=bar_color, + ) elif bar_end > bar_start: _ax.broken_barh( # type: ignore [(PAD_L + bar_start, bar_end - bar_start - PAD_L - PAD_R)], (bar_row + 0.55, 0.9), color=bar_color, ) - else: # bar_end < bar_start + else: # bar_end <= bar_start _ax.broken_barh( # type: ignore [ ( @@ -1224,7 +1228,7 @@ class ProcessCollection: Forward-Backward Register Allocation [1]. [1]: K. Parhi: VLSI Digital Signal Processing Systems: Design and - Implementation, Ch. 6.3.2 + Implementation, Ch. 6.3.2 Parameters ---------- diff --git a/test/baseline/test_max_min_lifetime_bar_plot.png b/test/baseline/test_max_min_lifetime_bar_plot.png new file mode 100644 index 0000000000000000000000000000000000000000..1c42a415a67107e00e5aa19325c24b0e8995b4de Binary files /dev/null and b/test/baseline/test_max_min_lifetime_bar_plot.png differ diff --git a/test/test_resources.py b/test/test_resources.py index 6248c41c955255dd1290626aa09a9615d773e66b..6751879f5f9f3819c1bcd66c879245c4e7787707 100644 --- a/test/test_resources.py +++ b/test/test_resources.py @@ -1,4 +1,3 @@ -import pickle import re import matplotlib.pyplot as plt @@ -145,3 +144,57 @@ class TestProcessCollectionPlainMemoryVariable: simple_collection.remove_process(new_proc) assert len(simple_collection) == 7 assert new_proc not in simple_collection + + @pytest.mark.mpl_image_compare(style='mpl20') + def test_max_min_lifetime_bar_plot(self): + fig, ax = plt.subplots() + collection = ProcessCollection( + { + # Process starting exactly at scheudle start + PlainMemoryVariable(0, 0, {0: 0}, "S1"), + PlainMemoryVariable(0, 0, {0: 5}, "S2"), + # Process starting somewhere between schedule start and end + PlainMemoryVariable(2, 0, {0: 0}, "M1"), + PlainMemoryVariable(2, 0, {0: 5}, "M2"), + # Process starting at the schedule end + PlainMemoryVariable(5, 0, {0: 0}, "E1"), + PlainMemoryVariable(5, 0, {0: 5}, "E2"), + }, + schedule_time=5, + ) + collection.plot(ax) + return fig + + def test_multiple_reads_exclusion_greaph(self): + # Initial collection + p0 = PlainMemoryVariable(0, 0, {0: 3}, 'P0') + p1 = PlainMemoryVariable(1, 0, {0: 2}, 'P1') + p2 = PlainMemoryVariable(2, 0, {0: 2}, 'P2') + p3 = PlainMemoryVariable(3, 0, {0: 3}, 'P3') + collection = ProcessCollection({p0, p1, p2, p3}, 5, cyclic=True) + exclusion_graph = collection.create_exclusion_graph_from_ports( + read_ports=1, + write_ports=1, + total_ports=1, + ) + for p in [p0, p1, p2, p3]: + assert p in exclusion_graph + assert exclusion_graph.degree(p0) == 2 + assert exclusion_graph.degree(p1) == 2 + assert exclusion_graph.degree(p2) == 0 + assert exclusion_graph.degree(p3) == 2 + + # Add multi-read process + p4 = PlainMemoryVariable(0, 0, {0: 1, 1: 2, 2: 3, 3: 4}, 'P4') + collection.add_process(p4) + exclusion_graph = collection.create_exclusion_graph_from_ports( + read_ports=1, + write_ports=1, + total_ports=1, + ) + for p in [p0, p1, p2, p3, p4]: + assert p in exclusion_graph + assert exclusion_graph.degree(p0) == 3 + assert exclusion_graph.degree(p1) == 3 + assert exclusion_graph.degree(p2) == 1 + assert exclusion_graph.degree(p3) == 3