Skip to content

Commit

Permalink
refactor(explorer): move stuff out of __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
goerlibe committed Sep 12, 2023
1 parent 6f170c0 commit b965279
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 69 deletions.
67 changes: 0 additions & 67 deletions discopop_explorer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,67 +0,0 @@
# 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 pathlib import Path
from typing import List, Optional

from pluginbase import PluginBase # type:ignore

from .PETGraphX import PETGraphX, NodeType
from .parser import parse_inputs
from .pattern_detection import PatternDetectorX
from discopop_library.result_classes.DetectionResult import DetectionResult


def run(
project_path: str,
cu_xml: str,
dep_file: str,
loop_counter_file: str, # TODO we should be able to read all info from the _dep.txt file (?)
reduction_file: str,
plugins: List[str],
file_mapping: Optional[str] = None,
cu_inst_result_file: Optional[str] = None,
llvm_cxxfilt_path: Optional[str] = None,
discopop_build_path: Optional[str] = None,
enable_task_pattern: bool = False,
) -> DetectionResult:
pet = PETGraphX.from_parsed_input(*parse_inputs(cu_xml, dep_file, reduction_file, file_mapping))
print("PET CREATION FINISHED.")
# pet.show()
# TODO add visualization

plugin_base = PluginBase(package="plugins")

plugin_source = plugin_base.make_plugin_source(searchpath=[Path(__file__).parent / "plugins"])

for plugin_name in plugins:
p = plugin_source.load_plugin(plugin_name)
print("executing plugin before: " + plugin_name)
pet = p.run_before(pet)

pattern_detector = PatternDetectorX(pet)

res: DetectionResult = pattern_detector.detect_patterns(
project_path,
cu_xml,
dep_file,
loop_counter_file,
reduction_file,
file_mapping,
cu_inst_result_file,
llvm_cxxfilt_path,
discopop_build_path,
enable_task_pattern,
)

for plugin_name in plugins:
p = plugin_source.load_plugin(plugin_name)
# print("executing plugin after: " + plugin_name)
pet = p.run_after(pet)

return res
61 changes: 59 additions & 2 deletions discopop_explorer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,24 @@

from docopt import docopt # type:ignore
from schema import Schema, Use, SchemaError # type:ignore
from typing import List, Optional
from pathlib import Path


from . import run
from .json_serializer import PatternInfoSerializer
from discopop_library.global_data.version.utils import get_version
from discopop_library.discopop_optimizer.Microbench.ExtrapInterpolatedMicrobench import (
ExtrapInterpolatedMicrobench,
)
from discopop_library.PathManagement.PathManagement import get_path


from pluginbase import PluginBase # type:ignore

from .PETGraphX import PETGraphX
from .parser import parse_inputs
from .pattern_detection import PatternDetectorX
from discopop_library.result_classes.DetectionResult import DetectionResult

docopt_schema = Schema(
{
"--path": Use(str),
Expand All @@ -84,6 +91,56 @@
)


def run(
project_path: str,
cu_xml: str,
dep_file: str,
loop_counter_file: str, # TODO we should be able to read all info from the _dep.txt file (?)
reduction_file: str,
plugins: List[str],
file_mapping: Optional[str] = None,
cu_inst_result_file: Optional[str] = None,
llvm_cxxfilt_path: Optional[str] = None,
discopop_build_path: Optional[str] = None,
enable_task_pattern: bool = False,
) -> DetectionResult:
pet = PETGraphX.from_parsed_input(*parse_inputs(cu_xml, dep_file, reduction_file, file_mapping))
print("PET CREATION FINISHED.")
# pet.show()
# TODO add visualization

plugin_base = PluginBase(package="plugins")

plugin_source = plugin_base.make_plugin_source(searchpath=[Path(__file__).parent / "plugins"])

for plugin_name in plugins:
p = plugin_source.load_plugin(plugin_name)
print("executing plugin before: " + plugin_name)
pet = p.run_before(pet)

pattern_detector = PatternDetectorX(pet)

res: DetectionResult = pattern_detector.detect_patterns(
project_path,
cu_xml,
dep_file,
loop_counter_file,
reduction_file,
file_mapping,
cu_inst_result_file,
llvm_cxxfilt_path,
discopop_build_path,
enable_task_pattern,
)

for plugin_name in plugins:
p = plugin_source.load_plugin(plugin_name)
# print("executing plugin after: " + plugin_name)
pet = p.run_after(pet)

return res


def main():
arguments = docopt(__doc__, version=f"DiscoPoP Version {get_version()}")

Expand Down

0 comments on commit b965279

Please sign in to comment.