Skip to content

Commit ea2f029

Browse files
authored
perf: move all benchmarks to buildkite (EnzymeAD#327)
1 parent 94ee140 commit ea2f029

File tree

4 files changed

+66
-178
lines changed

4 files changed

+66
-178
lines changed

.github/workflows/benchmark_pr.yml

Lines changed: 0 additions & 82 deletions
This file was deleted.

benchmark/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ CUDA_Driver_jll = "4ee394cb-3365-5eb0-8335-949819d2adfc"
2828

2929
[preferences.CUDA_Driver_jll]
3030
compat = false
31+
32+
[sources]
33+
Reactant = { path = ".." }

benchmark/benchmarks.jl

Lines changed: 0 additions & 96 deletions
This file was deleted.

benchmark/setup.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ using Zygote: Zygote
1717
@inline sumabs2(model, x, p, st) = sum(abs2, first(Lux.apply(model, x, p, st)))
1818
@inline sumabs2(model, x) = sum(abs2, model(x))
1919

20+
@inline sumcos(x) = sum(cos, x)
21+
@inline ∇sumcos(x) = Enzyme.gradient(Reverse, sumcos, x)
22+
2023
function benchmark_group_to_backend(benchmark_group::String)
2124
benchmark_group == "CPU" && return CPUDevice()
2225
benchmark_group == "CUDA" && return CUDADevice()
@@ -34,7 +37,39 @@ end
3437
function setup_benchmarks!(suite::BenchmarkGroup, backend::String)
3538
dev = benchmark_group_to_backend(backend)
3639

40+
# Simple Benchmarks
41+
setup_simple_benchmark!(suite, backend)
42+
43+
# Add Lux Benchmarks
3744
setup_vit_benchmark!(suite, backend, dev)
45+
setup_vgg_benchmark!(suite, backend, dev)
46+
47+
return nothing
48+
end
49+
50+
# Some Simple Benchmarks
51+
function setup_simple_benchmark!(suite::BenchmarkGroup, backend)
52+
for opt_pass in (:all, :only_enzyme, :after_enzyme, :before_enzyme)
53+
tag = opt_pass == :all ? "Reactant" : "Reactant (optimize = $(Meta.quot(opt_pass)))"
54+
55+
suite["(Basics) 2D sum (2 x 10)"]["forward (compilation)"][backend][tag] = @benchmarkable begin
56+
@compile optimize = $(opt_pass) sum(x)
57+
end setup = begin
58+
x = Reactant.ConcreteRArray(ones(2, 10))
59+
end
60+
61+
suite["(Basics) sum(cos, x) (2 x 10)"]["forward (compilation)"][backend][tag] = @benchmarkable begin
62+
@compile optimize = $(opt_pass) sumcos(x)
63+
end setup = begin
64+
x = Reactant.ConcreteRArray(ones(2, 10))
65+
end
66+
end
67+
68+
suite["Basics ∇sumcos (2 x 10)"]["forward (compilation)"][backend]["Reactant"] = @benchmarkable begin
69+
@compile optimize = :all ∇sumcos(x)
70+
end setup = begin
71+
x = Reactant.ConcreteRArray(ones(2, 10))
72+
end
3873

3974
return nothing
4075
end
@@ -50,6 +85,20 @@ function setup_vit_benchmark!(suite::BenchmarkGroup, backend, dev::AbstractDevic
5085
end
5186
end
5287

88+
function setup_vgg_benchmark!(suite::BenchmarkGroup, backend, dev::AbstractDevice)
89+
for depth in (11, 13, 16, 19), bsize in (4, 16, 32), batchnorm in (false, true)
90+
benchmark_name = "VGG$(depth) bn=$(batchnorm) (224 x 224 x 3 x $(bsize))"
91+
setup_lux_forward_pass_benchmark!(
92+
suite,
93+
benchmark_name,
94+
backend,
95+
Vision.VGG(depth; pretrained=false, batchnorm),
96+
(224, 224, 3, bsize),
97+
dev,
98+
)
99+
end
100+
end
101+
53102
function setup_lux_forward_pass_benchmark!(
54103
suite::BenchmarkGroup,
55104
benchmark_name::String,
@@ -89,6 +138,20 @@ function setup_lux_forward_pass_benchmark!(
89138
GC.gc()
90139
reclaim($dev)
91140
end
141+
142+
suite[benchmark_name]["forward (compilation)"][backend][tag] = @benchmarkable begin
143+
@compile optimize = $(opt_pass) Lux.apply($model, x_ra, ps_ra, st_test_ra)
144+
end setup = begin
145+
GC.gc()
146+
reclaim($dev)
147+
x, ps, st = general_lux_setup($model, $x_dims)
148+
st_test = Lux.testmode(st)
149+
x_ra = Reactant.to_rarray(x)
150+
ps_ra = Reactant.to_rarray(ps)
151+
st_test_ra = Reactant.to_rarray(st_test)
152+
GC.gc()
153+
reclaim($dev)
154+
end
92155
end
93156

94157
return nothing

0 commit comments

Comments
 (0)