Skip to content

Speed up BSR transpose and first-sample FEM construction - #1940

Closed
maxkra15 wants to merge 10 commits into
NVIDIA:mainfrom
maxkra15:maxkra15/fem-first-row-compression
Closed

maxkra15 wants to merge 10 commits into
NVIDIA:mainfrom
maxkra15:maxkra15/fem-first-row-compression

Conversation

@maxkra15

@maxkra15 maxkra15 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Speed up CUDA bsr_set_transpose() by sorting only destination-row bits. Stable radix sorting preserves source-row ordering and keeps padding last; sorting still scales with reserved capacity.

Enable FEM interpolation with reduction="first" and row compression. Reserve candidate storage from the restriction-node upper bound and assign capacity only to active rows using the existing bsr_set_zero() scan. Both operations support CUDA Graph replay without host readback.

The follow-up also fixes first-sample backward evaluation and gradient tracking in interpolation triplet storage. Sample ownership and forward arithmetic are preserved.

Measurements and validation

  • Memory: restricted Q1/S2–S3 construction reserves 13.7–15.0× fewer candidate blocks than uniform row allocation. This is not a total-simulation memory reduction.
  • Construction time: those compact cases still take 1.40–1.74× longer than triplets. Small maps can regress versus uniform rows, so Newton #4214 retains its sizing check.
  • Transpose time: earlier captured benchmarks at e33c4f8f measured 1.83–2.32× across six patterns. The native transpose code is unchanged by this follow-up.
  • Current validation: 26 FEM integration tests pass, including CPU/CUDA gradients and changing restrictions under graph replay; 32 forward matrix snapshots match 00d9967a bitwise. Eight guarded benchmark processes pass all 272 construction-policy comparisons. Regression tests fail without the fixes; pre-commit checks pass.

Current measurements and reproduction · Transpose benchmark commands

Earlier end-to-end results use the pinned Isaac Lab teapot demo, which requires Isaac Lab and demo assets. Those results and checkouts remain in the evidence archive; they were not rerun for this follow-up.

Closes #1970, #1971, and #1978.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date.
  • Changelog fragments describe the user-visible changes.

Summary by CodeRabbit

  • New Features

    • Row-compressed FEM interpolation now supports reduction="first" with changing restrictions and CUDA Graph replay.
    • CUDA BSR transpose operations now provide stable ordering, padded-topology preservation, and improved graph-capture support.
  • Bug Fixes

    • Improved correctness for sparse transpose operations, including aliasing, gradients, padding, and changing sparsity patterns.
  • Documentation

    • Added guidance for interpolation ownership, sparse transpose benchmarking, measurement, and result reporting.

@copy-pr-bot

copy-pr-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: NVIDIA/warp/.coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 51803a93-2071-4eed-be67-63bf36b1f03e

📥 Commits

Reviewing files that changed from the base of the PR and between e33c4f8 and 00d9967.

📒 Files selected for processing (3)
  • asv/benchmarks/sparse/transpose.py
  • warp/tests/fem/test_fem_integrate.py
  • warp/tests/test_sparse.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The change enables row-compressed FEM interpolation for reduction="first" and updates CUDA BSR transpose sorting. Tests cover restriction changes, capacity reuse, topology, gradients, aliasing, replay, and persistence. The transpose benchmark exports captured-batch measurements.

Changes

FEM first-row interpolation compression

Layer / File(s) Summary
Row-compressed first reduction
warp/_src/fem/integrate.py, changelog/1970.changed.md
Node-restricted interpolation reserves one trial-element stencil per destination row. BSR writes use partition-node rows, while COO writes retain restriction-local rows.
Changing restrictions and replay validation
warp/tests/fem/test_fem_integrate.py
Tests compare row-compressed and triplet construction across changing restrictions, capacity reuse, invalid indices, and CUDA Graph capture.

CUDA BSR transpose updates

Layer / File(s) Summary
Transpose sorting
warp/native/sparse.cu, changelog/1971.changed.md
Transpose uses stable CUB sorting over dynamically selected destination-row bits. The specialized large sparse path was removed.
Transpose correctness and replay validation
warp/tests/test_sparse.py, warp/tests/test_apic.py
Tests cover compact and padded layouts, changing sparsity, gradients, aliasing, block transposition, CUDA Graph replay, and save/load results.
Transpose benchmark and reporting
asv/benchmarks/sparse/transpose.py, asv/benchmarks/sparse/transpose.md
The benchmark runs 100 captured transposes per timing call. Its CLI records per-transpose timings and environment metadata in JSON.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant FEMInterpolation
  participant RowCompressedBSR
  participant TripletConstruction
  participant CUDAGraph
  FEMInterpolation->>RowCompressedBSR: reserve and write destination-row stencils
  FEMInterpolation->>TripletConstruction: build restriction-local triplets
  CUDAGraph->>RowCompressedBSR: replay with reused capacity
Loading

Suggested reviewers: shi-eric

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes CUDA bsr_set_transpose() sorting and padding behavior in warp/native/sparse.cu, adds extensive sparse-transpose tests, and adds a standalone transpose benchmark and documentati… Remove the unrelated CUDA BSR transpose implementation, tests, benchmark, and documentation changes from this PR, or link an issue that explicitly requires those changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 21.74% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #1970 requires fem.interpolate(..., reduction="first", bsr_options={"construction": "row_compress"}) with a space restriction. The PR adds node-restricted row-compression support and reserves …
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies both main changes: BSR transpose performance improvements and FEM construction support for first-sample behavior. It is concise and relevant to the changeset.
Full details: Out of Scope Changes check

