Skip to content

Commit c8ecd77

Browse files
Merge pull request #1074 from SciML/gd/update_sparse_benchmarks
Update sparse AD benchmarks
2 parents f17a4e8 + 5cace37 commit c8ecd77

File tree

3 files changed

+401
-310
lines changed

3 files changed

+401
-310
lines changed

benchmarks/AutomaticDifferentiationSparse/BrusselatorSparseAD.jmd

Lines changed: 93 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ backend = AutoSparse(
107107

108108
extras = DI.prepare_jacobian(brusselator_2d!, similar(x0_32), backend, x0_32);
109109
J1 = DI.jacobian!(
110-
brusselator_2d!, similar(x0_32), similar(S1, eltype(x0_32)), backend, x0_32, extras
110+
brusselator_2d!, similar(x0_32), similar(S1, eltype(x0_32)), extras, backend, x0_32
111111
)
112112

113113
cache = SDT.sparse_jacobian_cache(
@@ -145,23 +145,25 @@ for (i, N) in enumerate(N_values)
145145
)
146146
end
147147

148-
pld = plot(;
149-
title="Sparsity detection on the Brusselator",
150-
xlabel="Input size N",
151-
ylabel="Runtime [s]",
152-
)
153-
plot!(
154-
pld,
155-
N_values,
156-
td1;
157-
lw=2,
158-
linestyle=:auto,
159-
markershape=:auto,
160-
label="SparseConnectivityTracer",
161-
)
162-
plot!(pld, N_values, td2; lw=2, linestyle=:auto, markershape=:auto, label="Symbolics")
163-
plot!(pld; xscale=:log10, yscale=:log10, legend=:topleft, minorgrid=true)
164-
pld
148+
let
149+
pld = plot(;
150+
title="Sparsity detection on the Brusselator",
151+
xlabel="Input size N",
152+
ylabel="Runtime [s]",
153+
)
154+
plot!(
155+
pld,
156+
N_values,
157+
td1;
158+
lw=2,
159+
linestyle=:auto,
160+
markershape=:auto,
161+
label="SparseConnectivityTracer",
162+
)
163+
plot!(pld, N_values, td2; lw=2, linestyle=:auto, markershape=:auto, label="Symbolics")
164+
plot!(pld; xscale=:log10, yscale=:log10, legend=:topleft, minorgrid=true)
165+
pld
166+
end
165167
```
166168

167169
### Coloring
@@ -178,21 +180,23 @@ for (i, N) in enumerate(N_values)
178180
tc2[i] = @belapsed SDT.matrix_colors($S)
179181
end
180182

181-
plc = plot(;
182-
title="Coloring on the Brusselator", xlabel="Input size N", ylabel="Runtime [s]"
183-
)
184-
plot!(
185-
plc,
186-
N_values,
187-
tc1;
188-
lw=2,
189-
linestyle=:auto,
190-
markershape=:auto,
191-
label="SparseMatrixColorings",
192-
)
193-
plot!(plc, N_values, tc2; lw=2, linestyle=:auto, markershape=:auto, label="SparseDiffTools")
194-
plot!(plc; xscale=:log10, yscale=:log10, legend=:topleft, minorgrid=true)
195-
plc
183+
let
184+
plc = plot(;
185+
title="Coloring on the Brusselator", xlabel="Input size N", ylabel="Runtime [s]"
186+
)
187+
plot!(
188+
plc,
189+
N_values,
190+
tc1;
191+
lw=2,
192+
linestyle=:auto,
193+
markershape=:auto,
194+
label="SparseMatrixColorings",
195+
)
196+
plot!(plc, N_values, tc2; lw=2, linestyle=:auto, markershape=:auto, label="SparseDiffTools")
197+
plot!(plc; xscale=:log10, yscale=:log10, legend=:topleft, minorgrid=true)
198+
plc
199+
end
196200
```
197201

198202
### Differentiation
@@ -207,10 +211,10 @@ for (i, N) in enumerate(N_values)
207211
)
208212
J = similar(S, eltype(x0))
209213

