Files
xserv/crates/xserv-cuda/src/stream.rs
Gahow Wang 9806b4db35 phase 0+1: project scaffold + xserv-cuda crate
- Cargo workspace with xserv-cuda crate
- CUDA FFI bindings (cudart: memory, stream, device, error)
- GpuBuffer RAII wrapper with H2D/D2H/D2D copy
- CudaStream wrapper with RAII Drop
- CachingAllocator with size-bucketed free lists
- PinnedBuffer for page-locked host memory
- Device info query via cudaDeviceGetAttribute
- Vector-add CUDA kernel smoke test
- Integration test suite (11 tests)
- build.rs: cc crate compiles .cu for SM 12.0
- sync-and-build.sh for remote build on dash5
- Roadmap doc (docs/00-roadmap.md) and Phase 0+1 design doc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-21 18:40:22 +08:00

34 lines
758 B
Rust

use crate::error::{self, Result};
use crate::ffi;
pub struct CudaStream {
raw: ffi::CudaStream,
}
impl CudaStream {
pub fn new() -> Result<Self> {
let mut raw = std::ptr::null_mut();
error::check(unsafe { ffi::cudaStreamCreate(&mut raw) })?;
Ok(Self { raw })
}
pub fn synchronize(&self) -> Result<()> {
error::check(unsafe { ffi::cudaStreamSynchronize(self.raw) })
}
pub fn as_raw(&self) -> ffi::CudaStream {
self.raw
}
}
impl Drop for CudaStream {
fn drop(&mut self) {
if !self.raw.is_null() {
unsafe { ffi::cudaStreamDestroy(self.raw) };
}
}
}
// Can move across threads, but not shared without synchronization
unsafe impl Send for CudaStream {}