Skip to content

Commit 6038ff6

Browse files
author
Nathan Shreve
committed
Wrote scripts to help running tests and profile results
1 parent 0db85d9 commit 6038ff6

File tree

4 files changed

+321
-3
lines changed

4 files changed

+321
-3
lines changed

binary_heap_profiler.py

Whitespace-only changes.

binary_heap_profiling_helper.cpp

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
//
2+
// Created by shrevena on 23/05/24.
3+
//
4+
5+
#include <fstream>
6+
#include <vector>
7+
#include <sstream>
8+
#include <iomanip>
9+
#include <complex>
10+
11+
int main() {
12+
std::ofstream koios_medium_info_file("koios_medium_heap_profiling_info.txt", std::ios::out);
13+
auto original_precision = koios_medium_info_file.precision();
14+
15+
std::vector<std::string> koios_medium_test_types = {"attention_layer", "bnn", "dla_like.small", "robot_rl",
16+
"tpu_like.small.os", "tpu_like.small.ws"};
17+
18+
for (int i = 1; i <= 27; ++i) {
19+
std::string run_num;
20+
21+
if (i < 10)
22+
run_num = "00" + std::to_string(i);
23+
else
24+
run_num = "0" + std::to_string(i);
25+
26+
koios_medium_info_file << "run" + run_num + ": " << std::endl;
27+
28+
std::vector<float> percents;
29+
for (const auto& test_type: koios_medium_test_types) {
30+
std::string file_path = "./fine-grained-parallel-router/testing/koios_medium/run" + run_num +
31+
"/k6FracN10LB_mem20K_complexDSP_customSB_22nm.xml/" + test_type +
32+
".pre-vpr.blif/common/vpr.dot";
33+
34+
std::ifstream dot_file(file_path);
35+
std::stringstream buffer;
36+
buffer << dot_file.rdbuf();
37+
std::string dot_file_text = buffer.str();
38+
39+
float total_percent = 0.0;
40+
41+
size_t add_pos = dot_file_text.find("BinaryHeap::add_to_heap");
42+
if (add_pos != std::string::npos) {
43+
std::string time_percent_str = dot_file_text.substr(add_pos + 25, 4);
44+
45+
if (time_percent_str.back() == '%')
46+
time_percent_str.pop_back();
47+
48+
total_percent += std::stof(time_percent_str);
49+
}
50+
51+
size_t get_head_pos = dot_file_text.find("BinaryHeap::get_heap_head");
52+
if (get_head_pos != std::string::npos) {
53+
std::string time_percent_str = dot_file_text.substr(get_head_pos + 27, 4);
54+
55+
if (time_percent_str.back() == '%')
56+
time_percent_str.pop_back();
57+
58+
total_percent += std::stof(time_percent_str);
59+
}
60+
61+
size_t build_pos = dot_file_text.find("BinaryHeap::build_heap");
62+
if (build_pos != std::string::npos) {
63+
std::string time_percent_str = dot_file_text.substr(build_pos + 24, 4);
64+
65+
if (time_percent_str.back() == '%')
66+
time_percent_str.pop_back();
67+
68+
total_percent += std::stof(time_percent_str);
69+
}
70+
71+
koios_medium_info_file << "\t" + test_type + ": " << std::setprecision(3) << total_percent << "%"
72+
<< std::endl;
73+
74+
percents.push_back(total_percent);
75+
}
76+
77+
float product = 1.0;
78+
for (auto percent: percents) {
79+
product *= percent;
80+
}
81+
82+
float geomean = std::pow(product, 1.0 / 6.0);
83+
84+
koios_medium_info_file << "\tGEOMEAN = " << std::setprecision(original_precision) << geomean << "%" << std::endl
85+
<< std::endl;
86+
}
87+
88+
koios_medium_info_file.close();
89+
90+
std::ofstream titan_info_file("titan_heap_profiling_info.txt", std::ios::out);
91+
original_precision = titan_info_file.precision();
92+
93+
std::vector<std::string> titan_test_types = {"bitcoin_miner_stratixiv_arch_timing",
94+
"directrf_stratixiv_arch_timing", "LU230_stratixiv_arch_timing",
95+
"mes_noc_stratixiv_arch_timing", "sparcT1_chip2_stratixiv_arch_timing",
96+
"openCV_stratixiv_arch_timing"};
97+
98+
for (int i = 1; i <= 44; ++i) {
99+
std::string run_num;
100+
101+
if (i < 10)
102+
run_num = "00" + std::to_string(i);
103+
else
104+
run_num = "0" + std::to_string(i);
105+
106+
titan_info_file << "run" + run_num + ": " << std::endl;
107+
108+
std::vector<float> percents;
109+
for (const auto& test_type: titan_test_types) {
110+
std::string file_path = "./fine-grained-parallel-router/testing/titan/run" + run_num +
111+
"/stratixiv_arch.timing.xml/" + test_type +
112+
".blif/common/vpr.dot";
113+
114+
std::ifstream dot_file(file_path);
115+
std::stringstream buffer;
116+
buffer << dot_file.rdbuf();
117+
std::string dot_file_text = buffer.str();
118+
119+
float total_percent = 0.0;
120+
121+
size_t add_pos = dot_file_text.find("BinaryHeap::add_to_heap");
122+
if (add_pos != std::string::npos) {
123+
std::string time_percent_str = dot_file_text.substr(add_pos + 25, 4);
124+
125+
if (time_percent_str.back() == '%')
126+
time_percent_str.pop_back();
127+
128+
total_percent += std::stof(time_percent_str);
129+
}
130+
131+
size_t get_head_pos = dot_file_text.find("BinaryHeap::get_heap_head");
132+
if (get_head_pos != std::string::npos) {
133+
std::string time_percent_str = dot_file_text.substr(get_head_pos + 27, 4);
134+
135+
if (time_percent_str.back() == '%')
136+
time_percent_str.pop_back();
137+
138+
total_percent += std::stof(time_percent_str);
139+
}
140+
141+
size_t build_pos = dot_file_text.find("BinaryHeap::build_heap");
142+
if (build_pos != std::string::npos) {
143+
std::string time_percent_str = dot_file_text.substr(build_pos + 24, 4);
144+
145+
if (time_percent_str.back() == '%')
146+
time_percent_str.pop_back();
147+
148+
total_percent += std::stof(time_percent_str);
149+
}
150+
151+
titan_info_file << "\t" + test_type + ": " << std::setprecision(3) << total_percent << "%" << std::endl;
152+
153+
percents.push_back(total_percent);
154+
}
155+
156+
float product = 1.0;
157+
for (auto percent: percents) {
158+
product *= percent;
159+
}
160+
161+
float geomean = std::pow(product, 1.0 / 6.0);
162+
163+
titan_info_file << "\tGEOMEAN = " << std::setprecision(original_precision) << geomean << "%" << std::endl
164+
<< std::endl;
165+
}
166+
167+
titan_info_file.close();
168+
}

