Skip to content

Commit 23e0611

Browse files
authored
Merge pull request #491 from FluxML/bc/softmax-bench
Add (log)softmax benchmarks
2 parents acf87f5 + 8422479 commit 23e0611

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

benchmark/benchmarks.jl

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
11
using BenchmarkTools
22
using NNlib
3+
using NNlib.ChainRulesCore: rrule
4+
using Random
5+
6+
Random.seed!(1234567890)
37

48
const SUITE = BenchmarkGroup()
59

610
SUITE["activations"] = BenchmarkGroup()
11+
for et in (Float16, Float32, Float64)
12+
et_suite = BenchmarkGroup()
13+
SUITE["activations"][string(et)] = et_suite
14+
let x = rand(et, 1024, 1024), y = similar(x)
15+
for f in NNlib.ACTIVATIONS
16+
act = @eval($f)
17+
et_suite[string(f)] = @benchmarkable broadcast!($act, $y, $x)
18+
end
19+
end
20+
end
721

8-
x = rand(64, 64)
9-
10-
for f in NNlib.ACTIVATIONS
11-
act = @eval($f)
12-
SUITE["activations"][string(f)] = @benchmarkable $act.($x)
22+
for (fn!, fn_bw) in [(softmax!, NNlib.∇softmax_data), (logsoftmax!, NNlib.∇logsoftmax_data)]
23+
fn_suite = BenchmarkGroup()
24+
SUITE[rstrip(string(fn!), '!')] = fn_suite
25+
let SIZES = [
26+
(128, 384, 8),
27+
(512, 784, 8),
28+
(768, 1024, 4),
29+
(1024, 2048, 4),
30+
(2048, 2048, 2),
31+
(4096, 2048, 2),
32+
(4096, 4096, 2),
33+
(12288, 2048, 1)
34+
]
35+
for et in (Float16, Float32)
36+
et_suite = BenchmarkGroup("fw" => BenchmarkGroup(), "bw" => BenchmarkGroup())
37+
fn_suite[string(et)] = et_suite
38+
for sz in SIZES
39+
x = randn(et, sz)
40+
y = similar(x)
41+
dy = zero(x)
42+
fn!(y, x)
43+
et_suite["fw"][string(sz)] = @benchmarkable $fn!($y, $x)
44+
et_suite["bw"][string(sz)] = @benchmarkable $fn_bw($dy, $y)
45+
end
46+
end
47+
end
1348
end
49+

benchmark/runbenchmarks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function parse_commandline()
2424
default = "master"
2525
"--retune"
2626
help = "force re-tuning (ignore existing tuning data)"
27-
action = :store_true
27+
action = :store_false
2828
end
2929

3030
return parse_args(s)

0 commit comments

Comments
 (0)