-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpocc.py
More file actions
executable file
·158 lines (120 loc) · 4.87 KB
/
pocc.py
File metadata and controls
executable file
·158 lines (120 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import os
import utilities
import parser
import random
POCC_CMD = "/opt/polyopt/default/sources/polyopt-hls/pocc/bin/pocc"
# POCC_CMD = "apptainer exec /opt/public/apptainer/pocc/pocc.sif pocc"
def tile(name_file, output_name_file):
cloogf, cloogl = utilities.compute_cloogl_cloof(name_file)
res = utilities.launch(f"{POCC_CMD} --pluto-fuse maxfuse {name_file} --verbose --output {output_name_file} --pluto-tile --pluto-noskew --cloog-cloogl 42 --cloog-cloogf 42 --pluto-bounds 1")
return res
def tile_no_codegen(name_file):
res = utilities.launch(f"{POCC_CMD} --pluto-fuse maxfuse {name_file} --verbose --pluto-tile -n")
return res
def ponos(name_file):
try:
res = utilities.launch(f"timeout 1m {POCC_CMD} --pluto --letsee {name_file} --verbose")
except:
res = ""
print(f"Error Ponos {name_file}")
return res
def extract_flops(name_file):
res = utilities.launch(f"{POCC_CMD} {name_file} --polyfeat --verbose")
gf = 0
for line in res:
if "Flops executed" in line:
gf = line.split(":")[1].split("(")[0].replace(" ", "")
gf = float(gf)
return gf
def scoplib(folder, file_):
"""
Processes a given C file to generate SCOPLib output.
Args:
folder (str): The folder where temporary files will be created.
file_ (str): The path to the input C file.
Returns:
str: The output of the POCC command execution.
"""
# Extract the path and file name
path = "/".join(file_.split("/")[:-1])
name_file = file_.split("/")[-1].split(".c")[0]
# Create the temporary directory if it doesn't already exist
temp_folder = f"{folder}/tmp"
if not os.path.exists(temp_folder):
os.mkdir(temp_folder)
# Copy the file to the temporary location with a modified name
temp_file = f"{temp_folder}/.tmp2{name_file}.c"
os.system(f"cp {file_} {temp_file}")
# Process the file to add and delete pragmas
utilities.delete_pragma(temp_file)
utilities.add_pragma_scop(temp_file)
# Execute the POCC command and capture the result
res = utilities.launch(f"{POCC_CMD} {temp_file} --output-scop --verbose")
return res
def candl(folder, file_):
"""
Processes a given C file to generate dependencies using the CANDL tool.
Args:
folder (str): The folder where temporary files will be created.
file_ (str): The path to the input C file.
Returns:
str: The output of the POCC command execution with CANDL options.
"""
# Extract the path and file name
path = "/".join(file_.split("/")[:-1])
name_file = file_.split("/")[-1].split(".c")[0]
# Create the temporary directory if it doesn't already exist
temp_folder = f"{folder}/tmp"
if not os.path.exists(temp_folder):
os.mkdir(temp_folder)
# Copy the file to the temporary location with a modified name
temp_file = f"{temp_folder}/.tmp2{name_file}.c"
os.system(f"cp {file_} {temp_file}")
# Process the file to add and delete pragmas
utilities.delete_pragma(temp_file)
utilities.add_pragma_scop(temp_file)
# Execute the POCC command with CANDL options and capture the result
res = utilities.launch(f"{POCC_CMD} {temp_file} --candl-dep-isl-simp --verbose -n")
return res
def candl_ddv(file_):
res = utilities.launch(f"{POCC_CMD} {file_} --candl-ddv --candl-dep-prune --red-commute --verbose -n")
return res
def scop(folder, file_):
"""
Processes a given C file to generate SCOP output using POCC.
Args:
folder (str): The folder where temporary files will be created.
file_ (str): The path to the input C file.
Returns:
list: Lines from the generated SCOP output file.
"""
# Ensure the temporary directory exists
temp_folder = f"{folder}/tmp"
if not os.path.exists(temp_folder):
os.mkdir(temp_folder)
# Extract the file name without extension
name_file = file_.split("/")[-1].split(".c")[0]
# Prepare the temporary file path
temp_file = f"{temp_folder}/.tmp2{name_file}.c"
# Copy and preprocess the input file
os.system(f"cp {file_} {temp_file}")
utilities.delete_pragma(temp_file)
utilities.add_pragma_scop(temp_file)
# Run the POCC command to generate SCOP output
res = utilities.launch(f"{POCC_CMD} {temp_file} --output-scop")
# Read the generated SCOP file
scop_file = f"{temp_folder}/.tmp2{name_file}.pocc.c.scop"
with open(scop_file, "r") as f:
lines = f.readlines()
return lines
def compute_schedule(folder, fil):
if not os.path.exists("tmp"):
os.mkdir("tmp")
# os.system(f"cp {fil} tmp/.{fil}")
# utilities.delete_bracket(f"tmp/.{fil}")
# utilities.delete_comment(f"tmp/.{fil}")
# utilities.rename_register(f"tmp/.{fil}")
# utilities.delete_pragma_scop(f"tmp/.{fil}")
sched = parser.parser(folder, fil)
# os.system(f"rm tmp/.{fil}")
return sched