Skip to content

Fix rocSPARSE handle and test buffer leaks under ASAN (#388)#460

Open
zjin-lcf wants to merge 1 commit into
ORNL:developfrom
zjin-lcf:fix/issue-388-rocsparse-handle-leaks
Open

Fix rocSPARSE handle and test buffer leaks under ASAN (#388)#460
zjin-lcf wants to merge 1 commit into
ORNL:developfrom
zjin-lcf:fix/issue-388-rocsparse-handle-leaks

Conversation

@zjin-lcf

Copy link
Copy Markdown

Summary

Fixes #388. Under -DRESOLVE_USE_ASAN=yes on ROCm, LeakSanitizer reported leaks whose allocation site is inside librocsparse.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 → destroy reproducer 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 state rocsparse_destroy_mat_info frees all analysis metadata.

Changes

  • resolve/LinSolverDirectRocSparseILU0.cpp: setup() creates descr_A_, descr_L_, descr_U_, info_A_, and a device analysis buffer_, but the destructor only freed the ILU value/aux device arrays. Destroy the three matrix descriptors and the info object and free buffer_ on teardown.
  • tests/unit/matrix/SparseTests.hpp: copyValues allocated a host scratch buffer with new[] 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.

cmake -DRESOLVE_USE_ASAN=yes -DRESOLVE_USE_UBSAN=yes -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRESOLVE_USE_HIP=yes -DCMAKE_HIP_ARCHITECTURES=gfx942 ..
make -j && ctest -j
  • Before: all rocsparse_create_mat_descr / rocsparse_create_mat_info leaks present; sparse_matrix_test leaks a host buffer.
  • After: no ReSolve-attributed leaks remain. The only residual LSan reports are one-time ROCm runtime init allocations inside 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).

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>
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.

Bug: 35/46 tests fail on ROCm when using address sanitizers.

1 participant