-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrunArray.py
More file actions
142 lines (115 loc) · 4.96 KB
/
runArray.py
File metadata and controls
142 lines (115 loc) · 4.96 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
import subprocess
import argparse
import os
from pathlib import Path
experiment_folder = "./Array/"
output_filename = "array_experiments.csv"
def ensure_dir(path: str) -> str:
"""Ensure path is a directory; create it if missing; return absolute path."""
os.makedirs(path, exist_ok=True)
return os.path.abspath(path)
def set_autonuma(desired: int) -> None:
"""
Set AutoNUMA globally to 0 or 1.
Tries direct /proc write, then falls back to 'sudo sysctl -w'.
Verifies and raises on failure.
"""
try:
with open("/proc/sys/kernel/numa_balancing", "r") as f:
cur =int(f.read().strip())
except FileNotFoundError:
raise RuntimeError("This kernel doesn't expose /proc/sys/kernel/numa_balancing (no AutoNUMA support?)")
if desired not in (0, 1):
raise ValueError("AutoNUMA value must be 0 or 1")
if cur == desired:
print(f"AutoNUMA already {cur} (no change).")
return
# 1) Try direct write (works if running as root)
try:
with open("/proc/sys/kernel/numa_balancing", "w") as f:
f.write(str(desired))
except PermissionError:
# 2) Fall back to sudo sysctl
cmd = ["sudo", "sysctl", f"kernel.numa_balancing={desired}"]
r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
if r.returncode != 0:
msg = r.stdout.strip()
raise RuntimeError(f"Failed to set AutoNUMA via sysctl (exit {r.returncode}). Output:\n{msg}")
# Verify
try:
with open("/proc/sys/kernel/numa_balancing", "r") as f:
new_val =int(f.read().strip())
except FileNotFoundError:
raise RuntimeError("This kernel doesn't expose /proc/sys/kernel/numa_balancing (no AutoNUMA support?)")
if new_val != desired:
raise RuntimeError(f"Tried to set AutoNUMA to {desired}, but kernel reports {new_val}.")
print(f"AutoNUMA set to {new_val} successfully.")
def compile_experiment(UMF: bool) -> None:
# Clean previous builds
subprocess.run(f"cd {experiment_folder} && make clean", shell=True, check=False)
# Compile with or without UMF
if UMF:
subprocess.run(f"cd {experiment_folder} && make UMF=1", shell=True, check=False)
else:
subprocess.run(f"cd {experiment_folder} && make", shell=True, check=False)
def write_header_once(csv_path: Path) -> None:
"""Write header only if file doesn't exist or is empty."""
header = (
"Date, Time, num_arrays, num_threads, thread_config, DS_config, duration, array_size, interval,ops_node0, ops_node1, total_ops\n "
)
if not csv_path.exists() or csv_path.stat().st_size == 0:
# Ensure parent dir exists
csv_path.parent.mkdir(parents=True, exist_ok=True)
with csv_path.open("w") as f:
f.write(header)
def run_experiment(output_csv: Path) -> None:
# Append results under the header
# We’ll redirect stdout of meta.py to the SAME csv file
cmd = (
f'cd {experiment_folder} && '
f'python3 meta.py '
f'numactl --cpunodebind=0,1 --membind=0,1 '
f'./bin/array '
f'--meta th_config:numa '
f'--meta DS_config:numa '
f'--meta t:80 '
f'--meta u:180 '
f'--meta s:100000000 '
f'--meta i:20 '
f'--meta n:10'
f'>> "{output_csv}"'
)
subprocess.run(cmd, shell=True, check=False)
def graph_data(should_graph: bool, autonuma) -> None:
if should_graph:
if (autonuma == 1):
output_dir = Path(args.output) / "AN_on"
elif (autonuma == 0):
output_dir = Path(args.output) / "AN_off"
plot_cmd = f'cd Result/plots && python3 plot_array.py "{output_dir}/{output_filename}" --show --save {output_dir}/figs'
subprocess.run(plot_cmd, shell=True, check=False)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run ycsb experiment and append results to CSV.")
parser.add_argument('--UMF', action='store_true', help="Build with UMF=1.")
parser.add_argument(
"-d", "--output", type=ensure_dir, required=True, help="Directory where the CSV will be written (will be created if missing)."
)
parser.add_argument('--graph', action='store_true', help="Generate graphs after running experiments.")
parser.add_argument('--AN', type=int, choices=[0, 1], default=1, help="Set autonuma flag (0 or 1)")
args = parser.parse_args()
set_autonuma(args.AN)
output_dir = Path(args.output)
output_file_path = ""
if (args.AN == 1):
output_file_path = output_dir / "AN_on" / output_filename
elif (args.AN == 0):
output_file_path = output_dir / "AN_off" / output_filename
# 1) Ensure header exists (first line)
write_header_once(output_file_path)
# 2) Build
compile_experiment(args.UMF)
# 3) Run and append results
run_experiment(output_file_path)
#graph_data(args.graph, args.AN)
# 4) Graph experiments
print(f"Results appended to: {output_file_path}")