Skip to content

Commit

Permalink
chore: formatting according to black v. 24.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Apr 15, 2024
1 parent 01c416d commit d53e389
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 54 deletions.
24 changes: 9 additions & 15 deletions discopop_explorer/PEGraphX.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ class Node:
end_line: int
type: NodeType
name: str
parent_function_id: Optional[
NodeID
] = None # metadata to speedup some calculations (TODO FunctionNodes have themselves as parent)
parent_function_id: Optional[NodeID] = (
None # metadata to speedup some calculations (TODO FunctionNodes have themselves as parent)
)
workload: Optional[int] = None

# properties of CU Nodes
Expand Down Expand Up @@ -959,12 +959,10 @@ def node_at(self, node_id: NodeID) -> Node:
NodeT = TypeVar("NodeT", bound=Node)

@overload
def all_nodes(self) -> List[Node]:
...
def all_nodes(self) -> List[Node]: ...

@overload
def all_nodes(self, type: Union[Type[NodeT], Tuple[Type[NodeT], ...]]) -> List[NodeT]:
...
def all_nodes(self, type: Union[Type[NodeT], Tuple[Type[NodeT], ...]]) -> List[NodeT]: ...

def all_nodes(self, type=Node):
"""List of all nodes of specified type
Expand Down Expand Up @@ -1007,12 +1005,10 @@ def in_edges(
return [t for t in self.g.in_edges(node_id, data="data") if t[2].etype == etype]

@overload
def subtree_of_type(self, root: Node) -> List[Node]:
...
def subtree_of_type(self, root: Node) -> List[Node]: ...

@overload
def subtree_of_type(self, root: Node, type: Union[Type[NodeT], Tuple[Type[NodeT], ...]]) -> List[NodeT]:
...
def subtree_of_type(self, root: Node, type: Union[Type[NodeT], Tuple[Type[NodeT], ...]]) -> List[NodeT]: ...

def subtree_of_type(self, root, type=Node):
"""Gets all nodes in subtree of specified type including root
Expand All @@ -1024,14 +1020,12 @@ def subtree_of_type(self, root, type=Node):
return self.subtree_of_type_rec(root, set(), type)

@overload
def subtree_of_type_rec(self, root: Node, visited: Set[Node]) -> List[Node]:
...
def subtree_of_type_rec(self, root: Node, visited: Set[Node]) -> List[Node]: ...

@overload
def subtree_of_type_rec(
self, root: Node, visited: Set[Node], type: Union[Type[NodeT], Tuple[Type[NodeT], ...]]
) -> List[NodeT]:
...
) -> List[NodeT]: ...

