style: format Rust workspace
This commit is contained in:
@@ -22,7 +22,12 @@ impl GpuBuffer {
|
||||
assert!(len > 0, "cannot allocate 0 bytes on GPU");
|
||||
let mut ptr = std::ptr::null_mut();
|
||||
error::check(unsafe { ffi::cudaMalloc(&mut ptr, len) })?;
|
||||
Ok(Self { ptr, len, owned: true, pooled: false })
|
||||
Ok(Self {
|
||||
ptr,
|
||||
len,
|
||||
owned: true,
|
||||
pooled: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Mark this buffer as pooled (returned to caching allocator on drop)
|
||||
@@ -92,9 +97,7 @@ impl GpuBuffer {
|
||||
/// Copy from another GPU buffer (D2D).
|
||||
pub fn copy_from_device(&mut self, src: &GpuBuffer) -> Result<()> {
|
||||
let n = src.len.min(self.len);
|
||||
error::check(unsafe {
|
||||
ffi::cudaMemcpy(self.ptr, src.ptr, n, ffi::CUDA_MEMCPY_D2D)
|
||||
})
|
||||
error::check(unsafe { ffi::cudaMemcpy(self.ptr, src.ptr, n, ffi::CUDA_MEMCPY_D2D) })
|
||||
}
|
||||
|
||||
/// Fill buffer with zeros.
|
||||
@@ -103,7 +106,13 @@ impl GpuBuffer {
|
||||
}
|
||||
|
||||
/// Copy `count` bytes from `src` buffer at `src_offset` to this buffer at `dst_offset`.
|
||||
pub fn copy_from_device_at(&mut self, src: &GpuBuffer, src_offset: usize, dst_offset: usize, count: usize) -> Result<()> {
|
||||
pub fn copy_from_device_at(
|
||||
&mut self,
|
||||
src: &GpuBuffer,
|
||||
src_offset: usize,
|
||||
dst_offset: usize,
|
||||
count: usize,
|
||||
) -> Result<()> {
|
||||
assert!(src_offset + count <= src.len);
|
||||
assert!(dst_offset + count <= self.len);
|
||||
error::check(unsafe {
|
||||
@@ -117,7 +126,14 @@ impl GpuBuffer {
|
||||
}
|
||||
|
||||
/// Async copy `count` bytes from `src` at `src_offset` to `self` at `dst_offset` on `stream`.
|
||||
pub fn copy_from_device_at_async(&mut self, src: &GpuBuffer, src_offset: usize, dst_offset: usize, count: usize, stream: &CudaStream) -> Result<()> {
|
||||
pub fn copy_from_device_at_async(
|
||||
&mut self,
|
||||
src: &GpuBuffer,
|
||||
src_offset: usize,
|
||||
dst_offset: usize,
|
||||
count: usize,
|
||||
stream: &CudaStream,
|
||||
) -> Result<()> {
|
||||
assert!(src_offset + count <= src.len);
|
||||
assert!(dst_offset + count <= self.len);
|
||||
error::check(unsafe {
|
||||
@@ -161,9 +177,7 @@ impl GpuBuffer {
|
||||
|
||||
/// Async zero fill on stream.
|
||||
pub fn zero_async(&mut self, stream: &CudaStream) -> Result<()> {
|
||||
error::check(unsafe {
|
||||
ffi::cudaMemsetAsync(self.ptr, 0, self.len, stream.as_raw())
|
||||
})
|
||||
error::check(unsafe { ffi::cudaMemsetAsync(self.ptr, 0, self.len, stream.as_raw()) })
|
||||
}
|
||||
|
||||
/// Consume the buffer without freeing GPU memory. Returns the raw pointer and length.
|
||||
@@ -178,7 +192,12 @@ impl GpuBuffer {
|
||||
/// Reconstruct a GpuBuffer from a raw pointer + length.
|
||||
/// Safety: ptr must have been allocated with cudaMalloc, len must be correct.
|
||||
pub unsafe fn from_raw(ptr: *mut u8, len: usize) -> Self {
|
||||
Self { ptr, len, owned: true, pooled: false }
|
||||
Self {
|
||||
ptr,
|
||||
len,
|
||||
owned: true,
|
||||
pooled: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a non-owning view of GPU memory. Dropping this buffer does NOT
|
||||
@@ -189,7 +208,12 @@ impl GpuBuffer {
|
||||
/// `ptr` must point to a valid GPU allocation of at least `len` bytes that
|
||||
/// will remain live for the lifetime of the returned `GpuBuffer`.
|
||||
pub unsafe fn borrow_raw(ptr: *mut u8, len: usize) -> Self {
|
||||
Self { ptr, len, owned: false, pooled: false }
|
||||
Self {
|
||||
ptr,
|
||||
len,
|
||||
owned: false,
|
||||
pooled: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user