run_heap_tests.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import subprocess
2+
import os
3+
import time
4+
import re
5+
6+
7+
def extract_run_number(run):
8+
if run is None:
9+
return None
10+
match = re.match(r"run(\d+)", run)
11+
if match:
12+
return int(match.group(1))
13+
else:
14+
return None
15+
16+
17+
def get_run_num(benchmarks_name):
18+
runs = os.listdir(
19+
"/home/shrevena/Documents/vtr/vtr-verilog-to-routing/fine-grained-parallel-router/testing/" + benchmarks_name)
20+
runs.remove("config")
21+
last_run_num = 0
22+
if len(runs) != 0:
23+
last_run = sorted(runs)[-1]
24+
last_run_num = extract_run_number(last_run)
25+
if last_run_num is None:
26+
last_run_num = 0
27+
return last_run_num + 1
28+
29+
30+
def write_test_info(benchmarks_name, settings):
31+
run_info_file = open("heap_tests_run_info.txt", "a")
32+
run_name = "run{:03d}".format(get_run_num(benchmarks_name))
33+
run_info_file.write(benchmarks_name + "/" + run_name + " using settings:\n")
34+
for line in settings:
35+
run_info_file.write(f"{line}")
36+
run_info_file.write("\n---------------------------------------\n")
37+
38+
39+
def make_and_run(settings):
40+
# make vpr
41+
command = "make CMAKE_PARAMS=\"-DVTR_ENABLE_PROFILING=TRUE -DVTR_IPO_BUILD=on\" -j10 vpr"
42+
print("Running command:", command)
43+
make_process = subprocess.Popen(f"{command}", shell=True, stdout=True, stderr=True)
44+
print("PID:", make_process.pid)
45+
os.waitpid(make_process.pid, 0)
46+
47+
run_processes = []
48+
49+
# run koios_medium benchmarks
50+
command = "/home/shrevena/Documents/vtr/vtr-verilog-to-routing/fine-grained-parallel-router/testing/run_test.py koios_medium -j1 -vtr_dir /home/shrevena/Documents/vtr/vtr-verilog-to-routing | tee -a terminal_out.txt"
51+
for i in range(3):
52+
print("Running command:", command)
53+
write_test_info("koios_medium", settings)
54+
run_processes.append(subprocess.Popen(f"{command}", shell=True, stdout=True, stderr=True))
55+
print("PID:", run_processes[-1].pid)
56+
time.sleep(5)
57+
58+
# run titan benchmarks
59+
command = "/home/shrevena/Documents/vtr/vtr-verilog-to-routing/fine-grained-parallel-router/testing/run_test.py bwave_like -j1 -vtr_dir /home/shrevena/Documents/vtr/vtr-verilog-to-routing | tee -a terminal_out.txt"
60+
for i in range(3):
61+
print("Running command:", command)
62+
write_test_info("bwave_like", settings)
63+
run_processes.append(subprocess.Popen(f"{command}", shell=True, stdout=True, stderr=True))
64+
print("PID:", run_processes[-1].pid)
65+
time.sleep(5)
66+
67+
# wait for all tests to complete
68+
for process in run_processes:
69+
os.waitpid(process.pid, 0)
70+
71+
72+
with open('vpr/src/route/binary_heap.h', 'r') as binary_heap_header:
73+
data = binary_heap_header.readlines()
74+
75+
# NO 1,9
76+
data[4:9] = ['#define HEAP_DARITY_2\n', '//#define HEAP_DARITY_4\n', '\n', '//#define HEAP_USE_HEAP_ELEM\n',
77+
'//#define HEAP_USE_MEMORY_ALIGNMENT\n']
78+
79+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
80+
binary_heap_header.writelines(data)
81+
82+
make_and_run(data[4:9])
83+
84+
# NO 2,10
85+
data[4:9] = ['#define HEAP_DARITY_2\n', '//#define HEAP_DARITY_4\n', '\n', '//#define HEAP_USE_HEAP_ELEM\n',
86+
'#define HEAP_USE_MEMORY_ALIGNMENT\n']
87+
88+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
89+
binary_heap_header.writelines(data)
90+
91+
make_and_run(data[4:9])
92+
93+
# NO 3,11
94+
data[4:9] = ['#define HEAP_DARITY_2\n', '//#define HEAP_DARITY_4\n', '\n', '#define HEAP_USE_HEAP_ELEM\n',
95+
'//#define HEAP_USE_MEMORY_ALIGNMENT\n']
96+
97+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
98+
binary_heap_header.writelines(data)
99+
100+
make_and_run(data[4:9])
101+
102+
# NO 4,12
103+
data[4:9] = ['#define HEAP_DARITY_2\n', '//#define HEAP_DARITY_4\n', '\n', '#define HEAP_USE_HEAP_ELEM\n',
104+
'#define HEAP_USE_MEMORY_ALIGNMENT\n']
105+
106+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
107+
binary_heap_header.writelines(data)
108+
109+
make_and_run(data[4:9])
110+
111+
# NO 5,13
112+
data[4:9] = ['//#define HEAP_DARITY_2\n', '#define HEAP_DARITY_4\n', '\n', '//#define HEAP_USE_HEAP_ELEM\n',
113+
'//#define HEAP_USE_MEMORY_ALIGNMENT\n']
114+
115+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
116+
binary_heap_header.writelines(data)
117+
118+
make_and_run(data[4:9])
119+
120+
# NO 6,14
121+
data[4:9] = ['//#define HEAP_DARITY_2\n', '#define HEAP_DARITY_4\n', '\n', '//#define HEAP_USE_HEAP_ELEM\n',
122+
'#define HEAP_USE_MEMORY_ALIGNMENT\n']
123+
124+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
125+
binary_heap_header.writelines(data)
126+
127+
make_and_run(data[4:9])
128+
129+
# NO 7,15
130+
data[4:9] = ['//#define HEAP_DARITY_2\n', '#define HEAP_DARITY_4\n', '\n', '#define HEAP_USE_HEAP_ELEM\n',
131+
'//#define HEAP_USE_MEMORY_ALIGNMENT\n']
132+
133+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
134+
binary_heap_header.writelines(data)
135+
136+
make_and_run(data[4:9])
137+
138+
# NO 8,16
139+
data[4:9] = ['//#define HEAP_DARITY_2\n', '#define HEAP_DARITY_4\n', '\n', '#define HEAP_USE_HEAP_ELEM\n',
140+
'#define HEAP_USE_MEMORY_ALIGNMENT\n']
141+
142+
with open('vpr/src/route/binary_heap.h', 'w') as binary_heap_header:
143+
binary_heap_header.writelines(data)
144+
145+
make_and_run(data[4:9])

vpr/src/route/binary_heap.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
#define _BINARY_HEAP_H
33

44
// Only use one of these two DARITYs at a time
5-
#define HEAP_DARITY_2
6-
//#define HEAP_DARITY_4
5+
//#define HEAP_DARITY_2
6+
#define HEAP_DARITY_4
77

88
#define HEAP_USE_HEAP_ELEM
9-
//#define HEAP_USE_MEMORY_ALIGNMENT
9+
#define HEAP_USE_MEMORY_ALIGNMENT
1010

1111
#if defined(HEAP_USE_MEMORY_ALIGNMENT)
12+
13+
#if defined(HEAP_USE_HEAP_ELEM)
14+
#define MEMORY_ALIGNMENT_FACTOR 16
15+
#else
1216
#define MEMORY_ALIGNMENT_FACTOR 8
17+
#endif
1318

1419
#include <boost/align/aligned_allocator.hpp>
1520

0 commit comments

Comments
 (0)