|
5 | 5 | #include <stdexcept> |
6 | 6 | #include <string> |
7 | 7 |
|
8 | | -namespace spblas::detail { |
| 8 | +namespace spblas { |
9 | 9 |
|
10 | | -// throw an exception if the hipError_t is not hipSuccess. |
11 | | -void throw_if_error(hipError_t error_code) { |
| 10 | +namespace __rocsparse { |
| 11 | + |
| 12 | +// Throw an exception if the hipError_t is not hipSuccess. |
| 13 | +void throw_if_error(hipError_t error_code, std::string prefix = "") { |
12 | 14 | if (error_code == hipSuccess) { |
13 | 15 | return; |
14 | 16 | } |
15 | 17 | std::string name = hipGetErrorName(error_code); |
16 | 18 | std::string message = hipGetErrorString(error_code); |
17 | | - throw std::runtime_error(name + ":" + message); |
| 19 | + throw std::runtime_error(prefix + "HIP encountered an error " + name + |
| 20 | + ": \"" + message + "\""); |
18 | 21 | } |
19 | 22 |
|
20 | | -// throw an exception if the rocsparse_status is not rocsparse_status_success. |
| 23 | +// Throw an exception if the rocsparse_status is not rocsparse_status_success. |
21 | 24 | void throw_if_error(rocsparse_status error_code) { |
22 | | -#define REGISTER_ROCSPARSE_ERROR(error_name) \ |
23 | | - if (error_code == error_name) { \ |
24 | | - throw std::runtime_error(#error_name); \ |
25 | | - } |
26 | | - |
27 | 25 | if (error_code == rocsparse_status_success) { |
28 | 26 | return; |
| 27 | + } else if (error_code == rocsparse_status_invalid_handle) { |
| 28 | + throw std::runtime_error( |
| 29 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_handle\""); |
| 30 | + } else if (error_code == rocsparse_status_not_implemented) { |
| 31 | + throw std::runtime_error( |
| 32 | + "rocSPARSE encountered an error: \"rocsparse_status_not_implemented\""); |
| 33 | + } else if (error_code == rocsparse_status_invalid_pointer) { |
| 34 | + throw std::runtime_error( |
| 35 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_pointer\""); |
| 36 | + } else if (error_code == rocsparse_status_invalid_size) { |
| 37 | + throw std::runtime_error( |
| 38 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_size\""); |
| 39 | + } else if (error_code == rocsparse_status_memory_error) { |
| 40 | + throw std::runtime_error( |
| 41 | + "rocSPARSE encountered an error: \"rocsparse_status_memory_error\""); |
| 42 | + } else if (error_code == rocsparse_status_internal_error) { |
| 43 | + throw std::runtime_error( |
| 44 | + "rocSPARSE encountered an error: \"rocsparse_status_internal_error\""); |
| 45 | + } else if (error_code == rocsparse_status_invalid_value) { |
| 46 | + throw std::runtime_error( |
| 47 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_value\""); |
| 48 | + } else if (error_code == rocsparse_status_arch_mismatch) { |
| 49 | + throw std::runtime_error( |
| 50 | + "rocSPARSE encountered an error: \"rocsparse_status_arch_mismatch\""); |
| 51 | + } else if (error_code == rocsparse_status_zero_pivot) { |
| 52 | + throw std::runtime_error( |
| 53 | + "rocSPARSE encountered an error: \"rocsparse_status_zero_pivot\""); |
| 54 | + } else if (error_code == rocsparse_status_not_initialized) { |
| 55 | + throw std::runtime_error( |
| 56 | + "rocSPARSE encountered an error: \"rocsparse_status_not_initialized\""); |
| 57 | + } else if (error_code == rocsparse_status_type_mismatch) { |
| 58 | + throw std::runtime_error( |
| 59 | + "rocSPARSE encountered an error: \"rocsparse_status_type_mismatch\""); |
| 60 | + } else if (error_code == rocsparse_status_type_mismatch) { |
| 61 | + throw std::runtime_error( |
| 62 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_size\""); |
| 63 | + } else if (error_code == rocsparse_status_invalid_size) { |
| 64 | + throw std::runtime_error( |
| 65 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_size\""); |
| 66 | + } else if (error_code == rocsparse_status_invalid_size) { |
| 67 | + throw std::runtime_error( |
| 68 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_size\""); |
| 69 | + } else if (error_code == rocsparse_status_invalid_size) { |
| 70 | + throw std::runtime_error( |
| 71 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_size\""); |
| 72 | + } else if (error_code == rocsparse_status_invalid_size) { |
| 73 | + throw std::runtime_error( |
| 74 | + "rocSPARSE encountered an error: \"rocsparse_status_invalid_size\""); |
| 75 | + } else { |
| 76 | + throw std::runtime_error( |
| 77 | + "rocSPARSE encountered an error: \"unknown error\""); |
29 | 78 | } |
30 | | - |
31 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_invalid_handle); |
32 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_not_implemented); |
33 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_invalid_pointer); |
34 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_invalid_size); |
35 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_memory_error); |
36 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_internal_error); |
37 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_invalid_value); |
38 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_arch_mismatch); |
39 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_zero_pivot); |
40 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_not_initialized); |
41 | | - REGISTER_ROCSPARSE_ERROR(rocsparse_status_type_mismatch); |
42 | | -#undef REGISTER_ROCSPARSE_ERROR |
43 | | - |
44 | | - throw std::runtime_error("Unknown error from rocsparse_status"); |
45 | 79 | } |
46 | 80 |
|
47 | | -} // namespace spblas::detail |
| 81 | +} // namespace __rocsparse |
| 82 | + |
| 83 | +} // namespace spblas |
0 commit comments