-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatch_simeng.py
143 lines (124 loc) · 6.4 KB
/
dispatch_simeng.py
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
import os
import subprocess
import sys
import config_generator as generator
import psutil
import signal
import time
import shlex
import yaml
USING_SST = True
#PATH TO THE BASE DIR
PATH = "~/path/to/base/dir"
#PATH TO BENCHMARK BASE DIR
BENCHMARK_PATH_BASE="~/path/to/benchmark/dir"
#PATH TO BENCHMARK INPUT FILES BASE DIR
DATA_PATH_BASE = "~/path/to/input/files"
HOME = os.path.expanduser("~")
minibude_binary_path = os.path.join(BENCHMARK_PATH_BASE, "minibude/minibude-omp_armclang23_armv8.4-a+sve")
minibude_data_path = os.path.join(DATA_PATH_BASE, "minibude/bm1/")
stream_binary_path = os.path.join(BENCHMARK_PATH_BASE, "stream/stream-200k_armclang23_armv8.4-a+sve")
tealeaf_binary_path = os.path.join(BENCHMARK_PATH_BASE, "tealeaf/TeaLeaf-armclang23-armv8.4+sve")
minisweep_binary_path = os.path.join(BENCHMARK_PATH_BASE, "minisweep/minisweep-omp-armclang23-armv8.4-a+sve")
BENCHMARKS = {
"minibude" : [minibude_binary_path, "-n", "64", "-i", "1", "--deck", minibude_data_path],
"stream" : [stream_binary_path, "a"],
"tealeaf": [tealeaf_binary_path, "a"],
"minisweep": [minisweep_binary_path, "--ncell_x", "4", "--ncell_y", "4", "--ncell_z", \
"4", "--ne", "1", "--na", "32", "--niterations", "1", "--nblock_z", \
"1", "--nthread_e", "1"]
}
# Function to check memory usage of a given PID
def check_memory(pid, threshold_kb):
try:
process = psutil.Process(pid)
mem_usage = process.memory_info().rss / 1024 # Memory usage in KB
if mem_usage > threshold_kb:
print(f"Process {pid} is using too much memory: {mem_usage} KB")
return True
return False
except (psutil.NoSuchProcess, psutil.AccessDenied):
return False
def generate_batch():
config_file, original_parameters = generator.gen_random_config()
config_dest = os.path.join(PATH, "config-buffer", "config-%d.yaml" % BATCH_ID)
f = open(config_dest, "w")
f.write(config_file)
f.close()
sst_params = generator.gen_sst(original_parameters)
sst_dest = os.path.join(PATH, "sst-buffer", "sst-%d.yaml" % BATCH_ID)
with open(sst_dest, "w") as yaml_file:
yaml.dump(sst_params, yaml_file, default_flow_style=False)
return sst_params
def load_batch(index):
config_file, sst_params, original_parameters = generator.read_parameters(index)
config_dest = os.path.join(PATH, "config-buffer", "config-%d.yaml" % BATCH_ID)
f = open(config_dest, "w")
f.write(config_file)
f.close()
#sst_params = generator.gen_sst(original_parameters)
sst_dest = os.path.join(PATH, "sst-buffer", "sst-%d.yaml" % BATCH_ID)
with open(sst_dest, "w") as yaml_file:
yaml.dump(sst_params, yaml_file, default_flow_style=False)
return sst_params
def dispatch_batch(sst_params):
for i in BENCHMARKS:
#Create directories if needed
if not os.path.isdir(os.path.join(PATH, "results-buffer", i)):
os.mkdir(os.path.join(PATH, "results-buffer", i))
config_dest = os.path.join(PATH, "config-buffer", "config-%d.yaml" % BATCH_ID)
output_file = os.path.join(PATH, "results-buffer", i, "results-" + str(BATCH_ID) + ".txt")
f = open(output_file, "w")
if (not USING_SST):
process = subprocess.Popen(["simeng", config_dest] + BENCHMARKS[i], stdout=f)
else:
#print(sst_params)
#sst_params = generator.gen_sst()
# Janky code as subprocess arg parsing is really hard to use to specify ordering
model_options = " ".join([
"--simeng_config", config_dest,
"--bin_path", BENCHMARKS[i][0],
"--bin_args", f"\"{' '.join(BENCHMARKS[i][1:])}\"",
"--clw", str(sst_params["clw"]),
"--core_clock", str(sst_params["core_clock"]),
"--l1_latency", str(sst_params["l1_latency"]),
"--l1_clock", str(sst_params["l1_clock"]),
"--l1_associativity", str(sst_params["l1_associativity"]),
"--l1_size", str(sst_params["l1_size"]),
"--l2_latency", str(sst_params["l2_latency"]),
"--l2_clock", str(sst_params["l2_clock"]),
"--l2_associativity", str(sst_params["l2_associativity"]),
"--l2_size", str(sst_params["l2_size"]),
"--ram_timing", str(sst_params["ram_timing"]),
"--ram_clock", str(sst_params["ram_clock"]),
"--ram_size", str(sst_params["ram_size"])])
model_options = f"""sst sst-config.py --model-options
'--simeng_config {config_dest} --bin_path {BENCHMARKS[i][0]} --bin_args "{' '.join(BENCHMARKS[i][1:])}" --clw {sst_params["clw"]} --core_clock {sst_params["core_clock"]} --l1_latency {sst_params["l1_latency"]} --l1_clock {sst_params["l1_clock"]} --l1_associativity {sst_params["l1_associativity"]} --l1_size {sst_params["l1_size"]} --l2_latency {sst_params["l2_latency"]} --l2_clock {sst_params["l2_clock"]} --l2_associativity {sst_params["l2_associativity"]} --l2_size {sst_params["l2_size"]} --ram_timing {sst_params["ram_timing"]} --ram_clock {sst_params["ram_clock"]} --ram_size {sst_params["ram_size"]}'"""
model_options = shlex.split(model_options)
process = subprocess.Popen(model_options, stdout=f)
while process.poll() is None:
#Give 16GB headroom per simeng. Overkill, but just to be safe...
if check_memory(process.pid, 16*1024*1024):
os.kill(process.pid, signal.SIGKILL)
print(f"Killed process {process.pid} due to memory leak")
print("This process had config: ")
subprocess.call(["cat", config_dest])
break
time.sleep(1) # Check every second
#subprocess.call(["simeng", config_dest] + BENCHMARKS[i], stdout=f)
if __name__ == "__main__":
try:
BATCH_ID = int(sys.argv[1])
INDEX_ID = int(sys.argv[2])
except:
print("Invalid argument: supply the index within the batch as an int")
exit()
if not os.path.isdir(os.path.join(PATH, "config-buffer")):
os.mkdir(os.path.join(PATH, "config-buffer"))
if not os.path.isdir(os.path.join(PATH, "results-buffer")):
os.mkdir(os.path.join(PATH, "results-buffer"))
if not os.path.isdir(os.path.join(PATH, "sst-buffer")):
os.mkdir(os.path.join(PATH, "sst-buffer"))
#sst_params = generate_batch()
sst_params = load_batch(INDEX_ID)
dispatch_batch(sst_params)