pub struct ExternalMemory { /* private fields */ }Expand description
Owns an imported external-memory object in an explicit CUDA context.
Implementations§
Source§impl ExternalMemory
impl ExternalMemory
Sourcepub unsafe fn import_opaque_file_descriptor(
context: &Arc<Context>,
fd: RawFd,
size: usize,
flags: ExternalMemoryFlags,
) -> Result<Self>
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.
Sourcepub unsafe fn import_opaque_win32_handle(
context: &Arc<Context>,
handle: *mut c_void,
size: usize,
flags: ExternalMemoryFlags,
) -> Result<Self>
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.
Sourcepub unsafe fn import_opaque_win32_name(
context: &Arc<Context>,
name: *const c_void,
size: usize,
flags: ExternalMemoryFlags,
) -> Result<Self>
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.
Sourcepub fn map_buffer<T: DeviceRepr>(
self,
offset_bytes: usize,
length: usize,
) -> Result<MappedBuffer<MaybeUninit<T>>>
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.
Sourcepub const fn byte_len(&self) -> usize
pub const fn byte_len(&self) -> usize
Returns the byte size declared for the imported external-memory object.
Sourcepub const fn as_raw(&self) -> CUexternalMemory
pub const fn as_raw(&self) -> CUexternalMemory
Returns the borrowed native import handle without transferring ownership.
Sourcepub unsafe fn from_raw(raw: RawExternalMemory) -> Result<Self>
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.
Sourcepub fn into_raw(self) -> RawExternalMemory
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.