pub struct VirtualMemoryManager;Expand description
Manager for GPU virtual memory operations.
Provides methods for reserving virtual address ranges, allocating physical memory, mapping/unmapping, and setting access permissions.
§Status
The underlying CUDA virtual memory driver functions
(cuMemAddressReserve, cuMemCreate, cuMemMap, cuMemUnmap,
cuMemSetAccess, cuMemRelease, cuMemAddressFree) are wired
through oxicuda-driver. On systems without a CUDA driver
the calls fail with CudaError::NotInitialized; on systems
with a driver that lacks a specific VMM symbol the calls fail
with CudaError::NotSupported.
Implementations§
Source§impl VirtualMemoryManager
impl VirtualMemoryManager
Sourcepub fn reserve(size: usize, alignment: usize) -> CudaResult<VirtualAddressRange>
pub fn reserve(size: usize, alignment: usize) -> CudaResult<VirtualAddressRange>
Reserves a range of virtual addresses in the GPU address space.
The reserved range is not backed by physical memory until
map is called.
§Parameters
size- Size of the virtual range to reserve in bytes. Must be a multiple ofalignment.alignment- Alignment requirement in bytes. Must be a power of two and non-zero.
§Errors
CudaError::InvalidValueifsizeis zero,alignmentis zero,alignmentis not a power of two, orsizeis not a multiple ofalignment.
Sourcepub fn release(va: VirtualAddressRange) -> CudaResult<()>
pub fn release(va: VirtualAddressRange) -> CudaResult<()>
Releases a previously reserved virtual address range.
After this call, the virtual addresses are no longer reserved and may be reused by future reservations.
§Errors
CudaError::NotInitializedif no CUDA driver is available (e.g. on macOS).CudaError::NotSupportedif the driver does not exportcuMemAddressFree.- Other
CudaErrorvariants on driver failure.
Sourcepub fn alloc_physical(
size: usize,
device_ordinal: i32,
) -> CudaResult<PhysicalAllocation>
pub fn alloc_physical( size: usize, device_ordinal: i32, ) -> CudaResult<PhysicalAllocation>
Allocates physical memory on the specified device.
The allocated memory is not accessible until mapped into a
virtual address range via map.
§Parameters
size- Size of the allocation in bytes. Must be non-zero.device_ordinal- Ordinal of the device to allocate on.
§Errors
CudaError::InvalidValueifsizeis zero ordevice_ordinalis negative.CudaError::NotInitializedif no CUDA driver is available (e.g. on macOS).CudaError::NotSupportedif the driver does not exportcuMemCreate.- Other
CudaErrorvariants on driver failure.
Sourcepub fn free_physical(phys: PhysicalAllocation) -> CudaResult<()>
pub fn free_physical(phys: PhysicalAllocation) -> CudaResult<()>
Frees a physical memory allocation.
The allocation must not be currently mapped to any virtual range.
§Errors
CudaError::NotInitializedif no CUDA driver is available (e.g. on macOS).CudaError::NotSupportedif the driver does not exportcuMemRelease.- Other
CudaErrorvariants on driver failure.
Sourcepub fn map(
va: &VirtualAddressRange,
phys: &PhysicalAllocation,
offset: usize,
) -> CudaResult<()>
pub fn map( va: &VirtualAddressRange, phys: &PhysicalAllocation, offset: usize, ) -> CudaResult<()>
Maps a physical allocation to a region of a virtual address range.
After mapping, GPU kernels can access the virtual addresses and reads/writes will be routed to the physical memory.
§Parameters
va- The virtual address range to map into.phys- The physical allocation to map.offset- Byte offset within the virtual range at which to start the mapping. Must be aligned to the VA’s alignment.
§Errors
CudaError::InvalidValueifoffsetis not aligned, or if the physical allocation would extend past the end of the virtual range.CudaError::NotInitializedif no CUDA driver is available (e.g. on macOS).CudaError::NotSupportedif the driver does not exportcuMemMap.- Other
CudaErrorvariants on driver failure.
Sourcepub fn unmap(
va: &VirtualAddressRange,
offset: usize,
size: usize,
) -> CudaResult<()>
pub fn unmap( va: &VirtualAddressRange, offset: usize, size: usize, ) -> CudaResult<()>
Unmaps a region of a virtual address range.
After unmapping, accesses to the affected virtual addresses will fault. The physical memory is not freed — it can be remapped elsewhere.
§Parameters
va- The virtual address range to unmap from.offset- Byte offset within the range where unmapping starts.size- Number of bytes to unmap.
§Errors
CudaError::InvalidValueif the offset+size exceeds the virtual range bounds.CudaError::NotInitializedif no CUDA driver is available (e.g. on macOS).CudaError::NotSupportedif the driver does not exportcuMemUnmap.- Other
CudaErrorvariants on driver failure.
Sourcepub fn set_access(
va: &VirtualAddressRange,
device_ordinal: i32,
flags: AccessFlags,
) -> CudaResult<()>
pub fn set_access( va: &VirtualAddressRange, device_ordinal: i32, flags: AccessFlags, ) -> CudaResult<()>
Sets access permissions for a virtual address range on a device.
This controls whether the specified device can read and/or write to the mapped virtual addresses.
§Parameters
va- The virtual address range to set permissions on.device_ordinal- The device to grant/deny access for.flags- The access permission flags.
§Errors
CudaError::NotInitializedif no CUDA driver is available (e.g. on macOS).CudaError::NotSupportedif the driver does not exportcuMemSetAccess.- Other
CudaErrorvariants on driver failure.