Skip to content

Commit 4304bce

Browse files
authored
Format (#167)
* format * Add .JuliaFormatter.toml
1 parent 6d6a32b commit 4304bce

28 files changed

+1463
-732
lines changed

.JuliaFormatter.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
indent = 2
2+
margin = 80
3+
remove_extra_newlines = true
4+
long_to_short_function_def = true
5+
format_docstrings = true
6+
trailing_comma = false
7+
separate_kwargs_with_semicolon = true

benchmark/staticarraybench.jl

Lines changed: 81 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,101 @@ maybe_sleep() = iszero(SLEEPTIME) || sleep(SLEEPTIME)
99
# BenchmarkTools.DEFAULT_PARAMETERS.samples = 1_000_000
1010
# BenchmarkTools.DEFAULT_PARAMETERS.seconds = 10
1111

12-
matrix_sizes(x::Integer) = (x,x,x)
12+
matrix_sizes(x::Integer) = (x, x, x)
1313
matrix_sizes(x::NTuple{3}) = x
1414

15-
const matmulmethodnames = [:SMatrix, :MMatrix, :OctavianStatic, :OctavianDynamic];
16-
function fill_bench_results!(br, lp, (M,K,N), t, i, j)
17-
name = matmulmethodnames[j]
18-
br[i,j,1] = t
19-
gflops = 2e-9M*K*N / t
20-
br[i,j,2] = gflops
21-
lp[j+1] = (name, gflops)
22-
nothing
15+
const matmulmethodnames =
16+
[:SMatrix, :MMatrix, :OctavianStatic, :OctavianDynamic];
17+
function fill_bench_results!(br, lp, (M, K, N), t, i, j)
18+
name = matmulmethodnames[j]
19+
br[i, j, 1] = t
20+
gflops = 2e-9M * K * N / t
21+
br[i, j, 2] = gflops
22+
lp[j+1] = (name, gflops)
23+
nothing
2324
end
2425

2526
function runbenches(sr, ::Type{T} = Float64) where {T}
26-
bench_results = Array{Float64}(undef, length(sr), 4, 2)
27-
p = Progress(length(sr))
28-
last_perfs = Vector{Tuple{Symbol,Union{Float64,NTuple{3,Int}}}}(undef, size(bench_results,2) + 1)
29-
for (i,s) enumerate(sr)
30-
M, K, N = matrix_sizes(s)
31-
last_perfs[1] = (:Size, (M,K,N))
32-
Astatic = @SMatrix rand(T, M, K);
33-
Bstatic = @SMatrix rand(T, K, N);
34-
maybe_sleep()
35-
t = @belapsed $(Ref(Astatic))[] * $(Ref(Bstatic))[]
36-
fill_bench_results!(bench_results, last_perfs, (M,K,N), t, i, 1)
37-
Amutable = MArray(Astatic);
38-
Bmutable = MArray(Bstatic);
39-
Cmutable = MMatrix{M,N,T}(undef);
40-
maybe_sleep()
41-
t = @belapsed mul!($Cmutable, $Amutable, $Bmutable)
42-
fill_bench_results!(bench_results, last_perfs, (M,K,N), t, i, 2)
43-
Cmutable0 = copy(Cmutable); Cmutable .= NaN;
44-
maybe_sleep()
45-
t = @belapsed matmul!($Cmutable, $Amutable, $Bmutable)
46-
fill_bench_results!(bench_results, last_perfs, (M,K,N), t, i, 3)
47-
A = Array(Amutable); B = Array(Bmutable); C = Array(Cmutable);
48-
maybe_sleep()
49-
t = @belapsed matmul!($C, $A, $B)
50-
fill_bench_results!(bench_results, last_perfs, (M,K,N), t, i, 4)
51-
@assert Array(Cmutable) Array(Cmutable0) C
52-
ProgressMeter.next!(p; showvalues = last_perfs)
53-
end
54-
bench_results
27+
bench_results = Array{Float64}(undef, length(sr), 4, 2)
28+
p = Progress(length(sr))
29+
last_perfs = Vector{Tuple{Symbol,Union{Float64,NTuple{3,Int}}}}(
30+
undef,
31+
size(bench_results, 2) + 1
32+
)
33+
for (i, s) enumerate(sr)
34+
M, K, N = matrix_sizes(s)
35+
last_perfs[1] = (:Size, (M, K, N))
36+
Astatic = @SMatrix rand(T, M, K)
37+
Bstatic = @SMatrix rand(T, K, N)
38+
maybe_sleep()
39+
t = @belapsed $(Ref(Astatic))[] * $(Ref(Bstatic))[]
40+
fill_bench_results!(bench_results, last_perfs, (M, K, N), t, i, 1)
41+
Amutable = MArray(Astatic)
42+
Bmutable = MArray(Bstatic)
43+
Cmutable = MMatrix{M,N,T}(undef)
44+
maybe_sleep()
45+
t = @belapsed mul!($Cmutable, $Amutable, $Bmutable)
46+
fill_bench_results!(bench_results, last_perfs, (M, K, N), t, i, 2)
47+
Cmutable0 = copy(Cmutable)
48+
Cmutable .= NaN
49+
maybe_sleep()
50+
t = @belapsed matmul!($Cmutable, $Amutable, $Bmutable)
51+
fill_bench_results!(bench_results, last_perfs, (M, K, N), t, i, 3)
52+
A = Array(Amutable)
53+
B = Array(Bmutable)
54+
C = Array(Cmutable)
55+
maybe_sleep()
56+
t = @belapsed matmul!($C, $A, $B)
57+
fill_bench_results!(bench_results, last_perfs, (M, K, N), t, i, 4)
58+
@assert Array(Cmutable) Array(Cmutable0) C
59+
ProgressMeter.next!(p; showvalues = last_perfs)
60+
end
61+
bench_results
5562
end
5663

5764
sizerange = 2:48
5865
br = runbenches(sizerange);
5966
using DataFrames, VegaLite
6067

61-
df = DataFrame(@view(br[:,:,2]));
68+
df = DataFrame(@view(br[:, :, 2]));
6269
rename!(df, matmulmethodnames);
6370
df.Size = sizerange
6471

6572
function pick_suffix(desc = "")
66-
suffix = if Bool(Octavian.VectorizationBase.has_feature(Val(:x86_64_avx512f)))
67-
"AVX512"
68-
elseif Bool(Octavian.VectorizationBase.has_feature(Val(:x86_64_avx2)))
69-
"AVX2"
70-
elseif Bool(Octavian.VectorizationBase.has_feature(Val(:x86_64_avx)))
71-
"AVX"
72-
else
73-
"REGSIZE$(Octavian.VectorizationBase.register_size())"
74-
end
75-
if desc != ""
76-
suffix *= '_' * desc
77-
end
78-
"$(Sys.CPU_NAME)_$suffix"
73+
suffix = if Bool(Octavian.VectorizationBase.has_feature(Val(:x86_64_avx512f)))
74+
"AVX512"
75+
elseif Bool(Octavian.VectorizationBase.has_feature(Val(:x86_64_avx2)))
76+
"AVX2"
77+
elseif Bool(Octavian.VectorizationBase.has_feature(Val(:x86_64_avx)))
78+
"AVX"
79+
else
80+
"REGSIZE$(Octavian.VectorizationBase.register_size())"
81+
end
82+
if desc != ""
83+
suffix *= '_' * desc
84+
end
85+
"$(Sys.CPU_NAME)_$suffix"
7986
end
8087

81-
dfs = stack(df, matmulmethodnames, variable_name = :MatMulType, value_name = :GFLOPS);
82-
p = dfs |> @vlplot(:line, x = :Size, y = :GFLOPS, width = 900, height = 600, color = {:MatMulType});
83-
save(joinpath(pkgdir(Octavian), "docs/src/assets/sizedarraybenchmarks_$(pick_suffix()).svg"), p)
84-
85-
86-
88+
dfs = stack(
89+
df,
90+
matmulmethodnames;
91+
variable_name = :MatMulType,
92+
value_name = :GFLOPS
93+
);
94+
p =
95+
dfs |> @vlplot(
96+
:line,
97+
x = :Size,
98+
y = :GFLOPS,
99+
width = 900,
100+
height = 600,
101+
color = {:MatMulType}
102+
);
103+
save(
104+
joinpath(
105+
pkgdir(Octavian),
106+
"docs/src/assets/sizedarraybenchmarks_$(pick_suffix()).svg"
107+
),
108+
p
109+
)

0 commit comments

Comments
 (0)