Skip to main content

MemoryPool

Struct MemoryPool 

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

Shares ownership of a CUDA memory pool and retains its context.

Clones and pool-backed allocations keep an owned pool alive. Default pools are driver-owned and are not destroyed when the last wrapper is dropped.

Implementations§

Source§

impl MemoryPool

Source

pub fn create(context: &Arc<Context>, props: MemoryPoolProps) -> Result<Self>

Creates a CUDA memory pool. props determines the properties of the pool such as the backing device and IPC capabilities.

To create a memory pool for host memory not targeting a specific NUMA node, applications must set MemoryPoolProps::location to MemoryLocation::Host. MemoryLocation is ignored for such pools. Pools created with MemoryLocation::Host are not IPC-capable and MemoryPoolProps::handle_types must be empty; any other value returns crate::error::Status::InvalidValue. To create a memory pool targeting a specific host NUMA node, applications must set MemoryLocation to MemoryLocation::Numa and MemoryLocation must specify the NUMA ID of the host memory node. Specifying MemoryLocation::NumaCurrent as MemoryLocation returns crate::error::Status::InvalidValue. By default, the pool’s memory is accessible from the device where it is allocated. Pools created with MemoryLocation::Numa or MemoryLocation::Host are accessible from the host CPU by default. Applications can control the maximum size of the pool by specifying a non-zero value for MemoryPoolProps::max_size. A value of 0 uses a system-dependent maximum pool size.

Callers that intend to use AllocationHandleTypes::FABRIC based memory sharing must ensure: (1) the nvidia-caps-imex-channels character device is created by the driver and is listed under /proc/devices; (2) at least one IMEX channel file is accessible to the process.

When exporter and importer CUDA processes have been granted access to the same IMEX channel, they can securely share memory.

The IMEX channel security model works per operating-system account. All processes for an account can share memory if that account has access to a valid IMEX channel. When isolation between accounts is desired, each account needs a separate IMEX channel.

These channel files exist in /dev/nvidia-caps-imex-channels/channel* and can be created using standard OS native calls like mknod on Linux.

To create a managed memory pool, applications must set MemoryPoolProps::alloc_type to MemoryAllocationType::Managed. MemoryPoolProps::handle_types must also be empty because IPC is not supported. For managed memory pools, MemoryPoolProps::location is treated as the preferred location for all allocations created from the pool. An application can also set MemoryLocation::Unspecified to indicate no preferred location. MemoryPoolProps::max_size must be set to zero for managed memory pools. MemoryPoolProps::usage must be zero because decompression for managed memory is not supported. For managed memory pools, every device on the system must report DeviceAttribute::ConcurrentManagedAccess. If not, this call returns crate::error::Status::NotSupported.

Empty MemoryPoolProps::handle_types create a memory pool that does not support IPC.

§Errors

Returns an error if props describes an unsupported pool, CUDA cannot create the pool, or CUDA returns a null memory-pool handle.

Source

pub fn set_attribute( &mut self, attribute: MemoryPoolAttribute, value: MemoryPoolAttributeValue, ) -> Result<()>

Sets a pool attribute.

Settable attributes are:

§Errors

Returns an error if the value variant does not match the attribute, the context cannot be bound, or CUDA rejects the attribute or value. Current-usage statistics are read-only, and high watermarks only reset to zero.

Source

pub fn attribute( &self, attribute: MemoryPoolAttribute, ) -> Result<MemoryPoolAttributeValue>

Returns a pool attribute.

Besides the settable attributes described at MemoryPool::set_attribute, it reports:

§Errors

Returns an error if the context cannot be bound or CUDA cannot report the attribute.

Source

pub fn set_access( &mut self, access_descs: &[MemoryAccessDescriptor], ) -> Result<()>

Sets which locations can access the pool’s memory, and how.

§Errors

Returns an error if the context cannot be bound or CUDA rejects the access descriptors.

Source

pub fn access(&self, location: MemoryLocation) -> Result<MemoryAccessFlag>

Returns the accessibility of the pool’s memory from the specified location.

§Errors

Returns an error if the context cannot be bound or CUDA cannot report access from location.

Source

pub fn trim_to(&mut self, min_bytes_to_keep: usize) -> Result<()>

Releases memory back to the OS until the pool holds fewer than min_bytes_to_keep reserved bytes or has no more memory it can release. The allocator cannot release OS allocations that back outstanding asynchronous allocations. The OS allocations may happen at different granularity from the caller’s allocations.

  • Allocations that have not been freed count as outstanding.
  • Allocations that have been asynchronously freed but whose completion has not been observed on the host, for example by synchronization, can count as outstanding.
§Errors

Returns an error if the context cannot be bound or CUDA cannot trim the pool.

Source

pub fn as_raw(&self) -> CUmemoryPool

Returns the raw CUDA memory pool handle.

Source§

impl MemoryPool

Source

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

Returns the CUDA context retained by this allocation or pool.

Source

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

Takes ownership of a CUDA pool created for this context.

§Safety

The handle must identify a live pool that the caller may destroy. It must not be a driver-owned default pool or have another destroying owner.

§Errors

Returns an error if the pool handle is null.

Source

pub fn into_raw(self) -> StdResult<RawMemoryPool, Self>

Transfers an owned handle only when no allocations or other owners retain it. Driver-owned pools cannot transfer destruction responsibility.

§Errors

Returns the wrapper unchanged as the error if the pool is driver-owned or another wrapper or allocation retains it.

Source§

impl MemoryPool

Source

pub fn default_for( context: &Arc<Context>, location: MemoryLocation, allocation_type: MemoryAllocationType, ) -> Result<Self>

Borrows a driver-owned default pool for a location and allocation kind.

§Errors

Returns an error if the context cannot be bound, CUDA has no default pool for the location and allocation type, or CUDA returns a null handle.

Source

pub fn set_current(&self) -> Result<()>

Selects this pool for future implicit allocations of its location and kind.

This changes CUDA’s shared pool selection. Destroying the selected owned pool restores the driver’s default pool. Existing allocations retain their original backing memory regardless of later selection changes.

§Errors

Returns an error if the context cannot be bound, the pool’s location or allocation type cannot be read, or CUDA rejects the selection.

Source§

impl MemoryPool

Source

pub fn locality_domain_id(&self) -> Result<Option<u32>>

Returns the locality domain ID of a localized pool, or None for a full-device pool.

§Errors

Returns an error if the context cannot be bound, CUDA cannot report the attribute, or the identifier is negative other than the full-device value of -1.

Source

pub fn allocation_type(&self) -> Result<MemoryAllocationType>

Returns the allocation type of the memory pool.

§Errors

Returns an error if the context cannot be bound, CUDA cannot report the attribute, or the value is not a known allocation type.

Source

pub fn location(&self) -> Result<MemoryLocation>

Returns the location of the memory pool.

§Errors

Returns an error if the context cannot be bound, CUDA cannot report the attributes, the location type is unknown, or an identifier does not fit the localized device representation.

Source

pub fn maximum_size(&self) -> Result<u64>

Returns the maximum size of the pool in bytes, including alignment requirements.

§Errors

Returns an error if the context cannot be bound or CUDA cannot report the attribute.

Source

pub fn hardware_decompression_enabled(&self) -> Result<bool>

Returns whether hardware decompression is enabled for allocations from this pool.

§Errors

Returns an error if the context cannot be bound or CUDA cannot report the attribute.

Source

pub fn export_handle_types(&self) -> Result<AllocationHandleTypes>

Returns the handle types the pool can export.

§Errors

Returns an error if the context cannot be bound or CUDA cannot report the attribute.

Trait Implementations§

Source§

impl Clone for MemoryPool

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryPool

Source§

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

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.