210-
tj1[i] = @belapsed DI.jacobian!($brusselator_2d!, _y, _J, $backend, $x0, _extras) setup = (
214+
tj1[i] = @belapsed DI.jacobian!($brusselator_2d!, _y, _J, _prep, $backend, $x0) setup = (
211215
_y = similar($x0);
212216
_J = similar($J);
213-
_extras = DI.prepare_jacobian($brusselator_2d!, similar($x0), $backend, $x0)
217+
_prep = DI.prepare_jacobian($brusselator_2d!, similar($x0), $backend, $x0)
214218
) evals = 1
215219

216220
tj2[i] = @belapsed SDT.sparse_jacobian!(_J, $backend, _cache, $brusselator_2d!, _y, $x0) setup = (
@@ -226,59 +230,63 @@ for (i, N) in enumerate(N_values)
226230
) evals = 1
227231
end
228232

229-
plj = plot(;
230-
title="Sparse Jacobian on the Brusselator", xlabel="Input size N", ylabel="Runtime [s]"
231-
)
232-
plot!(
233-
plj,
234-
N_values,
235-
tj1;
236-
lw=2,
237-
linestyle=:auto,
238-
markershape=:auto,
239-
label="DifferentiationInterface",
240-
)
241-
plot!(plj, N_values, tj2; lw=2, linestyle=:auto, markershape=:auto, label="SparseDiffTools")
242-
plot!(plj; xscale=:log10, yscale=:log10, legend=:topleft, minorgrid=true)
243-
plj
233+
let
234+
plj = plot(;
235+
title="Sparse Jacobian on the Brusselator", xlabel="Input size N", ylabel="Runtime [s]"
236+
)
237+
plot!(
238+
plj,
239+
N_values,
240+
tj1;
241+
lw=2,
242+
linestyle=:auto,
243+
markershape=:auto,
244+
label="DifferentiationInterface",
245+
)
246+
plot!(plj, N_values, tj2; lw=2, linestyle=:auto, markershape=:auto, label="SparseDiffTools")
247+
plot!(plj; xscale=:log10, yscale=:log10, legend=:topleft, minorgrid=true)
248+
plj
249+
end
244250
```
245251

246252
### Summary
247253

248254
```julia
249-
pl = plot(;
250-
title="Is the new pipeline worth it?\nTest case: Brusselator",
251-
xlabel="Input size N",
252-
ylabel="Runtime ratio DI / SparseDiffTools",
253-
)
254-
plot!(
255-
pl,
256-
N_values,
257-
td2 ./ td1;
258-
lw=2,
259-
linestyle=:auto,
260-
markershape=:auto,
261-
label="sparsity detection speedup",
262-
)
263-
plot!(
264-
pl,
265-
N_values,
266-
tc2 ./ tc1;
267-
lw=2,
268-
linestyle=:auto,
269-
markershape=:auto,
270-
label="coloring speedup",
271-
)
272-
plot!(
273-
pl,
274-
N_values,
275-
tj2 ./ tj1;
276-
lw=2,
277-
linestyle=:auto,
278-
markershape=:auto,
279-
label="differentiation speedup",
280-
)
281-
plot!(pl, N_values, ones(length(N_values)); lw=3, color=:black, label="same speed")
282-
plot!(pl; xscale=:log10, yscale=:log10, minorgrid=true, legend=:right)
283-
pl
255+
let
256+
pl = plot(;
257+
title="Is the new pipeline worth it?\nTest case: Brusselator",
258+
xlabel="Input size N",
259+
ylabel="Runtime ratio DI / SparseDiffTools",
260+
)
261+
plot!(
262+
pl,
263+
N_values,
264+
td2 ./ td1;
265+
lw=2,
266+
linestyle=:dot,
267+
markershape=:utriangle,
268+
label="sparsity detection speedup",
269+
)
270+
plot!(
271+
pl,
272+
N_values,
273+
tc2 ./ tc1;
274+
lw=2,
275+
linestyle=:dashdot,
276+
markershape=:diamond,
277+
label="coloring speedup",
278+
)
279+
plot!(
280+
pl,
281+
N_values,
282+
tj2 ./ tj1;
283+
lw=2,
284+
linestyle=:dash,
285+
markershape=:pentagon,
286+
label="differentiation speedup",
287+
)
288+
plot!(pl, N_values, ones(length(N_values)); lw=3, color=:black, label="same speed")
289+
plot!(pl; xscale=:log10, yscale=:log10, minorgrid=true, legend=:right)
290+
pl
291+
end
284292
```

0 commit comments

Comments
 (0)