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

GPU-compatible neighborhood search #563

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions src/general/neighborhood_search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function PointNeighbors.foreach_point_neighbor(f, system::GPUSystem, neighbor_sy
neighborhood_search;
points=each_moving_particle(system),
parallel=true)
@threaded system for point in points
PointNeighbors.foreach_neighbor(f, system_coords, neighbor_coords,
neighborhood_search, point)
end
# For `GPUSystem`s, explicitly pass the backend, so that with a `GPUSystem` with CPU
# backend, it will actually launch the KernelAbstractions.jl kernels on the CPU.
efaulhaber marked this conversation as resolved.
Show resolved Hide resolved
foreach_point_neighbor(f, system_coords, neighbor_coords, neighborhood_search;
points, parallel=KernelAbstractions.get_backend(system_coords))
end
92 changes: 52 additions & 40 deletions src/general/semidiscretization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -644,20 +644,20 @@ function update_nhs!(neighborhood_search,
neighbor::Union{FluidSystem, TotalLagrangianSPHSystem},
u_system, u_neighbor)
# The current coordinates of fluids and solids change over time
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
end

function update_nhs!(neighborhood_search,
system::FluidSystem, neighbor::BoundarySPHSystem,
u_system, u_neighbor)
# Boundary coordinates only change over time when `neighbor.ismoving[]`
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, neighbor.ismoving[]))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, neighbor.ismoving[]))
end

function update_nhs!(neighborhood_search,
Expand All @@ -667,10 +667,10 @@ function update_nhs!(neighborhood_search,

# TODO: Update only `active_coordinates` of open boundaries.
# Problem: Removing inactive particles from neighboring lists is necessary.
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
end

function update_nhs!(neighborhood_search,
Expand All @@ -680,20 +680,20 @@ function update_nhs!(neighborhood_search,

# TODO: Update only `active_coordinates` of open boundaries.
# Problem: Removing inactive particles from neighboring lists is necessary.
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
end

function update_nhs!(neighborhood_search,
system::TotalLagrangianSPHSystem, neighbor::FluidSystem,
u_system, u_neighbor)
# The current coordinates of fluids and solids change over time
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
end

function update_nhs!(neighborhood_search,
Expand All @@ -708,10 +708,10 @@ function update_nhs!(neighborhood_search,
u_system, u_neighbor)
# The current coordinates of solids change over time.
# Boundary coordinates only change over time when `neighbor.ismoving[]`.
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, neighbor.ismoving[]))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, neighbor.ismoving[]))
end

function update_nhs!(neighborhood_search,
Expand All @@ -734,10 +734,10 @@ function update_nhs!(neighborhood_search,
#
# Boundary coordinates only change over time when `neighbor.ismoving[]`.
# The current coordinates of fluids and solids change over time.
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(system.ismoving[], true))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(system.ismoving[], true))
end

function update_nhs!(neighborhood_search,
Expand All @@ -746,30 +746,30 @@ function update_nhs!(neighborhood_search,
u_system, u_neighbor)
# `system` coordinates only change over time when `system.ismoving[]`.
# `neighbor` coordinates only change over time when `neighbor.ismoving[]`.
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(system.ismoving[], neighbor.ismoving[]))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(system.ismoving[], neighbor.ismoving[]))
end

function update_nhs!(neighborhood_search,
system::DEMSystem, neighbor::DEMSystem,
u_system, u_neighbor)
# Both coordinates change over time
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, true))
end

function update_nhs!(neighborhood_search,
system::DEMSystem, neighbor::BoundaryDEMSystem,
u_system, u_neighbor)
# DEM coordinates change over time, the boundary coordinates don't
PointNeighbors.update!(neighborhood_search,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, false))
update!(neighborhood_search, system,
current_coordinates(u_system, system),
current_coordinates(u_neighbor, neighbor),
points_moving=(true, false))
end

function update_nhs!(neighborhood_search,
Expand All @@ -788,6 +788,18 @@ function update_nhs!(neighborhood_search,
return neighborhood_search
end

# Forward to PointNeighbors.jl
function update!(neighborhood_search, system, x, y; points_moving=(true, false))
PointNeighbors.update!(neighborhood_search, x, y; points_moving)
end

# For `GPUSystem`s, explicitly pass the backend, so that with a `GPUSystem` with CPU
# backend, it will actually launch the KernelAbstractions.jl kernels on the CPU.
efaulhaber marked this conversation as resolved.
Show resolved Hide resolved
function update!(neighborhood_search, system::GPUSystem, x, y; points_moving=(true, false))
PointNeighbors.update!(neighborhood_search, x, y; points_moving,
parallelization_backend=KernelAbstractions.get_backend(system))
end

function check_configuration(systems)
foreach_system(systems) do system
check_configuration(system, systems)
Expand Down
Loading