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

Release/3.1.1 #520

Merged
merged 4 commits into from
Jan 17, 2024
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
3 changes: 3 additions & 0 deletions discopop_explorer/json_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from discopop_library.discopop_optimizer.classes.types.DataAccessType import WriteDataAccess

from discopop_library.result_classes.DetectionResult import DetectionResult
from discopop_library.result_classes.PatternStorage import PatternStorage
from .PEGraphX import Node
from .pattern_detectors.PatternInfo import PatternInfo
from .pattern_detectors.pipeline_detector import PipelineStage
Expand Down Expand Up @@ -52,6 +53,8 @@ def default(self, o):
return filter_members(o.__dict__)
if isinstance(o, DetectionResult):
return filter_members(o.__dict__)
if isinstance(o, PatternStorage):
return filter_members(o.__dict__)
if isinstance(o, PipelineStage):
return filter_members(o.__dict__)
if isinstance(o, Update):
Expand Down
12 changes: 6 additions & 6 deletions discopop_explorer/pattern_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,24 @@ def detect_patterns(

if "*" in enable_patterns or "reduction" in enable_patterns:
print("REDUCTIONS...")
res.reduction = detect_reduction(self.pet)
res.patterns.reduction = detect_reduction(self.pet)
print("\tDONE.")
if "*" in enable_patterns or "doall" in enable_patterns:
print("DOALL...")
res.do_all = detect_do_all(self.pet)
res.patterns.do_all = detect_do_all(self.pet)
print("\tDONE.")
if "*" in enable_patterns or "pipeline" in enable_patterns:
print("PIPELINE...")
res.pipeline = detect_pipeline(self.pet)
res.patterns.pipeline = detect_pipeline(self.pet)
print("\tDONE.")
if "*" in enable_patterns or "geodec" in enable_patterns:
print("GEO. DEC...")
res.geometric_decomposition = detect_gd(self.pet)
res.patterns.geometric_decomposition = detect_gd(self.pet)
print("\tDONE.")

# check if task pattern should be enabled
if enable_task_pattern:
res.task = detect_tp(
res.patterns.task = detect_tp(
cu_dict,
dependencies,
reduction_vars,
Expand All @@ -112,7 +112,7 @@ def detect_patterns(
# detect GPU patterns based on previously identified patterns
if "*" in enable_patterns or "simplegpu" in enable_patterns:
print("SIMPLE GPU...")
res.simple_gpu = detect_gpu(self.pet, res, project_path)
res.patterns.simple_gpu = detect_gpu(self.pet, res, project_path)
print("\tDONE.")

# detect combined GPU patterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def setCollapseClause(self, pet: PEGraphX, node_id: NodeID, res):
# calculate the number of iterations of this loop relative to the top loop
n: LoopNode = cast(LoopNode, map_node(pet, node_id))

do_all_loops = [node.node_id for node in res.do_all]
do_all_loops = [node.node_id for node in res.patterns.do_all]

loop_entry_node = cast(LoopNode, pet.node_at(node_id)).get_entry_node(pet)
if loop_entry_node is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def run_detection(pet: PEGraphX, res, project_folder_path: str) -> List[PatternI
# check for lastprivates, since they are not supported by the suggested pragma:
# pragma omp target teams distribute
# todo: instead of omitting, suggest #pragma omp target parallel for instead
if any(node.id == d.node_id for d in res.do_all if len(d.last_private) == 0) or any(
node.id == r.node_id for r in res.reduction if len(r.last_private) == 0
if any(node.id == d.node_id for d in res.patterns.do_all if len(d.last_private) == 0) or any(
node.id == r.node_id for r in res.patterns.reduction if len(r.last_private) == 0
):
reduction_vars: List[Variable] = []
if node.id in [r.node_id for r in res.reduction]:
parent_reduction = [r for r in res.reduction if r.node_id == node.id][0]
if node.id in [r.node_id for r in res.patterns.reduction]:
parent_reduction = [r for r in res.patterns.reduction if r.node_id == node.id][0]
reduction_vars = parent_reduction.reduction
gpulp = GPULoopPattern(
pet,
Expand Down
4 changes: 2 additions & 2 deletions discopop_library/JSONHandler/JSONHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def read_patterns_from_json_to_json(json_path: str, relevant_patterns: List[str]

with open(json_path, "r") as f:
data = json.load(f)
for key in data:
for key in data["patterns"]:
if len(relevant_patterns) > 0 and key not in relevant_patterns:
continue
if key not in pattern_json_strings_by_type:
pattern_json_strings_by_type[key] = []
for entry in data[key]:
for entry in data["patterns"][key]:
pattern_json_strings_by_type[key].append(json.dumps(entry))

return pattern_json_strings_by_type
2 changes: 1 addition & 1 deletion discopop_library/discopop_optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def run(arguments: OptimizerArguments):
if best_configuration is not None:
best_configuration = optimize_updates(experiment, best_configuration, arguments)
# append the configuration to the list of patterns
experiment.detection_result.optimizer_output.append(best_configuration)
experiment.detection_result.patterns.optimizer_output.append(best_configuration)

# save full experiment to disk
export_to_json(experiment, optimizer_dir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def import_suggestions(experiment: Experiment) -> nx.DiGraph:
"""Imports the suggestions specified in res into the graph stored in the given experiment and returns the modified graph"""

# import do-all
for do_all_suggestion in experiment.detection_result.do_all:
for do_all_suggestion in experiment.detection_result.patterns.do_all:
experiment.optimization_graph = import_doall(
experiment.optimization_graph, do_all_suggestion, experiment.get_next_free_node_id, experiment
)

# import reduction
for reduction_suggestion in experiment.detection_result.reduction:
for reduction_suggestion in experiment.detection_result.patterns.reduction:
experiment.optimization_graph = import_reduction(
experiment.optimization_graph, reduction_suggestion, experiment.get_next_free_node_id, experiment
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __collapse_loops_in_function(function_node_id):

# register pattern for output
# todo: find a nicer solution to duplicating the patterns for each device mapping
global_experiment.detection_result.do_all.append(pattern_info)
global_experiment.detection_result.patterns.do_all.append(pattern_info)
print("REGISTERED PATTERN INFO: ", pattern_id, " for Device: ", data_at(global_graph, csrc).device_id)
print(pattern_info)
print()
Expand Down
13 changes: 4 additions & 9 deletions discopop_library/result_classes/DetectionResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This software may be modified and distributed under the terms of
# the 3-Clause BSD License. See the LICENSE file in the package base
# directory for details.
from ast import Dict
from typing import List

import jsonpickle # type: ignore
Expand All @@ -17,24 +18,18 @@
from discopop_explorer.pattern_detectors.pipeline_detector import PipelineInfo
from discopop_explorer.pattern_detectors.reduction_detector import ReductionInfo
from discopop_library.global_data.version.utils import get_version
from discopop_library.result_classes.PatternStorage import PatternStorage


class DetectionResult(object):
version: str
pet: PEGraphX
reduction: List[ReductionInfo]
do_all: List[DoAllInfo]
pipeline: List[PipelineInfo]
geometric_decomposition: List[GDInfo]
task: List[PatternInfo]
simple_gpu: List[PatternInfo]
combined_gpu: List[PatternInfo]
optimizer_output: List[PatternBase]
patterns: PatternStorage

def __init__(self, pet: PEGraphX):
self.version = get_version() # discopop version
self.pet = pet
self.optimizer_output = []
self.patterns = PatternStorage()
pass

def __str__(self):
Expand Down
30 changes: 30 additions & 0 deletions discopop_library/result_classes/PatternStorage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is part of the DiscoPoP software (http://www.discopop.tu-darmstadt.de)
#
# Copyright (c) 2020, Technische Universitaet Darmstadt, Germany
#
# This software may be modified and distributed under the terms of
# the 3-Clause BSD License. See the LICENSE file in the package base
# directory for details.

from typing import List

from discopop_explorer.pattern_detectors.PatternBase import PatternBase
from discopop_explorer.pattern_detectors.PatternInfo import PatternInfo
from discopop_explorer.pattern_detectors.do_all_detector import DoAllInfo
from discopop_explorer.pattern_detectors.geometric_decomposition_detector import GDInfo
from discopop_explorer.pattern_detectors.pipeline_detector import PipelineInfo
from discopop_explorer.pattern_detectors.reduction_detector import ReductionInfo


class PatternStorage(object):
reduction: List[ReductionInfo]
do_all: List[DoAllInfo]
pipeline: List[PipelineInfo]
geometric_decomposition: List[GDInfo]
task: List[PatternInfo]
simple_gpu: List[PatternInfo]
combined_gpu: List[PatternInfo]
optimizer_output: List[PatternBase]

def __init__(self):
self.optimizer_output = []
2 changes: 1 addition & 1 deletion test/do_all/daxpy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def validate_results(self, test_dir, src_dir):

# convert DoAllInfo objects to DoAllInfoForValidation objects to make use of custom __eq__
converted_gold_standard = [DoAllInfoForValidation(elem) for elem in gold_standard.do_all]
converted_test_output = [DoAllInfoForValidation(elem) for elem in test_output.do_all]
converted_test_output = [DoAllInfoForValidation(elem) for elem in test_output.patterns.do_all]

# sort the lists
converted_gold_standard = sorted(
Expand Down
2 changes: 1 addition & 1 deletion test/optimizer/loop_collapse/negative/simple_1/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def validate_results(self, test_dir, src_dir):
test_output: DetectionResult = jsonpickle.decode(tmp_str)

# check identified DoAllInfo objects for collapse clauses > 1
for do_all_info in test_output.do_all:
for do_all_info in test_output.patterns.do_all:
self.assertTrue(do_all_info.collapse_level <= 1)


2 changes: 1 addition & 1 deletion test/optimizer/loop_collapse/positive/simple_1/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def validate_results(self, test_dir, src_dir):

# check identified DoAllInfo objects for collapse clauses > 1
two_level_collapse_found = False
for do_all_info in test_output.do_all:
for do_all_info in test_output.patterns.do_all:
if do_all_info.collapse_level == 2:
two_level_collapse_found = True

Expand Down