comparison benchmark/benchmarks.jl @ 1362:a6918dfb0cf5 bugfix/lazytensors

Merge with default
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sun, 21 May 2023 20:51:52 +0200
parents f59228534d3a
children 127d2558926e
comparison
equal deleted inserted replaced
1359:646027afe74b 1362:a6918dfb0cf5
1 using BenchmarkTools
2 using Sbplib
3 using Sbplib.Grids
4 using Sbplib.SbpOperators
5 using Sbplib.RegionIndices
6 using Sbplib.LazyTensors
7
8 const SUITE = BenchmarkGroup()
9
10
11 sz(d) = ntuple(i->100, d)
12 ll(d) = ntuple(i->0., d)
13 lu(d) = ntuple(i->1., d)
14
15 g1 = equidistant_grid(sz(1)[1],ll(1)[1],lu(1)[1])
16 g2 = equidistant_grid(sz(2),ll(2),lu(2))
17 g3 = equidistant_grid(sz(3),ll(3),lu(3))
18
19 v1 = rand(sz(1)...)
20 v2 = rand(sz(2)...)
21 v3 = rand(sz(3)...)
22
23 u1 = rand(sz(1)...)
24 u2 = rand(sz(2)...)
25 u3 = rand(sz(3)...)
26
27 stencil_set = read_stencil_set(joinpath(sbp_operators_path(),"standard_diagonal.toml"); order=4)
28
29 SUITE["derivatives"] = BenchmarkGroup()
30
31
32 SUITE["derivatives"]["first_derivative"] = BenchmarkGroup()
33
34 D₁ = first_derivative(g1,stencil_set)
35 SUITE["derivatives"]["first_derivative"]["1D"] = @benchmarkable $u1 .= $D₁*$v1
36
37 Dx = first_derivative(g2,stencil_set,1)
38 Dy = first_derivative(g2,stencil_set,2)
39 SUITE["derivatives"]["first_derivative"]["2D"] = BenchmarkGroup()
40 SUITE["derivatives"]["first_derivative"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2
41 SUITE["derivatives"]["first_derivative"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2
42
43 Dx = first_derivative(g3,stencil_set,1)
44 Dy = first_derivative(g3,stencil_set,2)
45 Dz = first_derivative(g3,stencil_set,3)
46 SUITE["derivatives"]["first_derivative"]["3D"] = BenchmarkGroup()
47 SUITE["derivatives"]["first_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3
48 SUITE["derivatives"]["first_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3
49 SUITE["derivatives"]["first_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3
50
51
52 SUITE["derivatives"]["second_derivative"] = BenchmarkGroup()
53
54 D₂ = second_derivative(g1,stencil_set)
55 SUITE["derivatives"]["second_derivative"]["1D"] = @benchmarkable $u1 .= $D₂*$v1
56
57 Dx = second_derivative(g2,stencil_set,1)
58 Dy = second_derivative(g2,stencil_set,2)
59 SUITE["derivatives"]["second_derivative"]["2D"] = BenchmarkGroup()
60 SUITE["derivatives"]["second_derivative"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2
61 SUITE["derivatives"]["second_derivative"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2
62
63 Dx = second_derivative(g3,stencil_set,1)
64 Dy = second_derivative(g3,stencil_set,2)
65 Dz = second_derivative(g3,stencil_set,3)
66 SUITE["derivatives"]["second_derivative"]["3D"] = BenchmarkGroup()
67 SUITE["derivatives"]["second_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3
68 SUITE["derivatives"]["second_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3
69 SUITE["derivatives"]["second_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3
70
71
72
73 SUITE["derivatives"]["addition"] = BenchmarkGroup()
74
75 D₁ = first_derivative(g1,stencil_set)
76 D₂ = second_derivative(g1,stencil_set)
77 SUITE["derivatives"]["addition"]["1D"] = BenchmarkGroup()
78 SUITE["derivatives"]["addition"]["1D"]["apply,add"] = @benchmarkable $u1 .= $D₁*$v1 + $D₂*$v1
79 SUITE["derivatives"]["addition"]["1D"]["add,apply"] = @benchmarkable $u1 .= ($D₁ + $D₂)*$v1
80
81 Dxx = second_derivative(g2,stencil_set,1)
82 Dyy = second_derivative(g2,stencil_set,2)
83 SUITE["derivatives"]["addition"]["2D"] = BenchmarkGroup()
84 SUITE["derivatives"]["addition"]["2D"]["apply,add"] = @benchmarkable $u2 .= $Dxx*$v2 + $Dyy*$v2
85 SUITE["derivatives"]["addition"]["2D"]["add,apply"] = @benchmarkable $u2 .= ($Dxx + $Dyy)*$v2
86
87 Dxx = second_derivative(g3,stencil_set,1)
88 Dyy = second_derivative(g3,stencil_set,2)
89 Dzz = second_derivative(g3,stencil_set,3)
90 SUITE["derivatives"]["addition"]["3D"] = BenchmarkGroup()
91 SUITE["derivatives"]["addition"]["3D"]["apply,add"] = @benchmarkable $u3 .= $Dxx*$v3 + $Dyy*$v3 + $Dzz*$v3
92 SUITE["derivatives"]["addition"]["3D"]["add,apply"] = @benchmarkable $u3 .= ($Dxx + $Dyy + $Dzz)*$v3
93
94
95 SUITE["derivatives"]["composition"] = BenchmarkGroup()
96
97 Dx = first_derivative(g1,stencil_set)
98 SUITE["derivatives"]["composition"]["1D"] = BenchmarkGroup()
99 SUITE["derivatives"]["composition"]["1D"]["apply,apply"] = @benchmarkable $u1 .= $Dx*($Dx*$v1)
100 SUITE["derivatives"]["composition"]["1D"]["compose,apply"] = @benchmarkable $u1 .= ($Dx∘$Dx)*$v1
101
102 Dx = first_derivative(g2,stencil_set,1)
103 Dy = first_derivative(g2,stencil_set,2)
104 SUITE["derivatives"]["composition"]["2D"] = BenchmarkGroup()
105 SUITE["derivatives"]["composition"]["2D"]["apply,apply"] = @benchmarkable $u2 .= $Dy*($Dx*$v2)
106 SUITE["derivatives"]["composition"]["2D"]["compose,apply"] = @benchmarkable $u2 .= ($Dy∘$Dx)*$v2
107
108 Dx = first_derivative(g3,stencil_set,1)
109 Dy = first_derivative(g3,stencil_set,2)
110 Dz = first_derivative(g3,stencil_set,3)
111 SUITE["derivatives"]["composition"]["3D"] = BenchmarkGroup()
112 SUITE["derivatives"]["composition"]["3D"]["xy"] = BenchmarkGroup()
113 SUITE["derivatives"]["composition"]["3D"]["xy"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dy*$v3)
114 SUITE["derivatives"]["composition"]["3D"]["xy"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dy)*$v3
115
116 SUITE["derivatives"]["composition"]["3D"]["yz"] = BenchmarkGroup()
117 SUITE["derivatives"]["composition"]["3D"]["yz"]["apply,apply"] = @benchmarkable $u3 .= $Dy*($Dz*$v3)
118 SUITE["derivatives"]["composition"]["3D"]["yz"]["compose,apply"] = @benchmarkable $u3 .= ($Dy∘$Dz)*$v3
119
120 SUITE["derivatives"]["composition"]["3D"]["xz"] = BenchmarkGroup()
121 SUITE["derivatives"]["composition"]["3D"]["xz"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dz*$v3)
122 SUITE["derivatives"]["composition"]["3D"]["xz"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dz)*$v3
123
124 SUITE["derivatives"]["composition"]["3D"]["xx"] = BenchmarkGroup()
125 SUITE["derivatives"]["composition"]["3D"]["xx"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dx*$v3)
126 SUITE["derivatives"]["composition"]["3D"]["xx"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dx)*$v3
127
128 SUITE["derivatives"]["composition"]["3D"]["yy"] = BenchmarkGroup()
129 SUITE["derivatives"]["composition"]["3D"]["yy"]["apply,apply"] = @benchmarkable $u3 .= $Dy*($Dy*$v3)
130 SUITE["derivatives"]["composition"]["3D"]["yy"]["compose,apply"] = @benchmarkable $u3 .= ($Dy∘$Dy)*$v3
131
132 SUITE["derivatives"]["composition"]["3D"]["zz"] = BenchmarkGroup()
133 SUITE["derivatives"]["composition"]["3D"]["zz"]["apply,apply"] = @benchmarkable $u3 .= $Dz*($Dz*$v3)
134 SUITE["derivatives"]["composition"]["3D"]["zz"]["compose,apply"] = @benchmarkable $u3 .= ($Dz∘$Dz)*$v3
135
136
137 SUITE["boundary_terms"] = BenchmarkGroup()
138
139 H = inner_product(g2, stencil_set)
140 H⁻¹ = inverse_inner_product(g2, stencil_set)
141 Dxx = second_derivative(g2, stencil_set, 1)
142 Dyy = second_derivative(g2, stencil_set, 2)
143
144 e₁ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,Lower}())
145 e₁ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,Upper}())
146 e₂ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,Lower}())
147 e₂ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,Upper}())
148
149 d₁ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{1,Lower}())
150 d₁ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{1,Upper}())
151 d₂ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{2,Lower}())
152 d₂ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{2,Upper}())
153
154 H₁ₗ = inner_product(boundary_grid(g2, CartesianBoundary{1,Lower}()), stencil_set)
155 H₁ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{1,Upper}()), stencil_set)
156 H₂ₗ = inner_product(boundary_grid(g2, CartesianBoundary{2,Lower}()), stencil_set)
157 H₂ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{2,Upper}()), stencil_set)
158
159 SUITE["boundary_terms"]["pre_composition"] = @benchmarkable $u2 .= $(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ)*$v2
160 SUITE["boundary_terms"]["composition"] = @benchmarkable $u2 .= ($H⁻¹∘$e₁ₗ'∘$H₁ₗ∘$d₁ₗ)*$v2
161 SUITE["boundary_terms"]["application"] = @benchmarkable $u2 .= $H⁻¹*$e₁ₗ'*$H₁ₗ* $d₁ₗ*$v2
162 # An investigation of these allocations can be found in the branch `allocation_test`
163
164 #TODO: Reorg with dimension as first level? To reduce operator creation?
165
166
167
168 SUITE["lazy_tensors"] = BenchmarkGroup()
169
170 SUITE["lazy_tensors"]["compositions"] = BenchmarkGroup()
171 s = ScalingTensor(1.,(10,))
172 u = rand(10)
173 v = similar(u)
174 s3 = s∘s∘s
175 s4 = s∘s∘s∘s
176 SUITE["lazy_tensors"]["compositions"]["s∘s∘s"] = @benchmarkable $v .= $s3*$u
177 SUITE["lazy_tensors"]["compositions"]["s∘s∘s∘s"] = @benchmarkable $v .= $s4*$u
178
179
180 SUITE