Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d06fe66
inital spgeam
ntrost57 Jul 21, 2026
3e17960
docs(hipsparse): add SpGEAM generic API reference
kliegeois Jul 21, 2026
7e89aa8
test(hipsparse): exercise SpGEAM pattern merge with independent B
kliegeois Jul 21, 2026
679bd42
test(hipsparse): cover SpGEAM alpha/beta zero edge cases
kliegeois Jul 21, 2026
e42c34c
fix(hipsparse): reject unsupported SpGEAM operations and formats
kliegeois Jul 21, 2026
f0c9974
chore(hipsparse): apply clang-format and fix SpGEAM copyright year
kliegeois Jul 21, 2026
b4a084e
chore(hipsparse): keep utility.h Entry alignment clang-format-13 clean
kliegeois Jul 21, 2026
d7f19f0
address review comments on SpGEAM PR
kliegeois Jul 21, 2026
17d8288
address review comments: cusparse casts and remove 12.8 tests
kliegeois Jul 21, 2026
5fcd674
fix(hipsparse): restrict SpGEAM cuSPARSE tests to supported cases
kliegeois Jul 21, 2026
fa2cc0a
test(hipsparse): match cuSPARSE SpGEAM zero-scalar semantics
kliegeois Jul 21, 2026
91751ab
test(hipsparse): use a single base index for cuSPARSE SpGEAM tests
kliegeois Jul 21, 2026
e162794
fix(hipsparse): install the SpGEAM public header
kliegeois Jul 22, 2026
319ba98
Merge remote-tracking branch 'upstream/develop' into task/spgeam
kliegeois Aug 5, 2026
3538267
feat(hipsparse): match cuSPARSE SpGEAM zero-scalar semantics on ROCm …
kliegeois Aug 5, 2026
5075ec5
docs(hipsparse): update SpGEAM zero-scalar test comments
kliegeois Aug 5, 2026
5d272a3
Merge branch 'develop' into users/kliegeois/hipsparse-spgeam
kliegeois Aug 5, 2026
c18a237
Merge branch 'develop' into users/kliegeois/hipsparse-spgeam
kliegeois Aug 5, 2026
eee22c7
feat(hipsparse): add SpGEAM \brief docs and a HIPSPARSE_WITH_SPGEAM f…
kliegeois Aug 5, 2026
c735e2c
docs(hipsparse): target the generic SpGEAM API at the 5.1 release
kliegeois Aug 5, 2026
5d90139
docs(hipsparse): drop build-option note from SpGEAM changelog entry
kliegeois Aug 5, 2026
21c4846
style(hipsparse): guard SpGEAM "#if(" directives from clang-format 19
kliegeois Aug 5, 2026
fa5cc41
Merge branch 'develop' into users/kliegeois/hipsparse-spgeam
kliegeois Aug 6, 2026
ee2cbdc
docs(hipsparse): mark 4.7.0 as released for ROCm 10.0 in changelog
kliegeois Aug 6, 2026
64ce56c
docs(hipsparse): restore blank line before 4.8.0 changelog header
kliegeois Aug 6, 2026
5912fce
fix(hipsparse): use include-root-relative path for hipsparse-config.h…
kliegeois Aug 6, 2026
d6a00ad
Move SpGEAM alg converter into wrapper to avoid utility.h format conf…
kliegeois Aug 6, 2026
96e6801
Merge branch 'develop' into users/kliegeois/hipsparse-spgeam
kliegeois Aug 7, 2026
9adc79f
Merge branch 'develop' into users/kliegeois/hipsparse-spgeam
kliegeois Aug 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions projects/hipsparse/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Documentation for hipSPARSE is available at
## (Unreleased) hipSPARSE 4.7.0

### Added
* Added the generic API routines `hipsparseSpGEAM_createDescr`, `hipsparseSpGEAM_destroyDescr`, `hipsparseSpGEAM_bufferSize`, `hipsparseSpGEAM_nnz`, and `hipsparseSpGEAM` for sparse matrix-matrix addition (`C = alpha * op(A) + beta * op(B)`), along with the `hipsparseSpGEAMDescr_t` type and the `hipsparseSpGEAMAlg_t` algorithm enum, to match the cuSPARSE 13.3 generic `SpGEAM` API.
* Added Blocked ELL format support to the `hipsparseDenseToSparse` routine, along with the new `hipsparseBlockedEllSetPointers` function.
* Added the `HIPSPARSE_SPMV_CSR_ALG3` algorithm to `hipsparseSpMV`, which exposes the rocSPARSE CSR nnz split algorithm (`rocsparse_spmv_alg_csr_nnzsplit`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ namespace hipsparse_test
};
#endif