def subtree_of_type_rec(self, root, visited, type=Node):
"""recursive helper function for subtree_of_type"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def __init__(self, pet: PEGraphX, contained_regions: List[GPURegionInfo], projec
) = get_written_and_read_memory_regions_by_cu(self.contained_regions, pet)

# get memory region and variable associations for each CU
cu_and_variable_to_memory_regions: Dict[
NodeID, Dict[VarName, Set[MemoryRegion]]
] = get_cu_and_varname_to_memory_regions(self.contained_regions, pet, written_memory_regions_by_cu)
cu_and_variable_to_memory_regions: Dict[NodeID, Dict[VarName, Set[MemoryRegion]]] = (
get_cu_and_varname_to_memory_regions(self.contained_regions, pet, written_memory_regions_by_cu)
)

print("WRITTEN MEMORY REGIONS BY CU: ", file=sys.stderr)
print(written_memory_regions_by_cu, file=sys.stderr)
Expand All @@ -136,9 +136,9 @@ def __init__(self, pet: PEGraphX, contained_regions: List[GPURegionInfo], projec
print(file=sys.stderr)

# get memory regions to cus and variables names
memory_regions_to_cus_and_variables: Dict[
MemoryRegion, Dict[NodeID, Set[VarName]]
] = get_memory_region_to_cu_and_variables_dict(cu_and_variable_to_memory_regions)
memory_regions_to_cus_and_variables: Dict[MemoryRegion, Dict[NodeID, Set[VarName]]] = (
get_memory_region_to_cu_and_variables_dict(cu_and_variable_to_memory_regions)
)
print("MEMORY REGIONS TO CUS AND VARIABLES:", file=sys.stderr)
print(memory_regions_to_cus_and_variables, file=sys.stderr)
print(file=sys.stderr)
Expand All @@ -150,9 +150,9 @@ def __init__(self, pet: PEGraphX, contained_regions: List[GPURegionInfo], projec
print(file=sys.stderr)

# extend device liveness with memory regions
device_liveness_plus_memory_regions: Dict[
VarName, List[Tuple[NodeID, Set[MemoryRegion]]]
] = add_memory_regions_to_device_liveness(live_device_variables, cu_and_variable_to_memory_regions)
device_liveness_plus_memory_regions: Dict[VarName, List[Tuple[NodeID, Set[MemoryRegion]]]] = (
add_memory_regions_to_device_liveness(live_device_variables, cu_and_variable_to_memory_regions)
)

# ### STEP 2.2: CALCULATE LIVE DATA BY PROPAGATING MEMORY REGIONS AND EXTENDING LIFESPAN

Expand Down Expand Up @@ -252,9 +252,9 @@ def __init__(self, pet: PEGraphX, contained_regions: List[GPURegionInfo], projec

# ### STEP 5: CONVERT MEMORY REGIONS IN UPDATES TO VARIABLE NAMES
# propagate memory region to variable name associations within function body
memory_regions_to_functions_and_variables: Dict[
MemoryRegion, Dict[NodeID, Set[VarName]]
] = propagate_variable_name_associations(pet, memory_regions_to_cus_and_variables)
memory_regions_to_functions_and_variables: Dict[MemoryRegion, Dict[NodeID, Set[VarName]]] = (
propagate_variable_name_associations(pet, memory_regions_to_cus_and_variables)
)
print("MEMORY REGIONS TO FUNCTIONS AND VARIABLES:", file=sys.stderr)
print(memory_regions_to_functions_and_variables, file=sys.stderr)
print(file=sys.stderr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from discopop_explorer.pattern_detectors.combined_gpu_patterns.classes.Dependency import Dependency


def get_dependencies_as_metadata(
pet: PEGraphX, all_dependencies: Set[Dependency]
) -> Tuple[List[Tuple[VarName, NodeID, str]], List[Tuple[VarName, NodeID, str]],]:
def get_dependencies_as_metadata(pet: PEGraphX, all_dependencies: Set[Dependency]) -> Tuple[
List[Tuple[VarName, NodeID, str]],
List[Tuple[VarName, NodeID, str]],
]:
in_deps_metadata: Set[Tuple[VarName, NodeID, str]] = set()
out_deps_metadata: Set[Tuple[VarName, NodeID, str]] = set()

Expand Down
10 changes: 9 additions & 1 deletion discopop_explorer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,15 @@ def classify_task_vars(
in_deps: List[Tuple[NodeID, NodeID, Dependency]],
out_deps: List[Tuple[NodeID, NodeID, Dependency]],
used_in_task_parallelism_detection=False,
) -> Tuple[List[Variable], List[Variable], List[Variable], List[Variable], List[Variable], List[Variable], List[str],]:
) -> Tuple[
List[Variable],
List[Variable],
List[Variable],
List[Variable],
List[Variable],
List[Variable],
List[str],
]:
"""Classify task variables
:param pet: CU graph
Expand Down
5 changes: 4 additions & 1 deletion discopop_library/discopop_optimizer/Microbench/Microbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class Microbench(ABC):
@abstractmethod
def getMeasurements(
self,
) -> Dict[MicrobenchType, Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],]:
) -> Dict[
MicrobenchType,
Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],
]:
raise TypeError("Pure virtual method called")

