Skip to content

Commit c2b05ba

Browse files
committed
add script to create tables for different flags
1 parent db330f4 commit c2b05ba

File tree

3 files changed

+114
-10
lines changed

3 files changed

+114
-10
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
build
22
build_debug
33
build_script
4+
outputs
5+
tags
46
compile_commands.json
57
.cache
8+
**/__pycache__
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python3
2+
import subprocess
3+
import os
4+
import platform
5+
from latex_table import generate_latex_table
6+
7+
# Configuration
8+
benchmark_executable = './build/benchmarks/benchmark'
9+
latex_script = './scripts/latex_table.py'
10+
output_dir = './outputs'
11+
input_files = [
12+
'data/canada.txt',
13+
'data/mesh.txt',
14+
]
15+
models = [
16+
'uniform_01',
17+
'uniform_all',
18+
'integer_uniform',
19+
'centered',
20+
'non_centered',
21+
]
22+
runs_r = 1_000
23+
volume_v = 1_000_000
24+
flag_combinations = [
25+
[],
26+
['-F6'],
27+
['-s'],
28+
['-F6', '-s'],
29+
]
30+
31+
32+
def get_cpu_model():
33+
if platform.system() == "Windows":
34+
return platform.processor()
35+
elif platform.system() == "Darwin":
36+
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + '/usr/sbin'
37+
command = "sysctl -n machdep.cpu.brand_string"
38+
return subprocess.check_output(command).strip()
39+
elif platform.system() == "Linux":
40+
command = "cat /proc/cpuinfo"
41+
output = subprocess.check_output(command, shell=True).decode().strip()
42+
for line in output.split("\n"):
43+
if line.startswith("model name"):
44+
return line.split(':', 1)[1].strip()
45+
return "unknown_cpu"
46+
47+
48+
CPUModel = get_cpu_model().replace(' ', '_').replace('/', '-').replace('@', '')
49+
os.makedirs(output_dir, exist_ok=True)
50+
51+
52+
# Helper to run a command and return its stdout
53+
def run_cmd(cmd):
54+
result = subprocess.run(cmd, capture_output=True, text=True)
55+
result.check_returncode()
56+
return result.stdout
57+
58+
59+
# Process a single benchmark invocation and generate .tex
60+
def process_job(label, cmd_args, flags):
61+
# Run the benchmark
62+
cmd = [benchmark_executable] + cmd_args + flags
63+
print(f"Running: {' '.join(cmd)}")
64+
output = run_cmd(cmd)
65+
66+
# Build output file name
67+
flag_label = ''.join([f.strip('-') for f in flags]) or 'none'
68+
safe_label = label.replace('.', '_')
69+
filename = f"{CPUModel}_{safe_label}_{flag_label}.tex"
70+
out_path = os.path.join(output_dir, filename)
71+
72+
# Write to file
73+
tex_content = generate_latex_table(output)
74+
with open(out_path, 'w') as f:
75+
f.write(tex_content)
76+
print(f"Written: {out_path}\n")
77+
78+
79+
if __name__ == '__main__':
80+
# File-based benchmarks
81+
for filepath in input_files:
82+
file_label = os.path.splitext(os.path.basename(filepath))[0]
83+
for flags in flag_combinations:
84+
process_job(
85+
label=file_label,
86+
cmd_args=['-f', filepath, '-r', str(runs_r)],
87+
flags=flags
88+
)
89+
90+
# Model-based benchmarks
91+
for model in models:
92+
for flags in flag_combinations:
93+
process_job(
94+
label=model,
95+
cmd_args=['-m', model, '-v', str(volume_v), '-r', str(runs_r)],
96+
flags=flags
97+
)

scripts/latex_table.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env python3
2-
32
import sys
43
import re
54
import argparse
65

6+
77
# Function to format a number to two significant digits
88
def format_to_two_sig_digits(value):
99
if not isinstance(value, (int, float)) or value == 0:
1010
return "N/A"
11-
11+
1212
# Handle negative numbers
1313
is_negative = value < 0
1414
abs_value = abs(value)
@@ -27,14 +27,15 @@ def format_to_two_sig_digits(value):
2727

2828
# Format the number
2929
if exponent >= 0 and exponent <= 4:
30-
format = f"{'-' if is_negative else ''}{abs_value*10**exponent}"
30+
format = f"{'-' if is_negative else ''}{abs_value * 10 ** exponent}"
3131
format = format.replace(".0", "")
3232
return format
3333
elif exponent < 0 and exponent >= -4:
34-
return f"{'-' if is_negative else ''}{abs_value*10**exponent:.1f}"
34+
return f"{'-' if is_negative else ''}{abs_value * 10 ** exponent:.1f}"
3535
else:
3636
return f"{'-' if is_negative else ''}{abs_value:.1f}e{exponent}"
3737

38+
3839
# Function to parse the raw input data
3940
def parse_input(data):
4041
lines = data.splitlines()
@@ -54,6 +55,7 @@ def parse_input(data):
5455
parsed_data.append(current_entry)
5556
if not current_entry:
5657
continue
58+
5759
# Match lines with ns/f
5860
match_ns = re.search(r"([\d.]+)\s*ns/f", line)
5961
if match_ns and current_entry:
@@ -72,27 +74,29 @@ def parse_input(data):
7274
# Filter out incomplete entries
7375
return parsed_data
7476

77+
7578
# Function to generate LaTeX table
76-
def generate_latex_table(data):
79+
def generate_latex_table(raw_input):
80+
data = parse_input(raw_input)
81+
7782
latex_table = r"""
7883
\begin{tabular}{lccc}
7984
\toprule
8085
\textbf{Name} & \textbf{ns/f} & \textbf{instructions/float} & \textbf{instructions/cycle} \\
8186
\midrule
8287
"""
83-
8488
for entry in data:
8589
name = entry["name"].replace("_", "\\_") # Escape underscores for LaTeX
8690
ns_per_float = format_to_two_sig_digits(entry['ns_per_float']) if 'ns_per_float' in entry else 'N/A'
8791
inst_per_float = format_to_two_sig_digits(entry['inst_per_float']) if 'inst_per_float' in entry else 'N/A'
8892
inst_per_cycle = format_to_two_sig_digits(entry['inst_per_cycle']) if 'inst_per_cycle' in entry else 'N/A'
8993
latex_table += f"{name} & {ns_per_float} & {inst_per_float} & {inst_per_cycle} \\\\ \n"
90-
9194
latex_table += r"""\bottomrule
9295
\end{tabular}
9396
"""
9497
return latex_table
9598

99+
96100
if __name__ == "__main__":
97101
parser = argparse.ArgumentParser(description="Generate LaTeX table from performance data")
98102
parser.add_argument("file", nargs="?", help="Optional input file name (if not provided, reads from stdin)")
@@ -111,6 +115,6 @@ def generate_latex_table(data):
111115
sys.exit(1)
112116
else:
113117
raw_input = sys.stdin.read()
114-
parsed_data = parse_input(raw_input)
115-
latex_output = generate_latex_table(parsed_data)
116-
print(latex_output)
118+
119+
latex_output = generate_latex_table(raw_input)
120+
print(latex_output)

0 commit comments

Comments
 (0)