Data Structures | |
struct | VPIArrayData |
Stores information about array characteristics and content. More... | |
Typedefs | |
typedef struct VPIArrayImpl * | VPIArray |
Functions | |
VPIStatus | vpiArrayCreate (uint32_t capacity, VPIArrayType fmt, uint32_t flags, VPIArray *array) |
Create an empty array instance with the specified flags. More... | |
void | vpiArrayDestroy (VPIArray array) |
Destroy an array instance as well as all resources it owns. More... | |
VPIStatus | vpiArrayWrapHostMem (const VPIArrayData *arrayData, uint32_t flags, VPIArray *array) |
Create an array object by wrapping around an existing host-memory block. More... | |
VPIStatus | vpiArrayWrapCudaDeviceMem (const VPIArrayData *arrayData, uint32_t flags, VPIArray *array) |
Create an array object by wrapping around an existing device-memory (CUDA) block. More... | |
VPIStatus | vpiArrayInvalidate (VPIArray array) |
This method is useful for unmanaged arrays only (created with 'vpiArrayWrap*`). More... | |
VPIStatus | vpiArrayGetSize (VPIArray array, uint32_t *size) |
Get the array size in elements. More... | |
VPIStatus | vpiArraySetSize (VPIArray array, uint32_t size) |
Set the array size in elements. More... | |
VPIStatus | vpiArrayGetCapacity (VPIArray array, uint32_t *capacity) |
Get the array capacity in elements. More... | |
VPIStatus | vpiArrayGetStride (VPIArray array, uint32_t *stride) |
Get the array stride (distance between two consecutive elements) in bytes. More... | |
VPIStatus | vpiArrayGetFlags (VPIArray array, uint32_t *flags) |
Get the array flags. More... | |
VPIStatus | vpiArrayGetType (VPIArray array, VPIArrayType *type) |
Get the array type. More... | |
VPIStatus | vpiArrayLock (VPIArray array, VPILockMode mode, VPIArrayData *arrayData) |
Acquires the lock on array object and returns a pointer to array data. More... | |
VPIStatus | vpiArrayUnlock (VPIArray array) |
Releases the lock on array object. More... | |
Array creation flags | |
#define | VPI_ARRAY_DISABLE_PVA VPI_BACKEND_DISABLE_PVA |
Array won't be used in a PVA stream. | |
#define | VPI_ARRAY_DISABLE_CPU VPI_BACKEND_DISABLE_CPU |
Array won't be used in a CPU stream. | |
#define | VPI_ARRAY_DISABLE_CUDA VPI_BACKEND_DISABLE_CUDA |
Array won't be used in a CUDA stream. | |
#define | VPI_ARRAY_ONLY_PVA VPI_BACKEND_ONLY_PVA |
Array will only be used in a PVA stream. | |
#define | VPI_ARRAY_ONLY_CPU VPI_BACKEND_ONLY_CPU |
Array will only be used in a CPU stream. | |
#define | VPI_ARRAY_ONLY_CUDA VPI_BACKEND_ONLY_CUDA |
Array will only be used in a CUDA stream. | |
Deprecated array creation flags | |
#define | VPI_ARRAY_NO_PVA VPI_ARRAY_DISABLE_PVA |
Deprecated. | |
#define | VPI_ARRAY_NO_CPU VPI_ARRAY_DISABLE_CPU |
Deprecated. | |
#define | VPI_ARRAY_NO_CUDA VPI_ARRAY_DISABLE_CUDA |
Deprecated. | |
An abstract representation of a generic 1D array.
There are two ways of creating 1D array containers with the API. The most basic one is to use vpiArrayCreate to allocate and initialize an empty (zeroed) VPIArray object. The memory for the array data is allocated and managed by the backend implementation. Parameters such as capacity format are immutable and specified at the construction time. The internal memory layout is also backend-specific. More importantly, efficient exchange of array data between different hardware blocks might force the implementation to allocate the memory in multiple memory pools (e.g. dGPU and system DRAM). In some scenarios (to optimize performance and memory use) it might be beneficial to constrain the internal allocation policy to support only a particular set of backends. This is implemented with VPI_ARRAY_DISABLE_PVA / VPI_ARRAY_DISABLE_CPU / VPI_ARRAY_DISABLE_CUDA set of flags which are passed during array construction. For example, an array allocated with VPI_ARRAY_DISABLE_CUDA flag set, will not be readable or writable by any CUDA VPIStream instance.
To enable interop with existing host-side code, the user can also create an array object that will wrap user-allocated (and managed) array data. Similarly to vpiArrayCreate, array parameters passed to vpiArrayWrap*()
are fixed. To prevent excessive copying, users can point to array data that resides directly in the CUDA device memory with vpiArrayWrapCudaDeviceMem.
The set of vpiArrayLock / vpiArrayUnlock allows to read from/write to the array data from the host. These functions are non-blocking and oblivious to the device command queue so it's up to the user to make sure that all pending operations using this array as input or output are finished. Also, depending on the VPIStream type lock/unlock operation might be time-consuming and, for example, involve copying data over PCIe bus for dGPUs.
struct VPIArrayData |
Data Fields | ||
---|---|---|
uint32_t | capacity | Maximum number of elements that the array can hold. |
void * | data | Points to the first element of the array. |
uint32_t | size | Number of elements in the array. |
uint32_t | stride | Size in bytes of each array element. |
VPIArrayType | type | Type of each array element. |
typedef struct VPIArrayImpl* VPIArray |
VPIStatus vpiArrayCreate | ( | uint32_t | capacity, |
VPIArrayType | fmt, | ||
uint32_t | flags, | ||
VPIArray * | array | ||
) |
#include <vpi/Array.h>
Create an empty array instance with the specified flags.
Array data is zeroed. Maximum capacity of the array is fixed and defined at the construction-time.
capacity | [in] capacity |
fmt | [in] array format |
flags | [in] flags |
array | [out] pointer to array handle |
void vpiArrayDestroy | ( | VPIArray | array | ) |
#include <vpi/Array.h>
Destroy an array instance as well as all resources it owns.
array | [in] array handle |
#include <vpi/Array.h>
Get the array capacity in elements.
array | [in] an array handle |
capacity | [out] a pointer to a variable which will be set to the capacity of the array |
#include <vpi/Array.h>
Get the array flags.
array | [in] an array handle |
flags | [out] a pointer to where the flags will be written to |
#include <vpi/Array.h>
Get the array size in elements.
array | [in] an array handle to a locked array |
size | [out] a pointer to a variable which will be set to the size of the array |
#include <vpi/Array.h>
Get the array stride (distance between two consecutive elements) in bytes.
array | [in] an array handle |
stride | [out] a pointer to a variable which will be set to the stride of the array |
VPIStatus vpiArrayGetType | ( | VPIArray | array, |
VPIArrayType * | type | ||
) |
#include <vpi/Array.h>
Get the array type.
array | [in] an array handle |
type | [out] a pointer to where the type will be written to |
#include <vpi/Array.h>
This method is useful for unmanaged arrays only (created with 'vpiArrayWrap*`).
If the underlying array data has been modified outside the API, use this method to mark the array as invalid. This will force the API to update its internal representation (e.g., re-upload to CUDA memory) when necessary.
array | [in] an array handle |
VPIStatus vpiArrayLock | ( | VPIArray | array, |
VPILockMode | mode, | ||
VPIArrayData * | arrayData | ||
) |
#include <vpi/Array.h>
Acquires the lock on array object and returns a pointer to array data.
Depending on the internal array representation, as well as the actual location in memory, this function might have a significant performance overhead (format conversion, layout conversion, device-to-host memory copy).
array | [in] an array handle |
mode | [in] Lock mode. |
arrayData | [out] a pointer to a variable which will be set to the pointer to the array data |
#include <vpi/Array.h>
Set the array size in elements.
array | [in] an array handle to a locked array |
size | [in] the size of the array |
#include <vpi/Array.h>
Releases the lock on array object.
This function might have a significant performance overhead (format conversion, layout conversion, host-to-device memory copy).
array | [in] an array handle |
VPIStatus vpiArrayWrapCudaDeviceMem | ( | const VPIArrayData * | arrayData, |
uint32_t | flags, | ||
VPIArray * | array | ||
) |
#include <vpi/Array.h>
Create an array object by wrapping around an existing device-memory (CUDA) block.
Stride between elements has to be at least as large as the element structure size. It also has to respect alignment requirements of the element data structure.
arrayData | [in] data |
flags | [in] flags |
array | [out] pointer to an array handle |
VPIStatus vpiArrayWrapHostMem | ( | const VPIArrayData * | arrayData, |
uint32_t | flags, | ||
VPIArray * | array | ||
) |
#include <vpi/Array.h>
Create an array object by wrapping around an existing host-memory block.
Stride between elements has to be at least as large as the element structure size. It also has to respect alignment requirements of the element data structure.
arrayData | [in] data |
flags | [in] flags |
array | [out] pointer to an array handle |