This is an automated email from the ASF dual-hosted git repository.
hcr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git
The following commit(s) were added to refs/heads/main by this push:
new 21e94b2cd Consolidate CUDA error code mapping and align error messages
(#841)
21e94b2cd is described below
commit 21e94b2cd7cdcf68cc00f429d891047c2e58eca9
Author: Guan-Ming (Wesley) Chiu <[email protected]>
AuthorDate: Fri Jan 16 19:10:08 2026 +0800
Consolidate CUDA error code mapping and align error messages (#841)
---
qdp/qdp-core/src/error.rs | 20 ++++++++++++++++++++
qdp/qdp-core/src/gpu/encodings/amplitude.rs | 23 +++--------------------
qdp/qdp-core/src/gpu/encodings/basis.rs | 24 +++---------------------
3 files changed, 26 insertions(+), 41 deletions(-)
diff --git a/qdp/qdp-core/src/error.rs b/qdp/qdp-core/src/error.rs
index 5d7adfbd0..387e7fc48 100644
--- a/qdp/qdp-core/src/error.rs
+++ b/qdp/qdp-core/src/error.rs
@@ -43,3 +43,23 @@ pub enum MahoutError {
/// Result type alias for Mahout operations
pub type Result<T> = std::result::Result<T, MahoutError>;
+
+/// Convert CUDA error code to human-readable string
+#[cfg(target_os = "linux")]
+pub fn cuda_error_to_string(code: i32) -> &'static str {
+ match code {
+ 0 => "cudaSuccess",
+ 1 => "cudaErrorInvalidValue",
+ 2 => "cudaErrorMemoryAllocation",
+ 3 => "cudaErrorInitializationError",
+ 4 => "cudaErrorLaunchFailure",
+ 6 => "cudaErrorInvalidDevice",
+ 8 => "cudaErrorInvalidConfiguration",
+ 11 => "cudaErrorInvalidHostPointer",
+ 12 => "cudaErrorInvalidDevicePointer",
+ 17 => "cudaErrorInvalidMemcpyDirection",
+ 30 => "cudaErrorUnknown",
+ 999 => "CUDA unavailable (non-Linux stub)",
+ _ => "Unknown CUDA error",
+ }
+}
diff --git a/qdp/qdp-core/src/gpu/encodings/amplitude.rs
b/qdp/qdp-core/src/gpu/encodings/amplitude.rs
index f6a02b0db..f4b8abd75 100644
--- a/qdp/qdp-core/src/gpu/encodings/amplitude.rs
+++ b/qdp/qdp-core/src/gpu/encodings/amplitude.rs
@@ -19,6 +19,8 @@
use std::sync::Arc;
use super::QuantumEncoder;
+#[cfg(target_os = "linux")]
+use crate::error::cuda_error_to_string;
use crate::error::{MahoutError, Result};
use crate::gpu::memory::GpuStateVector;
use crate::gpu::pipeline::run_dual_stream_pipeline;
@@ -168,7 +170,7 @@ impl QuantumEncoder for AmplitudeEncoder {
#[cfg(not(target_os = "linux"))]
{
Err(MahoutError::Cuda(
- "CUDA unavailable (non-Linux)".to_string(),
+ "CUDA unavailable (non-Linux stub)".to_string(),
))
}
}
@@ -452,22 +454,3 @@ impl AmplitudeEncoder {
Ok(inv_norm)
}
}
-
-/// Convert CUDA error code to human-readable string
-#[cfg(target_os = "linux")]
-fn cuda_error_to_string(code: i32) -> &'static str {
- match code {
- 0 => "cudaSuccess",
- 1 => "cudaErrorInvalidValue",
- 2 => "cudaErrorMemoryAllocation",
- 3 => "cudaErrorInitializationError",
- 4 => "cudaErrorLaunchFailure",
- 6 => "cudaErrorInvalidDevice",
- 8 => "cudaErrorInvalidConfiguration",
- 11 => "cudaErrorInvalidHostPointer",
- 12 => "cudaErrorInvalidDevicePointer",
- 17 => "cudaErrorInvalidMemcpyDirection",
- 30 => "cudaErrorUnknown",
- _ => "Unknown CUDA error",
- }
-}
diff --git a/qdp/qdp-core/src/gpu/encodings/basis.rs
b/qdp/qdp-core/src/gpu/encodings/basis.rs
index f93ca5c84..b40d42d6f 100644
--- a/qdp/qdp-core/src/gpu/encodings/basis.rs
+++ b/qdp/qdp-core/src/gpu/encodings/basis.rs
@@ -17,6 +17,8 @@
// Basis encoding: map integers to computational basis states
use super::QuantumEncoder;
+#[cfg(target_os = "linux")]
+use crate::error::cuda_error_to_string;
use crate::error::{MahoutError, Result};
use crate::gpu::memory::GpuStateVector;
use cudarc::driver::CudaDevice;
@@ -113,7 +115,7 @@ impl QuantumEncoder for BasisEncoder {
#[cfg(not(target_os = "linux"))]
{
Err(MahoutError::Cuda(
- "CUDA unavailable (non-Linux)".to_string(),
+ "CUDA unavailable (non-Linux stub)".to_string(),
))
}
}
@@ -296,23 +298,3 @@ impl BasisEncoder {
Ok(index)
}
}
-
-/// Convert CUDA error code to human-readable string
-#[cfg(target_os = "linux")]
-fn cuda_error_to_string(code: i32) -> &'static str {
- match code {
- 0 => "cudaSuccess",
- 1 => "cudaErrorInvalidValue",
- 2 => "cudaErrorMemoryAllocation",
- 3 => "cudaErrorInitializationError",
- 4 => "cudaErrorLaunchFailure",
- 6 => "cudaErrorInvalidDevice",
- 8 => "cudaErrorInvalidConfiguration",
- 11 => "cudaErrorInvalidHostPointer",
- 12 => "cudaErrorInvalidDevicePointer",
- 17 => "cudaErrorInvalidMemcpyDirection",
- 30 => "cudaErrorUnknown",
- 999 => "CUDA unavailable (non-Linux stub)",
- _ => "Unknown CUDA error",
- }
-}