Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/benchmark/CUDA/run.jl
5586 views
1
using Trixi
2
using CUDA
3
using TimerOutputs
4
using JSON
5
6
function main(elixir_path)
7
8
# setup
9
maxiters = 50
10
initial_refinement_level = 3
11
storage_type = CuArray
12
real_type = Float64
13
14
println("Warming up...")
15
16
# start simulation with tiny final time to trigger compilation
17
duration_compile = @elapsed begin
18
trixi_include(elixir_path,
19
tspan = (0.0, 1e-14),
20
storage_type = storage_type,
21
real_type = real_type)
22
trixi_include(elixir_path,
23
tspan = (0.0, 1e-14),
24
storage_type = storage_type,
25
real_type = Float32)
26
end
27
28
println("Finished warm-up in $duration_compile seconds\n")
29
println("Starting simulation...")
30
31
# start the real simulation
32
duration_elixir = @elapsed trixi_include(elixir_path,
33
maxiters = maxiters,
34
initial_refinement_level = initial_refinement_level,
35
storage_type = storage_type,
36
real_type = real_type)
37
38
# store metrics (on every rank!)
39
metrics = Dict{String, Float64}("elapsed time" => duration_elixir)
40
41
# read TimerOutputs timings
42
timer = Trixi.timer()
43
metrics["total time"] = 1.0e-9 * TimerOutputs.tottime(timer)
44
metrics["rhs! time"] = 1.0e-9 * TimerOutputs.time(timer["rhs!"])
45
46
# compute performance index
47
latest_semi = @invokelatest (@__MODULE__).semi
48
nrhscalls = Trixi.ncalls(latest_semi.performance_counter)
49
walltime = 1.0e-9 * take!(latest_semi.performance_counter)
50
metrics["PID"] = walltime * Trixi.mpi_nranks() /
51
(Trixi.ndofsglobal(latest_semi) * nrhscalls)
52
53
# write json file
54
open("metrics.out", "w") do f
55
indent = 2
56
JSON.print(f, metrics, indent)
57
end
58
59
# run profiler
60
maxiters = 5
61
initial_refinement_level = 1
62
63
println("Running profiler (Float64)...")
64
trixi_include(elixir_path,
65
maxiters = maxiters,
66
initial_refinement_level = initial_refinement_level,
67
storage_type = storage_type,
68
real_type = Float64,
69
run_profiler = true)
70
71
open("profile_float64.txt", "w") do io
72
show(io, @invokelatest (@__MODULE__).prof_result)
73
end
74
75
println("Running profiler (Float32)...")
76
trixi_include(elixir_path,
77
maxiters = maxiters,
78
initial_refinement_level = initial_refinement_level,
79
storage_type = storage_type,
80
real_type = Float32,
81
run_profiler = true)
82
83
open("profile_float32.txt", "w") do io
84
show(io, @invokelatest (@__MODULE__).prof_result)
85
end
86
end
87
88
# hardcoded elixir
89
elixir_path = joinpath(@__DIR__(), "elixir_euler_taylor_green_vortex.jl")
90
91
main(elixir_path)
92
93