From a02709b5218e8bc9797ac0afc2b76c2d3b99f9f2 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 6 Oct 2016 10:15:01 -0400 Subject: [PATCH 1/6] broadcast fusion and dot-operator benchmarks --- src/BaseBenchmarks.jl | 5 ++- src/broadcast/BroadcastBenchmarks.jl | 61 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/broadcast/BroadcastBenchmarks.jl diff --git a/src/BaseBenchmarks.jl b/src/BaseBenchmarks.jl index a30d4400..b2d3e5b4 100644 --- a/src/BaseBenchmarks.jl +++ b/src/BaseBenchmarks.jl @@ -14,6 +14,7 @@ BenchmarkTools.DEFAULT_PARAMETERS.memory_tolerance = 0.01 const PARAMS_PATH = joinpath(dirname(@__FILE__), "..", "etc", "params.jld") const SUITE = BenchmarkGroup() const MODULES = Dict("array" => :ArrayBenchmarks, + "broadcast" => :BroadcastBenchmarks, "io" => :IOBenchmarks, "linalg" => :LinAlgBenchmarks, "micro" => :MicroBenchmarks, @@ -36,7 +37,9 @@ function load!(group::BenchmarkGroup, id::AbstractString; tune::Bool = true) eval(BaseBenchmarks, :(include($modpath))) modsuite = eval(BaseBenchmarks, modsym).SUITE group[id] = modsuite - tune && loadparams!(modsuite, JLD.load(PARAMS_PATH, id), :evals) + tune && jldopen(PARAMS_PATH, "r") do file + JLD.exists(file, id) && loadparams!(modsuite, JLD.load(file, id), :evals) + end return group end diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl new file mode 100644 index 00000000..baa4d21c --- /dev/null +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -0,0 +1,61 @@ +module BroadcastBenchmarks + +include(joinpath(dirname(@__FILE__), "..", "utils", "RandUtils.jl")) + +using .RandUtils +using BenchmarkTools +using Compat + +const SUITE = BenchmarkGroup() + +# work around lack of Compat support for .= (Compat.jl issue #285) +if VERSION < v"0.5.0-dev+5575" #17510 + macro dotcompat(ex) + if Meta.isexpr(ex, :comparison, 3) && ex.args[2] == :.= + :(copy!($(ex.args[1]), $(ex.args[3]))) + else + ex + end + end +else + macro dotcompat(ex) + ex + end +end + +########################################################################### + +g = addgroup!(SUITE, "fusion", ["broadcast!", "array"]) + +f(x,y) = 3x - 4y^2 +h(x) = 6x + 2x^2 - 5 +perf_bcast!(r, x) = @dotcompat r .= @compat h.(f.(x, h.(x))) +perf_bcast!(R, x, y) = @dotcompat R .= @compat h.(f.(x, h.(y))) +perf_bcast!(R, x, y, z) = @dotcompat R .= @compat f.(X, f.(x, y)) + +x = randvec(10^3) +y = randvec(10^3)' +z = randvec(10^6) +X = randmat(10^3) +R = Array(Float64, length(x),length(y)) +r = similar(z) + +g["fusion", "Float64", size(r), 1] = @benchmarkable perf_bcast!($r, $z) +g["fusion", "Float64", size(R), 2] = @benchmarkable perf_bcast!($R, $x, $y) +g["fusion", "Float64", size(R), 3] = @benchmarkable perf_bcast!($R, $X, $x, $y) +g["fusion", "Float64", size(r), 2] = @benchmarkable perf_bcast!($r, $z, 17.3) + +########################################################################### + +g = addgroup!(SUITE, "dotop", ["broadcast!", "array"]) + +perf_op_bcast!(r, x) = @dotcompat r .= 3 .* x .- 4 .* x.^2 .+ x .* x .- x .^ 3 +perf_op_bcast!(R, x, y) = @dotcompat R .= 3 .* x .- 4 .* y.^2 .+ x .* y .- x .^ 3 + +g["dotop", "Float64", size(r), 1] = @benchmarkable perf_op_bcast!($r, $z) +g["dotop", "Float64", size(R), 2] = @benchmarkable perf_op_bcast!($R, $x, $y) +g["dotop", "Float64", size(r), 2] = @benchmarkable perf_op_bcast!($r, $z, 17.3) + +########################################################################### + +end # module From 615c103ea3523ffcce93f045a169349a359dce54 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 6 Oct 2016 10:27:52 -0400 Subject: [PATCH 2/6] add sparsevec broadcast benchmark --- src/broadcast/BroadcastBenchmarks.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl index baa4d21c..6a53012f 100644 --- a/src/broadcast/BroadcastBenchmarks.jl +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -58,4 +58,14 @@ g["dotop", "Float64", size(r), 2] = @benchmarkable perf_op_bcast!($r, $z, 17.3) ########################################################################### +g = addgroup!(SUITE, "sparse", ["broadcast", "array"]) + +s = samesprand(10^7, 1e-3, randn) +perf_sparse_op(s) = sqrt.(abs.(s .* 2)) +perf_sparse_op(s,t) = f.(s,t) +g["sparse", size(s), 1] = @benchmarkable perf_sparse_op($s) +g["sparse", size(s), 2] = @benchmarkable perf_sparse_op($s, $s) + +########################################################################### + end # module From ab514380e6e5c90e0e2e7f634ba592eae94ea8c3 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 7 Oct 2016 15:46:12 -0400 Subject: [PATCH 3/6] sparse vectors are new in Julia 0.5 --- src/broadcast/BroadcastBenchmarks.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl index 6a53012f..d68adf99 100644 --- a/src/broadcast/BroadcastBenchmarks.jl +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -60,11 +60,20 @@ g["dotop", "Float64", size(r), 2] = @benchmarkable perf_op_bcast!($r, $z, 17.3) g = addgroup!(SUITE, "sparse", ["broadcast", "array"]) -s = samesprand(10^7, 1e-3, randn) perf_sparse_op(s) = sqrt.(abs.(s .* 2)) perf_sparse_op(s,t) = f.(s,t) + +if VERSION < v"0.5.0-dev+763" + s = samesprand(10^7, 1, 1e-3, randn) +else + s = samesprand(10^7, 1e-3, randn) +end +S = samesprand(10^3, 10^3, 1e-3, randn) + g["sparse", size(s), 1] = @benchmarkable perf_sparse_op($s) g["sparse", size(s), 2] = @benchmarkable perf_sparse_op($s, $s) +g["sparse", size(S), 1] = @benchmarkable perf_sparse_op($S) +g["sparse", size(S), 2] = @benchmarkable perf_sparse_op($S, $S) ########################################################################### From b425abbadf1da5b46f89cacde30dafb8c54da608 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Fri, 7 Oct 2016 16:10:55 -0400 Subject: [PATCH 4/6] whoops, missing compat macro --- src/broadcast/BroadcastBenchmarks.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl index d68adf99..26de2522 100644 --- a/src/broadcast/BroadcastBenchmarks.jl +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -60,8 +60,8 @@ g["dotop", "Float64", size(r), 2] = @benchmarkable perf_op_bcast!($r, $z, 17.3) g = addgroup!(SUITE, "sparse", ["broadcast", "array"]) -perf_sparse_op(s) = sqrt.(abs.(s .* 2)) -perf_sparse_op(s,t) = f.(s,t) +perf_sparse_op(s) = @compat sqrt.(abs.(s .* 2)) +perf_sparse_op(s,t) = @compat f.(s,t) if VERSION < v"0.5.0-dev+763" s = samesprand(10^7, 1, 1e-3, randn) From d5d2bbef1dd59c55078b4ffcd85369c8b7d910e3 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sat, 8 Oct 2016 10:56:43 -0400 Subject: [PATCH 5/6] remove redundant key --- src/broadcast/BroadcastBenchmarks.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl index 26de2522..dfa4784b 100644 --- a/src/broadcast/BroadcastBenchmarks.jl +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -40,10 +40,10 @@ X = randmat(10^3) R = Array(Float64, length(x),length(y)) r = similar(z) -g["fusion", "Float64", size(r), 1] = @benchmarkable perf_bcast!($r, $z) -g["fusion", "Float64", size(R), 2] = @benchmarkable perf_bcast!($R, $x, $y) -g["fusion", "Float64", size(R), 3] = @benchmarkable perf_bcast!($R, $X, $x, $y) -g["fusion", "Float64", size(r), 2] = @benchmarkable perf_bcast!($r, $z, 17.3) +g["Float64", size(r), 1] = @benchmarkable perf_bcast!($r, $z) +g["Float64", size(R), 2] = @benchmarkable perf_bcast!($R, $x, $y) +g["Float64", size(R), 3] = @benchmarkable perf_bcast!($R, $X, $x, $y) +g["Float64", size(r), 2] = @benchmarkable perf_bcast!($r, $z, 17.3) ########################################################################### @@ -70,10 +70,10 @@ else end S = samesprand(10^3, 10^3, 1e-3, randn) -g["sparse", size(s), 1] = @benchmarkable perf_sparse_op($s) -g["sparse", size(s), 2] = @benchmarkable perf_sparse_op($s, $s) -g["sparse", size(S), 1] = @benchmarkable perf_sparse_op($S) -g["sparse", size(S), 2] = @benchmarkable perf_sparse_op($S, $S) +g[size(s), 1] = @benchmarkable perf_sparse_op($s) +g[size(s), 2] = @benchmarkable perf_sparse_op($s, $s) +g[size(S), 1] = @benchmarkable perf_sparse_op($S) +g[size(S), 2] = @benchmarkable perf_sparse_op($S, $S) ########################################################################### From 094696ef961b526a85a379f948213a216baa3689 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Tue, 11 Oct 2016 14:07:10 -0400 Subject: [PATCH 6/6] rm redundant dotop --- src/broadcast/BroadcastBenchmarks.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/broadcast/BroadcastBenchmarks.jl b/src/broadcast/BroadcastBenchmarks.jl index dfa4784b..42f8e427 100644 --- a/src/broadcast/BroadcastBenchmarks.jl +++ b/src/broadcast/BroadcastBenchmarks.jl @@ -52,9 +52,9 @@ g = addgroup!(SUITE, "dotop", ["broadcast!", "array"]) perf_op_bcast!(r, x) = @dotcompat r .= 3 .* x .- 4 .* x.^2 .+ x .* x .- x .^ 3 perf_op_bcast!(R, x, y) = @dotcompat R .= 3 .* x .- 4 .* y.^2 .+ x .* y .- x .^ 3 -g["dotop", "Float64", size(r), 1] = @benchmarkable perf_op_bcast!($r, $z) -g["dotop", "Float64", size(R), 2] = @benchmarkable perf_op_bcast!($R, $x, $y) -g["dotop", "Float64", size(r), 2] = @benchmarkable perf_op_bcast!($r, $z, 17.3) +g["Float64", size(r), 1] = @benchmarkable perf_op_bcast!($r, $z) +g["Float64", size(R), 2] = @benchmarkable perf_op_bcast!($R, $x, $y) +g["Float64", size(r), 2] = @benchmarkable perf_op_bcast!($r, $z, 17.3) ###########################################################################