Skip to main content

ManagedBuffer

Struct ManagedBuffer 

Source
pub struct ManagedBuffer<T: DeviceRepr> { /* private fields */ }
Expand description

Owned allocation of unified (managed) memory — a single pointer that is accessible from both the host and the GPU, with on-demand migration handled by the driver. Compare with DeviceBuffer, which is device-only and requires explicit memcpys.

On a discrete GPU, accessing the buffer from host code after a kernel finishes (and vice versa) requires a stream synchronize in the unified-memory model; ManagedBuffer::as_host_slice assumes the caller has done that.

Implementations§

Source§

impl<T: DeviceRepr> ManagedBuffer<T>

Source

pub fn new(context: &Context, len: usize) -> Result<Self>

Allocate len elements of unified memory with the default (ManagedAttach::Global) attach mode.

Source

pub fn new_with_flags( context: &Context, len: usize, attach: ManagedAttach, ) -> Result<Self>

Allocate with an explicit ManagedAttach mode.

Source

pub fn advise(&self, advice: MemAdvise, device: &Device) -> Result<()>

Provide a hint to the Unified-Memory subsystem about how this range will be accessed. device is the ordinal this advice targets (e.g. the compute device for SET_ACCESSED_BY); pass the current device’s ordinal when in doubt.

Source

pub fn prefetch_async(&self, device: &Device, stream: &Stream) -> Result<()>

Asynchronously prefetch this range to device on stream.

Source

pub unsafe fn as_host_slice(&self) -> &[T]

Access the buffer as a host slice. Safe to call on integrated GPUs or after a synchronize on discrete GPUs; otherwise you’ll see stale data.

§Safety

The caller must ensure:

  1. No concurrent kernel is writing to this buffer.
  2. On discrete GPUs, a relevant synchronize has been issued since the last device-side write.
Source

pub unsafe fn as_host_slice_mut(&mut self) -> &mut [T]

Mutable host view. Same safety rules as as_host_slice.

§Safety

The caller must ensure no concurrent device or host access.

Source

pub fn len(&self) -> usize

Number of elements.

Source

pub fn is_empty(&self) -> bool

true if zero elements.

Source

pub fn as_raw(&self) -> CUdeviceptr

Raw device pointer — the same value as the host pointer under UVM.

Source

pub fn context(&self) -> &Context

Owning context.

Trait Implementations§

Source§

impl<T: DeviceRepr> Debug for ManagedBuffer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: DeviceRepr> Drop for ManagedBuffer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T: DeviceRepr + Send> Send for ManagedBuffer<T>

Auto Trait Implementations§

§

impl<T> Freeze for ManagedBuffer<T>

§

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

§

impl<T> Sync for ManagedBuffer<T>
where T: Sync,

§

impl<T> Unpin for ManagedBuffer<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ManagedBuffer<T>

§

impl<T> UnwindSafe for ManagedBuffer<T>
where T: UnwindSafe,

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.