Skip to content

Commit 1a91597

Browse files
committed
Add accessor for CusparseError error code
Use this to check for CUSPARSE_STATUS_INSUFFICIENT_RESOURCES when falling back to spgemm ALG2.
1 parent 09ce3ad commit 1a91597

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

common/cuda_hip/matrix/csr_kernels.template.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -2534,8 +2534,7 @@ void spgemm(std::shared_ptr<const DefaultExecutor> exec,
25342534
// If estimated buffer size is too large and CUDA > 12.0, fall back to
25352535
// ALG2
25362536
#if CUDA_VERSION >= 12000
2537-
const char* error_code = "CUSPARSE_STATUS_INSUFFICIENT_RESOURCES";
2538-
if (strstr(cse.what(), error_code)) {
2537+
if (cse.get_error_code() == CUSPARSE_STATUS_INSUFFICIENT_RESOURCES) {
25392538
spgemm_alg = CUSPARSE_SPGEMM_ALG2;
25402539
// Memory estimate for Alg2/Alg3
25412540
sparselib::spgemm_work_estimation(
@@ -2745,8 +2744,7 @@ void advanced_spgemm(std::shared_ptr<const DefaultExecutor> exec,
27452744
// If estimated buffer size is too large and CUDA > 12.0, fall back to
27462745
// ALG2
27472746
#if CUDA_VERSION >= 12000
2748-
const char* error_code = "CUSPARSE_STATUS_INSUFFICIENT_RESOURCES";
2749-
if (strstr(cse.what(), error_code)) {
2747+
if (cse.get_error_code() == CUSPARSE_STATUS_INSUFFICIENT_RESOURCES) {
27502748
spgemm_alg = CUSPARSE_SPGEMM_ALG2;
27512749
// Memory estimate for Alg2/Alg3
27522750
sparselib::spgemm_work_estimation(

contributors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ Olenik Gregor <[email protected]> HPSim
2525
Ribizel Tobias <[email protected]> Karlsruhe Institute of Technology
2626
Riemer Lukas <[email protected]> Karlsruhe Institute of Technology
2727
Tsai Yuhsiang <[email protected]> National Taiwan University
28+
Ilya Zilberter <[email protected]> Tech-X Corporation

include/ginkgo/core/base/exception.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -250,11 +250,18 @@ class CusparseError : public Error {
250250
*/
251251
CusparseError(const std::string& file, int line, const std::string& func,
252252
int64 error_code)
253-
: Error(file, line, func + ": " + get_error(error_code))
253+
: Error(file, line, func + ": " + get_error(error_code)),
254+
err_code(error_code)
254255
{}
255256

257+
/**
258+
* Returns the error code
259+
*/
260+
int64 get_error_code() const noexcept { return err_code; }
261+
256262
private:
257263
static std::string get_error(int64 error_code);
264+
const int64 err_code;
258265
};
259266

260267

0 commit comments

Comments
 (0)