Skip to content

Commit 59d9860

Browse files
Adding benchmark cases obtained by a fuzzer (#21)
* Adding benchmark cases obtained by a fuzzer. Co-authored-by: Manasij Mukherjee <[email protected]> * Remove additional dead code from fuzzed benchmark cases. --------- Co-authored-by: Manasij Mukherjee <[email protected]>
1 parent 7b4fc96 commit 59d9860

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import _Differentiation
2+
import Foundation
3+
4+
// Functions generated via a fuzzer using standard math operators.
5+
6+
@differentiable(reverse)
7+
func fuzzedMath1(_ x0: Float, _ x1: Float, _ x2: Float) -> Float {
8+
var y = x0;
9+
let t3 = x0 + x2 + x2;
10+
let t4 = x1 + t3;
11+
let t5 = x0 + t3;
12+
let t6 = t3 - x1;
13+
let t7 = x1 * t5;
14+
let t8 = t7 + x1 + x0;
15+
let t10 = t8 + x0;
16+
let t11 = t4 * cos(t10 * (180 / Float.pi));
17+
let t12 = sin(x2 * t8);
18+
let t13 = t3 * t8 * t4;
19+
let t14 = t11 - t11;
20+
let t15 = x1 - t4 - x1;
21+
let t16 = t8 * sin(t6 * (180 / Float.pi));
22+
let t17 = t3 * t3;
23+
let t18 = t11 - x1 - t13;
24+
let t19 = sin(t10 * t15);
25+
let t20 = sin(t17 * t14);
26+
let t22 = t17 * t13;
27+
let t23 = x2 * t12 * t11;
28+
let t24 = t13 - t23 - t17 - t22;
29+
let t25 = t6 - t6;
30+
let t27 = x1 + x0;
31+
let t31 = t25 - t19 - t20;
32+
let t33 = t18 + t19 + x1;
33+
let t35 = (t3 * t12 - 1);
34+
let t37 = t15 * cos(t16 * (180 / Float.pi));
35+
let t41 = sin(t35 * t15);
36+
let t49 = t31 / (0.001 + t24);
37+
let t51 = (x2 * t49 - 1);
38+
let t54 = t8 * sin(t25 * (180 / Float.pi));
39+
let t64 = t20 * t24 * t25;
40+
let t72 = t41 * t27 * t33;
41+
let t78 = t14 - t72 - t54;
42+
let t86 = t78 + t64;
43+
let t102 = t37 * t86 * t51;
44+
let t = t102;
45+
y += t;
46+
return y;
47+
}
48+
@differentiable(reverse)
49+
func fuzzedMath2(_ x0: Float, _ x1: Float, _ x2: Float) -> Float {
50+
var y = x0;
51+
let t3 = x2 * cos(x2 * (180 / Float.pi));
52+
let t4 = t3 * x0;
53+
let t5 = (t4 * t4 - 1);
54+
let t6 = x2 * x1 * t3;
55+
let t7 = t4 * cos(x1 * (180 / Float.pi));
56+
let t8 = x2 * sin(x1 * (180 / Float.pi));
57+
let t9 = t7 / (0.001 + t3);
58+
let t10 = x0 * cos(x0 * (180 / Float.pi));
59+
let t12 = sin(t9 * t8);
60+
let t13 = t5 * cos(t10 * (180 / Float.pi));
61+
let t14 = (t7 * t8 - 1);
62+
let t15 = t10 + t4 + x2;
63+
let t16 = (t3 * t7 - 1);
64+
let t17 = (t16 * t4 - 1);
65+
let t18 = t5 + t3 + t16;
66+
let t19 = t4 + t16;
67+
let t22 = t3 + t19 + t6;
68+
let t23 = t22 / (0.001 + t22);
69+
let t24 = t15 * cos(x0 * (180 / Float.pi));
70+
let t26 = sin(t8 * t15);
71+
let t27 = t26 - x1;
72+
let t31 = t7 * sin(t12 * (180 / Float.pi));
73+
let t32 = t7 - t22 - t26 - t23;
74+
let t33 = t16 * cos(t3 * (180 / Float.pi));
75+
let t35 = t15 - t14 - t33;
76+
let t36 = t8 + x0 + x1;
77+
let t39 = t6 / (0.001 + t6);
78+
let t40 = t27 * cos(t8 * (180 / Float.pi));
79+
let t41 = t16 / (0.001 + t35);
80+
let t46 = (t17 * t32 - 1);
81+
let t50 = t18 + t41 + t46;
82+
let t52 = x2 + t39;
83+
let t54 = t40 * t4 * t31;
84+
let t61 = t36 / (0.001 + t52);
85+
let t64 = t50 * cos(t24 * (180 / Float.pi));
86+
let t74 = t14 + t13 + t54;
87+
let t90 = t74 - t61 - t10;
88+
let t98 = t90 / (0.001 + t64);
89+
let t102 = t98 / (0.001 + t9);
90+
let t = t102;
91+
y += t;
92+
return y;
93+
}
94+
95+
96+
// Functions generated via a fuzzer incorporating a ternary operator.
97+
98+
@differentiable(reverse)
99+
func fuzzedMathTernary1(_ x0: Float, _ x1: Float, _ x2: Float) -> Float {
100+
var y = x0;
101+
let t3 = x1 + x1 + x1;
102+
let t4 = x1 * x1 * x0;
103+
let t5 = x0 - x2 - t4;
104+
let t6 = (t4 + t3) / (t4 - t3 + 0.001);
105+
let t7 = x2 + x0 + t5;
106+
let t9 = (x1 * t7 - 1);
107+
let t10 = sin(t4) * sin(t6);
108+
let t11 = sin(t6) * sin(t6);
109+
let t12 = cos(t9) * cos(t6);
110+
let t15 = t12 / (0.001 + x1);
111+
let t16 = x0 * t7 * x1;
112+
let t17 = t6 / (0.001 + x1);
113+
let t18 = sin(t10) * sin(t4);
114+
let t19 = (t11 + t16) / (t11 - t16 + 0.001);
115+
let t22 = (t11 * t11 - 1);
116+
let t23 = (x1 * t10 - 1);
117+
let t25 = t17 < t23 ? t17 : t23;
118+
let t26 = t16 / (0.001 + t12);
119+
let t28 = t26 / (0.001 + t16);
120+
let t30 = t28 * sin(t23 * (180 / Float.pi));
121+
let t31 = t28 * t18 * t19;
122+
let t33 = t18 + t28 + t5 + t31 + t15;
123+
let t41 = (t33 + t6) / (t33 - t6 + 0.001);
124+
let t42 = t7 * t6 * t30;
125+
let t43 = t16 < t18 ? t16 : t18;
126+
let t59 = cos(t12) * cos(t25);
127+
let t81 = t42 + t59 + t22 + t43 + t41;
128+
let t102 = t81 + t33 + t11;
129+
let t = t102;
130+
y += t;
131+
return y;
132+
}
133+
134+
@differentiable(reverse)
135+
func fuzzedMathTernary2(_ x0: Float, _ x1: Float, _ x2: Float) -> Float {
136+
var y = x0;
137+
let t3 = x2 * x1;
138+
let t4 = t3 / (0.001 + t3);
139+
let t5 = x2 + t3 + x0;
140+
let t6 = t4 - t3;
141+
let t8 = x1 * sin(x1 * (180 / Float.pi));
142+
let t9 = t5 * sin(x2 * (180 / Float.pi));
143+
let t10 = t8 - t6 - t9;
144+
let t11 = t6 * t8;
145+
let t12 = (t10 + t4) / (t10 - t4 + 0.001);
146+
let t13 = x2 * t12;
147+
let t14 = t6 / (0.001 + t11);
148+
let t15 = t8 - x1 - x2;
149+
let t18 = sin(x2) * sin(t14);
150+
let t19 = t12 < t6 ? t12 : t6;
151+
let t20 = t4 * x0;
152+
let t21 = (t14 + t8) / (t14 - t8 + 0.001);
153+
let t22 = (t6 + x1) / (t6 - x1 + 0.001);
154+
let t23 = sin(x1 * t5);
155+
let t25 = t18 * t20 * t13;
156+
let t31 = t21 - t6 - t19 - t23;
157+
let t34 = t15 - t31 - t13 - t25;
158+
let t49 = t5 > t22 ? t5 : t22;
159+
let t102 = (t34 * t49 - 1);
160+
let t = t102;
161+
y += t;
162+
return y;
163+
}

Benchmarks/LanguageSuite/Benchmarks/LanguageCoverageBenchmarks/LanguageCoverageBenchmarks.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,60 @@ let benchmarks = {
222222
}
223223
}
224224
)
225+
226+
// Arithmetic and control flow functions generated by a fuzzer.
227+
228+
Benchmark(
229+
"fuzzed arithmetic 1",
230+
forward: { benchmark in
231+
for _ in benchmark.scaledIterations {
232+
blackHole(fuzzedMath1(1.0, 2.0, 3.0))
233+
}
234+
},
235+
reverse: { benchmark in
236+
for _ in benchmark.scaledIterations {
237+
blackHole(gradient(at: 1.0, 2.0, 3.0, of: fuzzedMath1))
238+
}
239+
}
240+
)
241+
Benchmark(
242+
"fuzzed arithmetic 2",
243+
forward: { benchmark in
244+
for _ in benchmark.scaledIterations {
245+
blackHole(fuzzedMath2(1.0, 2.0, 3.0))
246+
}
247+
},
248+
reverse: { benchmark in
249+
for _ in benchmark.scaledIterations {
250+
blackHole(gradient(at: 1.0, 2.0, 3.0, of: fuzzedMath2))
251+
}
252+
}
253+
)
254+
255+
Benchmark(
256+
"fuzzed arithmetic with ternary operators 1",
257+
forward: { benchmark in
258+
for _ in benchmark.scaledIterations {
259+
blackHole(fuzzedMathTernary1(1.0, 2.0, 3.0))
260+
}
261+
},
262+
reverse: { benchmark in
263+
for _ in benchmark.scaledIterations {
264+
blackHole(gradient(at: 1.0, 2.0, 3.0, of: fuzzedMathTernary1))
265+
}
266+
}
267+
)
268+
Benchmark(
269+
"fuzzed arithmetic with ternary operators 2",
270+
forward: { benchmark in
271+
for _ in benchmark.scaledIterations {
272+
blackHole(fuzzedMathTernary2(1.0, 2.0, 3.0))
273+
}
274+
},
275+
reverse: { benchmark in
276+
for _ in benchmark.scaledIterations {
277+
blackHole(gradient(at: 1.0, 2.0, 3.0, of: fuzzedMathTernary2))
278+
}
279+
}
280+
)
225281
}

0 commit comments

Comments
 (0)