Skip to content

Optional CPIC and per-node particle lists, plus opt-in kernel compilation#7

Merged
sebcrozet merged 4 commits into
dimforge:mainfrom
JulianRuiseco:perf/optional-features
Jul 15, 2026
Merged

Optional CPIC and per-node particle lists, plus opt-in kernel compilation#7
sebcrozet merged 4 commits into
dimforge:mainfrom
JulianRuiseco:perf/optional-features

Conversation

@JulianRuiseco

Copy link
Copy Markdown
Contributor

These are performance changes for running slosh in a pipeline that supplies its own P2G/G2P hooks and does not need CPIC or the per-node particle lists. Everything here is default-on or opt-in, so the default build behaves exactly as v0.6.2.

Two new default-on features

cpic gates the grid node's incompatible-momentum lane and CDF collision field. With it off, the GPU node shrinks from 48 to 16 bytes (roughly 3x less per-node grid traffic) and the CDF kernels are not compiled.

node_particle_lists gates the per-node particle linked lists built during the sort. With it off, the per-particle atomic head-exchange and the per-node clears go away.

register_shaders mirrors each feature into a shader macro (SLOSH_CPIC, SLOSH_NODE_PARTICLE_LISTS) so the slang Node layout and sort kernels stay in lockstep with the Rust GpuGridNode and GridArgs. Struct fields, kernel params and bindings are gated together, which matters because slang strips unused entry-point params and would otherwise drop a still-bound buffer.

Opt-in kernel compilation

MpmPipelineKernels lets a pipeline compile only the kernel families it will dispatch. The transfer, CDF, rigid-particle, grid_update and particles_update kernels become Option, are built via new_with_kernels, and launch_step skips the ones left out. hooks_only() covers the common case where run_p2g/run_g2p hooks replace the built-in transfers. It is also what lets a build without cpic avoid compiling the CDF kernels, which reference the gated-out Node.cdf.

Two lighter clears on the hot path

  • reset_hmap now clears only the entry state, not the key/value. Neither is read before being rewritten, so this drops 44 of 48 bytes per entry on a clear that sweeps the whole hashmap every substep.
  • node_reset gates the per-node reset pass. Its only unconditional job is zeroing Node.momentum_velocity_mass, which every P2G overwrites, so a lean pipeline can skip it. It stays forced whenever cpic or node_particle_lists is on, since reset also initializes the per-node data those features need.

Verification

cargo check passes for the default build and for every cpic / node_particle_lists on-off combination. rustfmt clean. The shader sources are unchanged from the reviewed version, and the Rust node layout stays 16-byte aligned per lane, so the shader-to-Rust bindings are unaffected.

JulianRuiseco and others added 4 commits July 15, 2026 06:47
Two new default-on features let a pipeline drop grid data it doesn't use.

cpic gates Node's incompatible-momentum lane and cdf collision field. With it
off the GPU node shrinks from 48 to 16 bytes and the CDF kernels are not
compiled.

node_particle_lists gates the per-node particle linked lists built during the
sort. With it off the per-particle atomic head-exchange and the per-node clears
go away.

register_shaders mirrors each feature into a shader macro (SLOSH_CPIC,
SLOSH_NODE_PARTICLE_LISTS) so the slang Node layout and sort kernels stay in
lockstep with GpuGridNode and GridArgs. Struct fields, kernel params and
bindings are gated together, and the default features keep behavior identical
to v0.6.2.
MpmPipelineKernels lets a pipeline compile only the kernel families it will
dispatch. The transfer, CDF, rigid-particle, grid_update and particles_update
kernels become Option, built via new_with_kernels, and launch_step skips the
ones left out. hooks_only() is the common case: run_p2g/run_g2p hooks replace
the built-in transfers. This is also what lets a build without cpic avoid
compiling the CDF kernels, which reference the gated-out Node.cdf.

Two clears on the hot path get trimmed:

- reset_hmap now clears only the entry state, not key/value. Neither is read
  before being rewritten, so this drops 44 of 48 bytes per entry on a clear
  that sweeps the whole hashmap every substep.
- node_reset gates the per-node reset pass. Its only unconditional job is
  zeroing Node.momentum_velocity_mass, which every P2G overwrites, so a lean
  pipeline can skip it. It stays forced whenever cpic or node_particle_lists is
  on, since reset also initializes the per-node data those features need.
@sebcrozet
sebcrozet merged commit ea294e6 into dimforge:main Jul 15, 2026
5 checks passed
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.

2 participants