Skip to content

Commit 7300439

Browse files
committed
Add LinalgBenchmarks
1 parent 75c3b87 commit 7300439

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
module LinalgBenchmarks
2+
3+
include(joinpath(@__DIR__, "..", "utils", "BenchUtils.jl"))
4+
5+
using .BenchUtils
6+
using BenchmarkTools
7+
using TensorKit
8+
using TOML
9+
10+
const SUITE = BenchmarkGroup()
11+
const all_parameters = TOML.parsefile(joinpath(@__DIR__, "benchparams.toml"))
12+
13+
# mul!
14+
# ----
15+
function init_mul_tensors(T, V)
16+
A = randn(T, V[1] V[2])
17+
B = randn(T, V[2] V[3])
18+
C = randn(T, V[1] V[3])
19+
return A, B, C
20+
end
21+
22+
function benchmark_mul!(benchgroup, params::Dict)
23+
haskey(benchgroup, "mul") || addgroup!(benchgroup, "mul")
24+
bench = benchgroup["mul"]
25+
for kwargs in expand_kwargs(params)
26+
benchmark_mul!(bench; kwargs...)
27+
end
28+
return nothing
29+
end
30+
31+
function benchmark_mul!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
32+
T_ = parse_type(T)
33+
I_ = parse_type(I)
34+
35+
Vs = generate_space.(I_, dims, sigmas)
36+
init() = init_mul_tensors(T_, Vs)
37+
38+
bench[T, I, dims, sigmas] = @benchmarkable mul!(C, A, B) setup = ((A, B, C) = $init())
39+
40+
return nothing
41+
end
42+
43+
if haskey(all_parameters, "mul")
44+
g = addgroup!(SUITE, "mul")
45+
for params in all_parameters["mul"]
46+
benchmark_mul!(g, params)
47+
end
48+
end
49+
50+
# svd!
51+
# ----
52+
function init_svd_tensor(T, V)
53+
A = randn(T, V[1] V[2])
54+
return A
55+
end
56+
57+
function benchmark_svd!(benchgroup, params::Dict)
58+
haskey(benchgroup, "svd") || addgroup!(benchgroup, "svd")
59+
bench = benchgroup["svd"]
60+
for kwargs in expand_kwargs(params)
61+
benchmark_svd!(bench; kwargs...)
62+
end
63+
return nothing
64+
end
65+
function benchmark_svd!(bench; sigmas=nothing, T="Float64", I="Trivial", dims)
66+
T_ = parse_type(T)
67+
I_ = parse_type(I)
68+
Vs = generate_space.(I_, dims, sigmas)
69+
init() = init_svd_tensor(T_, Vs)
70+
bench[T, I, dims, sigmas] = @benchmarkable tsvd!(A) setup = (A = $init())
71+
return nothing
72+
end
73+
74+
if haskey(all_parameters, "svd")
75+
g = addgroup!(SUITE, "svd")
76+
for params in all_parameters["svd"]
77+
benchmark_svd!(g, params)
78+
end
79+
end
80+
81+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[[mul]]
2+
T = ["Float64", "ComplexF64"]
3+
I = "Trivial"
4+
dims = [[2, 2, 2], [8, 8, 8], [32, 32, 32], [64, 64, 64], [128, 128, 128]]
5+
6+
[[mul]]
7+
T = ["Float64", "ComplexF64"]
8+
I = "Z2Irrep"
9+
dims = [[2, 2, 2], [8, 8, 8], [32, 32, 32], [64, 64, 64], [128, 128, 128]]
10+
sigmas = [[0.5, 0.5, 0.5]]
11+
12+
[[svd]]
13+
T = ["Float64", "ComplexF64"]
14+
I = "Trivial"
15+
dims = [[2, 2], [8, 8], [32, 32], [64, 64], [128, 128]]
16+
17+
[[svd]]
18+
T = ["Float64", "ComplexF64"]
19+
I = "Z2Irrep"
20+
dims = [[2, 2], [8, 8], [32, 32], [64, 64], [128, 128]]
21+
sigmas = [[0.5, 0.5]]

0 commit comments

Comments
 (0)