Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyuxie committed Jan 22, 2025
1 parent 3e00f6d commit b228d83
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 249 deletions.
103 changes: 35 additions & 68 deletions src/solvers/dg_1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ function volume_flux_dgfv_kernel!(volume_flux_arr, fstar1_L, fstar1_R, u,
return nothing
end

# Kernel for calculating DG volume integral contribution
function volume_integral_dg_kernel!(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split,
volume_flux_arr, equations::AbstractEquations{1})
# Kernel for calculating pure DG and DG-FV volume integrals
function volume_integral_dgfv_kernel!(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split,
inverse_weights, volume_flux_arr, fstar1_L, fstar1_R,
equations::AbstractEquations{1})
i = (blockIdx().x - 1) * blockDim().x + threadIdx().x
j = (blockIdx().y - 1) * blockDim().y + threadIdx().y
k = (blockIdx().z - 1) * blockDim().z + threadIdx().z
Expand Down Expand Up @@ -385,6 +386,9 @@ function volume_integral_dg_kernel!(du, element_ids_dg, element_ids_dgfv, alpha,
(1 - isequal(j, ii)) * # set diagonal elements to zeros
volume_flux_arr[i, j, ii, element_dgfv]
end

@inbounds du[i, j, element_dgfv] += alpha_element * inverse_weights[j] *
(fstar1_L[i, j + 1, element_dgfv] - fstar1_R[i, j, element_dgfv])
end
end

Expand Down Expand Up @@ -446,9 +450,10 @@ function volume_flux_dgfv_kernel!(volume_flux_arr, noncons_flux_arr, fstar1_L, f
return nothing
end

# Kernel for calculating DG volume integral contribution
function volume_integral_dg_kernel!(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split,
volume_flux_arr, noncons_flux_arr, equations::AbstractEquations{1})
# Kernel for calculating pure DG and DG-FV volume integrals
function volume_integral_dgfv_kernel!(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split,
inverse_weights, volume_flux_arr, noncons_flux_arr,
fstar1_L, fstar1_R, equations::AbstractEquations{1})
i = (blockIdx().x - 1) * blockDim().x + threadIdx().x
j = (blockIdx().y - 1) * blockDim().y + threadIdx().y
k = (blockIdx().z - 1) * blockDim().z + threadIdx().z
Expand Down Expand Up @@ -478,39 +483,17 @@ function volume_integral_dg_kernel!(du, element_ids_dg, element_ids_dgfv, alpha,
0.5f0 * (1 - alpha_element) *
derivative_split[j, ii] * noncons_flux_arr[i, j, ii, element_dgfv]
end
end
end

return nothing
end

# Kernel for calculating FV volume integral contribution
function volume_integral_fv_kernel!(du, fstar1_L, fstar1_R, inverse_weights, element_ids_dgfv,
alpha)
j = (blockIdx().x - 1) * blockDim().x + threadIdx().x
k = (blockIdx().y - 1) * blockDim().y + threadIdx().y

if (j <= size(du, 2) && k <= size(du, 3))
# length(element_ids_dgfv) == size(du, 3)

@inbounds begin
element_dgfv = element_ids_dgfv[k] # check if `element_dgfv` is zero
alpha_element = alpha[k]
end

if element_dgfv != 0 # bad
for ii in axes(du, 1)
@inbounds du[ii, j, element_dgfv] += alpha_element * inverse_weights[j] *
(fstar1_L[ii, j + 1, element_dgfv] - fstar1_R[ii, j, element_dgfv])
end
@inbounds du[i, j, element_dgfv] += alpha_element * inverse_weights[j] *
(fstar1_L[i, j + 1, element_dgfv] - fstar1_R[i, j, element_dgfv])
end
end

return nothing
end

############################################################################## New optimization
# Kernel for calculating DG-FV volume integrals without conservative terms
# Kernel for calculating pure DG and DG-FV volume integrals without conservative terms

# Kernel for prolonging two interfaces
function prolong_interfaces_kernel!(interfaces_u, u, neighbor_ids)
Expand Down Expand Up @@ -936,24 +919,16 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::
kernel_configurator_2d(volume_flux_dgfv_kernel, size(u, 2)^2,
size(u, 3))...)

volume_integral_dg_kernel = @cuda launch=false volume_integral_dg_kernel!(du, element_ids_dg,
element_ids_dgfv,
alpha,
derivative_split,
volume_flux_arr,
equations)
volume_integral_dg_kernel(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split,
volume_flux_arr, equations;
kernel_configurator_3d(volume_integral_dg_kernel, size(du)...)...)

volume_integral_fv_kernel = @cuda launch=false volume_integral_fv_kernel!(du, fstar1_L,
fstar1_R,
inverse_weights,
element_ids_dgfv,
alpha)
volume_integral_fv_kernel(du, fstar1_L, fstar1_R, inverse_weights, element_ids_dgfv, alpha;
kernel_configurator_2d(volume_integral_fv_kernel, size(u, 2),
size(u, 3))...)
volume_integral_dgfv_kernel = @cuda launch=false volume_integral_dgfv_kernel!(du, element_ids_dg,
element_ids_dgfv,
alpha, derivative_split,
inverse_weights,
volume_flux_arr,
fstar1_L, fstar1_R,
equations)
volume_integral_dgfv_kernel(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split, inverse_weights,
volume_flux_arr, fstar1_L, fstar1_R, equations;
kernel_configurator_3d(volume_integral_dgfv_kernel, size(du)...)...)

return nothing
end
Expand Down Expand Up @@ -1009,25 +984,17 @@ function cuda_volume_integral!(du, u, mesh::TreeMesh{1}, nonconservative_terms::
kernel_configurator_2d(volume_flux_dgfv_kernel, size(u, 2)^2,
size(u, 3))...)

volume_integral_dg_kernel = @cuda launch=false volume_integral_dg_kernel!(du, element_ids_dg,
element_ids_dgfv,
alpha,
derivative_split,
volume_flux_arr,
noncons_flux_arr,
equations)
volume_integral_dg_kernel(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split,
volume_flux_arr, noncons_flux_arr, equations;
kernel_configurator_3d(volume_integral_dg_kernel, size(du)...)...)

volume_integral_fv_kernel = @cuda launch=false volume_integral_fv_kernel!(du, fstar1_L,
fstar1_R,
inverse_weights,
element_ids_dgfv,
alpha)
volume_integral_fv_kernel(du, fstar1_L, fstar1_R, inverse_weights, element_ids_dgfv, alpha;
kernel_configurator_2d(volume_integral_fv_kernel, size(u, 2),
size(u, 3))...)
volume_integral_dgfv_kernel = @cuda launch=false volume_integral_dgfv_kernel!(du, element_ids_dg,
element_ids_dgfv,
alpha, derivative_split,
inverse_weights,
volume_flux_arr,
noncons_flux_arr,
fstar1_L, fstar1_R,
equations)
volume_integral_dgfv_kernel(du, element_ids_dg, element_ids_dgfv, alpha, derivative_split, inverse_weights,
volume_flux_arr, noncons_flux_arr, fstar1_L, fstar1_R, equations;
kernel_configurator_3d(volume_integral_dgfv_kernel, size(du)...)...)

return nothing
end
Expand Down
Loading

0 comments on commit b228d83

Please sign in to comment.