Add matrix-free action assembly (stiffness_action / mass_action)#242
Merged
Add matrix-free action assembly (stiffness_action / mass_action)#242
Conversation
New physics function interface for element-level matrix-vector products:
- stiffness_action(physics, ..., v_el, ...) → SVector: computes K_q·v_el
per quadrature point as G·A_v·(G'·v_el), avoiding the 24×24 K_q matrix
- mass_action(physics, ..., v_el, ...) → SVector: computes M_q·v_el as
JxW·ρ·(N_vec·v_el)·N_vec, avoiding the 24×24 M_q matrix
New assembly path:
- assemble_matrix_free_action!(assembler, func_action, Uu, Vu, p)
- CPU implementation: _assemble_block_matrix_free_action!
- GPU kernel: _assemble_block_matrix_free_action_kernel!
Accumulates Kv_el (SVector{24}) per element instead of K_el (SMatrix{24,24}),
eliminating the GPU register spilling bottleneck.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #242 +/- ##
==========================================
+ Coverage 61.90% 62.43% +0.53%
==========================================
Files 60 60
Lines 3344 3381 +37
==========================================
+ Hits 2070 2111 +41
+ Misses 1274 1270 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cmhamel
approved these changes
Mar 15, 2026
cmhamel
approved these changes
Mar 15, 2026
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.
Summary
assemble_matrix_free_action!— a new assembly path that accumulatesK·v(orM·v) directly as a vector per element, without forming the full element stiffness/mass matrixstiffness_actionandmass_actiontoPhysics.jlfor physics implementations to dispatch onassemble_matrix_free_action!,stiffness_action, andmass_actionMotivation
The existing
assemble_matrix_action!path accumulates a fullSMatrix{24,24}element stiffness matrix (576 Float64 = 4.6 KB) per GPU thread before multiplying byv_el. This far exceeds the GPU VGPR budget (~256–512 registers), causing register spilling to global memory and ~570 ms/call on an RX 7600 for a 530k-DOF torsion problem in Carina.jl.The new matrix-free path accumulates
Kv_el = SVector{24}directly by callingfunc_action(physics, ..., v_el, ...)per quadrature point, keeping only ~42 doubles of intermediates. Benchmark results on RX 7600 (530k DOFs):assemble_matrix_action!)assemble_matrix_free_action!)(K + c_M·M)·vInterface
Physics implementations define:
Assembly call: