Skip to main content

ExternalMemory

Struct ExternalMemory 

Source
pub struct ExternalMemory { /* private fields */ }
Expand description

Owns an imported external-memory object in an explicit CUDA context.

Implementations§

Source§

impl ExternalMemory

Source

pub unsafe fn import_opaque_file_descriptor( context: &Arc<Context>, fd: RawFd, size: usize, flags: ExternalMemoryFlags, ) -> Result<Self>

Imports an opaque file descriptor in context.

§Safety

fd must reference a compatible memory object of size bytes on this context’s device. CUDA takes descriptor ownership on success. Do not use it afterward. Keep external backing resources alive and coordinate foreign accesses with all CUDA accesses. Do not create independently mutable imports of overlapping external storage.

§Errors

Returns an error if size is zero, the context cannot be bound, CUDA rejects the import, or CUDA returns a null handle. Descriptor ownership remains with the caller if the native import fails.

Source

pub unsafe fn import_opaque_win32_handle( context: &Arc<Context>, handle: *mut c_void, size: usize, flags: ExternalMemoryFlags, ) -> Result<Self>

Imports an opaque Win32 shared handle in context.

§Safety

The handle must reference a compatible live external allocation of the stated size on this device. Ownership of the Win32 handle remains with the caller. Retain foreign backing resources, coordinate every foreign access, and prevent independently mutable aliases.

§Errors

Returns an error if handle is null, size is zero, the context cannot be bound, CUDA rejects the import, or CUDA returns a null handle.

Source

pub unsafe fn import_opaque_win32_name( context: &Arc<Context>, name: *const c_void, size: usize, flags: ExternalMemoryFlags, ) -> Result<Self>

Imports a named Win32 external memory object in context.

§Safety

name must reference a valid null-terminated UTF-16 object name throughout import. The object must be compatible with this device and have the stated size. Retain foreign backing resources, coordinate every foreign access, and prevent independently mutable aliases.

§Errors

Returns an error if name is null, size is zero, the context cannot be bound, CUDA rejects the import, or CUDA returns a null handle.

Source

pub fn map_buffer<T: DeviceRepr>( self, offset_bytes: usize, length: usize, ) -> Result<MappedBuffer<MaybeUninit<T>>>

Consumes this import and maps uninitialized typed storage.

One import owns one native mapping. Use borrowed views and splits for subranges. This avoids overlapping native mappings with distinct virtual aliases and coherence requirements. Mapping establishes no claim about externally produced values or completion. Offset and size must also satisfy the originating API’s alignment requirements.

§Errors

Returns an error if the typed byte count or range end overflows, the range exceeds the imported object, the context cannot be bound, or CUDA rejects the mapping. Also rejects a null nonempty mapping, a mapping address not aligned for T, or an invalid mapped address range. The consumed import is released on failure unless a native mapping cannot be safely freed.

§Panics

Panics if T’s alignment cannot be represented by a 64-bit device address.

Source

pub const fn byte_len(&self) -> usize

Returns the byte size declared for the imported external-memory object.

Source

pub const fn as_raw(&self) -> CUexternalMemory

Returns the borrowed native import handle without transferring ownership.

Source

pub fn context(&self) -> &Arc<Context> ⓘ

Returns the actual CUDA import context.

Source

pub unsafe fn from_raw(raw: RawExternalMemory) -> Result<Self>

Takes ownership of an unmapped native external-memory import.

§Safety

raw.handle must be live in raw.context, have the stated size, and have no other destroying owner or mapped buffers. Retain external backing resources, coordinate foreign accesses, and prevent independently mutable aliases.

§Errors

Returns an error if raw.handle is null or raw.size is zero.

Source

pub fn into_raw(self) -> RawExternalMemory

Transfers the unmapped native handle, byte size, and context to its next owner.

Bind the returned context before use and retain it through native destruction.

Trait Implementations§

Source§

impl Debug for ExternalMemory

Source§

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

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

impl Drop for ExternalMemory

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 Send for ExternalMemory

Source§

impl Sync for ExternalMemory

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.