Skip to content

Switch to Gadfly, set colors based on library #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ version = "0.1.0"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Fontconfig = "186bb1d3-e1f7-5a2c-a377-96d770f13627"
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
Gaius = "bffe22d1-cb55-4f4e-ac2c-f4dd4bf58912"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Expand All @@ -16,19 +20,18 @@ ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Tullio = "bc48ee85-29a4-5162-ae0b-a64e1601d4bc"
VectorizationBase = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a"
blis_jll = "6136c539-28a5-5bf0-87cc-b183200dce32"

[compat]
BenchmarkTools = "0.5"
DataFrames = "0.22"
Gaius = "0.5, 0.6"
LoopVectorization = "0.9, 0.10"
Colors = "0.12"
Gadfly = "1.3"
Gaius = "0.5,0.6"
LoopVectorization = "0.10"
Octavian = "0.2"
ProgressMeter = "1.4"
Tullio = "0.2"
VectorizationBase = "0.15"
VegaLite = "2.3"
VectorizationBase = "0.16"
julia = "1.5"

[extras]
Expand Down
11 changes: 6 additions & 5 deletions src/BLASBenchmarksCPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using Tullio, Octavian, Gaius

# utils: LoopVectorization for Tullio.jl, VectorizationBase for info
using LoopVectorization, VectorizationBase
using VectorizationBase: NUM_CORES, align
using VectorizationBase: num_cores, align

using Random

Expand All @@ -18,7 +18,8 @@ using LinearAlgebra
using BenchmarkTools, ProgressMeter

# Plotting & presenting results
using VegaLite, DataFrames
using Cairo
using Fontconfig, Gadfly, Colors, DataFrames

export benchmark_result_type
export benchmark_result_df
Expand Down Expand Up @@ -67,9 +68,9 @@ include("runbenchmark.jl")
include("plotting.jl")

function __init__()
mkl_set_num_threads(NUM_CORES)
openblas_set_num_threads(NUM_CORES)
blis_set_num_threads(NUM_CORES)
mkl_set_num_threads(num_cores())
openblas_set_num_threads(num_cores())
blis_set_num_threads(num_cores())
end

end
75 changes: 52 additions & 23 deletions src/plotting.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@

####################################################################################################
####################################### Colors #####################################################
####################################################################################################

const LIBRARIES = [:Octavian, :MKL, :OpenBLAS, :blis, :Tullio, :Gaius, :Generic];
"""
Defines the mapping between libraries and colors
"""# #0071c5 == Intel Blue
# make sure colors are distinguishable against white background by adding white to the seed list,
# then deleting it from the resultant palette
palette = distinguishable_colors(length(LIBRARIES) + 2, [colorant"white", colorant"black", colorant"#66023C", colorant"#0071c5"])
deleteat!(palette, 1); deleteat!(palette, 2)
const COLOR_MAP = Dict(zip(LIBRARIES, palette))
getcolor(l::Symbol) = COLOR_MAP[l]
for (alias,ref) ∈ [(:BLIS,:blis),(:generic,:Generic),(:GENERIC,:Generic)]
COLOR_MAP[alias] = COLOR_MAP[ref]
end

const JULIA_LIBS = Set(["Octavian", "Tullio", "Gaius", "Generic", "GENERIC", "generic"])
isjulialib(x) = x ∈ JULIA_LIBS


####################################################################################################
####################################### Plots ######################################################
####################################################################################################


