Skip to content
Snippets Groups Projects
Commit 580685c8 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Better drawing and ordering of cyclic schedules with latency offsets

parent c23b6e3b
No related branches found
No related tags found
No related merge requests found
Pipeline #158931 failed
...@@ -18,6 +18,7 @@ from matplotlib.lines import Line2D ...@@ -18,6 +18,7 @@ from matplotlib.lines import Line2D
from matplotlib.patches import PathPatch, Polygon from matplotlib.patches import PathPatch, Polygon
from matplotlib.path import Path from matplotlib.path import Path
from matplotlib.ticker import MaxNLocator from matplotlib.ticker import MaxNLocator
from matplotlib.transforms import Bbox, TransformedBbox
from b_asic import Signal from b_asic import Signal
from b_asic._preferences import ( from b_asic._preferences import (
...@@ -358,9 +359,7 @@ class Schedule: ...@@ -358,9 +359,7 @@ class Schedule:
usage_time = start_time + cast(int, input_port.latency_offset) usage_time = start_time + cast(int, input_port.latency_offset)
for signal in input_port.signals: for signal in input_port.signals:
source = cast(OutputPort, signal.source) source = cast(OutputPort, signal.source)
if isinstance(source.operation, DontCare): if isinstance(source.operation, (DontCare, Delay)):
available_time = 0
elif isinstance(source.operation, Delay):
available_time = 0 available_time = 0
else: else:
if self._schedule_time is not None: if self._schedule_time is not None:
...@@ -770,9 +769,7 @@ class Schedule: ...@@ -770,9 +769,7 @@ class Schedule:
source_port = source_op = input_port.signals[0].source source_port = source_op = input_port.signals[0].source
source_op = source_port.operation source_op = source_port.operation
if not isinstance(source_op, Delay) and not isinstance( if not isinstance(source_op, (Delay, DontCare)):
source_op, DontCare
):
if op_laps[source_op.graph_id] < current_lap: if op_laps[source_op.graph_id] < current_lap:
laps += current_lap - op_laps[source_op.graph_id] laps += current_lap - op_laps[source_op.graph_id]
source_available_time = ( source_available_time = (
...@@ -802,7 +799,7 @@ class Schedule: ...@@ -802,7 +799,7 @@ class Schedule:
and isinstance(op, DontCare) and isinstance(op, DontCare)
and self._laps[op.output(0).signals[0].graph_id] == 0 and self._laps[op.output(0).signals[0].graph_id] == 0
): ):
start = time start = time % self._schedule_time
self._start_times[op.graph_id] = start self._start_times[op.graph_id] = start
...@@ -1074,6 +1071,20 @@ class Schedule: ...@@ -1074,6 +1071,20 @@ class Schedule:
sorted(self._start_times, key=self._start_times.get) sorted(self._start_times, key=self._start_times.get)
): ):
self.set_y_location(graph_id, i) self.set_y_location(graph_id, i)
for graph_id in self._start_times:
op = cast(Operation, self._sfg.find_by_id(graph_id))
if isinstance(op, Output):
self.move_y_location(
graph_id,
self.get_y_location(op.preceding_operations[0].graph_id) + 1,
True,
)
if isinstance(op, DontCare):
self.move_y_location(
graph_id,
self.get_y_location(op.subsequent_operations[0].graph_id),
True,
)
def _plot_schedule(self, ax: Axes, operation_gap: float = OPERATION_GAP) -> None: def _plot_schedule(self, ax: Axes, operation_gap: float = OPERATION_GAP) -> None:
"""Draw the schedule.""" """Draw the schedule."""
...@@ -1083,6 +1094,10 @@ class Schedule: ...@@ -1083,6 +1094,10 @@ class Schedule:
start: Sequence[float], end: Sequence[float], name: str = "", laps: int = 0 start: Sequence[float], end: Sequence[float], name: str = "", laps: int = 0
) -> None: ) -> None:
"""Draw an arrow from *start* to *end*.""" """Draw an arrow from *start* to *end*."""
if end[0] > self.schedule_time:
end[0] %= self.schedule_time
if start[0] > self.schedule_time:
start[0] %= self.schedule_time
if end[0] < start[0] or laps > 0: # Wrap around if end[0] < start[0] or laps > 0: # Wrap around
if start not in line_cache: if start not in line_cache:
line = Line2D( line = Line2D(
...@@ -1175,10 +1190,15 @@ class Schedule: ...@@ -1175,10 +1190,15 @@ class Schedule:
_x, _y = zip(*latency_coordinates) _x, _y = zip(*latency_coordinates)
x = np.array(_x) x = np.array(_x)
y = np.array(_y) y = np.array(_y)
xy = np.stack((x + op_start_time, y + y_pos)) xvalues = x + op_start_time
ax.add_patch(Polygon(xy.T, fc=_LATENCY_COLOR)) xy = np.stack((xvalues, y + y_pos))
p = ax.add_patch(Polygon(xy.T, fc=_LATENCY_COLOR))
if 'in' in str(graph_id): p.set_clip_box(TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes))
if any(xvalues > self.schedule_time):
xy = np.stack((xvalues - self.schedule_time, y + y_pos))
p = ax.add_patch(Polygon(xy.T, fc=_LATENCY_COLOR))
p.set_clip_box(TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes))
if isinstance(operation, Input):
ax.annotate( ax.annotate(
graph_id, graph_id,
xy=(op_start_time - 0.48, y_pos + 0.7), xy=(op_start_time - 0.48, y_pos + 0.7),
...@@ -1196,12 +1216,21 @@ class Schedule: ...@@ -1196,12 +1216,21 @@ class Schedule:
_x, _y = zip(*execution_time_coordinates) _x, _y = zip(*execution_time_coordinates)
x = np.array(_x) x = np.array(_x)
y = np.array(_y) y = np.array(_y)
xvalues = x + op_start_time
ax.plot( ax.plot(
x + op_start_time, xvalues,
y + y_pos, y + y_pos,
color=_EXECUTION_TIME_COLOR, color=_EXECUTION_TIME_COLOR,
linewidth=3, linewidth=3,
) )
if any(xvalues > self.schedule_time):
ax.plot(
xvalues - self.schedule_time,
y + y_pos,
color=_EXECUTION_TIME_COLOR,
linewidth=3,
)
ytickpositions.append(y_pos + 0.5) ytickpositions.append(y_pos + 0.5)
yticklabels.append(cast(Operation, self._sfg.find_by_id(graph_id)).name) yticklabels.append(cast(Operation, self._sfg.find_by_id(graph_id)).name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment