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

Allowing SHAKE/RATTLE constraints on GPU simulation #175

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Omar-Elrefaei
Copy link

@Omar-Elrefaei Omar-Elrefaei commented Apr 25, 2024

As discussed I've adapted the constraint code to allow for GPU simulation.

testing with the protein simulation in `benchmarks.jl`
using Molly, DelimitedFiles, Test
data_dir = normpath("./data")
ff = MolecularForceField(
    joinpath(data_dir, "force_fields", "ff99SBildn.xml"),
    joinpath(data_dir, "force_fields", "tip3p_standard.xml"),
    joinpath(data_dir, "force_fields", "his.xml"),
)

# takes more than 40s
sys_init = System(joinpath(data_dir, "6mrr_equil.pdb"), ff; gpu=false)
sys_init_gpu = System(joinpath(data_dir, "6mrr_equil.pdb"), ff; gpu=true)

function protein(sys_init; is_constrained=false, nsteps=100)
    println("Constraints $is_constrained, GPU $(is_on_gpu(sys_init)), nsteps $nsteps")
    constraints = []
    bond_length = 0.0872u"nm"
    for i in 1171:3:15952
        push!(constraints, DistanceConstraint(i, i + 1, bond_length))
        push!(constraints, DistanceConstraint(i, i + 2, bond_length))
    end
    if is_constrained
        cons = (SHAKE_RATTLE([constraints...], length(sys_init), 1e-4u"nm", 1e-4u"nm^2 * ps^-1"),)
        sys_init = System(sys_init; constraints=cons)
    end

    sim = VelocityVerlet(dt=0.001u"ps")
    @time "Protein Simulation" simulate!(sys_init, sim, nsteps)
end

Note: the last example is not supported and crashes on master

julia> protein(sys_cpu, is_constrained=false);
Constraints false, GPU false 
Protein Simulation: 10.376156 seconds (4.97 k allocations: 623.307 MiB) 

julia> protein(sys_cpu, is_constrained=true); 
 Constraints true, GPU false 
Protein Simulation: 10.236894 seconds (5.17 k allocations: 660.505 MiB)

julia> protein(sys_gpu, is_constrained=false);
Constraints false, GPU true
Protein Simulation:  1.846926 seconds (129.68 k allocations: 198.061 MiB)

julia> protein(sys_gpu, is_constrained=true);
Constraints true, GPU true
Protein Simulation: 1.654842 seconds (242.76 k allocations: 200.673 MiB)

I'm submitting a draft PR, because there is a few concerns I was to attend to first before this is ready.

Omar-Elrefaei and others added 3 commits April 17, 2024 16:36
(this gpu path currently severely underperforms cpu)
the core algorithms remains the same
the comments about "# Cannot parallelize this" was deemed to be about
parallelizing the computation of constraints inside a cluster not different clusters
Copy link

codecov bot commented Apr 25, 2024

Codecov Report

Attention: Patch coverage is 45.71429% with 57 lines in your changes are missing coverage. Please review.

Project coverage is 71.81%. Comparing base (b769838) to head (6a7e014).

Files Patch % Lines
src/constraints/shake.jl 45.19% 57 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #175      +/-   ##
==========================================
- Coverage   72.55%   71.81%   -0.75%     
==========================================
  Files          36       36              
  Lines        5481     5542      +61     
==========================================
+ Hits         3977     3980       +3     
- Misses       1504     1562      +58     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jgreener64
Copy link
Collaborator

Looks like a great start.

Would be good to change the existing test to run on GPU too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants