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

added docstrings for scheduler

parent 11845eb0
Branches
No related tags found
1 merge request!461Finalize earliest deadline scheduler
Pipeline #154907 passed
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, cast from typing import TYPE_CHECKING, Optional, cast
from b_asic.port import OutputPort from b_asic.port import OutputPort
from b_asic.special_operations import Delay, Output from b_asic.special_operations import Delay, Output
...@@ -9,17 +9,16 @@ if TYPE_CHECKING: ...@@ -9,17 +9,16 @@ if TYPE_CHECKING:
from b_asic.schedule import Schedule from b_asic.schedule import Schedule
# class SchedulingAlgorithm(Enum):
# ASAP = "ASAP"
# ALAP = "ALAP"
# EARLIEST_DEADLINE = "earliest_deadline"
# # LEAST_SLACK = "least_slack" # to be implemented
# PROVIDED = "provided"
class Scheduler(ABC): class Scheduler(ABC):
@abstractmethod @abstractmethod
def apply_scheduling(self, schedule: "Schedule") -> None: def apply_scheduling(self, schedule: "Schedule") -> None:
"""Applies the scheduling algorithm on the given Schedule.
Parameters
----------
schedule : Schedule
Schedule to apply the scheduling algorithm on.
"""
pass pass
def _handle_outputs(self, schedule, non_schedulable_ops) -> None: def _handle_outputs(self, schedule, non_schedulable_ops) -> None:
...@@ -41,7 +40,16 @@ class Scheduler(ABC): ...@@ -41,7 +40,16 @@ class Scheduler(ABC):
class ASAPScheduler(Scheduler): class ASAPScheduler(Scheduler):
"""Scheduler that implements the as-soon-as-possible (ASAP) algorithm."""
def apply_scheduling(self, schedule: "Schedule") -> None: def apply_scheduling(self, schedule: "Schedule") -> None:
"""Applies the scheduling algorithm on the given Schedule.
Parameters
----------
schedule : Schedule
Schedule to apply the scheduling algorithm on.
"""
prec_list = schedule.sfg.get_precedence_list() prec_list = schedule.sfg.get_precedence_list()
if len(prec_list) < 2: if len(prec_list) < 2:
raise ValueError("Empty signal flow graph cannot be scheduled.") raise ValueError("Empty signal flow graph cannot be scheduled.")
...@@ -114,8 +122,16 @@ class ASAPScheduler(Scheduler): ...@@ -114,8 +122,16 @@ class ASAPScheduler(Scheduler):
class ALAPScheduler(Scheduler): class ALAPScheduler(Scheduler):
"""Scheduler that implements the as-late-as-possible (ALAP) algorithm."""
def apply_scheduling(self, schedule: "Schedule") -> None: def apply_scheduling(self, schedule: "Schedule") -> None:
# self.schedule_asap() """Applies the scheduling algorithm on the given Schedule.
Parameters
----------
schedule : Schedule
Schedule to apply the scheduling algorithm on.
"""
ASAPScheduler().apply_scheduling(schedule) ASAPScheduler().apply_scheduling(schedule)
max_end_time = schedule.get_max_end_time() max_end_time = schedule.get_max_end_time()
...@@ -137,10 +153,29 @@ class ALAPScheduler(Scheduler): ...@@ -137,10 +153,29 @@ class ALAPScheduler(Scheduler):
class EarliestDeadlineScheduler(Scheduler): class EarliestDeadlineScheduler(Scheduler):
def __init__(self, max_resources: dict[TypeName, int]) -> None: """
Scheduler that implements the earliest-deadline-first algorithm.
Parameters
----------
max_resources : dict, optional
Dictionary like ``{Addition.type_name(): 2}`` denoting the maximum number of
resources for a given operation type if the scheduling algorithm considers
that. If not provided, or an operation type is not provided, at most one
resource is used.
"""
def __init__(self, max_resources: Optional[dict[TypeName, int]]) -> None:
self._max_resources = max_resources self._max_resources = max_resources
def apply_scheduling(self, schedule: "Schedule") -> None: def apply_scheduling(self, schedule: "Schedule") -> None:
"""Applies the scheduling algorithm on the given Schedule.
Parameters
----------
schedule : Schedule
Schedule to apply the scheduling algorithm on.
"""
# ACT BASED ON THE NUMBER OF PEs! # ACT BASED ON THE NUMBER OF PEs!
prec_list = schedule.sfg.get_precedence_list() prec_list = schedule.sfg.get_precedence_list()
if len(prec_list) < 2: if len(prec_list) < 2:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment