|
| 1 | +module TestAMDGPU2D |
| 2 | + |
| 3 | +using Test |
| 4 | +using Trixi |
| 5 | + |
| 6 | +include("test_trixi.jl") |
| 7 | + |
| 8 | +EXAMPLES_DIR = joinpath(examples_dir(), "p4est_2d_dgsem") |
| 9 | + |
| 10 | +# Start with a clean environment: remove Trixi.jl output directory if it exists |
| 11 | +outdir = "out" |
| 12 | +isdir(outdir) && rm(outdir, recursive = true) |
| 13 | + |
| 14 | +@testset "AMDGPU 2D" begin |
| 15 | +#! format: noindent |
| 16 | + |
| 17 | +@trixi_testset "elixir_advection_basic_gpu.jl native" begin |
| 18 | + @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic_gpu.jl"), |
| 19 | + # Expected errors are exactly the same as with TreeMesh! |
| 20 | + l2=8.311947673061856e-6, |
| 21 | + linf=6.627000273229378e-5) |
| 22 | + # Ensure that we do not have excessive memory allocations |
| 23 | + # (e.g., from type instabilities) |
| 24 | + semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem. |
| 25 | + @test_allocations(Trixi.rhs!, semi, sol, 1000) |
| 26 | + @test real(ode.p.solver) == Float64 |
| 27 | + @test real(ode.p.solver.basis) == Float64 |
| 28 | + @test real(ode.p.solver.mortar) == Float64 |
| 29 | + # TODO: `mesh` is currently not `adapt`ed correctly |
| 30 | + @test real(ode.p.mesh) == Float64 |
| 31 | + |
| 32 | + @test ode.u0 isa Array |
| 33 | + @test ode.p.solver.basis.derivative_matrix isa Array |
| 34 | + |
| 35 | + @test Trixi.storage_type(ode.p.cache.elements) === Array |
| 36 | + @test Trixi.storage_type(ode.p.cache.interfaces) === Array |
| 37 | + @test Trixi.storage_type(ode.p.cache.boundaries) === Array |
| 38 | + @test Trixi.storage_type(ode.p.cache.mortars) === Array |
| 39 | +end |
| 40 | + |
| 41 | +@trixi_testset "elixir_advection_basic_gpu.jl Float32 / AMDGPU" begin |
| 42 | + # Using AMDGPU inside the testset since otherwise the bindings are hiddend by the anonymous modules |
| 43 | + using AMDGPU |
| 44 | + @test_trixi_include(joinpath(EXAMPLES_DIR, "elixir_advection_basic_gpu.jl"), |
| 45 | + # Expected errors are exactly the same as with TreeMesh! |
| 46 | + l2=[Float32(8.311947673061856e-6)], |
| 47 | + linf=[Float32(6.627000273229378e-5)], |
| 48 | + RealT_for_test_tolerances=Float32, |
| 49 | + real_type=Float32, |
| 50 | + storage_type=ROCArray) |
| 51 | + # Ensure that we do not have excessive memory allocations |
| 52 | + # (e.g., from type instabilities) |
| 53 | + semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem. |
| 54 | + @test_allocations(Trixi.rhs!, semi, sol, 50_000) |
| 55 | + @test real(ode.p.solver) == Float32 |
| 56 | + @test real(ode.p.solver.basis) == Float32 |
| 57 | + @test real(ode.p.solver.mortar) == Float32 |
| 58 | + # TODO: `mesh` is currently not `adapt`ed correctly |
| 59 | + @test real(ode.p.mesh) == Float64 |
| 60 | + |
| 61 | + @test ode.u0 isa ROCArray |
| 62 | + @test ode.p.solver.basis.derivative_matrix isa ROCArray |
| 63 | + |
| 64 | + @test Trixi.storage_type(ode.p.cache.elements) === ROCArray |
| 65 | + @test Trixi.storage_type(ode.p.cache.interfaces) === ROCArray |
| 66 | + @test Trixi.storage_type(ode.p.cache.boundaries) === ROCArray |
| 67 | + @test Trixi.storage_type(ode.p.cache.mortars) === ROCArray |
| 68 | +end |
| 69 | + |
| 70 | +# Clean up afterwards: delete Trixi.jl output directory |
| 71 | +@test_nowarn isdir(outdir) && rm(outdir, recursive = true) |
| 72 | +end |
| 73 | +end # module |
0 commit comments