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/line mapping initialization #431

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 5 additions & 1 deletion discopop_explorer/discopop_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import pstats2 # type:ignore
from pluginbase import PluginBase # type:ignore

from discopop_library.PathManagement.PathManagement import get_path
from discopop_library.LineMapping.initialize import initialize_line_mapping
from discopop_library.PathManagement.PathManagement import get_path, load_file_mapping
from discopop_library.discopop_optimizer.Microbench.ExtrapInterpolatedMicrobench import (
ExtrapInterpolatedMicrobench,
)
Expand Down Expand Up @@ -215,6 +216,9 @@ def run(arguments: ExplorerArguments):
stats = pstats2.Stats(profile, stream=f).sort_stats("time").reverse_order()
stats.print_stats()

# initialize the line_mapping.json
initialize_line_mapping(load_file_mapping(arguments.file_mapping_file), arguments.project_path)

print("Time taken for pattern detection: {0}".format(end - start))

# demonstration of Microbenchmark possibilities
Expand Down
Empty file.
40 changes: 40 additions & 0 deletions discopop_library/LineMapping/initialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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 json
import os.path
from pathlib import Path
from typing import Dict

from discopop_library.LineMapping.load import load_line_mapping
from discopop_library.LineMapping.save import save_line_mapping


def initialize_line_mapping(
file_mapping: Dict[int, Path],
discopop_path: str = ".discopop",
):
"""initializes the line mapping dictionary to track line shifts due to inserted pragmas.
The Dictionary will be stored in .discopop/line_mapping.json.
Line ids start with 1."""
line_mapping_dict: Dict[int, Dict[int, int]] = dict()

# initialize line mapping (1->1, 2->2, ...)
for file_id in file_mapping:
if file_id not in line_mapping_dict:
line_mapping_dict[file_id] = dict()
line_id = 1
with open(file_mapping[file_id], "r") as f:
for line in f.readlines():
line_mapping_dict[file_id][line_id] = line_id
line_id += 1

save_line_mapping(line_mapping_dict, discopop_path)

# debug
load_line_mapping(discopop_path)
18 changes: 18 additions & 0 deletions discopop_library/LineMapping/load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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 json
import os.path
from typing import Dict


def load_line_mapping(discopop_path: str = ".discopop") -> Dict[int, Dict[int, int]]:
"""Loads and returns the line_mapping dictionary"""
line_mapping_dict: Dict[int, Dict[int, int]] = dict()
with open(os.path.join(discopop_path, "line_mapping.json")) as f:
line_mapping_dict = json.load(f)
return line_mapping_dict
17 changes: 17 additions & 0 deletions discopop_library/LineMapping/save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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 json
import os
from typing import Dict


def save_line_mapping(line_mapping_dict: Dict[int, Dict[int, int]], discopop_path: str = ".discopop"):
"""dumps line_mapping_dict to line_mapping.json"""
# dump line mapping to json file
with open(os.path.join(discopop_path, "line_mapping.json"), "w+") as f:
json.dump(line_mapping_dict, f)