|
| 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 |
0 commit comments