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

Deterministic version of CUDA forces and stresses kernels #3693

Closed
wants to merge 4 commits into from

Conversation

mtaillefumier
Copy link

@mtaillefumier mtaillefumier commented Apr 19, 2024

Calculations of the forces and stress are deterministic on GPU. It does not imply that the DeepMD code is deterministic by default as TensorFlow also requires to be set up properly either at runtime or during the initialization phase.

To obtain the same model parameters, add the following variables to the job scripts

export TF_DETERMINISTIC_OPS=1
export TF_INTER_OP_PARALLELISM_THREADS=0
export TF_INTRA_OP_PARALLELISM_THREADS=0

Details of the changes:

  • Remove the use of atomic operations in the forces and stress kernels.
  • Use template programming to minimize code duplication and minor refactoring

Authors :

See PR #3684 for comments

Summary by CodeRabbit

  • New Features

    • Enhanced force and virial calculations in molecular dynamics simulations for improved accuracy and performance.
    • Added a new documentation guide on achieving determinism in DeepMD simulations.
  • Refactor

    • Optimized memory access and thread synchronization in GPU calculations.
  • Documentation

    • Provided detailed guidance on configuring deterministic runs in DeepMD using TensorFlow settings.
  • Bug Fixes

    • Removed deprecated functions to streamline codebase and enhance maintainability.

@njzjz njzjz added the Test CUDA Trigger test CUDA workflow label Apr 19, 2024
@github-actions github-actions bot removed the Test CUDA Trigger test CUDA workflow label Apr 19, 2024
Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.15%. Comparing base (ee47e75) to head (0041399).

Additional details and impacted files
@@           Coverage Diff           @@
##            devel    #3693   +/-   ##
=======================================
  Coverage   82.15%   82.15%           
=======================================
  Files         511      511           
  Lines       47364    47364           
  Branches     2952     2952           
=======================================
  Hits        38910    38910           
  Misses       7561     7561           
  Partials      893      893           

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

@njzjz
Copy link
Member

njzjz commented Apr 19, 2024

It seems that the current change cannot make the GPU CI pass.

@njzjz njzjz requested review from denghuilu, njzjz and wanghan-iapcm and removed request for denghuilu April 19, 2024 20:29
@njzjz njzjz linked an issue Apr 19, 2024 that may be closed by this pull request
@mtaillefumier
Copy link
Author

It seems that the current change cannot make the GPU CI pass.

The errors are unclear to me. It is not a compilation problem (which I would have fixed asap) but something deep in python. One file is just a text file, the two other files are source code. The there is no change in the API, no memory leak (I checked for this), etc.... I can also compile deepmd in containers etc....

NB : I use this docker file

FROM tensorflow/tensorflow:2.16.1-gpu

CMD ["/bin/bash"]
RUN apt-get update -qq && apt-get install -qq --no-install-recommends \
    cmake \
    gcc-12 \
    g++-12 \
    gfortran-12 \
    git
ENV DP_VARIANT=cuda

RUN git clone https://github.com/mtaillefumier/deepmd-kit.git
git checkout devel
WORKDIR deepmd-kit
ENV DP_VARIANT=cuda

RUN pip install .
ENTRYPOINT []

@njzjz njzjz added the Test CUDA Trigger test CUDA workflow label Apr 20, 2024
@github-actions github-actions bot removed the Test CUDA Trigger test CUDA workflow label Apr 20, 2024
@njzjz njzjz added the Test CUDA Trigger test CUDA workflow label Apr 21, 2024
@github-actions github-actions bot removed the Test CUDA Trigger test CUDA workflow label Apr 21, 2024
@njzjz njzjz added the Test CUDA Trigger test CUDA workflow label Apr 21, 2024
@github-actions github-actions bot removed the Test CUDA Trigger test CUDA workflow label Apr 21, 2024
@mtaillefumier
Copy link
Author

Something is wrong with this patch. It works with master but fails with the devel branch. I am missing something.

Copy link

coderabbitai bot commented Apr 30, 2024

Warning

Rate Limit Exceeded

@mtaillefumier has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 59 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 549ec52 and 0041399.

Walkthrough

The recent updates focus on enhancing CUDA kernels for molecular dynamics simulations by optimizing memory access, thread configurations, and introducing flags for radial calculations. Additionally, a new guide on achieving deterministic results with DeepMD has been introduced, improving reproducibility across different hardware setups.

Changes

Files Change Summary
.../gpu/prod_force.cu Modified CUDA kernels for force calculations, added boolean flags, and updated function declarations.
.../gpu/prod_virial.cu Refactored virial computation kernels for radial-only calculations and improved synchronization.
doc/determinism.md Introduced guidance on setting TensorFlow environment for deterministic results in DeepMD computations.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mtaillefumier
Copy link
Author

Sorry for the delay. I think I found the root of the problem. A missing synchronization barrier.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

source/lib/src/gpu/prod_virial.cu Outdated Show resolved Hide resolved
source/lib/src/gpu/prod_force.cu Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

doc/determinism.md Outdated Show resolved Hide resolved
doc/determinism.md Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

doc/determinism.md Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

doc/determinism.md Outdated Show resolved Hide resolved
doc/determinism.md Outdated Show resolved Hide resolved
- Remove atomic operations in the forces and stress kernels.
- Use template programming to minimize code duplication.

Authors :
- A. Sedova (ORNL)
- M. Taillefumier (ETH Zurich / CSCS)
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

doc/determinism.md Outdated Show resolved Hide resolved
mtaillefumier and others added 2 commits April 30, 2024 16:45
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Taillefumier Mathieu <29380261+mtaillefumier@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Taillefumier Mathieu <29380261+mtaillefumier@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

doc/determinism.md Outdated Show resolved Hide resolved
doc/determinism.md Show resolved Hide resolved
@njzjz njzjz added the Test CUDA Trigger test CUDA workflow label Apr 30, 2024
@github-actions github-actions bot removed the Test CUDA Trigger test CUDA workflow label Apr 30, 2024
@mtaillefumier
Copy link
Author

I found why this PR fails. I missed something important when I modified these kernels and I know how to correct them now. I will close the PR for the moment so that I can push changes without triggering the CI/CD all the time.

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

Successfully merging this pull request may close these issues.

Reproducibility of LAMMPS run with DP potential
2 participants