Repository navigation
feat(rocsparse): add the rocsparse_spsort public API #12553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4306388
Add the rocsparse_spsort public API
jsandham 6294f46
Address review comments on the rocsparse_spsort API
jsandham 76a480a
Fix the include order in rocsparse-generic.h for clang-format
jsandham 35afb02
Document that rocsparse_spsort only supports uniform batches
jsandham b49dca7
Move the rocsparse_spsort auxiliary docs after the rocsparse_spgeam ones
jsandham 5cd9ee9
Document that only the COO format uses the rocsparse_spsort direction
jsandham f206601
Address rocsparse_spsort API review comments
jsandham ee0206c
Fix the rocsparse_spsort documentation build and document new errors
jsandham c81eaf9
Add the SpSort routines to the CHANGELOG
jsandham ad34233
Merge branch 'develop' of https://github.com/ROCm/rocm-libraries into…
jsandham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
143 changes: 143 additions & 0 deletions
143
projects/rocsparse/library/include/internal/generic/rocsparse_spsort.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /*! \file */ | ||
| /* ************************************************************************ | ||
| * Copyright (C) 2026 Advanced Micro Devices, Inc. All rights Reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the Software), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| * ************************************************************************ */ | ||
|
|
||
| #ifndef ROCSPARSE_SPSORT_H | ||
| #define ROCSPARSE_SPSORT_H | ||
|
|
||
| #include "../../rocsparse-types.h" | ||
| #include "rocsparse/rocsparse-export.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /*! \ingroup generic_module | ||
| * \details | ||
| * \p rocsparse_spsort_buffer_size returns the size of the required buffer to execute the given stage of the SpSort operation. | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * @param[in] | ||
| * handle handle to the rocSPARSE library context queue. | ||
| * @param[in] | ||
| * descr SpSort descriptor. | ||
| * @param[in] | ||
| * mat_A sparse matrix \f$A\f$ descriptor, the matrix to sort. | ||
| * @param[in] | ||
| * mat_B sparse matrix \f$B\f$ descriptor, the sorted output matrix. \p mat_B can be the same | ||
| * descriptor as \p mat_A to sort in place. | ||
| * @param[in] | ||
| * stage SpSort stage for the SpSort computation. | ||
| * @param[out] | ||
| * buffer_size number of bytes of the temporary storage buffer. | ||
| * @param[out] | ||
| * error error descriptor created if the returned status is not \ref rocsparse_status_success. A null pointer can be passed if an error descriptor is not required. | ||
| * | ||
| * \retval rocsparse_status_success the operation completed successfully. | ||
| * \retval rocsparse_status_invalid_handle the library context was not initialized. | ||
| * \retval rocsparse_status_invalid_pointer \p descr, \p mat_A, \p mat_B, or \p buffer_size pointer is invalid. | ||
| * \retval rocsparse_status_invalid_size \p mat_A and \p mat_B do not have the same dimensions or number of non-zeros, or the batch strides make the batches overlap. | ||
| * \retval rocsparse_status_invalid_value \p mat_A and \p mat_B do not have the same format, index types, data type, index base or batch count, or the direction is not supported for the format of \p mat_A. | ||
| * \retval rocsparse_status_not_implemented \p mat_A is not in COO, CSR or CSC format. | ||
| */ | ||
| ROCSPARSE_EXPORT | ||
| rocsparse_status rocsparse_spsort_buffer_size(rocsparse_handle handle, | ||
| rocsparse_spsort_descr descr, | ||
| rocsparse_const_spmat_descr mat_A, | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| rocsparse_spmat_descr mat_B, | ||
| rocsparse_spsort_stage stage, | ||
| size_t* buffer_size, | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| rocsparse_error* error); | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
|
|
||
| /*! \ingroup generic_module | ||
| * \brief Sparse matrix sorting. | ||
| * | ||
| * \details | ||
| * \p rocsparse_spsort sorts the sparse matrix \f$A\f$ and writes the result to the sparse matrix | ||
| * \f$B\f$. \f$A\f$ is left unchanged. \f$B\f$ must be created with the same format, dimensions, | ||
| * number of non-zeros, index types, data type and index base as \f$A\f$. If the same descriptor | ||
| * is passed for \p mat_A and \p mat_B, the matrix is sorted in place. Otherwise, the arrays of | ||
| * \f$B\f$ must not overlap the arrays of \f$A\f$. | ||
| * | ||
| * The supported formats are \ref rocsparse_format_coo, \ref rocsparse_format_csr and | ||
| * \ref rocsparse_format_csc. The direction set with \ref rocsparse_spsort_input_direction | ||
| * selects the sort order: | ||
| * - COO: \ref rocsparse_direction_row sorts the entries by row and then by column, and | ||
| * \ref rocsparse_direction_column sorts them by column and then by row. | ||
| * - CSR: only the column indices within each row are sorted, so the direction must be | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * \ref rocsparse_direction_row. The row pointer of \f$B\f$ is a copy of the row pointer of \f$A\f$. | ||
| * - CSC: only the row indices within each column are sorted, so the direction must be | ||
| * \ref rocsparse_direction_column. The column pointer of \f$B\f$ is a copy of the column pointer of \f$A\f$. | ||
| * | ||
| * Batched matrices are supported. They are set up with \ref rocsparse_coo_set_strided_batch, | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * \ref rocsparse_csr_set_strided_batch or \ref rocsparse_csc_set_strided_batch. Each batch is | ||
| * sorted independently. \f$A\f$ and \f$B\f$ must have the same batch count, and the strides of | ||
| * \f$A\f$ and \f$B\f$ may differ. Batches must not overlap: | ||
| * - The COO batch stride, and the CSR/CSC columns/values batch stride, must be at least the | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * number of non-zeros. | ||
| * - The CSR/CSC offsets batch stride must be zero, meaning all batches share one pointer | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * array, or at least the size of the pointer array. The offsets batch stride of \f$B\f$ | ||
| * can only be zero if the offsets batch stride of \f$A\f$ is zero. | ||
| * | ||
| * \note | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * This routine does not support execution in a hipGraph context. | ||
| * | ||
| * @param[in] | ||
| * handle handle to the rocSPARSE library context queue. | ||
| * @param[in] | ||
| * descr SpSort descriptor. | ||
| * @param[in] | ||
| * mat_A sparse matrix \f$A\f$ descriptor, the matrix to sort. | ||
| * @param[inout] | ||
| * mat_B sparse matrix \f$B\f$ descriptor, the sorted output matrix. \p mat_B can be the same | ||
| * descriptor as \p mat_A to sort in place. | ||
| * @param[in] | ||
| * stage SpSort stage for the SpSort computation. | ||
| * @param[in] | ||
| * buffer_size number of bytes of the temporary storage buffer. \p buffer_size is | ||
| * determined by calling \ref rocsparse_spsort_buffer_size. | ||
| * @param[in] | ||
| * temp_buffer temporary storage buffer allocated by the user. | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * @param[out] | ||
| * error error descriptor created if the returned status is not \ref rocsparse_status_success. A null pointer can be passed if an error descriptor is not required. | ||
|
jsandham marked this conversation as resolved.
Resolved
|
||
| * | ||
| * \retval rocsparse_status_success the operation completed successfully. | ||
| * \retval rocsparse_status_invalid_handle the library context was not initialized. | ||
| * \retval rocsparse_status_invalid_pointer \p descr, \p mat_A, \p mat_B, or \p temp_buffer pointer is invalid. | ||
| * \retval rocsparse_status_invalid_size \p mat_A and \p mat_B do not have the same dimensions or number of non-zeros, or the batch strides make the batches overlap. | ||
| * \retval rocsparse_status_invalid_value \p mat_A and \p mat_B do not have the same format, index types, data type, index base or batch count, or the direction is not supported for the format of \p mat_A. | ||
| * \retval rocsparse_status_not_implemented \p mat_A is not in COO, CSR or CSC format. | ||
| */ | ||
| ROCSPARSE_EXPORT | ||
| rocsparse_status rocsparse_spsort(rocsparse_handle handle, | ||
| rocsparse_spsort_descr descr, | ||
| rocsparse_const_spmat_descr mat_A, | ||
| rocsparse_spmat_descr mat_B, | ||
| rocsparse_spsort_stage stage, | ||
| size_t buffer_size, | ||
| void* temp_buffer, | ||
| rocsparse_error* error); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* ROCSPARSE_SPSORT_H */ | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.