Fix rocSPARSE handle and test buffer leaks under ASAN (#388)#460
Open
zjin-lcf wants to merge 1 commit into
Open
Fix rocSPARSE handle and test buffer leaks under ASAN (#388)#460zjin-lcf wants to merge 1 commit into
zjin-lcf wants to merge 1 commit 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>
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 #388. Under
-DRESOLVE_USE_ASAN=yeson ROCm, LeakSanitizer reported leaks whose allocation site is insidelibrocsparse.so, which made them look like a rocSPARSE (AMD) defect. Investigation shows they are actually caused by ReSolve creating rocSPARSE handles it never destroys — LSan simply reports the allocation site inside the library.A minimal
create → dcsrmv_analysis → dcsrmv → destroyreproducer built with ASAN on ROCm 7.2.4 produces zero rocSPARSE-attributed leaks, confirming a correct create/destroy pairing does not leak in rocSPARSE. The docs also staterocsparse_destroy_mat_infofrees all analysis metadata.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.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).Test plan
Environment: AMD Instinct MI300A (gfx942), ROCm 7.2.4.
rocsparse_create_mat_descr/rocsparse_create_mat_infoleaks present;sparse_matrix_testleaks a host buffer.libhsa-runtime64.so/libamdhip64.so, which are external to ReSolve and rocSPARSE.Notes
The remaining ROCm-runtime init leaks are not addressed here (they require an LSan suppression that is out of scope for this PR).