Explanation

The PR also changes CUDA bsr_set_transpose() sorting and padding behavior in warp/native/sparse.cu, adds extensive sparse-transpose tests, and adds a standalone transpose benchmark and documentation. Issue #1970 defines FEM interpolation with first-sample row compression as its coding scope. The PR summary does not establish a connection between these transpose performance changes and that issue.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no outstanding correctness, security, or repository-rule issue was identified.

Summary

This PR improves sparse-matrix and FEM assembly performance while preserving graph replay and differentiation behavior.

  • Restricts CUDA BSR transpose radix sorting to destination-row bits while retaining stable source ordering and padding placement.
  • Adds row-compressed reduction="first" FEM interpolation with capacity assigned only to active restriction rows.
  • Preserves first-sample ownership during backward replay and enables gradient tracking for interpolation triplet storage.
  • Adds regression coverage for changing restrictions, compact and padded topology, gradients, aliasing, power-of-two boundaries, and saved graph replay.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    R[Space restriction] --> C[Active-row capacities]
    C --> Z[Initialize padded BSR topology]
    Z --> I[Evaluate owning first sample]
    I --> W[Write row-ordered candidates]
    W --> P[Compress to compact or padded result]
    P --> T[Tape backward replay]

    S[Source BSR blocks] --> K[Encode destination-row keys]
    K --> O[Stable radix sort of row bits]
    O --> X[Build transposed offsets and blocks]
Loading

Reviews (10) · Last reviewed commit: "Link the FEM gradient fix to its issue (..."

@maxkra15 maxkra15 changed the title [Experiment] Preserve first sampling in FEM row compression [Experiment] Add active-entry BSR transpose and first-sample FEM row compression Sep 10, 2026
@maxkra15
maxkra15 marked this pull request as ready for review September 17, 2026 10:21
@maxkra15

Copy link
Copy Markdown
Contributor Author

@shi-eric @gdaviet could you please review these changes? thanks!

Comment thread asv/benchmarks/sparse/transpose.py Resolved
Comment thread changelog/1970.changed.md Resolved
Comment thread warp/tests/test_sparse.py Resolved
@maxkra15 maxkra15 changed the title [Experiment] Add active-entry BSR transpose and first-sample FEM row compression [Experiment] Speed up BSR transpose and first-sample FEM construction Sep 17, 2026
@shi-eric

Copy link
Copy Markdown
Contributor

/ok to test e33c4f8

@shi-eric
shi-eric requested a review from gdaviet September 18, 2026 16:35
@shi-eric

Copy link
Copy Markdown
Contributor

@maxkra15 Thanks, can you open this pull request on the internal GitLab? You would fork omniverse/warp. This is because we currently merge changes there first and mirror to GitHub.

@maxkra15

Copy link
Copy Markdown
Contributor Author

@shi-eric opened

@maxkra15 maxkra15 changed the title [Experiment] Speed up BSR transpose and first-sample FEM construction Speed up BSR transpose and first-sample FEM construction Sep 22, 2026
@shi-eric

Copy link
Copy Markdown
Contributor

/ok to test 032b43d

Allow direct BSR construction to retain the owning element and coefficient arithmetic of first-sample interpolation. Reserve one stencil per partition row so sparse restrictions and captured rebuilds cannot write using restriction-local row indices.

Signed-off-by: Maximilian Krause <[email protected]>
Use the same captured batches for ASV and standalone timing, explain test sizes, and cover both merge-pass parities. Link the FEM and transpose changelog fragments to NVIDIAGH-1970 and NVIDIAGH-1971.

Signed-off-by: Maximilian Krause <[email protected]>
Use the stable global sort on destination-row bits instead of the experimental row sorter. Preserve source order and reserve a sentinel above valid rows, including padded input and CUDA Graph replay.

Signed-off-by: Maximilian Krause <[email protected]>
Disable global module loading during capture after warming the captured operations. Keep benchmark initialization in setup so discovery and import remain safe before worker creation.

Signed-off-by: Maximilian Krause <[email protected]>
Use the existing array-capacity scan and restriction-node bound to avoid reserving candidate stencils for inactive partition rows. Preserve offsets for backward and cover changing restrictions under graph replay.

Signed-off-by: Maximilian Krause <[email protected]>
Bound the element loop before evaluating the selected sample so backward replay does not exit before propagating derivatives. Track gradients in triplet storage as requested by the destination. Verify both construction policies and output layouts against the partition-of-unity derivative.

Signed-off-by: Maximilian Krause <[email protected]>
Avoid replaying the ineligible adjacency prefix after sample selection. This also preserves sample-index gradients when earlier neighbors have no eligible trial nodes. Extend the gradient test with sparse point trials and empty trial slots.

Signed-off-by: Maximilian Krause <[email protected]>
Remove the standalone benchmark notes from the repository and retain reproduction instructions in the evidence archive. Limit the gradient release note to the triplet bug reproduced on the upstream base, rather than intermediate row-compression fixes.

Signed-off-by: Maximilian Krause <[email protected]>
@maxkra15
maxkra15 force-pushed the maxkra15/fem-first-row-compression branch from bb6c25c to f7d7b45 Compare September 22, 2026 17:04
@maxkra15

Copy link
Copy Markdown
Contributor Author

merged in 85e3eea

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.

Support first-sample FEM interpolation with row compression

2 participants