function pick_suffix(desc = "")
suffix = if VectorizationBase.AVX512F
suffix = if VectorizationBase.has_feature("x86_64_avx512f")
"AVX512"
elseif VectorizationBase.AVX2
elseif VectorizationBase.has_feature("x86_64_avx2")
"AVX2"
elseif VectorizationBase.REGISTER_SIZE == 32
elseif VectorizationBase.has_feature("x86_64_avx")
"AVX"
else
"REGSIZE$(VectorizationBase.REGISTER_SIZE)"
"REGSIZE$(VectorizationBase.register_size())"
end
if desc != ""
suffix *= '_' * desc
Expand All @@ -34,8 +61,7 @@ end
function default_plot_filename(br::BenchmarkResult{T};
desc::AbstractString,
logscale::Bool) where {T}
df = br.df
l, u = extrema(df.Size)
l, u = extrema(br.sizes)
if logscale
desc *= "_logscale"
end
Expand All @@ -54,41 +80,44 @@ end
plot_filename = default_plot_filename(br; desc = desc, logscale = logscale),
file_extensions = ["svg", "png"])
"""
function plot(br::BenchmarkResult{T}; kwargs...) where {T}
function Gadfly.plot(br::BenchmarkResult{T}; kwargs...) where {T}
_plot(br; kwargs...)
return nothing
end

roundint(x) = round(Int,x)
# `_plot` is just like `plot`, except _plot returns the filenames
function _plot(
br::BenchmarkResult{T};
desc::AbstractString = "",
logscale::Bool = true,
width::Real = 1200,
height::Real = 600,
width = 12inch,
height = 8inch,
plot_directory::AbstractString = default_plot_directory(),
plot_filename::AbstractString = default_plot_filename(br; desc = desc, logscale = logscale),
file_extensions = ["svg", "png"],
) where {T}
df = br.df
plt = if logscale
df |> @vlplot(
:line, color = :Library,
x = {:Size, scale={type=:log}}, y = {:GFLOPS},
width = width, height = height
)
else
df |> @vlplot(
:line, color = :Library,
x = {:Size}, y = {:GFLOPS},
width = width, height = height
colors = getcolor.(br.libraries);
libraries = string.(br.libraries)
xscale = logscale ? Scale.x_log10(labels=string ∘ roundint ∘ exp10) : Scale.x_continuous
# xscale = logscale ? Scale.x_log10 : Scale.x_continuous
plt = plot(
Gadfly.Guide.manual_color_key("Libraries", libraries, colors),
Guide.xlabel("Size"), Guide.ylabel("GFLOPS"), xscale
)
for i ∈ eachindex(libraries)
linestyle = isjulialib(libraries[i]) ? :solid : :dash
l = layer(
x = br.sizes, y = br.gflops[:,i],
Geom.line, Theme(default_color = colors[i], line_style = [linestyle])
)
push!(plt, l)
end
mkpath(plot_directory)
_filenames = String[]
extension_dict = Dict("svg" => SVG, "png" => PNG, "pdf" => PDF, "ps" => PS)
for ext in file_extensions
_filename = joinpath(plot_directory, "$(plot_filename).$(ext)")
save(_filename, plt)
draw(extension_dict[ext](_filename, width, height), plt)
push!(_filenames, _filename)
end
return _filenames
Expand Down
35 changes: 19 additions & 16 deletions src/runbenchmark.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
struct BenchmarkResult{T}
df::DataFrame
struct BenchmarkResult{T,I<:Union{Int,NTuple{3,Int}}}
libraries::Vector{Symbol}
sizes::Vector{I}
gflops::Matrix{Float64}
times::Matrix{Float64}
threaded::Bool
end

Expand All @@ -26,7 +29,11 @@ end

function Base.show(io::IO, br::BenchmarkResult{T}) where {T}
println(io, "Bennchmark Result of Matrix{$T}, threaded = $(br.threaded)")
println(io, br.df)
df = DataFrame(Sizes = br.sizes)
for i ∈ eachindex(br.libraries)
setproperty!(df, br.libraries[i], br.gflops[:,i])
end
println(io, df)
end

function maybe_sleep(x)
Expand Down Expand Up @@ -121,6 +128,7 @@ Base.length(ls::LogSpace) = length(ls.r)
Base.size(ls::LogSpace) = (length(ls.r),)
Base.axes(ls::LogSpace) = axes(ls.r)
Base.eltype(::LogSpace) = Int
Base.convert(::Type{Vector{Int}}, l::LogSpace) = collect(l)

"""
all_libs()
Expand Down Expand Up @@ -172,9 +180,9 @@ function runbench(
sleep_time = 0.0
) where {T}
if threaded
mkl_set_num_threads(NUM_CORES)
openblas_set_num_threads(NUM_CORES)
blis_set_num_threads(NUM_CORES)
mkl_set_num_threads(num_cores())
openblas_set_num_threads(num_cores())
blis_set_num_threads(num_cores())
else
mkl_set_num_threads(1)
openblas_set_num_threads(1)
Expand All @@ -190,9 +198,8 @@ function runbench(
end
memory = Vector{T}(undef, max_matrix_sizes)
library = reduce(vcat, (libs for _ ∈ eachindex(sizevec)))
Nres = length(libs) * length(sizes)
times = Vector{Float64}(undef, Nres)
gflop = Vector{Float64}(undef, Nres)
times = Matrix{Float64}(undef, length(sizes), length(libs))
gflop = similar(times);
k = 0

force_belapsed = true # force when compiling
Expand All @@ -213,16 +220,12 @@ function runbench(
funcs[i], C, A, B, sleep_time, force_belapsed, ref
)
gflops = 2e-9M*K*N / t
times[(k += 1)] = t
gflop[k] = gflops
times[j,i] = t
gflop[j,i] = gflops
last_perfs[i+1] = (libs[i], round(gflops,sigdigits=4))
end
ProgressMeter.next!(p; showvalues = last_perfs)
force_belapsed = false
end
_sizes = kron(sizevec, trues(length(libs)))
BenchmarkResult{T}(
DataFrame(Size = _sizes, Library = library, GFLOPS = gflop, Time = times),
threaded
)
BenchmarkResult{T,eltype(sizes)}(libs, sizes, gflop, times, threaded)
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import VectorizationBase

include("test-suite-preamble.jl")

@info("VectorizationBase.NUM_CORES is $(VectorizationBase.NUM_CORES)")
@info("VectorizationBase.num_cores() is $(VectorizationBase.num_cores())")

include("main.jl")