Skip to content

Commit

Permalink
Add cache to kernel signature
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyuxie committed Sep 7, 2024
1 parent 559f84f commit 11e42fb
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 44 deletions.
22 changes: 17 additions & 5 deletions src/solvers/dg_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ end

# Pack kernels for calculating volume integrals
function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms,
equations, volume_integral::VolumeIntegralWeakForm, dg::DGSEM)
equations, volume_integral::VolumeIntegralWeakForm, dg::DGSEM, cache)
derivative_dhat = CuArray{Float64}(dg.basis.derivative_dhat)
flux_arr = similar(u)

Expand All @@ -410,7 +410,7 @@ end

function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::False,
equations, volume_integral::VolumeIntegralFluxDifferencing,
dg::DGSEM)
dg::DGSEM, cache)
volume_flux = volume_integral.volume_flux

derivative_split = dg.basis.derivative_split
Expand All @@ -435,7 +435,7 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::True, equations,
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM)
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM, cache)
symmetric_flux, nonconservative_flux = dg.volume_integral.volume_flux

derivative_split = dg.basis.derivative_split
Expand Down Expand Up @@ -470,7 +470,19 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::False, equations,
volume_integral::VolumeIntegralShockCapturingHG, dg::DGSEM)
volume_integral::VolumeIntegralShockCapturingHG, dg::DGSEM, cache)
element_ids_dg, element_ids_dgfv = cache.element_ids_dg, cache.element_ids_dgfv
volume_flux_dg, volume_flux_fv = dg.volume_integral.volume_flux_dg,
dg.volume_integral.volume_flux_fv
indicator = dg.volume_integral.indicator

# This will cause scalar indexing on the GPU
# alpha = CuArray{Float64}(indicator(u, mesh, equations, dg, cache))

# TODO: Get copies of `u` and `du` on both device and host
alpha = indicator(Array(u), mesh, equations, dg, cache)
alpha = CuArray{Float64}(alpha)

return nothing
end

Expand Down Expand Up @@ -737,7 +749,7 @@ function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{1}, equations, boundary_condi
du, u = copy_to_device!(du_cpu, u_cpu)

cuda_volume_integral!(du, u, mesh, have_nonconservative_terms(equations), equations,
dg.volume_integral, dg)
dg.volume_integral, dg, cache)

cuda_prolong2interfaces!(u, mesh, equations, cache)

Expand Down
10 changes: 5 additions & 5 deletions src/solvers/dg_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ end

# Pack kernels for calculating volume integrals
function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms, equations,
volume_integral::VolumeIntegralWeakForm, dg::DGSEM)
volume_integral::VolumeIntegralWeakForm, dg::DGSEM, cache)
derivative_dhat = CuArray{Float64}(dg.basis.derivative_dhat)
flux_arr1 = similar(u)
flux_arr2 = similar(u)
Expand All @@ -696,7 +696,7 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms,
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms::False, equations,
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM)
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM, cache)
volume_flux = volume_integral.volume_flux

derivative_split = dg.basis.derivative_split
Expand Down Expand Up @@ -727,7 +727,7 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms::
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms::True, equations,
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM)
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM, cache)
symmetric_flux, nonconservative_flux = dg.volume_integral.volume_flux

derivative_split = dg.basis.derivative_split
Expand Down Expand Up @@ -775,7 +775,7 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms::
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{2}, nonconservative_terms::False, equations,
volume_integral::VolumeIntegralShockCapturingHG, dg::DGSEM)
volume_integral::VolumeIntegralShockCapturingHG, dg::DGSEM, cache)
return nothing
end

Expand Down Expand Up @@ -1175,7 +1175,7 @@ function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{2}, equations, boundary_condi
du, u = copy_to_device!(du_cpu, u_cpu)

cuda_volume_integral!(du, u, mesh, have_nonconservative_terms(equations), equations,
dg.volume_integral, dg)
dg.volume_integral, dg, cache)

cuda_prolong2interfaces!(u, mesh, equations, cache)

Expand Down
10 changes: 5 additions & 5 deletions src/solvers/dg_3d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ end

# Pack kernels for calculating volume integrals
function cuda_volume_integral!(du, u, mesh::TreeMesh{3}, nonconservative_terms, equations,
volume_integral::VolumeIntegralWeakForm, dg::DGSEM)
volume_integral::VolumeIntegralWeakForm, dg::DGSEM, cache)
derivative_dhat = CuArray{Float64}(dg.basis.derivative_dhat)
flux_arr1 = similar(u)
flux_arr2 = similar(u)
Expand All @@ -765,7 +765,7 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{3}, nonconservative_terms,
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{3}, nonconservative_terms::False, equations,
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM)
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM, cache)
volume_flux = volume_integral.volume_flux

derivative_split = CuArray{Float64}(dg.basis.derivative_split)
Expand Down Expand Up @@ -799,13 +799,13 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{3}, nonconservative_terms::
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{3}, nonconservative_terms::True, equations,
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM)
volume_integral::VolumeIntegralFluxDifferencing, dg::DGSEM, cache)
# Wait for the unmutable MHD implementation in Trixi.jl
return nothing
end

function cuda_volume_integral!(du, u, mesh::TreeMesh{3}, nonconservative_terms::False, equations,
volume_integral::VolumeIntegralShockCapturingHG, dg::DGSEM)
volume_integral::VolumeIntegralShockCapturingHG, dg::DGSEM, cache)
return nothing
end

Expand Down Expand Up @@ -1160,7 +1160,7 @@ function rhs_gpu!(du_cpu, u_cpu, t, mesh::TreeMesh{3}, equations, boundary_condi
du, u = copy_to_device!(du_cpu, u_cpu)

cuda_volume_integral!(du, u, mesh, have_nonconservative_terms(equations), equations,
dg.volume_integral, dg)
dg.volume_integral, dg, cache)

cuda_prolong2interfaces!(u, mesh, equations, cache)

Expand Down
9 changes: 6 additions & 3 deletions test/dgsem_tree_test_suite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function run_dgsem_tree_tests_1D(semi, tspan)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -117,7 +118,8 @@ function run_dgsem_tree_tests_2D(semi, tspan)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -228,7 +230,8 @@ function run_dgsem_tree_tests_3D(semi, tspan)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down
6 changes: 4 additions & 2 deletions test/test_adevction_mortar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -188,7 +189,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down
9 changes: 6 additions & 3 deletions test/test_advection_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -157,7 +158,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -283,7 +285,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down
9 changes: 6 additions & 3 deletions test/test_euler_ec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -160,7 +161,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -287,7 +289,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down
9 changes: 6 additions & 3 deletions test/test_euler_source_terms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -158,7 +159,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -286,7 +288,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down
6 changes: 4 additions & 2 deletions test/test_eulermulti_ec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down Expand Up @@ -163,7 +164,8 @@ isdir(outdir) && rm(outdir, recursive = true)
# Test `cuda_volume_integral!`
TrixiGPU.cuda_volume_integral!(du_gpu, u_gpu, mesh_gpu,
Trixi.have_nonconservative_terms(equations_gpu),
equations_gpu, solver_gpu.volume_integral, solver_gpu)
equations_gpu, solver_gpu.volume_integral, solver_gpu,
cache_gpu)
Trixi.calc_volume_integral!(du, u, mesh, Trixi.have_nonconservative_terms(equations),
equations, solver.volume_integral, solver, cache)
@test CUDA.@allowscalar du_gpu du
Expand Down
Loading

0 comments on commit 11e42fb

Please sign in to comment.