Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add benchmark for matrix multiplication #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions hpp/benchmark_mm/bench.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import os
import sys
import timeit

import numpy as np
import threadpoolctl as th


def multiply_matrix(N, T):
x = np.zeros((N, N), dtype="float64")
with th.threadpool_limits(limits=T, user_api='blas'):
y = x @ x


if __name__ == '__main__':
processes = sys.argv[1]
times = []
results = open(f'results_{processes}', 'wt')
for n_threads in range(len(os.sched_getaffinity(0))):
for matrix_size in [30, 300, 3000]:
time = min(timeit.repeat(lambda: multiply_matrix(N=matrix_size, T=n_threads), number=5))/5
results.write(f'{n_threads}_{matrix_size}_{time}\n')
results.flush()
results.close()




30 changes: 30 additions & 0 deletions hpp/benchmark_mm/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import matplotlib.pyplot as plt
import pandas as pd

data = []
for i in range(1, 4):
with open(f"hpp/benchmark_mm/results_{i}", "r") as f:
# each row is: processes, threads, size, time
data.extend([f"{i}_{line}".split("_") for line in f.readlines()])

df = pd.DataFrame(data, columns=["processes", "threads", "size", "time"])

fig, ax = plt.subplots(3, 1)
fig.set_figheight(10)
fig.set_figwidth(6)

for i, s in enumerate(df["size"].unique()):
for p in df["processes"].unique():
xi = list(df.loc[(df["processes"] == p) & (df["size"] == s), "threads"].astype(float))
yi = list(df.loc[(df["processes"] == p) & (df["size"] == s), "time"].astype(float))
ax[i].plot(xi, yi, label=p)
ax[i].set_title(f"size={s}")

handles, labels = ax[i].get_legend_handles_labels()
fig.legend(handles, labels, loc='upper center', title="processes")

fig.text(0.5, 0.04, 'n_threads', ha='center')
fig.text(0.0, 0.5, 'time', va='center', rotation='vertical')
plt.savefig("hpp/benchmark_mm/results.png", dpi=300)


Binary file added hpp/benchmark_mm/results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions hpp/benchmark_mm/results_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
0_30_0.00027460739947855474
0_300_0.0006913389981491492
0_3000_0.4103931115998421
1_30_0.00025021140172611924
1_300_0.0019851766002830116
1_3000_1.1397250042005909
2_30_0.00022756299877073615
2_300_0.0008770572021603584
2_3000_0.6591780591988936
3_30_0.0003005806007422507
3_300_0.000931622800999321
3_3000_0.5624800918012625
4_30_0.00035497880016919223
4_300_0.0012595637992490083
4_3000_0.5415630329982377
5_30_0.0003646780009148642
5_300_0.0009647636004956439
5_3000_0.5020334165979875
6_30_0.0003636729990830645
6_300_0.0009608207998098806
6_3000_0.49886566500063056
7_30_0.00037808019842486826
7_300_0.001537017000373453
7_3000_0.5028969450009754
24 changes: 24 additions & 0 deletions hpp/benchmark_mm/results_2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
0_30_0.0003037196001969278
0_300_0.0007952529995236546
0_3000_0.5004591826000251
1_30_0.0003733070014277473
1_300_0.0028704026015475394
1_3000_1.2028277851990423
2_30_0.0002753072010818869
2_300_0.0010893295984715223
2_3000_0.7504769150022185
3_30_0.0003262779995566234
3_300_0.0009243134001735598
3_3000_0.5812608784006443
4_30_0.00032918679935391994
4_300_0.001281012801337056
4_3000_0.5160886729980121
5_30_0.0003709879994858056
5_300_0.0012151438015280292
5_3000_0.5070040075981523
6_30_0.0008059760002652183
6_300_0.0009575574018526823
6_3000_0.5152194449998205
7_30_0.0004826569987926632
7_300_0.0013204805989516899
7_3000_0.4981165808014339
24 changes: 24 additions & 0 deletions hpp/benchmark_mm/results_3
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
0_30_0.00032405359961558134
0_300_0.0013136355992173776
0_3000_0.49723099039983937
1_30_0.000379611601238139
1_300_0.0029519002011511473
1_3000_1.2366342330002227
2_30_0.00024287900014314802
2_300_0.0009623870020732284
2_3000_0.6633257908019005
3_30_0.0003105259995209053
3_300_0.000884313802816905
3_3000_0.5715091922000284
4_30_0.0003153233992634341
4_300_0.0013229422009317204
4_3000_0.4965488420013571
5_30_0.00035848779953084886
5_300_0.000948840199271217
5_3000_0.4973357428010786
6_30_0.00038418699987232687
6_300_0.000954620199627243
6_3000_0.5065642214001855
7_30_0.0003947592020267621
7_300_0.0009453961974941194
7_3000_0.5630277571995975
7 changes: 7 additions & 0 deletions hpp/benchmark_mm/submit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# the number of python processes to start, P=3 if not set
P=${1:-3}
# the size of the matrix, use the default in overcommit.py if not set
for i in $(seq $P); do
echo -n "Starting process ${i}… "
python bench.py $i
done