Skip to content

Commit 59308be

Browse files
authored
Benchmark result df (#40)
* Fix benchmark_result_df * Stack the DataFrame * Changed the layout of the data frame * Add interface test using * threads -> threaded in test
1 parent 51d23ea commit 59308be

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ julia = "1.5"
3939

4040
[extras]
4141
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
42+
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
4243
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
4344
VectorizationBase = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
4445

4546
[targets]
46-
test = ["InteractiveUtils", "Test", "VectorizationBase"]
47+
test = ["InteractiveUtils", "StatsPlots", "Test", "VectorizationBase"]

src/benchconfig.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ function getfuncs(libs::Vector{Symbol}, threaded::Bool)::Vector{Function}
2626
elseif i === :BLIS || i === :blis
2727
gemmblis!
2828
elseif i === :Octavian
29-
matmul!
29+
threaded ? matmul! : matmul_serial!
3030
elseif i === :Tullio
3131
threaded ? tmul_threads! : tmul_no_threads!
3232
elseif i === :Gaius
33-
Gaius.mul!
33+
threaded ? Gaius.mul! : Gaius.mul_serial!
3434
elseif i === :generic || i === :Generic || i === :GENERIC
3535
generic_matmul!
3636
else

src/runbenchmark.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@ function benchmark_result_type(::BenchmarkResult{T}) where {T}
1313
return T
1414
end
1515

16+
function _benchmark_result_df(sizes, libraries, mat)
17+
df = DataFrame(Size = sizes)
18+
for i eachindex(libraries)
19+
setproperty!(df, libraries[i], mat[:,i])
20+
end
21+
return df
22+
end
23+
function _benchmark_result_df(br::BenchmarkResult, s::Symbol = :gflops)
24+
_benchmark_result_df(br.sizes, br.libraries, getproperty(br, s))
25+
end
26+
27+
1628
"""
1729
benchmark_result_df(benchmark_result::BenchmarkResult)
1830
"""
1931
function benchmark_result_df(benchmark_result::BenchmarkResult)
20-
return deepcopy(benchmark_result.df)
32+
df = _benchmark_result_df(benchmark_result, :times)
33+
df = stack(df, Not(:Size), variable_name = :Library, value_name = :Seconds)
34+
df.GFLOPS = @. 2e-9 * matmul_length(df.Size) ./ df.Seconds
35+
return df
2136
end
2237

2338
"""
@@ -29,10 +44,7 @@ end
2944

3045
function Base.show(io::IO, br::BenchmarkResult{T}) where {T}
3146
println(io, "Bennchmark Result of Matrix{$T}, threaded = $(br.threaded)")
32-
df = DataFrame(Sizes = br.sizes)
33-
for i eachindex(br.libraries)
34-
setproperty!(df, br.libraries[i], br.gflops[:,i])
35-
end
47+
df = _benchmark_result_df(br)
3648
println(io, df)
3749
end
3850

@@ -70,6 +82,7 @@ end
7082

7183
matmul_sizes(s::Integer) = (s,s,s)
7284
matmul_sizes(mkn::Tuple{Vararg{Integer,3}}) = mkn
85+
matmul_length(s) = prod(matmul_sizes(s))
7386

7487
junk(::Type{T}) where {T <: Integer} = typemax(T) >> 1
7588
junk(::Type{T}) where {T} = T(NaN)

test/interface.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
import BLASBenchmarksCPU
3+
import StatsPlots
4+
@testset "Interface" begin
5+
benchmark_result = BLASBenchmarksCPU.runbench(Float64; sizes = [1, 2, 5, 10, 20, 50, 100, 200], threaded=false) #test that threads=false at least doesn't throw somewhere.
6+
df = BLASBenchmarksCPU.benchmark_result_df(benchmark_result)
7+
@test df isa BLASBenchmarksCPU.DataFrame
8+
df[!, :Size] = Float64.(df[!, :Size]);
9+
df[!, :GFLOPS] = Float64.(df[!, :GFLOPS]);
10+
df[!, :Seconds] = Float64.(df[!, :Seconds]);
11+
p = StatsPlots.@df df StatsPlots.plot(:Size, :GFLOPS; group = :Library, legend = :bottomright)
12+
@test p isa StatsPlots.Plots.Plot
13+
end

test/main.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ for T in [Float64, Float32]
1313
)
1414
@test benchmark_result isa BLASBenchmarksCPU.BenchmarkResult
1515
@test benchmark_result_type(benchmark_result) === T
16+
df = benchmark_result_df(benchmark_result)
17+
@test df isa BLASBenchmarksCPU.DataFrame
1618
plot_directory = mktempdir()
1719
BLASBenchmarksCPU.plot(
1820
benchmark_result;

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ include("test-suite-preamble.jl")
99
@info("VectorizationBase.num_cores() is $(VectorizationBase.num_cores())")
1010

1111
include("main.jl")
12+
include("interface.jl")
13+

0 commit comments

Comments
 (0)