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

Add support for increasing time resolution

parent 691e04ca
No related branches found
No related tags found
No related merge requests found
Pipeline #87902 passed
...@@ -916,7 +916,8 @@ class AbstractOperation(Operation, AbstractGraphComponent): ...@@ -916,7 +916,8 @@ class AbstractOperation(Operation, AbstractGraphComponent):
) )
@property @property
def execution_time(self) -> Optional[int]: def execution_time(self) -> Union[int, None]:
"""Execution time of operation."""
return self._execution_time return self._execution_time
@execution_time.setter @execution_time.setter
...@@ -925,6 +926,12 @@ class AbstractOperation(Operation, AbstractGraphComponent): ...@@ -925,6 +926,12 @@ class AbstractOperation(Operation, AbstractGraphComponent):
raise ValueError("Execution time cannot be negative") raise ValueError("Execution time cannot be negative")
self._execution_time = execution_time self._execution_time = execution_time
def _increase_time_resolution(self, factor: int):
if self._execution_time is not None:
self._execution_time *= factor
for port in [*self.inputs, *self.outputs]:
port.latency_offset *= factor
def get_plot_coordinates( def get_plot_coordinates(
self, self,
) -> Tuple[List[List[Number]], List[List[Number]]]: ) -> Tuple[List[List[Number]], List[List[Number]]]:
......
...@@ -30,14 +30,12 @@ class Schedule: ...@@ -30,14 +30,12 @@ class Schedule:
_laps: Dict[GraphID, List[int]] _laps: Dict[GraphID, List[int]]
_schedule_time: int _schedule_time: int
_cyclic: bool _cyclic: bool
_resolution: int
def __init__( def __init__(
self, self,
sfg: SFG, sfg: SFG,
schedule_time: Optional[int] = None, schedule_time: Optional[int] = None,
cyclic: bool = False, cyclic: bool = False,
resolution: int = 1,
scheduling_alg: str = "ASAP", scheduling_alg: str = "ASAP",
): ):
"""Construct a Schedule from an SFG.""" """Construct a Schedule from an SFG."""
...@@ -45,8 +43,6 @@ class Schedule: ...@@ -45,8 +43,6 @@ class Schedule:
self._start_times = {} self._start_times = {}
self._laps = defaultdict(lambda: 0) self._laps = defaultdict(lambda: 0)
self._cyclic = cyclic self._cyclic = cyclic
self._resolution = resolution
if scheduling_alg == "ASAP": if scheduling_alg == "ASAP":
self._schedule_asap() self._schedule_asap()
else: else:
...@@ -182,12 +178,22 @@ class Schedule: ...@@ -182,12 +178,22 @@ class Schedule:
def cyclic(self) -> bool: def cyclic(self) -> bool:
return self._cyclic return self._cyclic
@property
def resolution(self) -> int:
return self._resolution
def increase_time_resolution(self, factor: int) -> "Schedule": def increase_time_resolution(self, factor: int) -> "Schedule":
raise NotImplementedError """
Increase time resolution for a schedule.
Parameters
==========
factor : int
The time resolution increment.
"""
self._start_times = {
k: factor * v for k, v in self._start_times.items()
}
for op_id, op_start_time in self._start_times.items():
self._sfg.find_by_id(op_id)._increase_time_resolution(factor)
self._schedule_time *= factor
def decrease_time_resolution(self, factor: int) -> "Schedule": def decrease_time_resolution(self, factor: int) -> "Schedule":
raise NotImplementedError raise NotImplementedError
...@@ -198,12 +204,8 @@ class Schedule: ...@@ -198,12 +204,8 @@ class Schedule:
), "No operation with the specified op_id in this schedule." ), "No operation with the specified op_id in this schedule."
(backward_slack, forward_slack) = self.slacks(op_id) (backward_slack, forward_slack) = self.slacks(op_id)
if time < 0: if not -backward_slack <= time <= forward_slack:
if -time > backward_slack: raise ValueError
raise ValueError
else:
if time > forward_slack:
raise ValueError
tmp_start = self._start_times[op_id] + time tmp_start = self._start_times[op_id] + time
new_start = tmp_start % self._schedule_time new_start = tmp_start % self._schedule_time
......
...@@ -21,6 +21,7 @@ class TestInit: ...@@ -21,6 +21,7 @@ class TestInit:
"cmul1": 0, "cmul1": 0,
"out1": 0, "out1": 0,
} }
assert schedule.schedule_time == 9
def test_complicated_single_outputs_normal_latency( def test_complicated_single_outputs_normal_latency(
self, precedence_sfg_delays self, precedence_sfg_delays
...@@ -55,6 +56,7 @@ class TestInit: ...@@ -55,6 +56,7 @@ class TestInit:
"ADD4": 17, "ADD4": 17,
"OUT1": 21, "OUT1": 21,
} }
assert schedule.schedule_time == 21
def test_complicated_single_outputs_complex_latencies( def test_complicated_single_outputs_complex_latencies(
self, precedence_sfg_delays self, precedence_sfg_delays
...@@ -118,6 +120,8 @@ class TestInit: ...@@ -118,6 +120,8 @@ class TestInit:
"OUT1": 17, "OUT1": 17,
} }
assert schedule.schedule_time == 17
def test_independent_sfg( def test_independent_sfg(
self, sfg_two_inputs_two_outputs_independent_with_cmul self, sfg_two_inputs_two_outputs_independent_with_cmul
): ):
...@@ -146,6 +150,7 @@ class TestInit: ...@@ -146,6 +150,7 @@ class TestInit:
"OUT1": 9, "OUT1": 9,
"OUT2": 10, "OUT2": 10,
} }
assert schedule.schedule_time == 10
class TestSlacks: class TestSlacks:
...@@ -289,3 +294,74 @@ class TestRescheduling: ...@@ -289,3 +294,74 @@ class TestRescheduling:
schedule.move_operation( schedule.move_operation(
precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, 10 precedence_sfg_delays.find_by_name("ADD3")[0].graph_id, 10
) )
class TestTimeResolution:
def test_increase_time_resolution(
self, sfg_two_inputs_two_outputs_independent_with_cmul
):
schedule = Schedule(
sfg_two_inputs_two_outputs_independent_with_cmul,
scheduling_alg="ASAP",
)
old_schedule_time = schedule.schedule_time
schedule.increase_time_resolution(2)
start_times_names = {}
for op_id, start_time in schedule._start_times.items():
op_name = (
sfg_two_inputs_two_outputs_independent_with_cmul.find_by_id(
op_id
).name
)
start_times_names[op_name] = start_time
assert start_times_names == {
"C1": 0,
"IN1": 0,
"IN2": 0,
"CMUL1": 0,
"CMUL2": 10,
"ADD1": 0,
"CMUL3": 14,
"OUT1": 18,
"OUT2": 20,
}
assert 2 * old_schedule_time == schedule.schedule_time
def test_increase_time_resolution_twice(
self, sfg_two_inputs_two_outputs_independent_with_cmul
):
schedule = Schedule(
sfg_two_inputs_two_outputs_independent_with_cmul,
scheduling_alg="ASAP",
)
old_schedule_time = schedule.schedule_time
schedule.increase_time_resolution(2)
schedule.increase_time_resolution(3)
start_times_names = {}
for op_id, start_time in schedule._start_times.items():
op_name = (
sfg_two_inputs_two_outputs_independent_with_cmul.find_by_id(
op_id
).name
)
start_times_names[op_name] = start_time
assert start_times_names == {
"C1": 0,
"IN1": 0,
"IN2": 0,
"CMUL1": 0,
"CMUL2": 30,
"ADD1": 0,
"CMUL3": 42,
"OUT1": 54,
"OUT2": 60,
}
assert 6 * old_schedule_time == schedule.schedule_time
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