phase 0+1: fix Rust 2024 edition compat + memory query

- unsafe extern "C" blocks (Rust 2024 requirement)
- unsafe blocks inside unsafe fn bodies
- Use cudaMemGetInfo for accurate GPU memory reporting
- Remove cc "cuda" feature (doesn't exist, built-in)
- All 12 tests pass on RTX 5090 (CC 12.0, 170 SMs, 32GB)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-21 19:40:49 +08:00
parent 9806b4db35
commit c8f7bc0c3c
5 changed files with 40 additions and 24 deletions

View File

@@ -48,26 +48,30 @@ impl GpuBuffer {
/// Safety: `src` must remain valid until the stream operation completes.
pub unsafe fn copy_from_host_async(&mut self, src: &[u8], stream: &CudaStream) -> Result<()> {
assert!(src.len() <= self.len);
error::check(ffi::cudaMemcpyAsync(
self.ptr,
src.as_ptr(),
src.len(),
ffi::CUDA_MEMCPY_H2D,
stream.as_raw(),
))
unsafe {
error::check(ffi::cudaMemcpyAsync(
self.ptr,
src.as_ptr(),
src.len(),
ffi::CUDA_MEMCPY_H2D,
stream.as_raw(),
))
}
}
/// Async copy from device to host on the given stream.
/// Safety: `dst` must remain valid until the stream operation completes.
pub unsafe fn copy_to_host_async(&self, dst: &mut [u8], stream: &CudaStream) -> Result<()> {
assert!(dst.len() <= self.len);
error::check(ffi::cudaMemcpyAsync(
dst.as_mut_ptr(),
self.ptr,
dst.len(),
ffi::CUDA_MEMCPY_D2H,
stream.as_raw(),
))
unsafe {
error::check(ffi::cudaMemcpyAsync(
dst.as_mut_ptr(),
self.ptr,
dst.len(),
ffi::CUDA_MEMCPY_D2H,
stream.as_raw(),
))
}
}
/// Copy from another GPU buffer (D2D).