Skip to content

Commit

Permalink
Add and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyuxie committed Dec 18, 2024
1 parent 784d7b0 commit 3813679
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 20 deletions.
12 changes: 6 additions & 6 deletions benchmark/benchmark_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CUDA.@time TrixiCUDA.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
@info "Time for calc_volume_integral! on CPU"
@info "Time for volume_integral! on CPU"
@time Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)

Expand All @@ -86,7 +86,7 @@ CUDA.@time TrixiCUDA.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, ca
CUDA.@time TrixiCUDA.cuda_interface_flux!(mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_interface_flux! on CPU"
@info "Time for interface_flux! on CPU"
@time Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.surface_integral, solver, cache)
Expand All @@ -103,28 +103,28 @@ CUDA.@time TrixiCUDA.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditio
CUDA.@time TrixiCUDA.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_boundary_flux! on CPU"
@info "Time for boundary_flux! on CPU"
@time Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations,
solver.surface_integral, solver)

# Surface integral
@info "Time for surface_integral! on GPU"
CUDA.@time TrixiCUDA.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_surface_integral! on CPU"
@info "Time for surface_integral! on CPU"
@time Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral,
solver, cache)

# Jacobian
@info "Time for jacobian! on GPU"
CUDA.@time TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
@info "Time for apply_jacobian! on CPU"
@info "Time for jacobian! on CPU"
@time Trixi.apply_jacobian!(du, mesh, equations, solver, cache)

# Sources terms
@info "Time for sources! on GPU"
CUDA.@time TrixiCUDA.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu,
equations_gpu, cache_gpu)
@info "Time for calc_sources! on CPU"
@info "Time for sources! on CPU"
@time Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache)

# Semidiscretization process
Expand Down
14 changes: 7 additions & 7 deletions benchmark/benchmark_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CUDA.@time TrixiCUDA.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
@info "Time for calc_volume_integral! on CPU"
@info "Time for volume_integral! on CPU"
@time Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)

Expand All @@ -86,7 +86,7 @@ CUDA.@time TrixiCUDA.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, ca
CUDA.@time TrixiCUDA.cuda_interface_flux!(mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_interface_flux! on CPU"
@info "Time for interface_flux! on CPU"
@time Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.surface_integral, solver, cache)
Expand All @@ -103,7 +103,7 @@ CUDA.@time TrixiCUDA.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditio
CUDA.@time TrixiCUDA.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_boundary_flux! on CPU"
@info "Time for boundary_flux! on CPU"
@time Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations,
solver.surface_integral, solver)

Expand All @@ -121,29 +121,29 @@ CUDA.@time TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
CUDA.@time TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.check_cache_mortars(cache_gpu),
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_mortar_flux! on CPU"
@info "Time for mortar_flux! on CPU"
@time Trixi.calc_mortar_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.mortar, solver.surface_integral, solver, cache)

# Surface integral
@info "Time for surface_integral! on GPU"
CUDA.@time TrixiCUDA.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_surface_integral! on CPU"
@info "Time for surface_integral! on CPU"
@time Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral,
solver, cache)

# Jacobian
@info "Time for jacobian! on GPU"
CUDA.@time TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
@info "Time for apply_jacobian! on CPU"
@info "Time for jacobian! on CPU"
@time Trixi.apply_jacobian!(du, mesh, equations, solver, cache)

# Sources terms
@info "Time for sources! on GPU"
CUDA.@time TrixiCUDA.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu,
equations_gpu, cache_gpu)
@info "Time for calc_sources! on CPU"
@info "Time for sources! on CPU"
@time Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache)

# Semidiscretization process
Expand Down
14 changes: 7 additions & 7 deletions benchmark/benchmark_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CUDA.@time TrixiCUDA.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
@info "Time for calc_volume_integral! on CPU"
@info "Time for volume_integral! on CPU"
@time Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)

