Skip to content

Improve GPU performance of fluid-* interact#1116

Merged
efaulhaber merged 18 commits into
trixi-framework:mainfrom
efaulhaber:performance-fluid
Apr 21, 2026
Merged

Improve GPU performance of fluid-* interact#1116
efaulhaber merged 18 commits into
trixi-framework:mainfrom
efaulhaber:performance-fluid

Conversation

@efaulhaber
Copy link
Copy Markdown
Member

@efaulhaber efaulhaber commented Mar 23, 2026

This PR rewrites the interact! function for fluid-* interaction and is part of #1131.

  • The foreach_point_neighbor loop is now unrolled into an @threaded for particle and foreach_neighbor.
  • With this change, I can now load data for particle a once instead of loading it again for each neighbor.
  • This unrolled loop now also allows me to accumulate the dv values over all neighbors and write to dv only once per particle.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.10%. Comparing base (a3f1139) to head (07c71e4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/general/neighborhood_search.jl 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1116      +/-   ##
==========================================
- Coverage   89.17%   89.10%   -0.08%     
==========================================
  Files         128      128              
  Lines        9925     9925              
==========================================
- Hits         8851     8844       -7     
- Misses       1074     1081       +7     
Flag Coverage Δ
total 89.10% <94.73%> (-0.08%) ⬇️
unit 67.62% <81.57%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the fluid-* interact! implementation to improve GPU performance by unrolling the point-neighbor iteration into a per-particle threaded loop and reducing repeated loads/writes.

Changes:

  • Rewrites WCSPH interact! to thread over particles, use foreach_neighbor, and accumulate per-particle RHS contributions before writing.
  • Introduces foreach_neighbor wrapper with a GPU-unsafe fast path (bounds-check-free) for neighbor traversal.
  • Adds a 3D WCSPH ContinuityDensity fast path that combines velocity+density loads using SIMD wide loads; updates correction and pressure helper APIs accordingly.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/schemes/fluid/weakly_compressible_sph/rhs.jl Main WCSPH interact! refactor; adds neighbor_pressure and velocity_and_density helpers + SIMD load fast path.
src/schemes/fluid/implicit_incompressible_sph/rhs.jl Switches to neighbor_pressure helper to avoid redundant pressure loads / enable mirroring behavior.
src/general/neighborhood_search.jl Adds foreach_neighbor wrapper with a GPU specialization calling PointNeighbors.foreach_neighbor_unsafe.
src/general/corrections.jl Adjusts free_surface_correction API to accept (rho_a, rho_b) and compute rho_mean internally.
src/TrixiParticles.jl Adds SIMD import required by the new 3D fast path.
Project.toml Adds SIMD dependency and bumps PointNeighbors compat to 0.6.6.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/general/neighborhood_search.jl
Comment thread src/schemes/fluid/weakly_compressible_sph/rhs.jl
Comment thread src/schemes/fluid/weakly_compressible_sph/rhs.jl Outdated
Comment thread src/schemes/fluid/weakly_compressible_sph/rhs.jl Outdated
@efaulhaber efaulhaber closed this Apr 15, 2026
@efaulhaber efaulhaber reopened this Apr 15, 2026
@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

@efaulhaber efaulhaber marked this pull request as ready for review April 16, 2026 08:12
@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

@efaulhaber efaulhaber marked this pull request as draft April 16, 2026 14:45
@efaulhaber efaulhaber marked this pull request as ready for review April 16, 2026 14:59
This was referenced Apr 17, 2026
@efaulhaber efaulhaber requested review from LasNikas and svchb April 20, 2026 12:26
Copy link
Copy Markdown
Collaborator

@LasNikas LasNikas left a comment

Choose a reason for hiding this comment

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

The following remarks can also be resolved by creating an issue for each one:

  • There is still a PointNeighbors.foreach_neighbor call in mirroring.jl. Should that also be changed to foreach_neighbor in this PR?
  • Could the update_shifting methods also be optimized in this way?

@efaulhaber
Copy link
Copy Markdown
Member Author

There is still a PointNeighbors.foreach_neighbor call in mirroring.jl. Should that also be changed to foreach_neighbor in this PR?

No. This PointNeighbors.foreach_neighbor is the internal one that has the position as an argument. This is only supported by the GridNeighborhoodSearch and not yet documented.

Could the update_shifting methods also be optimized in this way?

Yes, absolutely. So far, we have TLSPH RHS (merged), TLSPH deformation gradient and stress tensor (merged), WCSPH RHS (this PR). Next are IISPH and EDAC RHS, open boundary RHS, shifting updates, etc.

@svchb svchb enabled auto-merge (squash) April 21, 2026 08:42
@efaulhaber efaulhaber disabled auto-merge April 21, 2026 08:42
@svchb
Copy link
Copy Markdown
Collaborator

svchb commented Apr 21, 2026

/run-gpu-tests

@efaulhaber efaulhaber merged commit 1d97487 into trixi-framework:main Apr 21, 2026
12 of 14 checks passed
@efaulhaber efaulhaber deleted the performance-fluid branch April 21, 2026 08:42
efaulhaber referenced this pull request Apr 29, 2026
Merge dev to main for 0.5 release
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.

4 participants