forked from trixi-framework/Trixi.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_performance_specializations_3d.jl
177 lines (151 loc) · 7.52 KB
/
test_performance_specializations_3d.jl
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
module TestPerformanceSpecializations3D
using Test
using Trixi
include("test_trixi.jl")
# Start with a clean environment: remove Trixi.jl output directory if it exists
outdir = "out"
isdir(outdir) && rm(outdir, recursive = true)
@testset "Performance specializations 3D" begin
#! format: noindent
@timed_testset "TreeMesh3D, flux_shima_etal_turbo" begin
trixi_include(@__MODULE__,
joinpath(examples_dir(), "tree_3d_dgsem", "elixir_euler_ec.jl"),
initial_refinement_level = 0, tspan = (0.0, 0.0), polydeg = 3,
volume_flux = flux_shima_etal_turbo,
surface_flux = flux_shima_etal_turbo)
u_ode = copy(sol.u[end])
du_ode = zero(u_ode)
# Preserve original memory since it will be `unsafe_wrap`ped and might
# thus otherwise be garbage collected
GC.@preserve u_ode du_ode begin
u = Trixi.wrap_array(u_ode, semi)
du = Trixi.wrap_array(du_ode, semi)
nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)
# Call the optimized default version
du .= 0
Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux,
semi.solver, semi.cache, true)
du_specialized = du[:, :, :, :, 1]
# Call the plain version - note the argument type `Function` of
# `semi.solver.volume_integral.volume_flux`
du .= 0
invoke(Trixi.flux_differencing_kernel!,
Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),
typeof(nonconservative_terms), typeof(semi.equations),
Function, typeof(semi.solver), typeof(semi.cache), Bool},
du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)
du_baseline = du[:, :, :, :, 1]
@test du_specialized ≈ du_baseline
end
end
@timed_testset "TreeMesh3D, flux_ranocha_turbo" begin
trixi_include(@__MODULE__,
joinpath(examples_dir(), "tree_3d_dgsem", "elixir_euler_ec.jl"),
initial_refinement_level = 0, tspan = (0.0, 0.0), polydeg = 3,
volume_flux = flux_ranocha_turbo, surface_flux = flux_ranocha_turbo)
u_ode = copy(sol.u[end])
du_ode = zero(u_ode)
# Preserve original memory since it will be `unsafe_wrap`ped and might
# thus otherwise be garbage collected
GC.@preserve u_ode du_ode begin
u = Trixi.wrap_array(u_ode, semi)
du = Trixi.wrap_array(du_ode, semi)
nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)
# Call the optimized default version
du .= 0
Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux,
semi.solver, semi.cache, true)
du_specialized = du[:, :, :, :, 1]
# Call the plain version - note the argument type `Function` of
# `semi.solver.volume_integral.volume_flux`
du .= 0
invoke(Trixi.flux_differencing_kernel!,
Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),
typeof(nonconservative_terms), typeof(semi.equations),
Function, typeof(semi.solver), typeof(semi.cache), Bool},
du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)
du_baseline = du[:, :, :, :, 1]
@test du_specialized ≈ du_baseline
end
end
@timed_testset "StructuredMesh3D, flux_shima_etal_turbo" begin
trixi_include(@__MODULE__,
joinpath(examples_dir(), "structured_3d_dgsem", "elixir_euler_ec.jl"),
cells_per_dimension = (1, 1, 1), tspan = (0.0, 0.0), polydeg = 3,
volume_flux = flux_shima_etal_turbo,
surface_flux = flux_shima_etal_turbo)
u_ode = copy(sol.u[end])
du_ode = zero(u_ode)
# Preserve original memory since it will be `unsafe_wrap`ped and might
# thus otherwise be garbage collected
GC.@preserve u_ode du_ode begin
u = Trixi.wrap_array(u_ode, semi)
du = Trixi.wrap_array(du_ode, semi)
nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)
# Call the optimized default version
du .= 0
Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux,
semi.solver, semi.cache, true)
du_specialized = du[:, :, :, :, 1]
# Call the plain version - note the argument type `Function` of
# `semi.solver.volume_integral.volume_flux`
du .= 0
invoke(Trixi.flux_differencing_kernel!,
Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),
typeof(nonconservative_terms), typeof(semi.equations),
Function, typeof(semi.solver), typeof(semi.cache), Bool},
du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)
du_baseline = du[:, :, :, :, 1]
@test du_specialized ≈ du_baseline
end
end
@timed_testset "StructuredMesh3D, flux_ranocha_turbo" begin
trixi_include(@__MODULE__,
joinpath(examples_dir(), "structured_3d_dgsem", "elixir_euler_ec.jl"),
cells_per_dimension = (1, 1, 1), tspan = (0.0, 0.0), polydeg = 3,
volume_flux = flux_ranocha_turbo, surface_flux = flux_ranocha_turbo)
u_ode = copy(sol.u[end])
du_ode = zero(u_ode)
# Preserve original memory since it will be `unsafe_wrap`ped and might
# thus otherwise be garbage collected
GC.@preserve u_ode du_ode begin
u = Trixi.wrap_array(u_ode, semi)
du = Trixi.wrap_array(du_ode, semi)
nonconservative_terms = Trixi.have_nonconservative_terms(semi.equations)
# Call the optimized default version
du .= 0
Trixi.flux_differencing_kernel!(du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux,
semi.solver, semi.cache, true)
du_specialized = du[:, :, :, :, 1]
# Call the plain version - note the argument type `Function` of
# `semi.solver.volume_integral.volume_flux`
du .= 0
invoke(Trixi.flux_differencing_kernel!,
Tuple{typeof(du), typeof(u), Integer, typeof(semi.mesh),
typeof(nonconservative_terms), typeof(semi.equations),
Function, typeof(semi.solver), typeof(semi.cache), Bool},
du, u, 1, semi.mesh,
nonconservative_terms, semi.equations,
semi.solver.volume_integral.volume_flux, semi.solver, semi.cache, true)
du_baseline = du[:, :, :, :, 1]
@test du_specialized ≈ du_baseline
end
end
end
# Clean up afterwards: delete Trixi.jl output directory
@test_nowarn rm(outdir, recursive = true)
end #module