Expand All @@ -90,7 +90,7 @@ CUDA.@time TrixiCUDA.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, ca
CUDA.@time TrixiCUDA.cuda_interface_flux!(mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_interface_flux! on CPU"
@info "Time for interface_flux! on CPU"
@time Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.surface_integral, solver, cache)
Expand All @@ -107,7 +107,7 @@ CUDA.@time TrixiCUDA.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditio
CUDA.@time TrixiCUDA.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_boundary_flux! on CPU"
@info "Time for boundary_flux! on CPU"
@time Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations,
solver.surface_integral, solver)

Expand All @@ -125,29 +125,29 @@ CUDA.@time TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
CUDA.@time TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.check_cache_mortars(cache_gpu),
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_mortar_flux! on CPU"
@info "Time for mortar_flux! on CPU"
@time Trixi.calc_mortar_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.mortar, solver.surface_integral, solver, cache)

# Surface integral
@info "Time for surface_integral! on GPU"
CUDA.@time TrixiCUDA.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu)
@info "Time for calc_surface_integral! on CPU"
@info "Time for surface_integral! on CPU"
@time Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral,
solver, cache)

# Jacobian
@info "Time for jacobian! on GPU"
CUDA.@time TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
@info "Time for apply_jacobian! on CPU"
@info "Time for jacobian! on CPU"
@time Trixi.apply_jacobian!(du, mesh, equations, solver, cache)

# Sources terms
@info "Time for sources! on GPU"
CUDA.@time TrixiCUDA.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu,
equations_gpu, cache_gpu)
@info "Time for calc_sources! on CPU"
@info "Time for sources! on CPU"
@time Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache)

# Semidiscretization process
Expand Down
147 changes: 147 additions & 0 deletions benchmark/example.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using Trixi, TrixiCUDA
using CUDA
using BenchmarkTools

# Set the precision
RealT = Float32

equations = IdealGlmMhdEquations3D(RealT(5 / 3))

initial_condition = initial_condition_convergence_test

volume_flux = (flux_hindenlang_gassner, flux_nonconservative_powell)
solver = DGSEM(polydeg = 3,
surface_flux = (flux_lax_friedrichs, flux_nonconservative_powell),
volume_integral = VolumeIntegralFluxDifferencing(volume_flux), RealT = RealT)

coordinates_min = (-1.0f0, -1.0f0, -1.0f0)
coordinates_max = (1.0f0, 1.0f0, 1.0f0)
mesh = TreeMesh(coordinates_min, coordinates_max,
initial_refinement_level = 2,
n_cells_max = 10_000, RealT = RealT)

# Cache initialization
@info "Time for cache initialization on CPU"
@time semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver)
@info "Time for cache initialization on GPU"
CUDA.@time semi_gpu = SemidiscretizationHyperbolicGPU(mesh, equations, initial_condition, solver)

tspan = tspan_gpu = (0.0f0, 1.0f0)
t = t_gpu = 0.0f0

# Semi on CPU
(; mesh, equations, boundary_conditions, source_terms, solver, cache) = semi

# Semi on GPU
equations_gpu = semi_gpu.equations
mesh_gpu, solver_gpu, cache_gpu = semi_gpu.mesh, semi_gpu.solver, semi_gpu.cache
boundary_conditions_gpu = semi_gpu.boundary_conditions
source_terms_gpu = semi_gpu.source_terms

# ODE on CPU
ode = semidiscretize(semi, tspan)
u_ode = copy(ode.u0)
du_ode = similar(u_ode)
u = Trixi.wrap_array(u_ode, mesh, equations, solver, cache)
du = Trixi.wrap_array(du_ode, mesh, equations, solver, cache)

# ODE on GPU
ode_gpu = semidiscretizeGPU(semi_gpu, tspan_gpu)
u_gpu = copy(ode_gpu.u0)
du_gpu = similar(u_gpu)

# Reset du
@info "Time for reset_du! on GPU"
CUDA.@time TrixiCUDA.reset_du!(du_gpu)
@info "Time for reset_du! on CPU"
@time Trixi.reset_du!(du, solver, cache)

# Volume integral
@info "Time for volume_integral! on GPU"
CUDA.@time TrixiCUDA.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
@info "Time for volume_integral! on CPU"
@time Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)

