Address #2194: spgemm input/output sortedness - #3270
Conversation
There was a problem hiding this comment.
Pull request overview
Adds configurable SpGEMM input/output sortedness, selecting native fallbacks when TPLs require sorted inputs.
Changes:
- Adds
input_sortedandresult_sortedoptions. - Implements backend-aware fallback and conditional output sorting.
- Adds documentation and sortedness tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
sparse/unit_test/Test_Sparse_spgemm.hpp |
Adds sortedness tests. |
sparse/tpls/KokkosSparse_spgemm_numeric_tpl_spec_decl.hpp |
Makes MKL reuse sorting conditional. |
sparse/tpls/KokkosSparse_spgemm_noreuse_tpl_spec_decl.hpp |
Extends TPL signatures. |
sparse/src/KokkosSparse_spgemm.hpp |
Extends non-reuse API and fallback dispatch. |
sparse/src/KokkosSparse_spgemm_symbolic.hpp |
Adds symbolic-phase fallback. |
sparse/src/KokkosSparse_spgemm_numeric.hpp |
Adds numeric-phase fallback. |
sparse/src/KokkosSparse_spgemm_handle.hpp |
Stores sortedness settings and backend requirements. |
sparse/src/KokkosKernels_Handle.hpp |
Extends handle creation API. |
sparse/impl/KokkosSparse_spgemm_numeric_spec.hpp |
Conditionally sorts native output. |
sparse/impl/KokkosSparse_spgemm_noreuse_spec.hpp |
Propagates sortedness options. |
sparse/impl/KokkosSparse_spgemm_impl.hpp |
Selects native algorithms during fallback. |
docs/source/API/sparse/spgemm_symbolic.rst |
Documents symbolic sortedness behavior. |
docs/source/API/sparse/spgemm_numeric.rst |
Updates numeric API documentation. |
docs/source/API/sparse/handle_get_create_destroy.rst |
Documents new handle parameters. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Add input_sorted and result_sorted as options in
handle, and in non-reuse spgemm interface
- input_sorted means user promises A,B are sorted on input
- default false for backward compatibility
- result_sorted means user needs output C to be sorted
- default true for backward compatibility
- if a TPL is known to require sorted inputs but input_sorted=false,
fall back to native
- Add tests for reuse and non-reuse cases where input_sorted
is explicitly false, and where result_sorted is explicitly true.
- Document the changes to create_spgemm_handle and spgemm itself
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Brian Kelley <bmkelle@sandia.gov>
Signed-off-by: Brian Kelley <bmkelle@sandia.gov>
61f4b73 to
a30cbed
Compare
| template <class CMatrix, class AMatrix, class BMatrix> | ||
| CMatrix spgemm(KokkosSparse::SPGEMMAlgorithm algo, const AMatrix& A, const bool Amode, const BMatrix& B, | ||
| const bool Bmode) { | ||
| const bool Bmode, bool input_sorted = false, bool result_sorted = true) { |
There was a problem hiding this comment.
@brian-kelley just to make sure I'm following, these new defaulted argument options keep existing behavior for backward compatibility?
There was a problem hiding this comment.
Correct, these are the most conservative settings for each option and match what was provided by most spgemm paths before this PR. We had all paths sort the output, and all TPLs had a debug check that inputs were sorted.
| // testing) | ||
| const bool useFallback = | ||
| !spgemmHandle->get_input_sorted() && Impl::algorithm_may_require_sorted_input<c_exec_t>(algo); | ||
| if (Impl::is_spgemm_algorithm_native(algo) || useFallback) { |
There was a problem hiding this comment.
Is there a way for users to know or be warned if their request for a particular algorithm was overridden by the fallback path?
There was a problem hiding this comment.
There isn't a warning, but the best way to know what's running is using the kokkos-tools kernel logger or timer. Then you will see a TPL region name for TPLs, or a KK kernel name for native. But this is at least consistent with how several other kernels do fallback paths (dot, gemv, spmv).
| const bool useFallback = | ||
| !spgemmHandle->get_input_sorted() && Impl::algorithm_may_require_sorted_input<c_exec_t>(algo); | ||
|
|
||
| if (Impl::is_spgemm_algorithm_native(algo) || useFallback) { |
There was a problem hiding this comment.
Is there a way for users to know or be warned if their request for a particular algorithm was overridden by the fallback path?
There was a problem hiding this comment.
See above about numeric
ndellingwood
left a comment
There was a problem hiding this comment.
Thanks @brian-kelley !
Addresses #2194 and fixes trilinos/Trilinos#15105.
Adds
input_sortedandresult_sortedas options in spgemm handle, and as parameters in non-reuse spgemm interface.This also adds test cases for reuse and non-reuse spgemm where input_sorted is explicitly false, and where result_sorted is explicitly true. The changes to
create_spgemm_handleand spgemm itself are documented on the wiki pages.