Skip to content

Add support for general CSR(A) x CSR(B) sparse matrix multiplication#22

Open
Saptami191 wants to merge 1 commit into
merledu:mainfrom
Saptami191:fix-general-spgemm
Open

Add support for general CSR(A) x CSR(B) sparse matrix multiplication#22
Saptami191 wants to merge 1 commit into
merledu:mainfrom
Saptami191:fix-general-spgemm

Conversation

@Saptami191

@Saptami191 Saptami191 commented May 20, 2026

Copy link
Copy Markdown

Fixes #21

Summary

This PR adds support for general CSR(A) × CSR(B) sparse matrix multiplication instead of assuming self-multiplication (A × A).

The current implementation in AxBRowIP.c loaded the same CSR files for both matrices and reused the same dimension metadata, which restricted the kernel to square self-multiplication workloads and caused incorrect handling for general rectangular SpGEMM cases.


Changes

General SpGEMM Support

  • Added separate CSR export/import for matrices A and B
  • Added support for independent:
    • dimensions (M, K, N)
    • NNZ counts (aNNZ, bNNZ)
    • CSR arrays for A and B

Dimension & Correctness Fixes

  • Fixed incorrect initialization of:
    • N
    • bNNZ
  • Updated accumulator/output traversal to correctly iterate across N instead of K
  • Added validation support for rectangular matrix multiplication

COO → CSR Improvements

  • Added sorting of COO entries before CSR conversion to ensure stable CSR row ordering
  • This helps preserve correctness assumptions for future traversal/merge-based sparse optimizations

Test Matrices

Added:

  • square matrix examples
  • rectangular matrix examples

for reproducible validation and testing.


Validation

Tested successfully on:

  • square matrix multiplication
  • rectangular matrix multiplication

Verified example:

[
(2 \times 3) \times (3 \times 4)
\rightarrow (2 \times 4)
]

Example runtime output:

Matrix A: 2 x 3, NNZ = 3
Matrix B: 3 x 4, NNZ = 4

Estimated cNNZ = 10
Actual cNNZ = 4

Resulting Matrix C (non-zero entries):
C[0][0] = 14.00
C[0][1] = 5.00
C[0][3] = 16.00
C[1][2] = 18.00

Screenshot 2026-05-20 231024

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.

Support general CSR(A) × CSR(B) sparse matrix multiplication

1 participant