Skip to content

Optimize smoothing kernels and gradients#1117

Open
efaulhaber wants to merge 28 commits intotrixi-framework:mainfrom
efaulhaber:optimize-kernels
Open

Optimize smoothing kernels and gradients#1117
efaulhaber wants to merge 28 commits intotrixi-framework:mainfrom
efaulhaber:optimize-kernels

Conversation

@efaulhaber
Copy link
Copy Markdown
Member

@efaulhaber efaulhaber commented Mar 25, 2026

This PR:

  • optimizes kernels and derivatives by reducing the number of instructions and especially divisions,
  • adds _unsafe versions of kernel and gradient, which skip the compact support and zero distance checks (to be used inside the hot loops where this is guaranteed) and safe wrappers that add these checks again for "casual usage".

Or, as @sloede said:

We like "unsafe" if it implies raw speed 😈

@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

Copy link
Copy Markdown

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

This PR refactors and optimizes smoothing kernel evaluation (kernels + gradients) for performance (including GPU considerations), and updates tests/examples accordingly.

Changes:

  • Refactors smoothing kernels into “safe wrapper” APIs (kernel, kernel_deriv, kernel_grad) plus _unsafe fast paths and more optimized normalization-factor usage.
  • Updates WCSPH RHS hot loop to skip near-zero distances and call an unsafe kernel-gradient variant for speed.
  • Adjusts kernel test coverage (integration slightly beyond support; derivative tests based on compact support) and re-enables a previously-disabled GPU example configuration.

Reviewed changes

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

Show a summary per file
File Description
src/general/smoothing_kernels.jl Introduces _unsafe kernel/derivative/gradient implementations and refactors safe wrappers for performance/GPU behavior.
src/general/abstract_system.jl Adds system-level skip_zero_distance and introduces a safe/unsafe split for smoothing_kernel_grad.
src/schemes/fluid/weakly_compressible_sph/rhs.jl Uses the new zero-distance skipping and unsafe gradient path in the interaction loop.
test/general/smoothing_kernels.jl Updates kernel integral/derivative tests to use compact support and verify zero outside support.
test/examples/gpu.jl Re-enables the Schoenberg quartic spline kernel configuration in GPU tests/examples.
src/TrixiParticles.jl Imports FastMath.div_fast for use in optimized derivative code paths.

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

@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 84.03042% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.03%. Comparing base (3a5900a) to head (26d0109).

Files with missing lines Patch % Lines
src/general/corrections.jl 0.00% 13 Missing ⚠️
src/general/smoothing_kernels.jl 93.04% 13 Missing ⚠️
src/preprocessing/particle_packing/rhs.jl 0.00% 4 Missing ⚠️
src/schemes/boundary/open_boundary/rhs.jl 0.00% 4 Missing ⚠️
src/general/abstract_system.jl 75.00% 3 Missing ⚠️
...c/schemes/structure/discrete_element_method/rhs.jl 0.00% 3 Missing ⚠️
...fluid/weakly_compressible_sph/density_diffusion.jl 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (3a5900a) and HEAD (26d0109). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (3a5900a) HEAD (26d0109)
total 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1117       +/-   ##
===========================================
- Coverage   88.70%   67.03%   -21.67%     
===========================================
  Files         128      128               
  Lines        9764     9808       +44     
===========================================
- Hits         8661     6575     -2086     
- Misses       1103     3233     +2130     
Flag Coverage Δ
total ?
unit 67.03% <84.03%> (+0.08%) ⬆️

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.

@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

Copy link
Copy Markdown

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

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


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

@efaulhaber efaulhaber marked this pull request as ready for review April 7, 2026 16:44
@efaulhaber efaulhaber requested a review from svchb April 7, 2026 16:44
svchb
svchb previously requested changes Apr 9, 2026
@svchb svchb dismissed their stale review April 9, 2026 13:55

completed

@svchb svchb self-requested a review April 9, 2026 13:55
svchb
svchb previously approved these changes Apr 9, 2026
@svchb svchb enabled auto-merge (squash) April 9, 2026 13:56
@svchb
Copy link
Copy Markdown
Collaborator

svchb commented Apr 9, 2026

/run-gpu-tests

@LasNikas LasNikas disabled auto-merge April 9, 2026 15:09
@LasNikas LasNikas enabled auto-merge (squash) April 10, 2026 16:53
@efaulhaber
Copy link
Copy Markdown
Member Author

/run-gpu-tests

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.

6 participants