Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proof of Concept] Constant-propagate sqrt(eps()) on GPUs #685

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/general/smoothing_kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ abstract type SmoothingKernel{NDIMS} end

@inline Base.ndims(::SmoothingKernel{NDIMS}) where {NDIMS} = NDIMS

@eval sqrt_eps(::Type{Float32}) = $(sqrt(eps(Float32)))
@eval sqrt_eps(::Type{Float64}) = $(sqrt(eps(Float64)))

@inline function kernel_grad(kernel, pos_diff, distance, h)
# TODO Use `eps` relative to `h` to allow scaling of simulations
distance < sqrt(eps(typeof(h))) && return zero(pos_diff)
distance < sqrt_eps(typeof(h)) && return zero(pos_diff)

return kernel_deriv(kernel, distance, h) / distance * pos_diff
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function update!(density_diffusion::DensityDiffusionAntuono, neighborhood_search
foreach_point_neighbor(system, system, system_coords, system_coords,
neighborhood_search) do particle, neighbor, pos_diff, distance
# Only consider particles with a distance > 0
distance < sqrt(eps(typeof(distance))) && return
distance < sqrt_eps(typeof(distance)) && return

rho_a = particle_density(v, system, particle)
rho_b = particle_density(v, system, neighbor)
Expand All @@ -204,7 +204,7 @@ end
pos_diff, distance, m_b, rho_a, rho_b,
particle_system::FluidSystem, grad_kernel)
# Density diffusion terms are all zero for distance zero
distance < sqrt(eps(typeof(distance))) && return
distance < sqrt_eps(typeof(distance)) && return

(; delta) = density_diffusion
(; smoothing_length, state_equation) = particle_system
Expand Down
Loading