Skip to main content

GpuBuffer

Struct GpuBuffer 

Source
pub struct GpuBuffer<T> { /* private fields */ }
Expand description

A typed buffer in GPU device memory, wrapping cudarc’s CudaSlice<T>.

Created via KaioDevice::alloc_from or KaioDevice::alloc_zeros.

§Memory management

GpuBuffer does not implement Drop manually — cudarc’s CudaSlice handles device memory deallocation automatically when the buffer is dropped. The CudaSlice holds an Arc<CudaContext> internally, ensuring the CUDA context outlives the allocation.

Implementations§

Source§

impl<T> GpuBuffer<T>

Source

pub fn len(&self) -> usize

Number of elements in the buffer.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer contains no elements.

Source

pub fn inner(&self) -> &CudaSlice<T>

Access the underlying CudaSlice for passing to cudarc launch operations.

This is the escape hatch for Sprint 1.7’s launch builder — the caller pushes &buf.inner() as a kernel argument.

Source

pub fn inner_mut(&mut self) -> &mut CudaSlice<T>

Mutable access to the underlying CudaSlice.

Source§

impl<T: DeviceRepr + Default + Clone + Unpin> GpuBuffer<T>

Source

pub fn to_host(&self, device: &KaioDevice) -> Result<Vec<T>>

Transfer buffer contents from device to host.

Requires a reference to the KaioDevice that created this buffer (for stream access). The device is borrowed, not consumed.

§Example
let device = KaioDevice::new(0)?;
let buf = device.alloc_from(&[1.0f32, 2.0, 3.0])?;
let host_data = buf.to_host(&device)?;
assert_eq!(host_data, vec![1.0, 2.0, 3.0]);

Auto Trait Implementations§

§

impl<T> Freeze for GpuBuffer<T>

§

impl<T> RefUnwindSafe for GpuBuffer<T>
where T: RefUnwindSafe,

§

impl<T> Send for GpuBuffer<T>

§

impl<T> Sync for GpuBuffer<T>

§

impl<T> Unpin for GpuBuffer<T>

§

impl<T> UnsafeUnpin for GpuBuffer<T>

§

impl<T> UnwindSafe for GpuBuffer<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V