Optional CPIC and per-node particle lists, plus opt-in kernel compilation#7
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
cpicgates 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_listsgates 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_shadersmirrors each feature into a shader macro (SLOSH_CPIC,SLOSH_NODE_PARTICLE_LISTS) so the slangNodelayout and sort kernels stay in lockstep with the RustGpuGridNodeandGridArgs. 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
MpmPipelineKernelslets a pipeline compile only the kernel families it will dispatch. The transfer, CDF, rigid-particle, grid_update and particles_update kernels becomeOption, are built vianew_with_kernels, andlaunch_stepskips the ones left out.hooks_only()covers the common case whererun_p2g/run_g2phooks replace the built-in transfers. It is also what lets a build withoutcpicavoid compiling the CDF kernels, which reference the gated-outNode.cdf.Two lighter clears on the hot path
reset_hmapnow 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_resetgates the per-node reset pass. Its only unconditional job is zeroingNode.momentum_velocity_mass, which every P2G overwrites, so a lean pipeline can skip it. It stays forced whenevercpicornode_particle_listsis on, since reset also initializes the per-node data those features need.Verification
cargo checkpasses 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.