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
impl MemoryPool
Sourcepub fn create(context: &Arc<Context>, props: MemoryPoolProps) -> Result<Self>
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.
Sourcepub fn set_attribute(
&mut self,
attribute: MemoryPoolAttribute,
value: MemoryPoolAttributeValue,
) -> Result<()>
pub fn set_attribute( &mut self, attribute: MemoryPoolAttribute, value: MemoryPoolAttributeValue, ) -> Result<()>
Sets a pool attribute.
Settable attributes are:
MemoryPoolAttribute::ReleaseThreshold: the reserved bytes the pool keeps before it tries to release memory back to the OS. When the pool holds more, it tries to release memory at the next stream, event, or context synchronization. The default is 0.MemoryPoolAttribute::ReuseFollowEventDependencies: lets a stream-ordered allocation reuse memory freed in another stream when the allocating stream depends on the free. Events and the null stream can create that dependency. The default is enabled.MemoryPoolAttribute::ReuseAllowOpportunistic: lets an allocation reuse a completed free that it has no dependency on. The default is enabled.MemoryPoolAttribute::ReuseAllowInternalDependencies: lets a stream-ordered allocation insert stream dependencies so it can reuse memory freed in another stream. The default is enabled.MemoryPoolAttribute::ReservedMemoryHigh: resets the high watermark of the pool’s backing memory, and only accepts zero.MemoryPoolAttribute::UsedMemoryHigh: resets the high watermark of the pool’s memory in use, and only accepts zero.
§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.
Sourcepub fn attribute(
&self,
attribute: MemoryPoolAttribute,
) -> Result<MemoryPoolAttributeValue>
pub fn attribute( &self, attribute: MemoryPoolAttribute, ) -> Result<MemoryPoolAttributeValue>
Returns a pool attribute.
Besides the settable attributes described at MemoryPool::set_attribute, it reports:
MemoryPoolAttribute::ReservedMemoryCurrent: the backing memory the pool holds.MemoryPoolAttribute::ReservedMemoryHigh: the high watermark of backing memory since the last reset.MemoryPoolAttribute::UsedMemoryCurrent: the pool’s memory in use by the application.MemoryPoolAttribute::UsedMemoryHigh: the high watermark of memory in use since the last reset.
§Errors
Returns an error if the context cannot be bound or CUDA cannot report the attribute.
Sourcepub fn set_access(
&mut self,
access_descs: &[MemoryAccessDescriptor],
) -> Result<()>
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.
Sourcepub fn access(&self, location: MemoryLocation) -> Result<MemoryAccessFlag>
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.
Sourcepub fn trim_to(&mut self, min_bytes_to_keep: usize) -> Result<()>
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.
Sourcepub fn as_raw(&self) -> CUmemoryPool
pub fn as_raw(&self) -> CUmemoryPool
Returns the raw CUDA memory pool handle.
Source§impl MemoryPool
impl MemoryPool
Sourcepub fn context(&self) -> &Arc<Context> ⓘ
pub fn context(&self) -> &Arc<Context> ⓘ
Returns the CUDA context retained by this allocation or pool.
Sourcepub unsafe fn from_raw(raw: RawMemoryPool) -> Result<Self>
pub unsafe fn from_raw(raw: RawMemoryPool) -> Result<Self>
Sourcepub fn into_raw(self) -> StdResult<RawMemoryPool, Self>
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
impl MemoryPool
Sourcepub fn default_for(
context: &Arc<Context>,
location: MemoryLocation,
allocation_type: MemoryAllocationType,
) -> Result<Self>
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.
Sourcepub fn set_current(&self) -> Result<()>
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
impl MemoryPool
Sourcepub fn locality_domain_id(&self) -> Result<Option<u32>>
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.
Sourcepub fn allocation_type(&self) -> Result<MemoryAllocationType>
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.
Sourcepub fn location(&self) -> Result<MemoryLocation>
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.
Sourcepub fn maximum_size(&self) -> Result<u64>
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.
Sourcepub fn hardware_decompression_enabled(&self) -> Result<bool>
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.
Sourcepub fn export_handle_types(&self) -> Result<AllocationHandleTypes>
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.