-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpc-perf-evaluation-cuda.py
executable file
·107 lines (83 loc) · 3.29 KB
/
hpc-perf-evaluation-cuda.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
#!/usr/bin/env python3
# Fabrizio Margotta 789072
import os
import csv
import logging
logging.basicConfig(level=logging.INFO)
# executable variables
exe_folder = "../"
exe_name = exe_folder + "earthquake"
steps = 100000
matrix_sides = [256, 512, 1024]
# matrix_sides = [256]
# run the simulation N times and take the average execution time
total_run = 5
result_dir = "../data"
os.makedirs(result_dir, exist_ok=True)
# csv info
serial_timings_filename = result_dir + "/serial-timings-py.csv"
cuda_timings_filename = result_dir + "/cuda-timings-py.csv"
avg_exe_time = dict()
t_serial = dict()
def get_execution_time(filename, regex):
exe_time = 0
with open(filename) as f:
for line in f:
if regex in line:
exe_time = float(line.split(':')[1].split(' ')[4])
logging.info("exe_time = {}".format(exe_time))
return exe_time
def save(column_headers, filename, data):
with open(filename, mode='w') as f:
headers = column_headers
writer = csv.DictWriter(f, headers)
writer.writeheader()
row = data
writer.writerow(row)
logging.info("################## SERIAL TIMINGS ###################")
for side in matrix_sides:
avg_exe_time[side] = 0
for n_run in range(1, total_run + 1):
logging.info("run #{}: L{}".format(n_run, side))
# run variables
out_file = "/dev/null"
res_file = result_dir + "/serial_res{}_{}".format(side, n_run)
cmd = "./{} {} {} > {} 2>{}".format(exe_name, steps, side, out_file,
res_file)
logging.info(cmd)
# execute run
os.system(cmd)
# get time
exe_time = get_execution_time(res_file, "seconds")
logging.info("exe_time #{} = {}".format(n_run, exe_time))
avg_exe_time[side] += exe_time
logging.info("sum_avg_exe_time #{} = {}".format(
n_run, avg_exe_time[side]))
avg_exe_time[side] = round(avg_exe_time[side] / total_run, 4)
logging.info("avg_exe_time = {}".format(avg_exe_time))
logging.info("####################### SAVING TO FILE ########################")
save(matrix_sides, serial_timings_filename, avg_exe_time)
exe_name = exe_folder + "cuda-earthquake"
logging.info("################## CUDA TIMINGS ###################")
for side in matrix_sides:
avg_exe_time[side] = 0
for n_run in range(1, total_run + 1):
logging.info("run #{}: L{}".format(n_run, side))
# run variables
out_file = "/dev/null"
res_file = result_dir + "/cuda_res{}_{}".format(side, n_run)
cmd = "./{} {} {} > {} 2>{}".format(exe_name, steps, side, out_file,
res_file)
logging.info(cmd)
# execute run
os.system(cmd)
# get time
exe_time = get_execution_time(res_file, "seconds")
logging.info("exe_time #{} = {}".format(n_run, exe_time))
avg_exe_time[side] += exe_time
logging.info("sum_avg_exe_time #{} = {}".format(
n_run, avg_exe_time[side]))
avg_exe_time[side] = round(avg_exe_time[side] / total_run, 4)
logging.info("avg_exe_time = {}".format(avg_exe_time))
logging.info("####################### SAVING TO FILE ########################")
save(matrix_sides, cuda_timings_filename, avg_exe_time)