#![cfg(feature = "cuda")]
use std::ffi::CStr;
use candle_core::{Error, Result};
use super::ffi;
pub fn check_cuda_kernel_launch() -> Result<()> {
let code = unsafe { ffi::cudaGetLastError() };
if code == 0 {
return Ok(());
}
let msg_ptr = unsafe { ffi::cudaGetErrorString(code) };
let msg = if msg_ptr.is_null() {
format!("CUDA kernel launch failed: code={code}")
} else {
let cstr = unsafe { CStr::from_ptr(msg_ptr) };
format!(
"CUDA kernel launch failed: {} (code={code})",
cstr.to_string_lossy(),
)
};
Err(Error::msg(msg))
}