-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathbenchmark.jl
More file actions
66 lines (58 loc) · 2 KB
/
benchmark.jl
File metadata and controls
66 lines (58 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Pkg
Pkg.add("ForwardDiff")
using ADTypes: ADTypes
using DifferentiationInterface, DifferentiationInterfaceTest
import DifferentiationInterface as DI
import DifferentiationInterfaceTest as DIT
using ForwardDiff: ForwardDiff
using StaticArrays: StaticArrays, @SVector
using Test
LOGGING = get(ENV, "CI", "false") == "false"
@info "Printing allocs"
const f! = DIT.diffsquare!
x, y = rand(10), zeros(9);
backend = MyAutoSparse(AutoForwardDiff());
prep = prepare_jacobian(f!, y, backend, x);
J = similar(sparsity_pattern(prep), Float64)
jacobian!(f!, y, J, prep, backend, x)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate = 1 jacobian!(f!, y, J, prep, backend, x)
Profile.Allocs.print()
@info "Printing allocs done"
@testset verbose = true "Benchmarking static" begin
filtered_static_scenarios = filter(static_scenarios(; include_batchified = false)) do scen
DIT.function_place(scen) == :out && DIT.operator_place(scen) == :out
end
data = benchmark_differentiation(
AutoForwardDiff(),
filtered_static_scenarios;
benchmark = :prepared,
excluded = [:hessian, :pullback], # TODO: figure this out
logging = LOGGING,
)
@testset "Analyzing benchmark results" begin
@testset "$(row[:scenario])" for row in eachrow(data)
@test row[:allocs] == 0
end
end
end
@testset "Benchmarking sparse" begin
filtered_sparse_scenarios = filter(sparse_scenarios(; band_sizes = [])) do scen
DIT.function_place(scen) == :in &&
DIT.operator_place(scen) == :in &&
scen.x isa AbstractVector &&
scen.y isa AbstractVector
end
data = benchmark_differentiation(
MyAutoSparse(AutoForwardDiff()),
filtered_sparse_scenarios;
benchmark = :prepared,
excluded = SECOND_ORDER,
logging = LOGGING,
)
@testset "Analyzing benchmark results" begin
@testset "$(row[:scenario])" for row in eachrow(data)
@test row[:allocs] == 0
end
end
end