diff --git a/b_asic/schema.py b/b_asic/schema.py index 6d0c5f92e03b18fa2e6e3d92d9de44e8fd9806a8..044df1ca1976a95db0e6e6836b9fab599bde7194 100644 --- a/b_asic/schema.py +++ b/b_asic/schema.py @@ -126,11 +126,19 @@ class Schema: print("Empty signal flow graph cannot be scheduled.") return - non_schedulable_ops = set((outp.operation.graph_id for outp in pl[0])) + non_schedulable_ops = set() + for outport in pl[0]: + op = outport.operation + if op.type_name() not in [Delay.type_name()]: + if op.graph_id not in self._start_times: + # Set start time of all operations in the first iter to 0 + self._start_times[op.graph_id] = 0 + else: + non_schedulable_ops.add(op.graph_id) for outport in pl[1]: op = outport.operation - if op not in self._start_times: + if op.graph_id not in self._start_times: # Set start time of all operations in the first iter to 0 self._start_times[op.graph_id] = 0 @@ -164,6 +172,9 @@ class Schema: op_start_time, op_start_time_from_in) self._start_times[op.graph_id] = op_start_time + for output in self._sfg.find_by_type_name(Output.type_name()): + source_port = output.inputs[0].signals[0].source + self._start_times[output.graph_id] = self._start_times[source_port.operation.graph_id] + source_port.latency_offset self._remove_delays() def plot_schedule(self) -> None: @@ -235,15 +246,14 @@ class Schema: for output_port in op.outputs: for output_signal in output_port.signals: dest_op = output_signal.destination.operation - if dest_op.type_name() and dest_op.type_name() != Output.type_name(): - dest_start_time = self._start_times[dest_op.graph_id] - dest_ypos = ypositions[dest_op.graph_id] - dest_in_coords, _ = output_signal.destination.operation.get_io_coordinates() - _draw_offset_arrow(out_coords[output_port.index], - dest_in_coords[output_signal.destination.index], - [op_start_time, source_ypos], - [dest_start_time, dest_ypos], name=op_id, - laps=self._laps[output_signal.graph_id]) + dest_start_time = self._start_times[dest_op.graph_id] + dest_ypos = ypositions[dest_op.graph_id] + dest_in_coords, _ = output_signal.destination.operation.get_io_coordinates() + _draw_offset_arrow(out_coords[output_port.index], + dest_in_coords[output_signal.destination.index], + [op_start_time, source_ypos], + [dest_start_time, dest_ypos], name=op_id, + laps=self._laps[output_signal.graph_id]) plt.yticks(ytickpositions, yticklabels) plt.axis([-1, self._schedule_time+1, 0, ypos]) diff --git a/b_asic/special_operations.py b/b_asic/special_operations.py index dc84f0bcb8186b0db31ca96551f2876f48b9b523..88c729314465d95454c2d55d69911eac48f489a1 100644 --- a/b_asic/special_operations.py +++ b/b_asic/special_operations.py @@ -5,7 +5,7 @@ normal operations in an SFG. """ from numbers import Number -from typing import Optional, Sequence +from typing import Optional, Sequence, Tuple, List from b_asic.operation import AbstractOperation, ResultKey, DelayMap, MutableResultMap, MutableDelayMap from b_asic.graph_component import Name, TypeName @@ -21,7 +21,7 @@ class Input(AbstractOperation): def __init__(self, name: Name = ""): """Construct an Input operation.""" - super().__init__(input_count=0, output_count=1, name=name) + super().__init__(input_count=0, output_count=1, name=name, latency_offsets={'out0' : 0}) self.set_param("value", 0) @classmethod @@ -41,6 +41,13 @@ class Input(AbstractOperation): """Set the current value of this input.""" self.set_param("value", value) + def get_plot_coordinates(self) -> Tuple[List[List[Number]], List[List[Number]]]: + return ([[-0.5, 0], [-0.5, 1], [-0.25, 1], [0, 0.5], [-0.25, 0], [-0.5, 0]], + [[-0.5, 0], [-0.5, 1], [-0.25, 1], [0, 0.5], [-0.25, 0], [-0.5, 0]]) + + def get_io_coordinates(self) -> Tuple[List[List[Number]], List[List[Number]]]: + return ([], [[0, 0.5]]) + class Output(AbstractOperation): """Output operation. @@ -53,7 +60,7 @@ class Output(AbstractOperation): def __init__(self, src0: Optional[SignalSourceProvider] = None, name: Name = ""): """Construct an Output operation.""" super().__init__(input_count=1, output_count=0, - name=name, input_sources=[src0]) + name=name, input_sources=[src0], latency_offsets={'in0' : 0}) @classmethod def type_name(cls) -> TypeName: @@ -62,6 +69,13 @@ class Output(AbstractOperation): def evaluate(self, _): return None + def get_plot_coordinates(self) -> Tuple[List[List[Number]], List[List[Number]]]: + return ([[0, 0], [0, 1], [0.25, 1], [0.5, 0.5], [0.25, 0], [0, 0]], + [[0, 0], [0, 1], [0.25, 1], [0.5, 0.5], [0.25, 0], [0, 0]]) + + def get_io_coordinates(self) -> Tuple[List[List[Number]], List[List[Number]]]: + return ([[0, 0.5]], []) + class Delay(AbstractOperation): """Unit delay operation.