Skip to content

Commit 802cef6

Browse files
committed
numpy: parametrize windowing benchmark over different window sizes
1 parent 82b4bc9 commit 802cef6

File tree

1 file changed

+66
-24
lines changed

1 file changed

+66
-24
lines changed

numpy/windowing.py

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,36 @@
55

66
from util import RandomScipySparseTensorLoader, RandomPydataSparseTensorLoader
77

8-
@pytest.mark.skip(reason="too slow right now")
9-
def bench_add_window(tacoBench):
10-
dim = 10000
11-
matrix = random(dim, dim, format="csr").todense()
12-
def bench():
13-
x = matrix[1:(dim-1), 1:(dim-1)]
14-
res = x + x
15-
tacoBench(bench)
8+
# Want to run these windows so that they operate on
9+
# * A small, constant size grid: 500x500
10+
# * A constant fraction of the tensor size : 1/4 x 1/4
11+
# * Almost the entire tensor (I'm unsure what the point of this comparison is)
12+
# * No windowing (TACO should use a window so we can measure the overhead).
13+
# These options map to the corresponding config values:
14+
sizeConfigs = ["constant", "constant-fraction", "almost-whole", "no-windowing"]
15+
16+
def sliceTensor(tensor, dim, config):
17+
if config == "constant":
18+
return tensor[250:750, 250:750]
19+
elif config == "constant-fraction":
20+
size = dim//4
21+
start = dim//4
22+
return tensor[start:(start+size), start:(start+size)]
23+
elif config == "almost-whole":
24+
return tensor[1:(dim-1), 1:(dim-1)]
25+
elif config == "no-windowing":
26+
return tensor
27+
else:
28+
assert(False)
1629

1730
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
1831
@pytest.mark.parametrize("format", ['csr', 'csc'])
19-
def bench_add_sparse_window(tacoBench, dim, format):
32+
@pytest.mark.parametrize("config", sizeConfigs)
33+
def bench_add_sparse_window(tacoBench, dim, format, config):
2034
loader = RandomScipySparseTensorLoader(format)
2135
matrix = loader.random((dim, dim), 0.01)
2236
def bench():
23-
x = matrix[1:(dim-1), 1:(dim-1)]
37+
x = sliceTensor(matrix, dim, config)
2438
res = x + x
2539
# Sanity check that this has a similar runtime as taco.
2640
# res = matrix + matrix
@@ -29,47 +43,75 @@ def bench():
2943
# TODO (rohany): This is really slow (compared to scipy.sparse). Check with hameer
3044
# that this result makes sense.
3145
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
32-
def bench_add_pydata_sparse_window(tacoBench, dim):
46+
@pytest.mark.parametrize("config", sizeConfigs)
47+
def bench_add_pydata_sparse_window(tacoBench, dim, config):
3348
loader = RandomPydataSparseTensorLoader()
3449
matrix = loader.random((dim, dim), 0.01)
3550
def bench():
36-
x = matrix[1:(dim-1), 1:(dim-1)]
51+
x = sliceTensor(matrix, dim, config)
3752
res = x + x
3853
tacoBench(bench)
3954

55+
# TODO (rohany): Parametrize the below tests by appropriate windowing config.
56+
4057
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
4158
@pytest.mark.parametrize("format", ['csr', 'csc'])
4259
def bench_add_sparse_strided_window(tacoBench, dim, format):
43-
matrix = random(dim, dim, format=format)
60+
loader = ScipySparseTensorLoader(format)
61+
matrix = loader.random((dim, dim), 0.01)
4462
def bench():
4563
x = matrix[1:(dim-1):4, 1:(dim-1):4]
4664
res = x + x
4765
tacoBench(bench)
4866

4967
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
5068
@pytest.mark.parametrize("format", ['csr', 'csc'])
51-
def bench_add_multiple_sparse_windows(tacoBench, dim, format):
52-
matrix1 = random(dim, dim, format=format)
53-
matrix2 = random(dim, dim, format=format)
69+
def bench_add_sparse_index_set(tacoBench, dim, format):
70+
indexes = [i * 2 for i in range(0, dim//2)]
71+
loader = ScipySparseTensorLoader(format)
72+
matrix = loader.random((dim, dim), 0.01)
5473
def bench():
55-
res = matrix1[1:(dim-1), 1:(dim-1)] + matrix2[1:(dim-1), 1:(dim-1)] + matrix1[0:(dim-2), 0:(dim-2)]
74+
x = matrix[:, indexes]
75+
res = x + x
5676
tacoBench(bench)
5777

5878
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
59-
@pytest.mark.parametrize("format", ['csr', 'csc'])
60-
def bench_add_sparse_strided_window(tacoBench, dim, format):
61-
matrix = random(dim, dim, format=format)
79+
def bench_add_pydata_sparse_strided_window(tacoBench, dim):
80+
loader = RandomPydataSparseTensorLoader()
81+
matrix = loader.random((dim, dim), 0.01)
6282
def bench():
63-
x = matrix[1:(dim-1):2, 1:(dim-1):2]
83+
x = matrix[1:(dim-1):4, 1:(dim-1):4]
6484
res = x + x
6585
tacoBench(bench)
6686

87+
# TODO (rohany): This is really slow (compared to scipy.sparse). Check with hameer
88+
# that this result makes sense.
6789
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
68-
@pytest.mark.parametrize("format", ['csr', 'csc'])
69-
def bench_add_sparse_index_set(tacoBench, dim, format):
90+
def bench_add_pydata_sparse_index_set(tacoBench, dim):
91+
loader = RandomPydataSparseTensorLoader()
7092
indexes = [i * 2 for i in range(0, dim//2)]
71-
matrix = random(dim, dim, format=format)
93+
matrix = loader.random((dim, dim), 0.01)
7294
def bench():
7395
x = matrix[:, indexes]
7496
res = x + x
7597
tacoBench(bench)
98+
99+
# TODO (rohany): I don't know if we care about this benchmark.
100+
@pytest.mark.parametrize("dim", [5000, 10000, 20000])
101+
@pytest.mark.parametrize("format", ['csr', 'csc'])
102+
def bench_add_multiple_sparse_windows(tacoBench, dim, format):
103+
matrix1 = random(dim, dim, format=format)
104+
matrix2 = random(dim, dim, format=format)
105+
def bench():
106+
res = matrix1[1:(dim-1), 1:(dim-1)] + matrix2[1:(dim-1), 1:(dim-1)] + matrix1[0:(dim-2), 0:(dim-2)]
107+
tacoBench(bench)
108+
109+
@pytest.mark.skip(reason="too slow right now")
110+
def bench_add_window(tacoBench):
111+
dim = 10000
112+
matrix = random(dim, dim, format="csr").todense()
113+
def bench():
114+
x = matrix[1:(dim-1), 1:(dim-1)]
115+
res = x + x
116+
tacoBench(bench)
117+

0 commit comments

Comments
 (0)