Skip to content

Commit 06da800

Browse files
authored
add more benchmark targets for inference benchmark suite (#296)
1 parent 6fe4c7f commit 06da800

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

Manifest.toml

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
5858
deps = ["Printf"]
5959
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
6060

61+
[[REPL]]
62+
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
63+
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
64+
6165
[[Random]]
6266
deps = ["Serialization"]
6367
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
88
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
11+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1112
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1213
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1314
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

src/inference/InferenceBenchmarks.jl

+47-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ This benchmark group `"inference"` is composed of the following subgroups:
1111
"""
1212
module InferenceBenchmarks
1313

14+
# InferenceBenchmarker
15+
# ====================
16+
# this new `AbstractInterpreter` satisfies the minimum interface requirements and manages
17+
# its cache independently in a way it is totally separated from the native code cache
18+
# managed by the runtime system: this allows us to profile Julia-level inference reliably
19+
# without being influenced by previous trials or some native execution
20+
1421
using BenchmarkTools, InteractiveUtils
1522

1623
const CC = Core.Compiler
@@ -147,39 +154,78 @@ function tune_benchmarks!(
147154
end
148155
end
149156

150-
const SUITE = BenchmarkGroup()
157+
# "inference" benchmark targets
158+
# =============================
151159

152160
# TODO add TTFP?
161+
# XXX some targets below really depends on the compiler implementation itself
162+
# (e.g. `abstract_call_gf_by_type`) and thus a bit more unreliable -- ideally
163+
# we want to replace them with other functions that have the similar characteristics
164+
# but whose call graph are orthogonal to the Julia's compiler implementation
165+
166+
using REPL
167+
brdcast(xs, x) = findall(>(x), abs.(xs))
168+
let # see https://github.com/JuliaLang/julia/pull/45276
169+
n = 10000
170+
ex = Expr(:block)
171+
var = gensym()
172+
push!(ex.args, :($var = x))
173+
for _ = 1:n
174+
newvar = gensym()
175+
push!(ex.args, :($newvar = $var + 1))
176+
var = newvar
177+
end
178+
@eval global function quadratic(x)
179+
$ex
180+
end
181+
end
182+
183+
const SUITE = BenchmarkGroup()
153184

154185
let g = addgroup!(SUITE, "abstract interpretation")
155186
g["sin(42)"] = @benchmarkable (@abs_call sin(42))
156187
g["rand(Float64)"] = @benchmarkable (@abs_call rand(Float64))
157188
g["println(::QuoteNode)"] = @benchmarkable (abs_call(println, (QuoteNode,)))
189+
g["broadcast"] = @benchmarkable abs_call(brdcast, (Vector{Float64},Float64))
190+
g["REPL.REPLCompletions.completions"] = @benchmarkable abs_call(
191+
REPL.REPLCompletions.completions, (String,Int))
192+
g["Base.init_stdio(::Ptr{Cvoid})"] = @benchmarkable abs_call(Base.init_stdio, (Ptr{Cvoid},))
158193
g["abstract_call_gf_by_type"] = @benchmarkable abs_call(
159194
CC.abstract_call_gf_by_type, (NativeInterpreter,Any,CC.ArgInfo,Any,InferenceState,Int))
160195
g["construct_ssa!"] = @benchmarkable abs_call(CC.construct_ssa!, (Core.CodeInfo,CC.IRCode,CC.DomTree,Vector{CC.SlotInfo},Vector{Any}))
161196
g["domsort_ssa!"] = @benchmarkable abs_call(CC.domsort_ssa!, (CC.IRCode,CC.DomTree))
197+
g["quadratic"] = @benchmarkable abs_call(quadratic, (Int,))
162198
tune_benchmarks!(g)
163199
end
164200

165201
let g = addgroup!(SUITE, "optimization")
166202
g["sin(42)"] = @benchmarkable f() (setup = (f = @opt_call sin(42)))
167203
g["rand(Float64)"] = @benchmarkable f() (setup = (f = @opt_call rand(Float64)))
168204
g["println(::QuoteNode)"] = @benchmarkable f() (setup = (f = opt_call(println, (QuoteNode,))))
205+
g["broadcast"] = @benchmarkable f() (setup = (f = opt_call(brdcast, (Vector{Float64},Float64))))
206+
g["REPL.REPLCompletions.completions"] = @benchmarkable f() (setup = (f = opt_call(
207+
REPL.REPLCompletions.completions, (String,Int))))
208+
g["Base.init_stdio(::Ptr{Cvoid})"] = @benchmarkable f() (setup = (f = opt_call(Base.init_stdio, (Ptr{Cvoid},))))
169209
g["abstract_call_gf_by_type"] = @benchmarkable f() (setup = (f = opt_call(CC.abstract_call_gf_by_type, (NativeInterpreter,Any,CC.ArgInfo,Any,InferenceState,Int))))
170210
g["construct_ssa!"] = @benchmarkable f() (setup = (f = opt_call(CC.construct_ssa!, (Core.CodeInfo,CC.IRCode,CC.DomTree,Vector{CC.SlotInfo},Vector{Any}))))
171211
g["domsort_ssa!"] = @benchmarkable f() (setup = (f = opt_call(CC.domsort_ssa!, (CC.IRCode,CC.DomTree))))
212+
g["quadratic"] = @benchmarkable f() (setup = (f = opt_call(quadratic, (Int,))))
172213
tune_benchmarks!(g)
173214
end
174215

175216
let g = addgroup!(SUITE, "allinference")
176217
g["sin(42)"] = @benchmarkable (@inf_call sin(42))
177218
g["rand(Float64)"] = @benchmarkable (@inf_call rand(Float64))
178219
g["println(::QuoteNode)"] = @benchmarkable (inf_call(println, (QuoteNode,)))
220+
g["broadcast"] = @benchmarkable inf_call(brdcast, (Vector{Float64},Float64))
221+
g["REPL.REPLCompletions.completions"] = @benchmarkable inf_call(
222+
REPL.REPLCompletions.completions, (String,Int))
223+
g["Base.init_stdio(::Ptr{Cvoid})"] = @benchmarkable inf_call(Base.init_stdio, (Ptr{Cvoid},))
179224
g["abstract_call_gf_by_type"] = @benchmarkable inf_call(
180225
CC.abstract_call_gf_by_type, (NativeInterpreter,Any,CC.ArgInfo,Any,InferenceState,Int))
181226
g["construct_ssa!"] = @benchmarkable inf_call(CC.construct_ssa!, (Core.CodeInfo,CC.IRCode,CC.DomTree,Vector{CC.SlotInfo},Vector{Any}))
182227
g["domsort_ssa!"] = @benchmarkable inf_call(CC.domsort_ssa!, (CC.IRCode,CC.DomTree))
228+
g["quadratic"] = @benchmarkable inf_call(quadratic, (Int,))
183229
tune_benchmarks!(g)
184230
end
185231

0 commit comments

Comments
 (0)