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

Add support for operator processcollections

parent 595bd54f
Branches operationspc2
No related tags found
1 merge request!290Add support for operator processcollections
Pipeline #94130 passed
...@@ -29,8 +29,8 @@ class Process: ...@@ -29,8 +29,8 @@ class Process:
self._start_time = start_time self._start_time = start_time
self._execution_time = execution_time self._execution_time = execution_time
if name is None: if name is None:
self._name = f"Proc. {PlainMemoryVariable._name_cnt}" self._name = f"Proc. {Process._name_cnt}"
PlainMemoryVariable._name_cnt += 1 Process._name_cnt += 1
else: else:
self._name = name self._name = name
...@@ -87,12 +87,12 @@ class OperatorProcess(Process): ...@@ -87,12 +87,12 @@ class OperatorProcess(Process):
execution_time = operation.execution_time execution_time = operation.execution_time
if execution_time is None: if execution_time is None:
raise ValueError( raise ValueError(
"Operation {operation!r} does not have an execution time specified!" f"Operation {operation!r} does not have an execution time specified!"
) )
super().__init__( super().__init__(
start_time, start_time,
execution_time, execution_time,
name=name, name=name or operation.name or operation.graph_id,
) )
self._operation = operation self._operation = operation
...@@ -109,8 +109,8 @@ class MemoryVariable(Process): ...@@ -109,8 +109,8 @@ class MemoryVariable(Process):
write_port : :class:`~b_asic.port.OutputPort` write_port : :class:`~b_asic.port.OutputPort`
The OutputPort that the memory variable originates from. The OutputPort that the memory variable originates from.
reads : dict reads : dict
Dictionary with :class:`~b_asic.port.InputPort` that reads the memory variable as key and Dictionary with :class:`~b_asic.port.InputPort` that reads the memory variable
for how long after the *write_time* it will read. as key and for how long after the *write_time* it will read.
name : str, optional name : str, optional
The name of the process. The name of the process.
""" """
......
...@@ -9,7 +9,8 @@ from matplotlib.axes import Axes ...@@ -9,7 +9,8 @@ from matplotlib.axes import Axes
from matplotlib.ticker import MaxNLocator from matplotlib.ticker import MaxNLocator
from b_asic._preferences import LATENCY_COLOR from b_asic._preferences import LATENCY_COLOR
from b_asic.process import MemoryVariable, PlainMemoryVariable, Process from b_asic.process import MemoryVariable, OperatorProcess, PlainMemoryVariable, Process
from b_asic.types import TypeName
# Default latency coloring RGB tuple # Default latency coloring RGB tuple
_LATENCY_COLOR = tuple(c / 255 for c in LATENCY_COLOR) _LATENCY_COLOR = tuple(c / 255 for c in LATENCY_COLOR)
...@@ -1120,3 +1121,28 @@ class ProcessCollection: ...@@ -1120,3 +1121,28 @@ class ProcessCollection:
write_ports=write_ports, write_ports=write_ports,
total_ports=total_ports, total_ports=total_ports,
) )
def get_by_type_name(self, type_name: TypeName) -> "ProcessCollection":
"""
Return a ProcessCollection with only a given type of operations.
Parameters
----------
type_name : TypeName
The type_name of the operation.
Returns
-------
ProcessCollection
"""
return ProcessCollection(
{
process
for process in self._collection
if isinstance(process, OperatorProcess)
and process._operation.type_name() == type_name
},
self._schedule_time,
self._cyclic,
)
...@@ -31,7 +31,7 @@ from b_asic._preferences import ( ...@@ -31,7 +31,7 @@ from b_asic._preferences import (
from b_asic.graph_component import GraphID from b_asic.graph_component import GraphID
from b_asic.operation import Operation from b_asic.operation import Operation
from b_asic.port import InputPort, OutputPort from b_asic.port import InputPort, OutputPort
from b_asic.process import MemoryVariable from b_asic.process import MemoryVariable, OperatorProcess
from b_asic.resources import ProcessCollection from b_asic.resources import ProcessCollection
from b_asic.signal_flow_graph import SFG from b_asic.signal_flow_graph import SFG
from b_asic.special_operations import Delay, Input, Output from b_asic.special_operations import Delay, Input, Output
...@@ -294,13 +294,13 @@ class Schedule: ...@@ -294,13 +294,13 @@ class Schedule:
@property @property
def start_times(self) -> Dict[GraphID, int]: def start_times(self) -> Dict[GraphID, int]:
"""The start times of the operations in the current schedule.""" """The start times of the operations in the schedule."""
return self._start_times return self._start_times
@property @property
def laps(self) -> Dict[GraphID, int]: def laps(self) -> Dict[GraphID, int]:
""" """
The number of laps for the start times of the operations in the current schedule. The number of laps for the start times of the operations in the schedule.
""" """
return self._laps return self._laps
...@@ -674,8 +674,8 @@ class Schedule: ...@@ -674,8 +674,8 @@ class Schedule:
] + cast(int, source_port.latency_offset) ] + cast(int, source_port.latency_offset)
self._remove_delays() self._remove_delays()
def _get_memory_variables_list(self) -> List['MemoryVariable']: def _get_memory_variables_list(self) -> List[MemoryVariable]:
ret: List['MemoryVariable'] = [] ret: List[MemoryVariable] = []
for graph_id, start_time in self._start_times.items(): for graph_id, start_time in self._start_times.items():
slacks = self._forward_slacks(graph_id) slacks = self._forward_slacks(graph_id)
for outport, signals in slacks.items(): for outport, signals in slacks.items():
...@@ -707,6 +707,25 @@ class Schedule: ...@@ -707,6 +707,25 @@ class Schedule:
set(self._get_memory_variables_list()), self.schedule_time set(self._get_memory_variables_list()), self.schedule_time
) )
def get_operations(self) -> ProcessCollection:
"""
Return a :class:`~b_asic.resources.ProcessCollection` containing all
operations.
Returns
-------
ProcessCollection
"""
return ProcessCollection(
{
OperatorProcess(start_time, self._sfg.find_by_id(graph_id))
for graph_id, start_time in self._start_times.items()
},
self.schedule_time,
self.cyclic,
)
def _get_y_position( def _get_y_position(
self, graph_id, operation_height=1.0, operation_gap=None self, graph_id, operation_height=1.0, operation_gap=None
) -> float: ) -> float:
......
...@@ -35,6 +35,8 @@ sfg.set_latency_of_type(ConstantMultiplication.type_name(), 2) ...@@ -35,6 +35,8 @@ sfg.set_latency_of_type(ConstantMultiplication.type_name(), 2)
sfg.set_latency_of_type(Addition.type_name(), 1) sfg.set_latency_of_type(Addition.type_name(), 1)
sfg.set_execution_time_of_type(ConstantMultiplication.type_name(), 1) sfg.set_execution_time_of_type(ConstantMultiplication.type_name(), 1)
sfg.set_execution_time_of_type(Addition.type_name(), 1) sfg.set_execution_time_of_type(Addition.type_name(), 1)
sfg.set_execution_time_of_type(Input.type_name(), 1)
sfg.set_execution_time_of_type(Output.type_name(), 1)
# %% # %%
# Create schedule # Create schedule
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment