Skip to content
Snippets Groups Projects
Commit 4d351708 authored by Simon Bjurek's avatar Simon Bjurek
Browse files

Cyclic scheduling is up and running, examples functional

parent 05b3d917
No related branches found
No related tags found
No related merge requests found
Pipeline #157099 passed
...@@ -235,7 +235,7 @@ class ListScheduler(Scheduler, ABC): ...@@ -235,7 +235,7 @@ class ListScheduler(Scheduler, ABC):
) )
alap_schedule = copy.copy(self._schedule) alap_schedule = copy.copy(self._schedule)
alap_schedule.set_schedule_time(sys.maxsize) alap_schedule._schedule_time = None
ALAPScheduler().apply_scheduling(alap_schedule) ALAPScheduler().apply_scheduling(alap_schedule)
alap_start_times = alap_schedule.start_times alap_start_times = alap_schedule.start_times
self._schedule.start_times = {} self._schedule.start_times = {}
...@@ -248,14 +248,9 @@ class ListScheduler(Scheduler, ABC): ...@@ -248,14 +248,9 @@ class ListScheduler(Scheduler, ABC):
f"{alap_schedule.schedule_time}." f"{alap_schedule.schedule_time}."
) )
used_resources_ready_times = {}
self._remaining_resources = self._max_resources.copy() self._remaining_resources = self._max_resources.copy()
remaining_ops = ( remaining_ops = self._sfg.operations
self._sfg.operations
# + self._sfg.find_by_type_name(Input.type_name())
# + self._sfg.find_by_type_name(Output.type_name())
)
remaining_ops = [op.graph_id for op in remaining_ops] remaining_ops = [op.graph_id for op in remaining_ops]
self._schedule.start_times = {} self._schedule.start_times = {}
...@@ -292,24 +287,12 @@ class ListScheduler(Scheduler, ABC): ...@@ -292,24 +287,12 @@ class ListScheduler(Scheduler, ABC):
self._get_next_op_id(ready_ops_priority_table) self._get_next_op_id(ready_ops_priority_table)
) )
if next_op.type_name() in self._remaining_resources:
self._remaining_resources[next_op.type_name()] -= 1
if self._schedule.schedule_time is not None:
used_resources_ready_times[next_op] = (
self._current_time + max(next_op.execution_time, 1)
) % self._schedule.schedule_time
else:
used_resources_ready_times[next_op] = self._current_time + max(
next_op.execution_time, 1
)
self.remaining_reads -= next_op.input_count self.remaining_reads -= next_op.input_count
remaining_ops = [ remaining_ops = [
op_id for op_id in remaining_ops if op_id != next_op.graph_id op_id for op_id in remaining_ops if op_id != next_op.graph_id
] ]
print("Next:", next_op.graph_id, self._current_time)
self._time_out_counter = 0 self._time_out_counter = 0
self._schedule.place_operation(next_op, self._current_time) self._schedule.place_operation(next_op, self._current_time)
self._op_laps[next_op.graph_id] = ( self._op_laps[next_op.graph_id] = (
...@@ -336,20 +319,7 @@ class ListScheduler(Scheduler, ABC): ...@@ -336,20 +319,7 @@ class ListScheduler(Scheduler, ABC):
remaining_ops, remaining_ops,
) )
# update available reads and operators
if self._schedule.schedule_time is not None:
time = self._current_time % self._schedule.schedule_time
else:
time = self._current_time
self.remaining_reads = self._max_concurrent_reads self.remaining_reads = self._max_concurrent_reads
for operation, ready_time in used_resources_ready_times.items():
if ready_time >= time:
self._remaining_resources[operation.type_name()] += 1
used_resources_ready_times = dict(
[pair for pair in used_resources_ready_times.items() if pair[1] > time]
)
self._current_time -= 1 self._current_time -= 1
...@@ -435,13 +405,31 @@ class ListScheduler(Scheduler, ABC): ...@@ -435,13 +405,31 @@ class ListScheduler(Scheduler, ABC):
for op_id, start_time in alap_start_times.items() for op_id, start_time in alap_start_times.items()
} }
def _op_satisfies_resource_constraints(self, op: "Operation") -> bool:
if self._schedule.schedule_time is not None:
time_slot = self._current_time % self._schedule.schedule_time
else:
time_slot = self._current_time
count = 0
for op_id, start_time in self._schedule.start_times.items():
if self._schedule.schedule_time is not None:
start_time = start_time % self._schedule.schedule_time
if time_slot >= start_time:
if time_slot < start_time + max(
self._sfg.find_by_id(op_id).execution_time, 1
):
if op_id.startswith(op.type_name()):
if op.graph_id != op_id:
count += 1
return count < self._remaining_resources[op.type_name()]
def _op_is_schedulable( def _op_is_schedulable(
self, op: "Operation", remaining_ops: list["GraphID"] self, op: "Operation", remaining_ops: list["GraphID"]
) -> bool: ) -> bool:
if ( if not self._op_satisfies_resource_constraints(op):
op.type_name() in self._remaining_resources
and self._remaining_resources[op.type_name()] == 0
):
return False return False
op_finish_time = self._current_time + op.latency op_finish_time = self._current_time + op.latency
......
...@@ -33,7 +33,7 @@ schedule.show() ...@@ -33,7 +33,7 @@ schedule.show()
# %% # %%
# Generate a non-cyclic Schedule from HybridScheduler with custom IO times. # Generate a non-cyclic Schedule from HybridScheduler with custom IO times.
resources = {Butterfly.type_name(): 1, ConstantMultiplication.type_name(): 1} resources = {Butterfly.type_name(): 1, ConstantMultiplication.type_name(): 1}
input_times = {f"in{i}": i for i in range(points)} input_times = {f"in{i}": i - 2 for i in range(points)}
output_delta_times = {f"out{i}": i for i in range(points)} output_delta_times = {f"out{i}": i for i in range(points)}
schedule = Schedule( schedule = Schedule(
sfg, sfg,
......
...@@ -86,6 +86,7 @@ schedule = Schedule( ...@@ -86,6 +86,7 @@ schedule = Schedule(
scheduler=HybridScheduler( scheduler=HybridScheduler(
resources, input_times=input_times, output_delta_times=output_delta_times resources, input_times=input_times, output_delta_times=output_delta_times
), ),
schedule_time=32,
cyclic=True, cyclic=True,
) )
print("Scheduling time:", schedule.schedule_time) print("Scheduling 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