-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheval_tilings.py
72 lines (58 loc) · 1.79 KB
/
eval_tilings.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
import setup # noqa # isort:skip
from itertools import product
import numpy as np
import tensorflow as tf
from measure import measure_all
from onnx2code.ops.gemm import LoopTilingParams, set_tiling_params
FLOAT_SIZE = 4
KB = 1024
L1_SIZE = 32 * KB
L2_SIZE = 256 * KB
# Custom MNIST-like model
input = tf.keras.Input([4096 * 64])
out = tf.keras.layers.Lambda(lambda x: x)(input)
input_shape = (512, 512)
model = tf.keras.Sequential(
[
tf.keras.Input(shape=input_shape),
tf.keras.layers.Dense(512, activation="relu"),
]
)
# nc, kc, mc, mr, nr
nc_options = [4096]
kc_options = [256]
mc_options = [256]
mr_options = [4]
nr_options = [8]
mv_options = [4]
nu_options = [4]
for nc, kc, mc, mr, nr, mv, nu in product(
nc_options, kc_options, mc_options, mr_options, nr_options, mv_options, nu_options
):
set_tiling_params(LoopTilingParams(nc=nc, kc=kc, mc=mc, mr=mr, nr=nr, mv=mv, nu=nu))
print(f"\n## nc={nc}, kc={kc}, mc={mc}, mr={mr}, nr={nr}\n")
B_sliver = nr * kc * FLOAT_SIZE
A_sliver = mr * kc * FLOAT_SIZE
AB = mr * nr * FLOAT_SIZE
L1_total = A_sliver + B_sliver + AB
L1_remaining = L1_SIZE - L1_total
print("L1:")
print(f"\t{A_sliver=}")
print(f"\t{B_sliver=}")
print(f"\t{AB=}")
print(f"\t{L1_total=}")
print(f"\t{L1_remaining=}")
A_panel = mc * kc * FLOAT_SIZE
C_writeback = AB
L2_total = A_panel + B_sliver + C_writeback
L2_remaining = L2_SIZE - L2_total
print("\nL2:")
print(f"\t{A_panel=}")
print(f"\t{B_sliver=}")
print(f"\t{C_writeback=}")
print(f"\t{L2_total=}")
print(f"\t{L2_remaining=}")
data = measure_all(model, variations=["loop-tiling"], measure_base=False)
assert len(data) == 1
result = data[next(iter(data.keys()))]
print(f"result: {np.mean(result):.2f}ms")