-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimings.py
157 lines (126 loc) · 3.28 KB
/
Timings.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# ---
# jupyter:
# jupytext:
# cell_metadata_filter: -papermill
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.11.3
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---
# %% [markdown]
# # Timing Functions
#
# This notebook has the results of timing various CSR functions. It uses the data produced by the benchmark suite and saved in `bench.json`; to prepare that data, run:
#
# python -m pytest --benchmark-only
#
# We use Jupytext to maintain the primary version of this notebook as a Python script. To re-run the notebook and generate the `.ipynb` file:
#
# jupytext -s Timings.py
# %%
import json
import numpy as np
import scipy.sparse as sps
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# %% [markdown]
# Let's load the benchmark data:
# %% tags=["parameters"]
bench_file = 'bench.json'
# %%
with open(bench_file, 'r') as jsf:
data = json.load(jsf)
list(data.keys())
# %% [markdown]
# And define a function to get the various benchmark runs:
# %%
def get_runs(group, *params):
marks = [b for b in data['benchmarks'] if b['group'] == group]
ps = ['kernel'] + list(params)
runs = {}
for b in data['benchmarks']:
if b['group'] != group:
continue
key = tuple(b['params'][p] for p in ps)
runs[key] = pd.Series(b['stats']['data'], name='time')
runs = pd.concat(runs, names=ps)
runs = runs.reset_index(ps)
runs = runs.reset_index(drop=True)
return runs
# %%
get_runs('MultAB')
# %% [markdown]
# ## Matrix Multiplication
#
# Our first benchmark is a simple matrix multiplication.
# %%
mab = get_runs('MultAB')
mab['time'] *= 1000
mab.groupby('kernel')['time'].describe()
# %%
sns.catplot(data=mab, x='kernel', y='time', kind='bar')
plt.ylabel('ms / op')
plt.show()
# %% [markdown]
# And multiplying by the transpose:
# %%
mab = get_runs('MultABt')
mab['time'] *= 1000
mab.groupby('kernel')['time'].describe()
# %%
sns.catplot(data=mab, x='kernel', y='time', kind='bar')
plt.ylabel('ms / op')
plt.plot()
# %% [markdown]
# ### Sweep by Density
#
# We now measure sweeping a 100x100 square matrix multiply by increasing density.
# %%
dens = get_runs('MultAB-Density', 'density')
dens['time'] *= 1000
# %%
sns.lineplot(data=dens, x='density', y='time', hue='kernel')
plt.title('AB (100x100 square)')
plt.ylabel('ms/op')
plt.show()
# %% [markdown]
# And the transpose:
# %%
dens = get_runs('MultABt-Density', 'density')
dens['time'] *= 1000
# %%
sns.lineplot(data=dens, x='density', y='time', hue='kernel')
plt.title('AB\' (100x100 square)')
plt.ylabel('ms/op')
plt.show()
# %% [markdown]
# ### Sweep by Size
#
# We now measure sweeping a 10% square matrix multiply by increasing size.
# %%
sizes = get_runs('MultAB-Size', 'size')
sizes['time'] *= 1000
# %%
sns.lineplot(data=sizes, x='size', y='time', hue='kernel')
plt.title('AB (square, 10%)')
plt.ylabel('ms/op')
plt.show()
# %% [markdown]
# ## Matrix-Vector Multiplication
#
# Now we'll look at matrix/vector multiplication ($A\vec{x}$)
# %%
muax = get_runs('MultAx')
muax['time'] *= 1000
muax.groupby('kernel')['time'].describe()
# %%
sns.catplot(data=muax, x='kernel', y='time', kind='bar')
plt.ylabel('ms / op')
plt.show()
# %%