Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added error handling to recursive workload calculation to make the analysis more robust for large codes. #445

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion discopop_explorer/pattern_detectors/PatternInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ def get_workload(self, pet: PETGraphX) -> int:
"""returns the workload of self._node"""
if self.workload is not None:
return self.workload
self.workload = calculate_workload(pet, self._node)
try:
self.workload = calculate_workload(pet, self._node)
except RecursionError as rerr:
import warnings

warnings.warn("Cost calculation not possible for node: " + str(self._node.id) + "!")
self.workload = 0

return self.workload

def get_per_iteration_workload(self, pet: PETGraphX) -> int:
Expand Down
11 changes: 9 additions & 2 deletions discopop_explorer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import List, Sequence, Set, Dict, Tuple, cast

import numpy as np
import warnings

from .PETGraphX import (
CUNode,
Expand Down Expand Up @@ -213,9 +214,15 @@ def calculate_per_iteration_workload_of_loop(pet: PETGraphX, node: Node) -> int:
elif "for.cond" in cast(CUNode, child).basic_block_id:
continue
else:
res += calculate_workload(pet, child)
try:
res += calculate_workload(pet, child)
except RecursionError as rerr:
warnings.warn("Cost calculation not possible for node: " + str(child.id) + "!")
else:
res += calculate_workload(pet, child)
try:
res += calculate_workload(pet, child)
except RecursionError as rerr:
warnings.warn("Cost calculation not possible for node: " + str(child.id) + "!")
return res


Expand Down
23 changes: 17 additions & 6 deletions discopop_library/discopop_optimizer/PETParser/PETParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Dict, List, Tuple, Set

import networkx as nx # type: ignore
import warnings

from discopop_explorer.PETGraphX import (
PETGraphX,
Expand Down Expand Up @@ -217,16 +218,21 @@ def __add_cu_nodes(self):
self.cu_id_to_graph_node_id[cu_node.id] = new_node_id
# calculate accessed data
written_memory_regions, read_memory_regions = get_data_accesses_for_cu(self.pet, cu_node.id)
try:
parallelizable_workload = calculate_workload(
self.pet, cu_node, ignore_function_calls_and_cached_values=True
)
except RecursionError as rerr:
warnings.warn("Cost calculation not possible for node: " + str(cu_node.id) + "!")
parallelizable_workload = 0
self.graph.add_node(
new_node_id,
data=Workload(
node_id=new_node_id,
experiment=self.experiment,
cu_id=cu_node.id,
sequential_workload=0,
parallelizable_workload=calculate_workload(
self.pet, cu_node, ignore_function_calls_and_cached_values=True
),
parallelizable_workload=parallelizable_workload,
written_memory_regions=written_memory_regions,
read_memory_regions=read_memory_regions,
),
Expand All @@ -250,14 +256,19 @@ def __add_loop_nodes(self):
# create new node for Loop
new_node_id = self.get_new_node_id()
self.cu_id_to_graph_node_id[loop_node.id] = new_node_id
try:
discopop_workload = calculate_workload(
self.pet, loop_node, ignore_function_calls_and_cached_values=True
)
except RecursionError as rerr:
warnings.warn("Cost calculation not possible for node: " + str(loop_node.id) + "!")
discopop_workload = 0
self.graph.add_node(
new_node_id,
data=Loop(
node_id=new_node_id,
cu_id=loop_node.id,
discopop_workload=calculate_workload(
self.pet, loop_node, ignore_function_calls_and_cached_values=True
),
discopop_workload=discopop_workload,
iterations=iteration_count,
position=loop_node.start_position(),
experiment=self.experiment,
Expand Down