Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/test_kernelabstractions.jl
5582 views
1
module TestExamplesKernelAbstractions
2
3
using Test
4
using Trixi
5
6
include("test_trixi.jl")
7
8
EXAMPLES_DIR = examples_dir()
9
10
# Start with a clean environment: remove Trixi.jl output directory if it exists
11
outdir = "out"
12
Trixi.mpi_isroot() && isdir(outdir) && rm(outdir, recursive = true)
13
Trixi.MPI.Barrier(Trixi.mpi_comm())
14
15
@testset "basic" begin
16
@test Trixi._PREFERENCE_THREADING == :kernelabstractions
17
end
18
19
@testset "KernelAbstractions CPU 2D" begin
20
#! format: noindent
21
22
@trixi_testset "elixir_advection_basic_gpu.jl" begin
23
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
24
"elixir_advection_basic_gpu.jl"),
25
# Expected errors are exactly the same as with TreeMesh!
26
l2=8.311947673061856e-6,
27
linf=6.627000273229378e-5)
28
# Ensure that we do not have excessive memory allocations
29
# (e.g., from type instabilities)
30
semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.
31
@test_allocations(Trixi.rhs!, ode.p, sol, 75_000)
32
end
33
34
@trixi_testset "elixir_advection_basic_gpu.jl Float32" begin
35
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",
36
"elixir_advection_basic_gpu.jl"),
37
# Expected errors similar to reference on CPU
38
l2=[Float32(8.311947673061856e-6)],
39
linf=[Float32(6.627000273229378e-5)],
40
RealT_for_test_tolerances=Float32,
41
real_type=Float32)
42
# Ensure that we do not have excessive memory allocations
43
# (e.g., from type instabilities)
44
semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.
45
@test_allocations(Trixi.rhs!, ode.p, sol, 60_000)
46
end
47
end
48
49
@testset "KernelAbstractions CPU 3D" begin
50
#! format: noindent
51
52
@trixi_testset "elixir_advection_basic_gpu.jl" begin
53
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_3d_dgsem",
54
"elixir_advection_basic_gpu.jl"),
55
# Expected errors are exactly the same as with TreeMesh!
56
l2=[0.00016263963870641478],
57
linf=[0.0014537194925779984])
58
# Ensure that we do not have excessive memory allocations
59
# (e.g., from type instabilities)
60
semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.
61
@test_allocations(Trixi.rhs!, semi, sol, 450_000)
62
end
63
64
@trixi_testset "elixir_advection_basic_gpu.jl Float32" begin
65
@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_3d_dgsem",
66
"elixir_advection_basic_gpu.jl"),
67
# Expected errors similar to reference on CPU
68
l2=[Float32(0.00016263963870641478)],
69
linf=[Float32(0.0014537194925779984)],
70
RealT_for_test_tolerances=Float32,
71
real_type=Float32)
72
# Ensure that we do not have excessive memory allocations
73
# (e.g., from type instabilities)
74
semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.
75
@test_allocations(Trixi.rhs!, semi, sol, 370_000)
76
end
77
end
78
79
# Clean up afterwards: delete Trixi.jl output directory
80
Trixi.mpi_isroot() && isdir(outdir) && @test_nowarn rm(outdir, recursive = true)
81
Trixi.MPI.Barrier(Trixi.mpi_comm())
82
83
end # module
84
85