Skip to content

Fix segfault - #19

Merged
alexkorovko merged 2 commits into
mainfrom
dev/ak/fix_segfault
Jul 13, 2026
Merged

Fix segfault#19
alexkorovko merged 2 commits into
mainfrom
dev/ak/fix_segfault

Conversation

@alexkorovko

@alexkorovko alexkorovko commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Fixed optimization failures when reusing a minimizer after switching to a problem with fewer state batches.
    • Updated GPU state and pointer buffers to resize correctly for both growth and shrinkage, preventing stale entries.
  • Tests

    • Added regression coverage for consecutive Gauss-Newton optimizations where the state batch count decreases between runs.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 7ae93168-349f-4af5-8db8-74728f5fe82e

📥 Commits

Reviewing files that changed from the base of the PR and between d4dd454 and 9c750b3.

📒 Files selected for processing (2)
  • cunls/minimizer/minimizer_state.cu
  • tests/gauss_newton_test.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • cunls/minimizer/minimizer_state.cu
  • tests/gauss_newton_test.cpp

📝 Walkthrough

Walkthrough

The CUDA minimizer now resizes state and pointer buffers on both growth and shrinkage of problem topology. A regression test reuses one Gauss-Newton minimizer across problems with decreasing state-batch counts.

Changes

Minimizer state batch reuse

Layer / File(s) Summary
Exact-size buffer management
cunls/minimizer/minimizer_state.cu
State, state-pointer, and problem-pointer buffers resize when their required batch counts change, including topology shrinkage; surrounding formatting changes preserve behavior.
Decreasing batch regression coverage
tests/gauss_newton_test.cpp
Tests reuse a Gauss-Newton minimizer across two-state-batch and one-state-batch problems, checking consistency, synchronizing CUDA execution, and validating that the second minimization does not throw.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is directly related to the change set, which fixes a segfault caused by buffer/state reuse issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/ak/fix_segfault

Warning

Tools execution failed with the following error:

Failed to run tools: 14 UNAVAILABLE: read ECONNRESET


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cunls/minimizer/minimizer_state.cu (1)

70-90: 🚀 Performance & Scalability | 🔵 Trivial | 🏗️ Heavy lift

Avoid freeing batch buffers on the shrink path. states_.resize(state_batches.size()) only makes the outer vector shorter, but that still destroys the dropped DeviceVectors, and DeviceVector::~DeviceVector() calls cudaFree. The inner state_vec.resize(size) is cheap when the new size fits capacity, so the stall risk here comes from recurring topology shrink itself; if that path is common, keep the removed buffers around or move DeviceVector to an async/pool-backed allocator.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cunls/minimizer/minimizer_state.cu` around lines 70 - 90, Update
MinimizerState::CreateStates so shrinking the topology does not destroy dropped
DeviceVectors or invoke cudaFree through their destructors. Preserve removed
batch buffers for reuse, or replace their allocation with an async/pool-backed
strategy, while retaining existing resizing behavior for active batches.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cunls/minimizer/minimizer_state.cu`:
- Around line 70-90: Update MinimizerState::CreateStates so shrinking the
topology does not destroy dropped DeviceVectors or invoke cudaFree through their
destructors. Preserve removed batch buffers for reuse, or replace their
allocation with an async/pool-backed strategy, while retaining existing resizing
behavior for active batches.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 62fab16a-e1f5-43f4-83bb-caa2ab233f22

📥 Commits

Reviewing files that changed from the base of the PR and between d0aa5a2 and d4dd454.

📒 Files selected for processing (2)
  • cunls/minimizer/minimizer_state.cu
  • tests/gauss_newton_test.cpp

@alexkorovko
alexkorovko merged commit 71609ba into main Jul 13, 2026
10 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.

1 participant