Skip to content

Commit eff072e

Browse files
chore: mypy type fixes
1 parent cce5a09 commit eff072e

File tree

20 files changed

+70
-62
lines changed

20 files changed

+70
-62
lines changed

discopop_explorer/PETGraphX.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import copy
1212
import sys
1313
from time import sleep
14-
from typing import Dict, List, Sequence, Tuple, Set, Optional, Type, TypeVar, cast, Union, overload
14+
from typing import Dict, List, Sequence, Tuple, Set, Optional, Type, TypeVar, cast, Union, overload, Any
1515
from enum import IntEnum, Enum
1616
import itertools
1717

@@ -570,7 +570,7 @@ class PETGraphX(object):
570570
g: nx.MultiDiGraph
571571
reduction_vars: List[Dict[str, str]]
572572
main: Node
573-
pos: Dict
573+
pos: Dict[Any, Any]
574574

575575
def __init__(self, g: nx.MultiDiGraph, reduction_vars: List[Dict[str, str]], pos):
576576
self.g = g

discopop_explorer/json_serializer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# directory for details.
88

99
from json import JSONEncoder
10+
from typing import Dict, Any
1011

1112
from .PETGraphX import Node
1213
from discopop_library.result_classes.DetectionResult import DetectionResult
@@ -16,7 +17,7 @@
1617
from .pattern_detectors.task_parallelism.classes import TPIType
1718

1819

