Skip to content
Merged
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
3 changes: 2 additions & 1 deletion src/neighborhood_search.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
abstract type AbstractNeighborhoodSearch end

@inline search_radius(search::AbstractNeighborhoodSearch) = search.search_radius
@inline Base.eltype(search::AbstractNeighborhoodSearch) = eltype(search_radius(search))

"""
requires_update(search::AbstractNeighborhoodSearch)
Expand Down Expand Up @@ -220,7 +221,7 @@ end
neighbor_coords = extract_svector(neighbor_system_coords,
Val(ndims(neighborhood_search)), neighbor)

pos_diff = point_coords - neighbor_coords
pos_diff = convert.(eltype(neighborhood_search), point_coords - neighbor_coords)
distance2 = dot(pos_diff, pos_diff)

pos_diff,
Expand Down
2 changes: 1 addition & 1 deletion src/nhs_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ end
neighbor_coords = extract_svector(neighbor_system_coords,
Val(ndims(neighborhood_search)), neighbor)

pos_diff = point_coords - neighbor_coords
pos_diff = convert.(eltype(neighborhood_search), point_coords - neighbor_coords)
distance2 = dot(pos_diff, pos_diff)

pos_diff,
Expand Down
15 changes: 9 additions & 6 deletions src/nhs_precomputed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ end
for neighbor_ in eachindex(neighbors)
neighbor = @inbounds neighbors[neighbor_]

# Making the following `@inbounds` yields a ~2% speedup on an NVIDIA H100.
# But we don't know if `neighbor` (extracted from the cell list) is in bounds.
neighbor_coords = extract_svector(neighbor_system_coords,
Val(ndims(neighborhood_search)), neighbor)

pos_diff = point_coords - neighbor_coords
# Making this `@inbounds` is not perfectly safe because
# `neighbor` (extracted from the neighbor list) is only guaranteed to be in bounds
# if the neighbor lists were constructed correctly and have not been corrupted.
# However, adding this `@inbounds` yields a ~20% speedup for TLSPH on GPUs (A4500).
neighbor_coords = @inbounds extract_svector(neighbor_system_coords,
Val(ndims(neighborhood_search)),
neighbor)

pos_diff = convert.(eltype(neighborhood_search), point_coords - neighbor_coords)
distance2 = dot(pos_diff, pos_diff)

pos_diff,
Expand Down