|
VART-ML
0.3.0
|
This class represents a tensor in the VART API. More...
#include <vart_npu_tensor.hpp>
Public Member Functions | |
| NpuTensor (const NpuTensorInfo &info, void *buffer, MemoryType mem_type) | |
| Construct a NpuTensor from a user-supplied buffer. More... | |
| NpuTensor (const NpuTensorInfo &info, const void *buffer, MemoryType mem_type) | |
| Construct a NpuTensor from a user-supplied constant buffer. More... | |
| NpuTensor () | |
| Default-constructs an empty NpuTensor with no buffer or metadata. More... | |
| void * | get_buffer () |
| Retrieves a pointer to the tensor's buffer. More... | |
| const void * | get_buffer () const |
| Retrieves a pointer to the tensor's buffer. More... | |
| void * | get_virtual_address () |
| Returns the virtual address of the tensor buffer. More... | |
| const void * | get_virtual_address () const |
| Returns the virtual address of the tensor buffer. More... | |
| uint64_t | get_physical_address () const |
| Returns the physical address of the tensor buffer. More... | |
| const NpuTensorInfo & | get_info () const |
| Returns the NpuTensorInfo metadata of the tensor. More... | |
| MemoryType | get_memory_type () const |
| Get the memory type of the tensor. More... | |
| void | sync_buffer () const |
| Synchronizes the tensor buffer between CPU and AIE. More... | |
| int | export_buffer () const |
| Export the tensor buffer as a dma-buf file descriptor. More... | |
| void | print_info () const |
| Prints the metadata of the tensor. More... | |
Friends | |
| class | NpuTensorPrivAccess |
This class represents a tensor in the VART API.
This class encapsulates tensor metadata and offers access to the tensor's data buffer. It can either wrap a user-supplied buffer (constructed directly) or own a runner-allocated buffer (obtained via vart::Runner::allocate_npu_tensor or vart::Runner::allocate_sub_tensor).
NpuTensor is copyable; copies are shallow and share the same underlying buffer via reference counting. Moving an NpuTensor transfers ownership of the internal reference without a copy.
| vart::NpuTensor::NpuTensor | ( | const NpuTensorInfo & | info, |
| void * | buffer, | ||
| MemoryType | mem_type | ||
| ) |
Construct a NpuTensor from a user-supplied buffer.
Initializes the tensor using the specified metadata and buffer.
| info | Tensor metadata (NpuTensorInfo). |
| buffer | Pointer to the user buffer containing the tensor data. The buffer must remain valid for the lifetime of the NpuTensor object. |
| mem_type | Specifies the memory type of the buffer. |
| std::runtime_error | if the buffer is null, memory type is invalid, or tensor info validation fails. |
| vart::NpuTensor::NpuTensor | ( | const NpuTensorInfo & | info, |
| const void * | buffer, | ||
| MemoryType | mem_type | ||
| ) |
Construct a NpuTensor from a user-supplied constant buffer.
Initializes the tensor using the specified metadata and constant buffer.
| info | Tensor metadata (NpuTensorInfo). |
| buffer | Pointer to the user constant buffer containing the tensor data. |
| mem_type | Specifies the memory type of the buffer. |
| std::runtime_error | if the buffer is null, memory type is invalid, or tensor info validation fails. |
| vart::NpuTensor::NpuTensor | ( | ) |
Default-constructs an empty NpuTensor with no buffer or metadata.
| int vart::NpuTensor::export_buffer | ( | ) | const |
Export the tensor buffer as a dma-buf file descriptor.
Exports the underlying buffer as a dma-buf file descriptor for inter-process or inter-device sharing.
| void* vart::NpuTensor::get_buffer | ( | ) |
Retrieves a pointer to the tensor's buffer.
This function provides access to the buffer that was provided during tensor construction.
void*; the caller must cast back to xrt::bo* to use it). If the memory type is MemoryType::DMA_FD, it returns a pointer to the file descriptor integer. For MemoryType::USER_POINTER_CMA and MemoryType::USER_POINTER_NON_CMA, it returns the user-provided virtual pointer as-is. | const void* vart::NpuTensor::get_buffer | ( | ) | const |
Retrieves a pointer to the tensor's buffer.
This function is the overloaded version for immutable (const) access.
| const NpuTensorInfo& vart::NpuTensor::get_info | ( | ) | const |
Returns the NpuTensorInfo metadata of the tensor.
This method returns the NpuTensorInfo object that contains metadata about the tensor, such as its name, shape, strides, data type, and memory layout.
| MemoryType vart::NpuTensor::get_memory_type | ( | ) | const |
Get the memory type of the tensor.
| uint64_t vart::NpuTensor::get_physical_address | ( | ) | const |
Returns the physical address of the tensor buffer.
| void* vart::NpuTensor::get_virtual_address | ( | ) |
Returns the virtual address of the tensor buffer.
| const void* vart::NpuTensor::get_virtual_address | ( | ) | const |
Returns the virtual address of the tensor buffer.
This function is the overloaded version for immutable (const) access.
| void vart::NpuTensor::print_info | ( | ) | const |
Prints the metadata of the tensor.
This method prints the NpuTensorInfo metadata, including name, shape, strides, data type, memory layout, and size. It is useful for debugging and understanding the tensor's properties.
| void vart::NpuTensor::sync_buffer | ( | ) | const |
Synchronizes the tensor buffer between CPU and AIE.
Ensures data consistency between CPU and AIE by performing cache operations based on the tensor's direction:
Call this method after writing data to an INPUT tensor (before execute) and after execute completes for an OUTPUT tensor (before reading results).
|
friend |