Skip to content

Commit 10bf133

Browse files
committed
Add basic benchmark harness
Co-authored by: Andrei Zhabinski <[email protected]>
1 parent 806b0ef commit 10bf133

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

.buildkite/pipeline.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ steps:
4040
NNLIB_TEST_CUDA: true
4141
timeout_in_minutes: 60
4242

43+
- label: "Benchmarks"
44+
plugins:
45+
- JuliaCI/julia#v1:
46+
version: 1
47+
env:
48+
JULIA_NUM_THREADS: 4
49+
command:
50+
- julia --project=benchmark -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
51+
- julia --project=benchmark benchmark/runbenchmarks.jl
52+
- printf '%b\n' "$(cat benchmark/report.md)" | buildkite-agent annotate --style "info"
53+
agents:
54+
queue: "juliagpu"
55+
if: build.pull_request.labels includes "benchmark"
56+
timeout_in_minutes: 30
57+
4358
# - label: "GPU julia nightly"
4459
# plugins:
4560
# - JuliaCI/julia#v1:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ deps.jl
1313
.vscode/
1414
/Manifest.toml
1515
lib/NNlibCUDA/Manifest.toml
16+
benchmark/Manifest.toml
17+
benchmark/*.json
18+
benchmark/report.md

benchmark/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[deps]
2+
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
3+
BenchmarkCI = "20533458-34a3-403d-a444-e18f38190b5b"
4+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
5+
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
6+
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"

benchmark/benchmarks.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using BenchmarkTools
2+
using NNlib
3+
4+
const SUITE = BenchmarkGroup()
5+
6+
SUITE["activations"] = BenchmarkGroup()
7+
8+
x = rand(64, 64)
9+
10+
for f in NNlib.ACTIVATIONS
11+
act = @eval($f)
12+
SUITE["activations"][string(f)] = @benchmarkable $act.($x)
13+
end

benchmark/runbenchmarks.jl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Adapted from
2+
# https://github.com/kul-forbes/ProximalOperators.jl/tree/master/benchmark
3+
using ArgParse
4+
using PkgBenchmark
5+
using BenchmarkCI: displayjudgement, printresultmd, CIResult
6+
using Markdown
7+
8+
function markdown_report(judgement)
9+
md = sprint(printresultmd, CIResult(judgement = judgement))
10+
md = replace(md, ":x:" => "")
11+
md = replace(md, ":white_check_mark:" => "")
12+
return md
13+
end
14+
15+
function parse_commandline()
16+
s = ArgParseSettings()
17+
18+
@add_arg_table! s begin
19+
"--target"
20+
help = "the branch/commit/tag to use as target"
21+
default = "HEAD"
22+
"--baseline"
23+
help = "the branch/commit/tag to use as baseline"
24+
default = "master"
25+
"--retune"
26+
help = "force re-tuning (ignore existing tuning data)"
27+
action = :store_true
28+
end
29+
30+
return parse_args(s)
31+
end
32+
33+
function main()
34+
parsed_args = parse_commandline()
35+
36+
mkconfig(; kwargs...) =
37+
BenchmarkConfig(
38+
env = Dict(
39+
"JULIA_NUM_THREADS" => get(ENV, "JULIA_NUM_THREADS", "1"),
40+
);
41+
kwargs...
42+
)
43+
44+
target = parsed_args["target"]
45+
group_target = benchmarkpkg(
46+
dirname(@__DIR__),
47+
mkconfig(id = target),
48+
resultfile = joinpath(@__DIR__, "result-$(target).json"),
49+
retune = parsed_args["retune"],
50+
)
51+
52+
baseline = parsed_args["baseline"]
53+
group_baseline = benchmarkpkg(
54+
dirname(@__DIR__),
55+
mkconfig(id = baseline),
56+
resultfile = joinpath(@__DIR__, "result-$(baseline).json"),
57+
)
58+
59+
judgement = judge(group_target, group_baseline)
60+
report_md = markdown_report(judgement)
61+
write(joinpath(@__DIR__, "report.md"), report_md)
62+
display(Markdown.parse(report_md))
63+
end
64+
65+
main()

0 commit comments

Comments
 (0)