19-
def filter_members(d: dict) -> dict:
20+
def filter_members(d: Dict[Any, Any]) -> Dict[Any, Any]:
2021
"""Removes private and protected members (which starts with '_')
2122
2223
:param d: member dictionary

discopop_explorer/pattern_detectors/geometric_decomposition_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, pet: PETGraphX, node: Node, min_iter: int):
4646
self.num_tasks = math.floor(nt)
4747

4848
self.pragma = "for (i = 0; i < num-tasks; i++) #pragma omp task"
49-
lp: List = []
49+
lp: List[Variable] = []
5050
fp, p, s, in_dep, out_dep, in_out_dep, r = classify_task_vars(pet, node, "GeometricDecomposition", [], [])
5151
fp.append(Variable("int", "i", "", sizeInByte=4))
5252

discopop_explorer/pattern_detectors/simple_gpu_patterns/GPULoop.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ def omp_construct_dict(
145145
line: LineID,
146146
clauses: List[str],
147147
positioning: OmpConstructPositioning = OmpConstructPositioning.BEFORE_LINE,
148-
) -> dict:
148+
) -> Dict[str, Union[str, LineID, List[str], OmpConstructPositioning]]:
149149
"""
150150
151151
:param name:
152152
:param line:
153153
:param clauses:
154154
:return:
155155
"""
156-
result: Dict[str, Union[str, int, List[str]]] = dict()
156+
result: Dict[str, Union[str, LineID, List[str], OmpConstructPositioning]] = dict()
157157
result["name"] = name
158158
result["line"] = line
159159
result["clauses"] = clauses
@@ -180,7 +180,7 @@ class GPULoopPattern(PatternInfo):
180180
parentLoop: str
181181
collapse: int
182182
scheduling: str
183-
constructs: List[dict]
183+
constructs: List[Dict[Any, Any]]
184184
project_folder_path: str
185185

186186
def __init__(
@@ -281,8 +281,10 @@ def toJson(self, pet: PETGraphX, project_folder_path: str) -> str:
281281
json_output += "]}"
282282
return json_output
283283

284-
def __get_constructs(self, pet: PETGraphX, project_folder_path: str) -> List[dict]:
285-
constructs: List[dict] = []
284+
def __get_constructs(
285+
self, pet: PETGraphX, project_folder_path: str
286+
) -> List[Dict[str, Union[str, LineID, List[str], OmpConstructPositioning]]]:
287+
constructs: List[Dict[str, Union[str, LineID, List[str], OmpConstructPositioning]]] = []
286288

287289
# == default construct ==
288290
clauses: List[str] = []

discopop_explorer/pattern_detectors/simple_gpu_patterns/GPUMemory.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# directory for details.
88

99
from enum import Enum
10-
from typing import List, Set, cast
10+
from typing import List, Set, cast, Tuple
1111
from discopop_explorer.variable import Variable
1212
from discopop_explorer.PETGraphX import (
1313
PETGraphX,
@@ -19,6 +19,7 @@
1919
DummyNode,
2020
FunctionNode,
2121
LoopNode,
22+
Dependency,
2223
)
2324
from discopop_explorer.utils import is_func_arg, is_global, __get_dep_of_type as get_dep_of_type
2425

@@ -91,12 +92,12 @@ def getCalledFunctions(
9192
def getDeps(
9293
cuIDs: List[CUNode],
9394
pet: PETGraphX,
94-
RAWDepsOn: Set,
95-
WARDepsOn: Set,
96-
WAWDepsOn: Set,
97-
reverseRAWDepsOn: Set,
98-
reverseWARDepsOn: Set,
99-
reverseWAWDepsOn: Set,
95+
RAWDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
96+
WARDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
97+
WAWDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
98+
reverseRAWDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
99+
reverseWARDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
100+
reverseWAWDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
100101
) -> None:
101102
"""gather all dependencies of the nodes specified in 'cuIDs'
102103
---doesnt work here because addresses---
@@ -127,8 +128,8 @@ def assignMapType(
127128
var: Variable,
128129
isScalar: bool,
129130
pet: PETGraphX,
130-
RAWDepsOn: Set,
131-
reverseRAWDepsOn: Set,
131+
RAWDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
132+
reverseRAWDepsOn: Set[Tuple[NodeID, NodeID, Dependency]],
132133
) -> map_type_t:
133134
"""assigns a map-type to the variable 'var'
134135

discopop_explorer/pattern_detectors/task_parallelism/alias_detection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pathlib
1111
import re
1212
import subprocess
13-
from typing import Dict, List, Optional, Match, cast
13+
from typing import Dict, List, Optional, Match, cast, Any
1414
from lxml import objectify # type: ignore
1515

1616

@@ -178,7 +178,9 @@ def __get_alias_from_statement(var_name: str, var_type: str, statement: str) ->
178178
return None
179179

180180

181-
def __add_alias_information(function_information_list: List[Dict], statements_file: str) -> List[Dict]:
181+
def __add_alias_information(
182+
function_information_list: List[Dict[str, Any]], statements_file: str
183+
) -> List[Dict[str, Any]]:
182184
"""Wrapper to gather and append alias information to the entries in function_information as a new field.
183185
Aliases can be found up to a depth of 2.
184186
Alias detection ignores scopes.
@@ -241,7 +243,7 @@ def __add_alias_information(function_information_list: List[Dict], statements_fi
241243
return result_list
242244

243245

244-
def __get_function_information(cu_xml: str) -> List[Dict]:
246+
def __get_function_information(cu_xml: str) -> List[Dict[str, Any]]:
245247
"""Extracts information on functions from given cu_xml file and stores it in a dictionary representation.
246248
:param cu_xml: path to cu_xml file
247249
:return: List of dictionaries representing functions from cu_xml"""

discopop_explorer/pattern_detectors/task_parallelism/suggesters/barriers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ def __count_adjacent_nodes(
175175
pet: PETGraphX,
176176
suggestions: List[PatternInfo],
177177
out_dep_edges: List[Tuple[Any, Any, Any]],
178-
task_nodes: List,
179-
barrier_nodes: List,
180-
omittable_nodes: List,
178+
task_nodes: List[Node],
179+
barrier_nodes: List[Node],
180+
omittable_nodes: List[Tuple[Node, List[Node]]],
181181
) -> Tuple[int, int, int, int]:
182182
"""Checks the types of nodes pointed to by out_dep_edges and increments the respective counters.
183183
:param pet: PET Graph

discopop_explorer/pattern_detectors/task_parallelism/suggesters/dependency_clauses.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# directory for details.
88

99
import os
10-
from typing import List, Dict, Tuple, Optional, Union, cast
10+
from typing import List, Dict, Tuple, Optional, Union, cast, Any
1111

1212
from discopop_explorer.PETGraphX import (
1313
CUNode,
@@ -176,7 +176,7 @@ def get_alias_information(pet: PETGraphX, suggestions: List[PatternInfo], source
176176
task_suggestions = [s for s in [e for e in suggestions if type(e) == TaskParallelismInfo] if s.type is TPIType.TASK]
177177
# collect alias information
178178
aliases: Dict[TaskParallelismInfo, List[List[Tuple[str, str, LineID, LineID]]]] = dict()
179-
called_function_cache: Dict = dict()
179+
called_function_cache: Dict[Any, Any] = dict()
180180
for ts in task_suggestions:
181181
current_alias_entry = []
182182
potential_parent_functions = __get_potential_parent_functions(pet, ts)
@@ -298,9 +298,9 @@ def get_function_internal_parameter_aliases(
298298
def identify_dependencies_for_different_functions(
299299
pet: PETGraphX,
300300
suggestions: List[PatternInfo],
301-
aliases: Dict,
302-
source_code_files: Dict,
303-
raw_dependency_information: Dict,
301+
aliases: Dict[TaskParallelismInfo, List[List[Tuple[str, str, LineID, LineID]]]],
302+
source_code_files: Dict[str, str],
303+
raw_dependency_information: Dict[str, List[Tuple[str, str]]],
304304
) -> List[PatternInfo]:
305305
"""Identify dependency clauses for all combinations of suggested tasks concerning different called functions
306306
and supplement the suggestions.
@@ -496,8 +496,8 @@ def __get_recursive_calls_from_function(potential_children: List[Node], parent_f
496496
def identify_dependencies_for_same_functions(
497497
pet: PETGraphX,
498498
suggestions: List[PatternInfo],
499-
source_code_files: Dict,
500-
cu_inst_result_dict: Dict,
499+
source_code_files: Dict[str, str],
500+
cu_inst_result_dict: dict[str, List[Dict[str, Optional[str]]]],
501501
function_parameter_alias_dict: Dict[str, List[Tuple[str, str]]],
502502
) -> List[PatternInfo]:
503503
"""Identify dependency clauses for all combinations of suggested tasks concerning equal called functions
@@ -700,7 +700,7 @@ def get_alias_for_parameter_at_position(
700700
parameter_position: int,
701701
source_code_files: Dict[str, str],
702702
visited: List[Tuple[Node, int]],
703-
called_function_cache: Dict,
703+
called_function_cache: Dict[Any, Any],
704704
) -> List[Tuple[str, str, LineID, LineID]]:
705705
"""Returns alias information for a parameter at a specific position.
706706
:param pet: PET Graph
@@ -756,8 +756,8 @@ def get_alias_for_parameter_at_position(
756756

757757

758758
def check_dependence_of_task_pair(
759-
aliases: Dict,
760-
raw_dependency_information: Dict,
759+
aliases: Dict[TaskParallelismInfo, List[List[Tuple[str, str, LineID, LineID]]]],
760+
raw_dependency_information: Dict[str, List[Tuple[str, str]]],
761761
task_suggestion_1: TaskParallelismInfo,
762762
param_names_1: List[Optional[str]],
763763
task_suggestion_2: TaskParallelismInfo,

discopop_explorer/pattern_detectors/task_parallelism/suggesters/tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ def find_taskwaits(cu_node: Node, visited: List[Node]):
316316
return suggestions
317317

318318

319-
def __identify_atomic_or_critical_sections(pet: PETGraphX, ts: TaskParallelismInfo, found_cus: List, selector: bool):
319+
def __identify_atomic_or_critical_sections(
320+
pet: PETGraphX, ts: TaskParallelismInfo, found_cus: List[Node], selector: bool
321+
):
320322
"""Identifies and marks atomic or critical sections.
321323
:param pet: PET Graph
322324
:param ts: task suggestion

discopop_explorer/pattern_detectors/task_parallelism/tp_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# directory for details.
88

99
import subprocess
10-
from typing import Union, cast, IO, Dict, List, Tuple, Optional
10+
from typing import Union, cast, IO, Dict, List, Tuple, Optional, Any
1111

1212
from lxml import objectify # type: ignore
1313
from discopop_explorer.PETGraphX import (
@@ -528,7 +528,7 @@ def set_global_llvm_cxxfilt_path(value: str):
528528

529529

530530
def get_called_functions_recursively(
531-
pet: PETGraphX, root: Node, visited: List[Node], cache: Dict
531+
pet: PETGraphX, root: Node, visited: List[Node], cache: Dict[Any, Any]
532532
) -> List[Union[FunctionNode, DummyNode]]:
533533
"""returns a recursively generated list of called functions, started at root."""
534534
visited.append(root)

0 commit comments

Comments
 (0)