Skip to content

Add cuSPARSE safe wrapper#569

Open
g-ampo wants to merge 3 commits into
chelsea0x3b:mainfrom
g-ampo:cusparse-safe
Open

Add cuSPARSE safe wrapper#569
g-ampo wants to merge 3 commits into
chelsea0x3b:mainfrom
g-ampo:cusparse-safe

Conversation

@g-ampo

@g-ampo g-ampo commented May 6, 2026

Copy link
Copy Markdown

Add cuSPARSE safe wrapper

cuSPARSE had no safe.rs and only 2 functions in result.rs.

  • result.rs: expanded to 26 functions (handle, CSR/CSC/COO/dense descriptors, SpMV, SpMM, sparse-dense conversions). Cfg-gated for CUDA 11 vs 12.
  • safe.rs: RAII descriptor wrappers, spmv(), spmm() with automatic workspace management.

Tested SpMV and SpMM on RTX 3060 Ti (CUDA 13.0).

@g-ampo g-ampo requested a review from chelsea0x3b as a code owner May 6, 2026 21:53

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces safe abstractions for cuSPARSE, including high-level wrappers for handles and descriptors with automatic workspace management for SpMV and SpMM operations, alongside low-level FFI wrappers supporting CUDA 11 and 12. Feedback identifies critical safety issues where descriptors must hold a reference to the CUDA context to prevent undefined behavior during destruction. Additionally, several destruction functions in the low-level API contain incorrect type casts for CUDA 12, and safe wrappers for format conversions are currently missing from the implementation.

Comment thread src/cusparse/safe.rs
Comment thread src/cusparse/result.rs
Comment thread src/cusparse/safe.rs
Comment thread src/cusparse/result.rs
Comment thread src/cusparse/result.rs
Comment thread src/cusparse/result.rs
@chelsea0x3b

Copy link
Copy Markdown
Owner

Hey I'm gonna be honest, this PR is way too big for me to review and needs to be split into multiple sub PRs. I appreciate the use of agents, but this is not set up nicely for me.

Did you run the tests?

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