VART-X  0.3.0
vart::Memory Class Reference

This module is responsible for allocating and managing memory on the device. More...

#include <vart_memory.hpp>

Public Member Functions

 Memory (MemoryImplType type, size_t size, uint8_t mbank_idx, std::shared_ptr< Device > device)
 Memory() - Constructor to allocate memory using implementation specific method based on input 'type'. More...
 
 Memory (MemoryImplType type, uint8_t *data, size_t size, std::shared_ptr< Device > device)
 Memory() - Constructor to create Memory instance using user provided data pointer. More...
 
 Memory (std::shared_ptr< MemoryImplBase > ptr)
 Memory() - Constructor for using user defined implementation. More...
 
 Memory (MemoryImplType type, int dma_fd, size_t size, std::shared_ptr< Device > device)
 Memory() - Constructor to create Memory instance from a dma-buf file descriptor. More...
 
 ~Memory ()=default
 
const uint8_t * map (DataMapFlags map_flags)
 map() - Maps allocated memory to user space. More...
 
void unmap ()
 unmap() - Unmaps allocated memory from user space. More...
 
const std::shared_ptr< MemoryImplBase > & get_pimpl_handle () const
 get_pimpl_handle() - Retrieves pointer to Memory Implementation Base class More...
 
std::shared_ptr< Deviceget_device_handle () const
 get_device_handle() - Retrieves the device handle associated with memory allocation More...
 
size_t get_size ()
 get_size() - gets the size of the allocated memory More...
 
uint64_t get_physical_addr ()
 get_physical_addr() - Retrieves the physical address of the allocated memory. More...
 
int export_buffer () const
 export_buffer() - Export the underlying buffer as a dma-buf file descriptor More...
 

Detailed Description

This module is responsible for allocating and managing memory on the device.

See also
MemoryImplBase

Constructor & Destructor Documentation

◆ Memory() [1/4]

vart::Memory::Memory ( MemoryImplType  type,
size_t  size,
uint8_t  mbank_idx,
std::shared_ptr< Device device 
)

Memory() - Constructor to allocate memory using implementation specific method based on input 'type'.

Parameters
[in]typeEnum class to specify which type of memory allocation method to use
[in]sizeSize of the buffer
[in]mbank_idxmemory bank index on which memory needs to be allocated
[in]deviceDevice handle. Must be non-null. See vart::Device for more details.

◆ Memory() [2/4]

vart::Memory::Memory ( MemoryImplType  type,
uint8_t *  data,
size_t  size,
std::shared_ptr< Device device 
)

Memory() - Constructor to create Memory instance using user provided data pointer.

Parameters
[in]typeEnum class to specify which type of memory allocation method to use
[in]dataUser-allocated buffer pointer. Ownership remains with the caller; the caller must keep the buffer valid for the lifetime of this Memory.
[in]sizeSize of the buffer in bytes (must match the allocation pointed to by data).
[in]deviceDevice handle. Must be non-null. See vart::Device for more details.

◆ Memory() [3/4]

vart::Memory::Memory ( std::shared_ptr< MemoryImplBase ptr)

Memory() - Constructor for using user defined implementation.

Parameters
[in]ptrPointer to user's implementation instance. Must be non-null; the constructor stores it as the pimpl and subsequent method calls dereference it without an additional null check.

◆ Memory() [4/4]

vart::Memory::Memory ( MemoryImplType  type,
int  dma_fd,
size_t  size,
std::shared_ptr< Device device 
)

Memory() - Constructor to create Memory instance from a dma-buf file descriptor.

Parameters
[in]typeEnum class to specify which type of memory allocation method to use. type must be MemoryImplType::XRT. Any other type throws std::runtime_error.
[in]dma_fdDMA-BUF file descriptor to import. The file descriptor represents a CMA-backed buffer exported from another component.
[in]sizeSize of the buffer (must match the actual buffer size)
[in]deviceDevice handle. Must be non-null. See vart::Device for more details.
Exceptions
std::runtime_errorIf type is not MemoryImplType::XRT, the file descriptor is invalid, the buffer is not CMA-backed, or the import operation fails.

◆ ~Memory()

vart::Memory::~Memory ( )
default

Member Function Documentation

◆ export_buffer()

int vart::Memory::export_buffer ( ) const

export_buffer() - Export the underlying buffer as a dma-buf file descriptor

Returns
Returns a file descriptor (int) representing the dma-buf on success (>= 0). Returns -1 on failure (buffer not CMA-backed, invalid state, or export error).

◆ get_device_handle()

std::shared_ptr<Device> vart::Memory::get_device_handle ( ) const

get_device_handle() - Retrieves the device handle associated with memory allocation

Returns
Returns Device handle

◆ get_physical_addr()

uint64_t vart::Memory::get_physical_addr ( )

get_physical_addr() - Retrieves the physical address of the allocated memory.

Returns
Physical (device) address of the underlying buffer for XRT-backed allocations.
Exceptions
std::runtime_errorIf the memory was not allocated with MemoryImplType::XRT.

◆ get_pimpl_handle()

const std::shared_ptr<MemoryImplBase>& vart::Memory::get_pimpl_handle ( ) const

get_pimpl_handle() - Retrieves pointer to Memory Implementation Base class

Returns
Returns a constant reference of pointer to implementation class.

◆ get_size()

size_t vart::Memory::get_size ( )

get_size() - gets the size of the allocated memory

Returns
returns the memory size

◆ map()

const uint8_t* vart::Memory::map ( DataMapFlags  map_flags)

map() - Maps allocated memory to user space.

Parameters
[in]map_flagsFlag used to indicate mode of memory mapping. May combine bits from DataMapFlags (e.g. READ|WRITE).
Returns
Virtual address of the mapped buffer on success, or nullptr on failure.
Note
Both XRT and NON_CMA memory types support map().

◆ unmap()

void vart::Memory::unmap ( )

unmap() - Unmaps allocated memory from user space.

Exceptions
std::runtime_errorIf called without a prior successful map().

The documentation for this class was generated from the following file: