-
Notifications
You must be signed in to change notification settings - Fork 55
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
Nonbonded kernel #194
base: master
Are you sure you want to change the base?
Nonbonded kernel #194
Changes from all commits
a1311ce
ab5b297
0d0b7f5
769530d
b1ada3c
b79ff1a
0fd0f88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ export | |
find_neighbors, | ||
DistanceNeighborFinder, | ||
TreeNeighborFinder, | ||
CellListMapNeighborFinder | ||
CellListMapNeighborFinder, | ||
GPUNeighborFinder | ||
|
||
""" | ||
use_neighbors(inter) | ||
|
@@ -64,6 +65,29 @@ function DistanceNeighborFinder(; | |
eligible, dist_cutoff, special, n_steps, zero(eligible)) | ||
end | ||
|
||
mutable struct GPUNeighborFinder{B, D} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move up to line 44 since this is just a placeholder. Also add a docstring. |
||
eligible::B | ||
dist_cutoff::D | ||
special::B | ||
n_steps_reorder::Int | ||
initialized::Bool | ||
end | ||
|
||
function GPUNeighborFinder(; | ||
eligible, | ||
dist_cutoff, | ||
special=zero(eligible), | ||
n_steps_reorder=10, | ||
initialized=false) | ||
return GPUNeighborFinder{typeof(eligible), typeof(dist_cutoff)}( | ||
eligible, dist_cutoff, special, n_steps_reorder, initialized) | ||
end | ||
|
||
find_neighbors(sys::System{D, true}, nf::GPUNeighborFinder, current_neighbors=nothing, step_n::Integer=0, initialized::Bool=false; kwargs...) where D = nothing | ||
|
||
find_neighbors(sys::System, nf::GPUNeighborFinder, args...; kwargs...) = nothing | ||
|
||
|
||
function find_neighbors(sys::System{D, false}, | ||
nf::DistanceNeighborFinder, | ||
current_neighbors=nothing, | ||
|
@@ -365,3 +389,10 @@ function Base.show(io::IO, neighbor_finder::Union{DistanceNeighborFinder, | |
println(io, " n_steps = " , neighbor_finder.n_steps) | ||
print( io, " dist_cutoff = ", neighbor_finder.dist_cutoff) | ||
end | ||
|
||
function Base.show(io::IO, neighbor_finder::Union{GPUNeighborFinder}) | ||
println(io, typeof(neighbor_finder)) | ||
println(io, " Size of eligible matrix = " , size(neighbor_finder.eligible)) | ||
println(io, " n_steps_reorder = " , neighbor_finder.n_steps_reorder) | ||
print( io, " dist_cutoff = ", neighbor_finder.dist_cutoff) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,10 @@ Custom simulators should implement this function. | |
coords_copy = similar(sys.coords) | ||
F_nounits = ustrip_vec.(similar(sys.coords)) | ||
F = F_nounits .* sys.force_units | ||
forces_buffer = init_forces_buffer(F_nounits, n_threads) | ||
forces_buffer = init_forces_buffer(F_nounits, sys.coords, n_threads) | ||
F_nounits = forces_nounits!(F_nounits, sys, neighbors, forces_buffer, 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
n_threads=n_threads) | ||
|
||
|
||
for step_n in 1:sim.max_steps | ||
F_nounits .= forces_nounits!(F_nounits, sys, neighbors, forces_buffer, step_n; | ||
|
@@ -141,11 +144,13 @@ end | |
sys.coords .= wrap_coords.(sys.coords, (sys.boundary,)) | ||
!iszero(sim.remove_CM_motion) && remove_CM_motion!(sys) | ||
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads) | ||
forces_t = forces(sys, neighbors; n_threads=n_threads) | ||
forces_nounits_t = ustrip_vec.(zero(sys.coords)) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; n_threads=n_threads) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
accels_t = forces_t ./ masses(sys) | ||
forces_nounits_t_dt = ustrip_vec.(similar(sys.coords)) | ||
forces_t_dt = forces_nounits_t_dt .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t_dt, n_threads) | ||
accels_t_dt = zero(accels_t) | ||
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads, current_forces=forces_t) | ||
using_constraints = length(sys.constraints) > 0 | ||
|
@@ -231,7 +236,9 @@ end | |
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads) | ||
forces_nounits_t = ustrip_vec.(similar(sys.coords)) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t, n_threads) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line probably not required (and below). |
||
n_threads=n_threads) | ||
accels_t = forces_t ./ masses(sys) | ||
using_constraints = length(sys.constraints) > 0 | ||
if using_constraints | ||
|
@@ -306,7 +313,9 @@ StormerVerlet(; dt, coupling=NoCoupling()) = StormerVerlet(dt, coupling) | |
coords_last, coords_copy = similar(sys.coords), similar(sys.coords) | ||
forces_nounits_t = ustrip_vec.(similar(sys.coords)) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t, n_threads) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; | ||
n_threads=n_threads) | ||
accels_t = forces_t ./ masses(sys) | ||
using_constraints = length(sys.constraints) > 0 | ||
|
||
|
@@ -389,7 +398,9 @@ end | |
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads) | ||
forces_nounits_t = ustrip_vec.(similar(sys.coords)) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t, n_threads) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; | ||
n_threads=n_threads) | ||
accels_t = forces_t ./ masses(sys) | ||
noise = similar(sys.velocities) | ||
using_constraints = length(sys.constraints) > 0 | ||
|
@@ -497,7 +508,9 @@ end | |
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads) | ||
forces_nounits_t = ustrip_vec.(similar(sys.coords)) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t, n_threads) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; | ||
n_threads=n_threads) | ||
accels_t = forces_t ./ masses(sys) | ||
noise = similar(sys.velocities) | ||
|
||
|
@@ -617,7 +630,9 @@ end | |
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads) | ||
forces_nounits_t = ustrip_vec.(similar(sys.coords)) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t, n_threads) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; | ||
n_threads=n_threads) | ||
accels_t = forces_t ./ masses(sys) | ||
noise = similar(sys.velocities) | ||
|
||
|
@@ -685,11 +700,13 @@ end | |
sys.coords .= wrap_coords.(sys.coords, (sys.boundary,)) | ||
!iszero(sim.remove_CM_motion) && remove_CM_motion!(sys) | ||
neighbors = find_neighbors(sys, sys.neighbor_finder; n_threads=n_threads) | ||
forces_t = forces(sys, neighbors; n_threads=n_threads) | ||
forces_nounits_t = ustrip_vec.(zero(sys.coords)) | ||
forces_buffer = init_forces_buffer(forces_nounits_t, sys.coords, n_threads) | ||
forces_nounits_t = forces_nounits!(forces_nounits_t, sys, neighbors, forces_buffer, 0; n_threads=n_threads) | ||
forces_t = forces_nounits_t .* sys.force_units | ||
accels_t = forces_t ./ masses(sys) | ||
forces_nounits_t_dt = ustrip_vec.(similar(sys.coords)) | ||
forces_t_dt = forces_nounits_t_dt .* sys.force_units | ||
forces_buffer = init_forces_buffer(forces_nounits_t_dt, n_threads) | ||
accels_t_dt = zero(accels_t) | ||
apply_loggers!(sys, neighbors, 0, run_loggers; n_threads=n_threads, current_forces=forces_t) | ||
v_half = zero(sys.velocities) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make
::M
in case we want to reuse this in non-CUDA contexts.