Repository navigation
feat (sparse) : add support for the BSR sparse format - #1201
Merged
Merged
Conversation
- Add BSR_type to stdlib_sparse_kinds - Add spmv_bsr implementation in new stdlib_sparse_spmv_bsr.fypp - Register stdlib_sparse_spmv_bsr.fypp in CMakeLists.txt - Add BLAS linkage to sparse target - Update spmv interface with BSR subroutine declarations - Update COO spmv to use do concurrent with entry_index naming - Add BSR documentation to stdlib_sparse.md - Add BSR tests to test_linalg_sparse.fypp Rebased onto fortran-lang/stdlib master (0e45050)
# Conflicts: # src/sparse/stdlib_sparse_spmv_coo.fypp # src/sparse/stdlib_sparse_spmv_csc.fypp # src/sparse/stdlib_sparse_spmv_ell.fypp
feat(sparse): add BSR format and rebase sparse_bsr onto fortran-lang/stdlib master
* Initial plan
* Refactor stdlib_sparse_spmv_bsr: split OOP procedures into non-OOP kernels and thin wrappers
- Create spmv_bsr_1d_${s1}$_kernel and spmv_bsr_2d_${s1}$_kernel non-OOP subroutines
containing the full computational logic for rank=1 and rank=2 BSR SpMV respectively
- Kernel signature: (data, rowptr, col, nrows, ncols, storage, block_shape, vec_x, vec_y, alpha, beta, op)
- Update spmv_bsr_1d_${s1}$ and spmv_bsr_2d_${s1}$ OOP module subroutines to thin wrappers
that unpack matrix components and forward them to the corresponding kernel
- Eliminate all `associate` statements from OOP wrappers
- Preserve all existing numerical behavior: storage modes, ops, BLAS call semantics
* Apply remaining changes
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1201 +/- ##
=======================================
Coverage 69.62% 69.62%
=======================================
Files 20 20
Lines 2565 2565
=======================================
Hits 1786 1786
Misses 779 779 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jvdp1
approved these changes
Aug 13, 2026
| #:for k1, t1, s1 in (KINDS_TYPES) | ||
|
|
||
| !> Non-OOP rank=1 kernel for BSR SpMV | ||
| subroutine spmv_kernel_bsr_1d_${s1}$(data, rowptr, col, nrows, ncols, storage, block_shape, & |
Member
There was a problem hiding this comment.
Suggested change
| subroutine spmv_kernel_bsr_1d_${s1}$(data, rowptr, col, nrows, ncols, storage, block_shape, & | |
| subroutine spmv_kernel_bsr_1d_${s1}$(nrows, ncols, data, rowptr, col, storage, block_shape, & |
Based on #1184 , to be discussed. The goal is to be somewhat aligned on the deprecated MKL sparse subroutines.
Contributor
Author
There was a problem hiding this comment.
Actually we had discussed about extracting the dimensions from the array descriptors as we are using assumed-shape inputs.
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
Replace the per-block gemv/gemm calls by plain-loop kernels generated for square blocks of size 2 to 8, with a generic fallback for other shapes. Per-block BLAS calls were 1.3-11x slower than fixed-size loops, which now run at memory bandwidth. The BLAS dependency of the sparse library is gone. - Add the public low-level spmv_kernel_bsr with the CSR argument order. - Rank-2 vectors follow the COO/CSR convention vec(k,n): the same matrix is applied to k vectors in one pass (also fixes wrong results for k>1). - Symmetric storage: one triangle of square blocks, full diagonal blocks; lower and upper share the same kernel. - beta = 0 does not read vec_y; op 'H' on real types behaves as 'T'. - Declare the wrapper vectors contiguous to avoid copy-in/copy-out. - Fix at() mirroring for symmetric storage. - Tests: fixed hand-checkable examples plus a sweep over all kernels. - Document the BSR format and spmv_kernel_bsr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gfortran (seen with 11, 13 and 15) at -O1 and above reallocates the left-hand side of `yref = 2*matmul(opA, x) - y` with its previous size when op(A) changes shape between ops, writing past the end of yref and aborting later with "double free or corruption" (fpm CI, exit 134). Use explicit-shape arrays in a block for each op instead of reallocation on assignment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jalvesz
marked this pull request as ready for review
November 2, 2026 08:45
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add shared CSR and BSR grid example * Move grid example explanation into source ---------
Contributor
Author
|
I'll go ahead and merge this to have it available for broader testing |
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.
PR to introduce the BSR (Block Sparse Row) matrix format. Similar to the CSR format but allowing dense NxM blocks per index entry in the sparse graph.