# Prolong to interfaces
@info "Time for prolong2interfaces! on GPU"
CUDA.@time TrixiCUDA.cuda_prolong2interfaces!(u_gpu, mesh_gpu, equations_gpu, cache_gpu)
@info "Time for prolong2interfaces! on CPU"
@time Trixi.prolong2interfaces!(cache, u, mesh, equations, solver.surface_integral, solver)

# Interface flux
@info "Time for interface_flux! on GPU"
CUDA.@time TrixiCUDA.cuda_interface_flux!(mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for interface_flux! on CPU"
@time Trixi.calc_interface_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.surface_integral, solver, cache)

# Prolong to boundaries
@info "Time for prolong2boundaries! on GPU"
CUDA.@time TrixiCUDA.cuda_prolong2boundaries!(u_gpu, mesh_gpu, boundary_conditions_gpu,
equations_gpu, cache_gpu)
@info "Time for prolong2boundaries! on CPU"
@time Trixi.prolong2boundaries!(cache, u, mesh, equations, solver.surface_integral, solver)

# Boundary flux
@info "Time for boundary_flux! on GPU"
CUDA.@time TrixiCUDA.cuda_boundary_flux!(t_gpu, mesh_gpu, boundary_conditions_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for boundary_flux! on CPU"
@time Trixi.calc_boundary_flux!(cache, t, boundary_conditions, mesh, equations,
solver.surface_integral, solver)

# Prolong to mortars
@info "Time for prolong2mortars! on GPU"
CUDA.@time TrixiCUDA.cuda_prolong2mortars!(u_gpu, mesh_gpu,
TrixiCUDA.check_cache_mortars(cache_gpu),
solver_gpu, cache_gpu)
@info "Time for prolong2mortars! on CPU"
@time Trixi.prolong2mortars!(cache, u, mesh, equations,
solver.mortar, solver.surface_integral, solver)

# Mortar flux
@info "Time for mortar_flux! on GPU"
CUDA.@time TrixiCUDA.cuda_mortar_flux!(mesh_gpu, TrixiCUDA.check_cache_mortars(cache_gpu),
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu, cache_gpu)
@info "Time for mortar_flux! on CPU"
@time Trixi.calc_mortar_flux!(cache.elements.surface_flux_values, mesh,
Trixi.have_nonconservative_terms(equations), equations,
solver.mortar, solver.surface_integral, solver, cache)

# Surface integral
@info "Time for surface_integral! on GPU"
CUDA.@time TrixiCUDA.cuda_surface_integral!(du_gpu, mesh_gpu, equations_gpu, solver_gpu, cache_gpu)
@info "Time for surface_integral! on CPU"
@time Trixi.calc_surface_integral!(du, u, mesh, equations, solver.surface_integral,
solver, cache)

# Jacobian
@info "Time for jacobian! on GPU"
CUDA.@time TrixiCUDA.cuda_jacobian!(du_gpu, mesh_gpu, equations_gpu, cache_gpu)
@info "Time for jacobian! on CPU"
@time Trixi.apply_jacobian!(du, mesh, equations, solver, cache)

# Sources terms
@info "Time for sources! on GPU"
CUDA.@time TrixiCUDA.cuda_sources!(du_gpu, u_gpu, t_gpu, source_terms_gpu,
equations_gpu, cache_gpu)
@info "Time for sources! on CPU"
@time Trixi.calc_sources!(du, u, t, source_terms, equations, solver, cache)

# Semidiscretization process
@info "Time for rhs! on GPU"
CUDA.@time TrixiCUDA.rhs_gpu!(du_gpu, u_gpu, t_gpu, mesh_gpu, equations_gpu,
boundary_conditions_gpu, source_terms_gpu,
solver_gpu, cache_gpu)
@info "Time for rhs! on CPU"
@time Trixi.rhs!(du, u, t, mesh, equations, boundary_conditions, source_terms,
solver, cache)

0 comments on commit 3813679

Please sign in to comment.