Skip to content

Fix cuSPARSE handle and test buffer leaks under ASAN - #461

Closed
zjin-lcf wants to merge 1 commit into
ORNL:developfrom
zjin-lcf:fix/issue-387-cusparse-handle-leaks
Closed

Fix cuSPARSE handle and test buffer leaks under ASAN#461
zjin-lcf wants to merge 1 commit into
ORNL:developfrom
zjin-lcf:fix/issue-387-cusparse-handle-leaks

Conversation

@zjin-lcf

Copy link
Copy Markdown

Summary

Addresses #387. When ReSolve is built with the address sanitizer (-DRESOLVE_USE_ASAN=yes) on CUDA, many unit tests fail with leaks reported from libcusparse. The root cause is that the cuSPARSE ILU0 direct solver never releases the cuSPARSE resources it creates.

LinSolverDirectCuSparseILU0::setup() allocates:

  • a matrix descriptor (descr_A_),
  • two sparse-matrix descriptors (mat_L_, mat_U_),
  • two SpSV descriptors (descr_spsv_L_, descr_spsv_U_),
  • a csrilu02Info_t info structure (info_A_),
  • and three device work buffers (buffer_, buffer_L_, buffer_U_),

but the destructor only freed d_aux1_, d_aux2_, and d_ILU_vals_. Every solver instance therefore leaked the descriptors, info struct, and buffers, which ASAN attributes to the cuSPARSE library.

Changes

  • Destroy all cuSPARSE descriptors/info and free the device work buffers in ~LinSolverDirectCuSparseILU0().
  • Free the scratch host buffer allocated in the device path of the sparse matrix copy test (tests/unit/matrix/SparseTests.hpp), which leaked on device builds.

This mirrors the approach taken for the rocSPARSE analog in #388.

Notes

Some of the allocations reported by ASAN in the issue originate inside NVIDIA libraries (libcuda/libcublas one-time initialization via cuInit) and are outside ReSolve's control; those are not addressed here.

Test plan

  • Configure with -DRESOLVE_USE_ASAN=yes -DRESOLVE_USE_UBSAN=yes -DRESOLVE_USE_CUDA=yes and run ctest -j; verify the previously failing tests no longer report leaks from the ILU0 solver or the sparse matrix copy test.

The CuSPARSE ILU0 direct solver allocated matrix descriptors, sparse
matrix descriptors, SpSV descriptors, an ILU02 info structure, and three
device work buffers in setup() but never released them, so every solver
instance leaked these resources. Under AddressSanitizer these surfaced as
leaks originating from libcusparse, causing unit tests to fail.

Release all of these resources in the destructor. Also free the scratch
host buffer allocated in the device path of the sparse matrix copy test,
which leaked on device builds.

Fixes ORNL#387

Co-authored-by: Cursor <cursoragent@cursor.com>
@pelesh

pelesh commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

@zjin-lcf, thank you for your contribution. Please re-open the pull request when reproducible test results (before and after) are available together with hardware specs and CUDA version. Closing for now.

@pelesh pelesh closed this Jul 31, 2026
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.

2 participants