Path: blob/main/test/test_kernelabstractions.jl
5582 views
module TestExamplesKernelAbstractions12using Test3using Trixi45include("test_trixi.jl")67EXAMPLES_DIR = examples_dir()89# Start with a clean environment: remove Trixi.jl output directory if it exists10outdir = "out"11Trixi.mpi_isroot() && isdir(outdir) && rm(outdir, recursive = true)12Trixi.MPI.Barrier(Trixi.mpi_comm())1314@testset "basic" begin15@test Trixi._PREFERENCE_THREADING == :kernelabstractions16end1718@testset "KernelAbstractions CPU 2D" begin19#! format: noindent2021@trixi_testset "elixir_advection_basic_gpu.jl" begin22@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",23"elixir_advection_basic_gpu.jl"),24# Expected errors are exactly the same as with TreeMesh!25l2=8.311947673061856e-6,26linf=6.627000273229378e-5)27# Ensure that we do not have excessive memory allocations28# (e.g., from type instabilities)29semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.30@test_allocations(Trixi.rhs!, ode.p, sol, 75_000)31end3233@trixi_testset "elixir_advection_basic_gpu.jl Float32" begin34@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_2d_dgsem",35"elixir_advection_basic_gpu.jl"),36# Expected errors similar to reference on CPU37l2=[Float32(8.311947673061856e-6)],38linf=[Float32(6.627000273229378e-5)],39RealT_for_test_tolerances=Float32,40real_type=Float32)41# Ensure that we do not have excessive memory allocations42# (e.g., from type instabilities)43semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.44@test_allocations(Trixi.rhs!, ode.p, sol, 60_000)45end46end4748@testset "KernelAbstractions CPU 3D" begin49#! format: noindent5051@trixi_testset "elixir_advection_basic_gpu.jl" begin52@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_3d_dgsem",53"elixir_advection_basic_gpu.jl"),54# Expected errors are exactly the same as with TreeMesh!55l2=[0.00016263963870641478],56linf=[0.0014537194925779984])57# Ensure that we do not have excessive memory allocations58# (e.g., from type instabilities)59semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.60@test_allocations(Trixi.rhs!, semi, sol, 450_000)61end6263@trixi_testset "elixir_advection_basic_gpu.jl Float32" begin64@test_trixi_include(joinpath(EXAMPLES_DIR, "p4est_3d_dgsem",65"elixir_advection_basic_gpu.jl"),66# Expected errors similar to reference on CPU67l2=[Float32(0.00016263963870641478)],68linf=[Float32(0.0014537194925779984)],69RealT_for_test_tolerances=Float32,70real_type=Float32)71# Ensure that we do not have excessive memory allocations72# (e.g., from type instabilities)73semi = ode.p # `semidiscretize` adapts the semi, so we need to obtain it from the ODE problem.74@test_allocations(Trixi.rhs!, semi, sol, 370_000)75end76end7778# Clean up afterwards: delete Trixi.jl output directory79Trixi.mpi_isroot() && isdir(outdir) && @test_nowarn rm(outdir, recursive = true)80Trixi.MPI.Barrier(Trixi.mpi_comm())8182end # module838485