trt-runner 0.1.0

Minimal TensorRT 10 inference runner: deserialize an engine, bind I/O tensors, enqueue V3. No bindings generator, no runtime dependencies.
Documentation
//! The README example, kept compilable: load an engine, bind every I/O tensor, run once, read the
//! outputs back.
//!
//! ```text
//! cargo run --release --example quickstart -- model_fp16.engine
//! ```

use trt_runner::{cuda, DeviceBuffer, Engine, IoMode, PinnedBuffer, Stream};

fn main() -> trt_runner::Result<()> {
    let path = std::env::args()
        .nth(1)
        .unwrap_or_else(|| "model_fp16.engine".to_string());

    cuda::set_device(0)?;
    let engine = Engine::from_file(&path)?;
    let stream = Stream::new()?;
    let mut context = engine.context()?;

    // One device buffer per I/O tensor, sized from the engine's own metadata.
    let mut buffers = Vec::new();
    for info in engine.io() {
        let bytes = info.size_bytes().expect("a static shape");
        let mut buffer = DeviceBuffer::zeroed(bytes, &stream)?;
        if info.mode == IoMode::Input {
            let mut host = PinnedBuffer::new(bytes)?;
            host.f32s_mut().fill(0.5);
            buffer.copy_from_host(host.bytes(), &stream)?;
        }
        // SAFETY: `buffers` is alive until after the synchronised run below.
        unsafe { context.bind_buffer(&info.name, &buffer)? };
        buffers.push((info.name.clone(), info.mode, buffer));
    }

    context.run(&stream)?; // enqueue plus synchronize

    for (name, mode, buffer) in &buffers {
        if *mode == IoMode::Output {
            let mut out = vec![0u8; buffer.size_bytes()];
            // copy_to_host waits for the stream, so these bytes are real.
            buffer.copy_to_host(&mut out, &stream)?;
            println!("{name}: read back {} bytes", out.len());
        }
    }
    Ok(())
}