metrale_gpu_runtime/
stream.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-25: [`MetraleStream`]: a CUDA stream paired with the device it was created on.
4//!
5//! Owner: gpu-runtime.
6//! Invariants: none beyond the types.
7
8use cudarc::driver::CudaStream;
9use std::sync::Arc;
10
11use metrale_core::device::MetraleDevice;
12use metrale_core::error::Result;
13
14/// 2026-09-25: A CUDA stream and the device whose context created it.
15pub struct MetraleStream {
16    pub stream: Arc<CudaStream>,
17    pub device: MetraleDevice,
18}
19
20impl MetraleStream {
21    /// 2026-09-25: Create a stream on `device`'s context (cudarc `new_stream`, non-blocking).
22    pub fn new(device: &MetraleDevice) -> Result<Self> {
23        let stream = device
24            .ctx
25            .new_stream()
26            .map_err(metrale_core::error::MetraleError::CudaDriver)?;
27        Ok(Self {
28            stream,
29            device: device.clone(),
30        })
31    }
32}