Skip to content

Commit cad66ae

Browse files
committed
Update plotting script
1 parent 7ba1c4c commit cad66ae

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

perf/lu.jl

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using BenchmarkTools
2-
import LinearAlgebra, RecursiveFactorization
2+
using LinearAlgebra, RecursiveFactorization
33

44
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 0.08
55

@@ -17,37 +17,39 @@ function luflop(m, n=m; innerflop=2)
1717
end
1818

1919
bas_mflops = Float64[]
20-
rec8_mflops = Float64[]
21-
rec16_mflops = Float64[]
22-
rec32_mflops = Float64[]
20+
rec_mflops = Float64[]
2321
ref_mflops = Float64[]
24-
ns = 4:32:500
22+
ns = 4:8:500
2523
for n in ns
2624
@info "$n × $n"
2725
A = rand(n, n)
2826
bt = @belapsed LinearAlgebra.lu!($(copy(A)))
2927
push!(bas_mflops, luflop(n)/bt/1e9)
3028

31-
rt8 = @belapsed RecursiveFactorization.lu!($(copy(A)); blocksize=8)
32-
push!(rec8_mflops, luflop(n)/rt8/1e9)
33-
34-
rt16 = @belapsed RecursiveFactorization.lu!($(copy(A)); blocksize=16)
35-
push!(rec16_mflops, luflop(n)/rt16/1e9)
36-
37-
rt32 = @belapsed RecursiveFactorization.lu!($(copy(A)); blocksize=32)
38-
push!(rec32_mflops, luflop(n)/rt32/1e9)
29+
rt = @belapsed RecursiveFactorization.lu!($(copy(A)))
30+
push!(rec_mflops, luflop(n)/rt/1e9)
3931

4032
ref = @belapsed LinearAlgebra.generic_lufact!($(copy(A)))
4133
push!(ref_mflops, luflop(n)/ref/1e9)
4234
end
4335

44-
using Plots
45-
plt = plot(ns, bas_mflops, legend=:bottomright, lab="OpenBLAS", title="LU Factorization Benchmark", marker=:auto, dpi=150)
46-
plot!(plt, ns, rec8_mflops, lab="RF8", marker=:auto)
47-
plot!(plt, ns, rec16_mflops, lab="RF16", marker=:auto)
48-
plot!(plt, ns, rec32_mflops, lab="RF32", marker=:auto)
36+
using DataFrames, VegaLite
37+
df = DataFrame(Size = ns, RecursiveFactorization = rec_mflops, OpenBLAS = bas_mflops, Reference = ref_mflops)
38+
df = stack(df, [:RecursiveFactorization, :OpenBLAS, :Reference], variable_name = :Library, value_name = :GFLOPS)
39+
plt = df |> @vlplot(
40+
:line, color = :Library,
41+
x = {:Size}, y = {:GFLOPS},
42+
width = 2400, height = 600
43+
)
44+
save(joinpath(homedir(), "Pictures", "lu_float64.png"), plt)
45+
46+
#=
47+
using Plot
48+
plt = plot(ns, bas_mflops, legend=:bottomright, lab="OpenBLAS", title="LU Factorization Benchmark", marker=:auto, dpi=300)
49+
plot!(plt, ns, rec_mflops, lab="RecursiveFactorization", marker=:auto)
4950
plot!(plt, ns, ref_mflops, lab="Reference", marker=:auto)
5051
xaxis!(plt, "size (N x N)")
5152
yaxis!(plt, "GFLOPS")
5253
savefig("lubench.png")
5354
savefig("lubench.pdf")
55+
=#

src/lu.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using LoopVectorization
2-
using LinearAlgebra: BlasInt, BlasFloat, LU, UnitLowerTriangular, ldiv!, mul!, checknonsingular
2+
using LinearAlgebra: BlasInt, BlasFloat, LU, UnitLowerTriangular, ldiv!, checknonsingular, BLAS
33

44
function lu(A::AbstractMatrix, pivot::Union{Val{false}, Val{true}} = Val(true); kwargs...)
55
lu!(copy(A), pivot; kwargs...)
@@ -9,13 +9,16 @@ function lu!(A, pivot::Union{Val{false}, Val{true}} = Val(true); kwargs...)
99
lu!(A, Vector{BlasInt}(undef, min(size(A)...)), pivot; kwargs...)
1010
end
1111

12+
# Use a function here to make sure it gets optimized away
13+
# OpenBLAS' TRSM isn't very good, we use a higher threshold for recursion
14+
pick_threshold() = BLAS.vendor() === :mkl ? 48 : 192
15+
1216
function lu!(A::AbstractMatrix{T}, ipiv::AbstractVector{<:Integer},
1317
pivot::Union{Val{false}, Val{true}} = Val(true);
1418
check::Bool=true,
1519
# the performance is not sensitive wrt blocksize, and 16 is a good default
1620
blocksize::Integer=16,
17-
# OpenBLAS' TRSM isn't very good, we use a higher threshold for recursion
18-
threshold::Integer=BLAS.vendor() === :mkl ? 48 : 192) where T
21+
threshold::Integer=pick_threshold()) where T
1922
info = Ref(zero(BlasInt))
2023
m, n = size(A)
2124
mnmin = min(m, n)

0 commit comments

Comments
 (0)