@abstractmethod
Expand Down
15 changes: 12 additions & 3 deletions discopop_library/discopop_optimizer/Microbench/MixedMicrobench.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,28 @@ def __init__(self, inner: Microbench, outer: Microbench, threshold: MicrobenchCo

def getMeasurements(
self,
) -> Dict[MicrobenchType, Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],]:
) -> Dict[
MicrobenchType,
Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],
]:
raise TypeError(
"This MixedMicrobench might be based on two different sets of measurements. Use getInnerMeasurements() or getOuterMeasurements() instead."
)

def getInnerMeasurements(
self,
) -> Dict[MicrobenchType, Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],]:
) -> Dict[
MicrobenchType,
Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],
]:
return self.inner.getMeasurements()

def getOuterMeasurements(
self,
) -> Dict[MicrobenchType, Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],]:
) -> Dict[
MicrobenchType,
Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],
]:
return self.outer.getMeasurements()

def toJSON(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ class PureDataMicrobench(Microbench):
]

@overload
def __getitem__(self, key: MicrobenchType) -> Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]]:
...
def __getitem__(
self, key: MicrobenchType
) -> Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]]: ...

@overload
def __getitem__(self, key: Tuple[MicrobenchType, MicrobenchDimension]) -> Dict[MicrobenchCoordinate, List[float]]:
...
def __getitem__(
self, key: Tuple[MicrobenchType, MicrobenchDimension]
) -> Dict[MicrobenchCoordinate, List[float]]: ...

@overload
def __getitem__(self, key: Tuple[MicrobenchType, MicrobenchDimension, MicrobenchCoordinate]) -> List[float]:
...
def __getitem__(self, key: Tuple[MicrobenchType, MicrobenchDimension, MicrobenchCoordinate]) -> List[float]: ...

# allow to use this class like a dictionary
def __getitem__(self, key):
Expand Down Expand Up @@ -181,7 +182,10 @@ def mergeAll(self, others: List[PureDataMicrobench]):
# inherited from Microbench
def getMeasurements(
self,
) -> Dict[MicrobenchType, Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],]:
) -> Dict[
MicrobenchType,
Dict[MicrobenchDimension, Dict[MicrobenchCoordinate, List[float]]],
]:
return self.measurements

# inherited from Microbench
Expand Down
6 changes: 3 additions & 3 deletions discopop_library/discopop_optimizer/OptimizationGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def __init__(
experiment.substitutions[cast(Symbol, function.sequential_costs)] = experiment.selected_paths_per_function[
function
][0].sequential_costs
experiment.substitutions[
cast(Symbol, function.parallelizable_costs)
] = experiment.selected_paths_per_function[function][0].parallelizable_costs
experiment.substitutions[cast(Symbol, function.parallelizable_costs)] = (
experiment.selected_paths_per_function[function][0].parallelizable_costs
)

# TODO END OF DUMMY

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ def show_options(

def __update_selection(cm, ctx):
experiment.selected_paths_per_function[function_root] = (cm, ctx)
experiment.substitutions[
cast(Symbol, function_root.sequential_costs)
] = experiment.selected_paths_per_function[function_root][0].sequential_costs
experiment.substitutions[
cast(Symbol, function_root.parallelizable_costs)
] = experiment.selected_paths_per_function[function_root][0].parallelizable_costs
experiment.substitutions[cast(Symbol, function_root.sequential_costs)] = (
experiment.selected_paths_per_function[function_root][0].sequential_costs
)
experiment.substitutions[cast(Symbol, function_root.parallelizable_costs)] = (
experiment.selected_paths_per_function[function_root][0].parallelizable_costs
)
# update displayed value
label2.configure(state=NORMAL)
label2.delete(0, END)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ def __collapse_loops_in_function(function_node_id):
inner_queue += [
(
p,
tmp_dist
if isinstance(data_at(global_graph, p), ContextNode)
else tmp_dist + 1,
(
tmp_dist
if isinstance(data_at(global_graph, p), ContextNode)
else tmp_dist + 1
),
)
for p in preds
]
Expand Down

0 comments on commit d53e389

Please sign in to comment.