-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.tex
172 lines (153 loc) · 3.68 KB
/
benchmark.tex
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
\lstset{basicstyle=\fontsize{9pt}{10pt}\ttfamily}
\begin{minipage}{\linewidth}
\begin{lstlisting}[caption={Maximum value over a 1D array}, label={lst:benchmark_max}]
Func maxf;
RDom r(0, size);
maxf() = 0;
maxf() = max(maxf(), A(r));
RVar rxo, rxi, rxio, rxii;
Var u, v;
Func intm =
maxf.update()
.split(r.x, rxo, rxi, 4*8192)
.rfactor(rxo, u);
intm.compute_root()
.update()
.parallel(u)
.split(rxi, rxio, rxii, 8)
.rfactor(rxii, v)
.compute_at(intm, u)
.vectorize(v)
.update()
.vectorize(v);
\end{lstlisting}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{lstlisting}[caption={Histogram of a two-dimensional image.}, label={lst:benchmark_histogram}]
Func hist;
Var x, y;
RDom r(0, size, 0, size);
hist(x) = 0;
hist(in(r.x, r.y)) += 1;
RVar ryo, ryi;
hist.update()
.split(r.y, ryo, ryi, 16)
.rfactor(ryo, y)
.compute_root()
.vectorize(x, 8)
.update().parallel(y);
\end{lstlisting}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{lstlisting}[caption={Argmin over 4D array}, label={lst:benchmark_argmin}]
Func amin;
RDom r(0, size, 0, size, 0, size, 0, size);
amin() = {255, 0, 0, 0, 0};
amin() = {
min(amin()[0], input(r.x, r.y, r.z, r.w)),
select(amin()[0] < input(r.x, r.y, r.z, r.w),
amin()[1], r.x),
select(amin()[0] < input(r.x, r.y, r.z, r.w),
amin()[2], r.y),
select(amin()[0] < input(r.x, r.y, r.z, r.w),
amin()[3], r.z),
select(amin()[0] < input(r.x, r.y, r.z, r.w),
amin()[4], r.w)
};
Var u, v;
Func intm1 = amin.update().rfactor(r.w, u);
intm1.compute_root().update().parallel(u);
RVar rxo, rxi;
Func intm2 =
intm1.update()
.split(r.x, rxo, rxi, 16)
.rfactor(rxi, v);
intm2.compute_at(intm1, u)
.update().vectorize(v);
\end{lstlisting}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{lstlisting}[caption={Complex product}, label={lst:benchmark_complex_multiply}]
Func mult;
RDom r(0, size);
mult() = {1, 0};
mult() = {
mult()[0]*input0(r) - mult()[1]*input1(r),
mult()[0]*input1(r) + mult()[1]*input0(r)
};
RVar rxi, rxo, rxii, rxio;
Var u, v;
Func intm =
mult.update()
.split(r.x, rxo, rxi, 2*8192)
.rfactor(rxo, u);
intm.compute_root()
.vectorize(u, 8)
.update()
.parallel(u)
.split(rxi, rxio, rxii, 8)
.rfactor(rxii, v)
.compute_at(intm, u)
.vectorize(v)
.update()
.vectorize(v);
\end{lstlisting}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{lstlisting}[caption={Dot product}, label={lst:benchmark_dot_product}]
Func dot;
RDom r(0, size);
dot() = 0;
dot() += cast<int>(A(r.x))*B(r.x);
RVar rxo, rxi, rxio, rxii;
Var u, v;
Func intm =
dot.update()
.split(r.x, rxo, rxi, 4*8192)
.rfactor(rxo, u);
intm.compute_root()
.update()
.parallel(u)
.split(rxi, rxio, rxii, 8)
.rfactor(rxii, v)
.compute_at(intm, u)
.vectorize(v)
.update()
.vectorize(v);
\end{lstlisting}
\end{minipage}
\begin{minipage}{\linewidth}
\begin{lstlisting}[caption={Everything but the kitchen sink.}, label={lst:benchmark_kitchen_sink}]
Func sink;
RDom r(0, size);
sink() = {
0, 0, int(0x80000000), 0,
int(0x7fffffff), 0, 0, 0
};
sink() = {
sink()[0] * A(r),
sink()[1] + A(r),
max(sink()[2], A(r)),
select(sink()[2] > A(r), sink()[3], r),
min(sink()[4], A(r)),
select(sink()[4] < A(r), sink()[5], r),
sink()[6] + A(r)*A(r),
sink()[7] + select(A(r) % 2 == 0, 1, 0)
};
RVar rxo, rxi, rxio, rxii;
Var u, v;
Func intm =
sink.update()
.split(r.x, rxo, rxi, 8192)
.rfactor(rxo, u);
intm.compute_root()
.update()
.parallel(u)
.split(rxi, rxio, rxii, 8)
.rfactor(rxii, v)
.compute_at(intm, u)
.vectorize(v)
.update()
.vectorize(v);
\end{lstlisting}
\end{minipage}