//! Load precompiled cubins via the CUDA driver API.
//! Uses CudaContext::load_cubin() from our patched cudarc — zero nvrtc.

use std::sync::Arc;

use cudarc::driver::{CudaFunction, CudaModule, CudaStream};

use crate::MLError;

/// Load a cubin and return a CudaModule.
pub(crate) fn load_cubin(cubin: &[u8], stream: &Arc<CudaStream>) -> Result<Arc<CudaModule>, MLError> {
    stream.context()
        .load_cubin(cubin.to_vec())
        .map_err(|e| MLError::ModelError(format!("cubin load: {e}")))
}

/// Load a kernel function by name from a CudaModule.
pub(crate) fn get_fn(module: &Arc<CudaModule>, name: &str) -> Result<CudaFunction, MLError> {
    module.load_function(name)
        .map_err(|e| MLError::ModelError(format!("{name}: {e}")))
}