#if(!defined(CUDART_VERSION) || CUDART_VERSION >= 13030)
struct spgeam_struct
{
hipsparseSpGEAMDescr_t descr;
spgeam_struct()
{
hipsparseStatus_t status = hipsparseSpGEAM_createDescr(&descr);
verify_hipsparse_status_success(status, "ERROR: spgeam_struct constructor");
}

~spgeam_struct()
{
hipsparseStatus_t status = hipsparseSpGEAM_destroyDescr(descr);
verify_hipsparse_status_success(status, "ERROR: spgeam_struct destructor");
}
};
#endif

} // namespace hipsparse_test

using hipsparse_unique_ptr = std::unique_ptr<void, void (*)(void*)>;
Expand Down
616 changes: 616 additions & 0 deletions projects/hipsparse/clients/include/testing_spgeam_csr.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ add_executable(example_hipsparse_sparse_to_dense_cpp)
target_sources(example_hipsparse_sparse_to_dense_cpp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/example_hipsparse_sparse_to_dense_cpp.cpp")
target_link_libraries(example_hipsparse_sparse_to_dense_cpp PRIVATE hipsparse::samples-common)

add_executable(example_hipsparse_spgeam_cpp)
target_sources(example_hipsparse_spgeam_cpp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/example_hipsparse_spgeam_cpp.cpp")
target_link_libraries(example_hipsparse_spgeam_cpp PRIVATE hipsparse::samples-common)

add_executable(example_hipsparse_spgemm_cpp)
target_sources(example_hipsparse_spgemm_cpp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/example_hipsparse_spgemm_cpp.cpp")
target_link_libraries(example_hipsparse_spgemm_cpp PRIVATE hipsparse::samples-common)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
/* ************************************************************************
* 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.
*
* ************************************************************************ */

#include <hip/hip_runtime_api.h>
#include <hipsparse/hipsparse.h>
#include <iostream>
#include <vector>

#define HIP_CHECK(stat) \
{ \
if(stat != hipSuccess) \
{ \
std::cerr << "Error: hip error in line " << __LINE__ << std::endl; \
return -1; \
} \
}

#define HIPSPARSE_CHECK(stat) \
{ \
if(stat != HIPSPARSE_STATUS_SUCCESS) \
{ \
std::cerr << "Error: hipsparse error in line " << __LINE__ << std::endl; \
return -1; \
} \
}

//! [doc example start]
int main()
{
// C = alpha * A + beta * B, where A, B and C are m x n CSR matrices.
// 1 2 0 0
// A = 0 0 3 0
// 0 4 0 5
int m = 3;
int n = 4;

std::vector<int> hcsr_row_ptr_A = {0, 2, 3, 5};
std::vector<int> hcsr_col_ind_A = {0, 1, 2, 1, 3};
std::vector<float> hcsr_val_A = {1, 2, 3, 4, 5};

// 0 1 0 6
// B = 2 0 0 0
// 0 0 7 8
std::vector<int> hcsr_row_ptr_B = {0, 2, 3, 5};
std::vector<int> hcsr_col_ind_B = {1, 3, 0, 2, 3};
std::vector<float> hcsr_val_B = {1, 6, 2, 7, 8};

int nnz_A = hcsr_col_ind_A.size();
int nnz_B = hcsr_col_ind_B.size();

float alpha = 1.0f;
float beta = 1.0f;

// Device memory for A and B
int* dcsr_row_ptr_A;
int* dcsr_col_ind_A;
float* dcsr_val_A;
int* dcsr_row_ptr_B;
int* dcsr_col_ind_B;
float* dcsr_val_B;

HIP_CHECK(hipMalloc((void**)&dcsr_row_ptr_A, sizeof(int) * (m + 1)));
HIP_CHECK(hipMalloc((void**)&dcsr_col_ind_A, sizeof(int) * nnz_A));
HIP_CHECK(hipMalloc((void**)&dcsr_val_A, sizeof(float) * nnz_A));
HIP_CHECK(hipMalloc((void**)&dcsr_row_ptr_B, sizeof(int) * (m + 1)));
HIP_CHECK(hipMalloc((void**)&dcsr_col_ind_B, sizeof(int) * nnz_B));
HIP_CHECK(hipMalloc((void**)&dcsr_val_B, sizeof(float) * nnz_B));

HIP_CHECK(hipMemcpy(
dcsr_row_ptr_A, hcsr_row_ptr_A.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(
dcsr_col_ind_A, hcsr_col_ind_A.data(), sizeof(int) * nnz_A, hipMemcpyHostToDevice));
HIP_CHECK(
hipMemcpy(dcsr_val_A, hcsr_val_A.data(), sizeof(float) * nnz_A, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(
dcsr_row_ptr_B, hcsr_row_ptr_B.data(), sizeof(int) * (m + 1), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(
dcsr_col_ind_B, hcsr_col_ind_B.data(), sizeof(int) * nnz_B, hipMemcpyHostToDevice));
HIP_CHECK(
hipMemcpy(dcsr_val_B, hcsr_val_B.data(), sizeof(float) * nnz_B, hipMemcpyHostToDevice));

// The C row offsets array can be allocated up front
int* dcsr_row_ptr_C;
HIP_CHECK(hipMalloc((void**)&dcsr_row_ptr_C, sizeof(int) * (m + 1)));

hipsparseHandle_t handle;
HIPSPARSE_CHECK(hipsparseCreate(&handle));

hipsparseConstSpMatDescr_t matA, matB;
hipsparseSpMatDescr_t matC;

HIPSPARSE_CHECK(hipsparseCreateConstCsr(&matA,
m,
n,
nnz_A,
dcsr_row_ptr_A,
dcsr_col_ind_A,
dcsr_val_A,
HIPSPARSE_INDEX_32I,
HIPSPARSE_INDEX_32I,
HIPSPARSE_INDEX_BASE_ZERO,
HIP_R_32F));
HIPSPARSE_CHECK(hipsparseCreateConstCsr(&matB,
m,
n,
nnz_B,
dcsr_row_ptr_B,
dcsr_col_ind_B,
dcsr_val_B,
HIPSPARSE_INDEX_32I,
HIPSPARSE_INDEX_32I,
HIPSPARSE_INDEX_BASE_ZERO,
HIP_R_32F));

// Create C with a zero nnz for now, its column indices and values are allocated later
HIPSPARSE_CHECK(hipsparseCreateCsr(&matC,
m,
n,
0,
dcsr_row_ptr_C,
nullptr,
nullptr,
HIPSPARSE_INDEX_32I,
HIPSPARSE_INDEX_32I,
HIPSPARSE_INDEX_BASE_ZERO,
HIP_R_32F));

hipsparseSpGEAMDescr_t spgeamDescr;
HIPSPARSE_CHECK(hipsparseSpGEAM_createDescr(&spgeamDescr));

// Query and allocate the shared workspace
size_t bufferSize = 0;
HIPSPARSE_CHECK(hipsparseSpGEAM_bufferSize(handle,
HIPSPARSE_OPERATION_NON_TRANSPOSE,
HIPSPARSE_OPERATION_NON_TRANSPOSE,
&alpha,
matA,
&beta,
matB,
matC,
HIP_R_32F,
HIPSPARSE_SPGEAM_ALG1,
spgeamDescr,
&bufferSize));

void* dbuffer;
HIP_CHECK(hipMalloc(&dbuffer, bufferSize));

// Compute the number of non-zeros and the row offsets of C
HIPSPARSE_CHECK(hipsparseSpGEAM_nnz(handle,
HIPSPARSE_OPERATION_NON_TRANSPOSE,
HIPSPARSE_OPERATION_NON_TRANSPOSE,
&alpha,
matA,
&beta,
matB,
matC,
HIP_R_32F,
HIPSPARSE_SPGEAM_ALG1,
spgeamDescr,
dbuffer));

// Retrieve the number of non-zeros in C
int64_t rows_C, cols_C, nnz_C;
HIPSPARSE_CHECK(hipsparseSpMatGetSize(matC, &rows_C, &cols_C, &nnz_C));

// Allocate the C column indices and values arrays and set them on the descriptor
int* dcsr_col_ind_C;
float* dcsr_val_C;
HIP_CHECK(hipMalloc((void**)&dcsr_col_ind_C, sizeof(int) * nnz_C));
HIP_CHECK(hipMalloc((void**)&dcsr_val_C, sizeof(float) * nnz_C));
HIPSPARSE_CHECK(hipsparseCsrSetPointers(matC, dcsr_row_ptr_C, dcsr_col_ind_C, dcsr_val_C));

// Compute C = alpha * A + beta * B
HIPSPARSE_CHECK(hipsparseSpGEAM(handle,
HIPSPARSE_OPERATION_NON_TRANSPOSE,
HIPSPARSE_OPERATION_NON_TRANSPOSE,
&alpha,
matA,
&beta,
matB,
matC,
HIP_R_32F,
HIPSPARSE_SPGEAM_ALG1,
spgeamDescr,
dbuffer));

// Copy C back to the host and print it
std::vector<int> hcsr_row_ptr_C(m + 1);
std::vector<int> hcsr_col_ind_C(nnz_C);
std::vector<float> hcsr_val_C(nnz_C);

HIP_CHECK(hipMemcpy(
hcsr_row_ptr_C.data(), dcsr_row_ptr_C, sizeof(int) * (m + 1), hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(
hcsr_col_ind_C.data(), dcsr_col_ind_C, sizeof(int) * nnz_C, hipMemcpyDeviceToHost));
HIP_CHECK(
hipMemcpy(hcsr_val_C.data(), dcsr_val_C, sizeof(float) * nnz_C, hipMemcpyDeviceToHost));

std::cout << "C = alpha * A + beta * B (nnz = " << nnz_C << ")" << std::endl;
for(int i = 0; i < m; i++)
{
std::vector<float> row(n, 0.0f);
for(int j = hcsr_row_ptr_C[i]; j < hcsr_row_ptr_C[i + 1]; j++)
{
row[hcsr_col_ind_C[j]] = hcsr_val_C[j];
}
for(int j = 0; j < n; j++)
{
std::cout << row[j] << " ";
}
std::cout << std::endl;
}

// Clean up
HIPSPARSE_CHECK(hipsparseSpGEAM_destroyDescr(spgeamDescr));
HIPSPARSE_CHECK(hipsparseDestroySpMat(matA));
HIPSPARSE_CHECK(hipsparseDestroySpMat(matB));
HIPSPARSE_CHECK(hipsparseDestroySpMat(matC));
HIPSPARSE_CHECK(hipsparseDestroy(handle));

HIP_CHECK(hipFree(dbuffer));
HIP_CHECK(hipFree(dcsr_row_ptr_A));
HIP_CHECK(hipFree(dcsr_col_ind_A));
HIP_CHECK(hipFree(dcsr_val_A));
HIP_CHECK(hipFree(dcsr_row_ptr_B));
HIP_CHECK(hipFree(dcsr_col_ind_B));
HIP_CHECK(hipFree(dcsr_val_B));
HIP_CHECK(hipFree(dcsr_row_ptr_C));
HIP_CHECK(hipFree(dcsr_col_ind_C));
HIP_CHECK(hipFree(dcsr_val_C));

return 0;
}
//! [doc example end]
1 change: 1 addition & 0 deletions projects/hipsparse/clients/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ target_sources(hipsparse-test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/test_spmm_batched_coo.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_spmm_bell.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_spmm_bsr.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_spgeam_csr.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_spgemm_csr.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_spgemmreuse_csr.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_sddmm_csr.cpp"
Expand Down
2 changes: 2 additions & 0 deletions projects/hipsparse/clients/tests/cuda/13/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(HIPSPARSE_TEST_SOURCES
test_sparse_to_dense_coo.cpp
test_sparse_to_dense_csc.cpp
test_sparse_to_dense_csr.cpp
test_spgeam_csr.cpp
test_spgemm_csr.cpp
test_spgemmreuse_csr.cpp
test_spmat_descr.cpp
Expand Down Expand Up @@ -67,6 +68,7 @@ set(HIPSPARSE_TEST_YAMLS
cuda/13/test_sparse_to_dense_coo.yaml
cuda/13/test_sparse_to_dense_csc.yaml
cuda/13/test_sparse_to_dense_csr.yaml
cuda/13/test_spgeam_csr.yaml
cuda/13/test_spgemm_csr.yaml
cuda/13/test_spgemmreuse_csr.yaml
cuda/13/test_spmm_batched_coo.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include: test_dense_to_sparse_csr.yaml
include: test_sparse_to_dense_coo.yaml
include: test_sparse_to_dense_csc.yaml
include: test_sparse_to_dense_csr.yaml
include: test_spgeam_csr.yaml
include: test_spgemm_csr.yaml
include: test_spgemmreuse_csr.yaml
include: test_spmm_batched_coo.yaml
Expand Down
Loading
Loading