use onnx_runtime_ep_api::EpError;
pub(crate) fn driver_err(context: &str, e: cudarc::driver::DriverError) -> EpError {
EpError::KernelFailed(format!("cuda_ep: {context}: CUDA driver error: {e:?}"))
}
pub(crate) fn cublas_err(context: &str, e: cudarc::cublaslt::result::CublasError) -> EpError {
EpError::KernelFailed(format!("cuda_ep: {context}: cuBLASLt error: {e:?}"))
}
pub(crate) fn cudnn_err(context: &str, e: cudarc::cudnn::CudnnError) -> EpError {
EpError::KernelFailed(format!("cuda_ep: {context}: cuDNN error: {e:?}"))
}
pub(crate) fn cudnn_unavailable() -> EpError {
EpError::KernelFailed(
"cuda_ep: cuDNN (libcudnn.so.9 / cudnn64_9.dll) was not found at runtime. \
Install it with 'pip install nvidia-cudnn-cu13' or \
'conda install -c nvidia cudnn', or add the cuDNN library directory to \
the platform library search path."
.into(),
)
}
pub(crate) fn nvrtc_err(context: &str, e: cudarc::nvrtc::CompileError) -> EpError {
let detail = match &e {
cudarc::nvrtc::CompileError::CompileError { nvrtc, log, .. } => {
format!(
"NVRTC compilation failed ({nvrtc:?}); compiler log:\n{}",
log.to_string_lossy()
)
}
other => format!("NVRTC error: {other:?}"),
};
EpError::KernelFailed(format!("cuda_ep: {context}: {detail}"))
}
pub(crate) fn not_implemented(what: impl std::fmt::Display) -> EpError {
EpError::KernelFailed(format!(
"cuda_ep: {what} is not yet implemented on the CUDA EP. See \
docs/CUDA_COVERAGE.md for the op → backend roadmap; this op/case can run \
on the CPU EP in the meantime."
))
}