Fix rocSPARSE handle and test buffer leaks under ASAN (#388) - #460
Open
zjin-lcf wants to merge 2 commits into
Open
Fix rocSPARSE handle and test buffer leaks under ASAN (#388)#460zjin-lcf wants to merge 2 commits into
zjin-lcf wants to merge 2 commits into
Conversation
LeakSanitizer attributed leaks to librocsparse.so, but they were caused by ReSolve creating rocSPARSE handles it never released: - LinSolverDirectRocSparseILU0 created descr_A_/descr_L_/descr_U_, info_A_, and a device buffer_ in setup() but its destructor only freed the ILU value/aux device arrays. Destroy the matrix descriptors and info object and free the analysis buffer on teardown. - SparseTests::copyValues allocated a host scratch buffer with new[] in the device code path and never freed it. Delete it (only in the device case, where it is owned; on host it aliases matrix data). A minimal create/analysis/destroy reproducer shows rocSPARSE 7.2.4 itself does not leak, so this is a ReSolve ownership bug, not a rocSPARSE defect. Co-authored-by: Cursor <cursoragent@cursor.com>
superwhiskers
approved these changes
Jul 28, 2026
superwhiskers
left a comment
Collaborator
There was a problem hiding this comment.
this will not close #388, but it does reduce the leak load
LinSolverDirectRocSolverRf::setup() creates the rocSOLVER refactorization info object infoM_ (rocsolver_create_rfinfo) and the combined-factor matrix M_ (new matrix::Csr in combineFactors), but the destructor freed neither, and repeated setup() calls leaked both again. Under LeakSanitizer this shows up as allocations attributed to librocsolver.so plus large indirect leaks from matrix::Csr::allocateMatrixData (~1.16 MB per solve in klu_rf_test). - Destroy infoM_ and delete M_ in the destructor. - Destroy any previous infoM_ before recreating it in setup(). - Delete any previous M_ before reallocating it in combineFactors(). This mirrors the existing CUDA teardown (LinSolverDirectCuSolverGLU deletes M_, CholeskySolverHip destroys its rfinfo). Verified with a KLU + HIP + ASAN build: rocsolver_rf_test drops from 1169156 B / 139 allocs to 6192 B / 108 allocs, with the residual being only one-time libhsa-runtime64.so/libamdhip64.so runtime-init allocations. Also add tests/lsan.supp, an LSan suppression file for those external ROCm runtime init allocations (see ORNL#388), which are not fixable from within ReSolve. Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
|
i think the leak suppression list added there is too broad. unless i'm misunderstanding how the suppression list works, that will, in addition to hiding the runtime globals, also hide future rocm adjacent leaks because it targets the shared objects and not the individual functions responsible for the leak |
pelesh
self-requested a review
July 31, 2026 17:04
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
Fixes handle/memory leaks in the ROCm (HIP) backend that LeakSanitizer reports under
-DRESOLVE_USE_ASAN=yes. LSan attributes the allocation sites tolibrocsparse.so/librocsolver.so, which makes them look like AMD defects, but they are actually caused by ReSolve creating rocSPARSE/rocSOLVER handles (and a device matrix) that it never destroys.Changes
resolve/LinSolverDirectRocSparseILU0.cpp:setup()createsdescr_A_,descr_L_,descr_U_,info_A_, and a device analysisbuffer_, but the destructor only freed the ILU value/aux device arrays. Destroy the three matrix descriptors and the info object and freebuffer_on teardown.resolve/LinSolverDirectRocSolverRf.cpp:setup()creates the rocSOLVER refactorization info objectinfoM_(rocsolver_create_rfinfo) and the combined-factor matrixM_(new matrix::CsrincombineFactors), but the destructor freed neither, and repeatedsetup()calls leaked both again. Now: destroyinfoM_and deleteM_in the destructor, destroy any previousinfoM_before recreating it insetup(), and delete any previousM_before reallocating it. This mirrors the existing CUDA teardown (LinSolverDirectCuSolverGLUdeletesM_;CholeskySolverHipdestroys itsrfinfo).tests/unit/matrix/SparseTests.hpp:copyValuesallocated a host scratch buffer withnew[]in the device path and never freed it. Free it in the device case (on host it aliases matrix-owned data and must not be freed).tests/lsan.supp(new): LSan suppression file for the residual, external ROCm runtime-init allocations that are not fixable from within ReSolve.Test plan
Environment: AMD Instinct MI300A (gfx942), ROCm 7.2.4.
rocsparse_create_mat_descr/rocsparse_create_mat_infoleaks present andsparse_matrix_testleaks a host buffer; after, gone.rocsolver_rf_test, requires KLU): before 1169156 B / 139 allocs (LSan namescombineFactors ... :338→M_and itsCsr::allocateMatrixDatachildren, plusrocsolver_create_rfinfo→infoM_); after 6192 B / 108 allocs.Remaining leaks (external ROCm runtime init, suppressed)
The only residual LSan output is a fixed ~6 KB inside
libhsa-runtime64.so/libamdhip64.so. Symbolizing against the library's embedded.gnu_debugdata:These are one-time HSA/HIP runtime-initialization allocations owned by the process-global
rocr::core::Runtimesingleton; HIP never callshsa_shut_down()at exit, so LSan flags them. They are:AMD's own GPU sanitizer docs classify these language-runtime allocations as "not considered to be leaks" and recommend exactly this suppression-file approach, which
tests/lsan.suppimplements.Relationship to #388
This does not fully close #388, but it eliminates all ReSolve-owned leaks in the HIP backend (ILU0 handles, rocSOLVER-Rf
infoM_/M_, and the test host buffer). The remaining LSan reports are exclusively the external, one-time ROCm runtime-init allocations covered bytests/lsan.supp.