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: add utility: GEPDependencyRemover #655

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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 dataclasses import dataclass
import logging
import os
from discopop_library.ArgumentClasses.GeneralArguments import GeneralArguments

logger = logging.getLogger("AutotunerArguments")


@dataclass
class GEPDependencyRemoverArguments(GeneralArguments):
"""Container Class for the arguments passed to the discopop GEPDependencyRemover"""

dyndep_file_path: str

def __post_init__(self) -> None:
self.__validate()

def log(self) -> None:
logger.debug("Arguments:")
for entry in self.__dict__:
logger.debug("-- " + str(entry) + ": " + str(self.__dict__[entry]))

def __validate(self) -> None:
"""Validate the arguments passed to the discopop GEPDependencyRemover, e.g check if given files exist"""

required_files = [
self.dyndep_file_path,
]
for file in required_files:
if not os.path.exists(file):
raise FileNotFoundError(file)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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.

import logging
import os
import re
from typing import List, Tuple, cast

import jsonpickle # type: ignore
from discopop_explorer.classes.PEGraph.LoopNode import LoopNode
from discopop_explorer.functions.PEGraph.queries.nodes import all_nodes
from discopop_library.Compatibility.LegacyDiscoPoP.GEPDependencyRemover.ArgumentClasses import (
GEPDependencyRemoverArguments,
)
from discopop_library.EmpiricalAutotuning.Classes.CodeConfiguration import CodeConfiguration
from discopop_library.EmpiricalAutotuning.Classes.ExecutionResult import ExecutionResult
from discopop_library.EmpiricalAutotuning.Statistics.StatisticsGraph import NodeColor, NodeShape, StatisticsGraph
from discopop_library.EmpiricalAutotuning.Types import SUGGESTION_ID
from discopop_library.EmpiricalAutotuning.utils import get_applicable_suggestion_ids
from discopop_library.HostpotLoader.HotspotLoaderArguments import HotspotLoaderArguments
from discopop_library.HostpotLoader.HotspotNodeType import HotspotNodeType
from discopop_library.HostpotLoader.HotspotType import HotspotType
from discopop_library.HostpotLoader.hostpot_loader import run as load_hotspots
from discopop_library.result_classes.DetectionResult import DetectionResult

logger = logging.getLogger("GEPDependencyRemover")


def run(arguments: GEPDependencyRemoverArguments) -> None:
logger.info("Starting DiscoPoP GEPDependencyRemover.")

filtered_lines: List[str] = []

# unpack dynamic dependency file
with open(arguments.dyndep_file_path, "r") as dyn_dep_file:
for line in dyn_dep_file.readlines():
line = line.replace("\n", "")
# unpack line and remove GEPRESULT dependencies
logger.debug("line: \t" + line)
line = re.sub(r"((RAW)|(WAR)|(WAW)|(INIT))\s+[\*(\d+\:\d+)]+\|\S+\(GEPRESULT_\S+\)\s*", "", line)
logger.debug("Line post:\t" + line)
line = line + "\n"
filtered_lines.append(line)
logger.debug("")

# write the updated file
logger.info("Overwriting " + arguments.dyndep_file_path)
with open(arguments.dyndep_file_path, "w") as dyn_dep_file:
for line in filtered_lines:
dyn_dep_file.write(line)
logger.info("Done writing " + arguments.dyndep_file_path)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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.

SUGGESTION_ID = int
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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 argparse import ArgumentParser
import os
from discopop_library.Compatibility.LegacyDiscoPoP.GEPDependencyRemover.ArgumentClasses import (
GEPDependencyRemoverArguments,
)
from discopop_library.GlobalLogger.setup import setup_logger
from discopop_library.Compatibility.LegacyDiscoPoP.GEPDependencyRemover.GEPDependencyRemover import run


def parse_args() -> GEPDependencyRemoverArguments:
"""Parse the arguments passed to the discopop GEPDependencyRemover"""
parser = ArgumentParser(description="DiscoPoP GEPDependencyRemover")

# fmt: off

parser.add_argument("--log", type=str, default="WARNING", help="Specify log level: DEBUG, INFO, WARNING, ERROR, CRITICAL")
parser.add_argument("--write-log", action="store_true", help="Create Logfile.")
parser.add_argument("--dyndep-file-path", type=str, default=os.path.join(os.getcwd(), ".discopop", "profiler", "dynamic_dependencies.txt"), help="Path to the dynamic dependencies file to be converted.")
# fmt: on

arguments = parser.parse_args()

return GEPDependencyRemoverArguments(
log_level=arguments.log.upper(), write_log=arguments.write_log, dyndep_file_path=arguments.dyndep_file_path
)


def main() -> None:
arguments = parse_args()
setup_logger(arguments)
arguments.log()
run(arguments)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

import logging
from typing import List

from discopop_library.EmpiricalAutotuning.Types import SUGGESTION_ID
from discopop_library.result_classes.DetectionResult import DetectionResult

logger = logging.getLogger("uitls")


def get_applicable_suggestion_ids(file_id: int, start_line: int, dtres: DetectionResult) -> List[SUGGESTION_ID]:
"""Identify suggestions where start position matches the given start position and return their ids."""
res: List[int] = []
for pattern_type in dtres.patterns.__dict__:
for pattern in dtres.patterns.__dict__[pattern_type]:
if pattern.start_line == str(file_id) + ":" + str(start_line) and pattern.applicable_pattern:
res.append(pattern.pattern_id)
return res
Empty file.
Loading