TIOVX User Guide
tivx_tensor.h File Reference

Interface to Tensor APIs (modeled after OpenVX 1.2 tensor support) More...

Go to the source code of this file.

Typedefs

typedef struct _vx_tensor * vx_tensor
 The multidimensional data object (Tensor). More...
 

Enumerations

enum  vx_ext_type_e { VX_TYPE_TENSOR = 0x815 }
 The Object Type Enumeration for Imports.
 
enum  vx_ext_context_attribute_e { VX_CONTEXT_MAX_TENSOR_DIMS = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_CONTEXT) + 0xE }
 A list of context attributes.
 
enum  vx_tensor_attribute_e {
  VX_TENSOR_NUMBER_OF_DIMS = VX_ATTRIBUTE_BASE( VX_ID_KHRONOS, VX_TYPE_TENSOR ) + 0x0,
  VX_TENSOR_DIMS = VX_ATTRIBUTE_BASE( VX_ID_KHRONOS, VX_TYPE_TENSOR ) + 0x1,
  VX_TENSOR_DATA_TYPE = VX_ATTRIBUTE_BASE( VX_ID_KHRONOS, VX_TYPE_TENSOR ) + 0x2,
  VX_TENSOR_FIXED_POINT_POSITION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_TENSOR) + 0x3,
  TIVX_TENSOR_SCALING_DIVISOR = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_TENSOR) + 0x4,
  TIVX_TENSOR_SCALING_DIVISOR_FIXED_POINT_POSITION = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_TENSOR) + 0x5
}
 tensor Data attributes. More...
 

Functions

VX_API_ENTRY vx_tensor VX_API_CALL vxCreateTensor (vx_context context, vx_size number_of_dims, const vx_size *dims, vx_enum data_type, vx_int8 fixed_point_position)
 Creates an opaque reference to a tensor data buffer. More...
 
VX_API_ENTRY vx_status VX_API_CALL vxCopyTensorPatch (vx_tensor tensor, vx_size number_of_dims, const vx_size *view_start, const vx_size *view_end, const vx_size *user_stride, void *user_ptr, vx_enum usage, vx_enum user_memory_type)
 Allows the application to copy a view patch from/into an tensor object . More...
 
VX_API_ENTRY vx_status VX_API_CALL vxQueryTensor (vx_tensor tensor, vx_enum attribute, void *ptr, vx_size size)
 Retrieves various attributes of a tensor data. More...
 
VX_API_ENTRY vx_status VX_API_CALL vxSetTensorAttribute (vx_tensor tensor, vx_enum attribute, const void *ptr, vx_size size)
 Sets attributes of a tensor object. More...
 
VX_API_ENTRY vx_status VX_API_CALL vxReleaseTensor (vx_tensor *tensor)
 Releases a reference to a tensor data object. The object may not be garbage collected until its total reference count is zero. More...
 
VX_API_ENTRY vx_status VX_API_CALL tivxMapTensorPatch (vx_tensor tensor, vx_size number_of_dims, const vx_size *view_start, const vx_size *view_end, vx_map_id *map_id, vx_size *stride, void **ptr, vx_enum usage, vx_enum mem_type)
 Allows the application to get direct access to a patch of tensor object. More...
 
VX_API_ENTRY vx_status VX_API_CALL tivxUnmapTensorPatch (vx_tensor tensor, vx_map_id map_id)
 Unmap and commit potential changes to a tensor object patch that were previously mapped. Unmapping a tensor patch invalidates the memory location from which the patch could be accessed by the application. Accessing this memory location after the unmap function completes has an undefined behavior. More...
 

Detailed Description

Interface to Tensor APIs (modeled after OpenVX 1.2 tensor support)

Definition in file tivx_tensor.h.

Typedef Documentation

◆ vx_tensor

typedef struct _vx_tensor* vx_tensor

The multidimensional data object (Tensor).

See also
vxCreateTensor

Definition at line 83 of file tivx_tensor.h.

Enumeration Type Documentation

◆ vx_tensor_attribute_e

tensor Data attributes.

Enumerator
VX_TENSOR_NUMBER_OF_DIMS 

Number of dimensions.

VX_TENSOR_DIMS 

Dimension sizes.

VX_TENSOR_DATA_TYPE 

tensor Data element data type. vx_type_e

VX_TENSOR_FIXED_POINT_POSITION 

fixed point position when the input element type is integer. Read-Write.

TIVX_TENSOR_SCALING_DIVISOR 

scaling divisor to be applied to each element when the input element type is integer. Read-Write.

TIVX_TENSOR_SCALING_DIVISOR_FIXED_POINT_POSITION 

fixed point position of the scaling divisor Read-Write.

Definition at line 103 of file tivx_tensor.h.

Function Documentation

◆ vxCreateTensor()

VX_API_ENTRY vx_tensor VX_API_CALL vxCreateTensor ( vx_context  context,
vx_size  number_of_dims,
const vx_size dims,
vx_enum  data_type,
vx_int8  fixed_point_position 
)

Creates an opaque reference to a tensor data buffer.

Not guaranteed to exist until the vx_graph containing it has been verified. Since functions using tensors, need to understand the context of each dimension. We describe a layout of the dimensions in each function using tensors. That layout is not mandatory. It is done specifically to explain the functions and not to mandate layout. Different implementation may have different layout. Therefore the layout description is logical and not physical. It refers to the order of dimensions given in this function.

Parameters
[in]contextThe reference to the implementation context.
[in]number_of_dimsThe number of dimensions.
[in]dimsDimensions sizes in elements.
[in]data_typeThe vx_type_e that represents the data type of the tensor data elements.
[in]fixed_point_positionSpecifies the fixed point position when the input element type is integer. if 0, calculations are performed in integer math.
Returns
A tensor data reference. Any possible errors preventing a successful creation should be checked using vxGetStatus.

◆ vxCopyTensorPatch()

VX_API_ENTRY vx_status VX_API_CALL vxCopyTensorPatch ( vx_tensor  tensor,
vx_size  number_of_dims,
const vx_size view_start,
const vx_size view_end,
const vx_size user_stride,
void *  user_ptr,
vx_enum  usage,
vx_enum  user_memory_type 
)

Allows the application to copy a view patch from/into an tensor object .

Parameters
[in]tensorThe reference to the tensor object that is the source or the destination of the copy.
[in]number_of_dimsNumber of patch dimension. Error return if 0 or greater than number of tensor dimensions. If smaller than number of tensor dimensions, the lower dimensions are assumed.
[in]view_startArray of patch start points in each dimension
[in]view_endArray of patch end points in each dimension
[in]user_strideArray of user memory strides in each dimension
[in]user_ptrThe address of the memory location where to store the requested data if the copy was requested in read mode, or from where to get the data to store into the tensor object if the copy was requested in write mode. The accessible memory must be large enough to contain the specified patch with the specified layout:
accessible memory in bytes >= (end[last_dimension] - start[last_dimension]) * stride[last_dimension].
The layout of the user memory must follow a row major order.
[in]usageThis declares the effect of the copy with regard to the tensor object using the vx_accessor_e enumeration. Only VX_READ_ONLY and VX_WRITE_ONLY are supported:
  • VX_READ_ONLY means that data is copied from the tensor object into the application memory
  • VX_WRITE_ONLY means that data is copied into the tensor object from the application memory
[in]user_memory_typeA vx_memory_type_e enumeration that specifies the memory type of the memory referenced by the user_addr.
Returns
A vx_status_e enumeration.
Return values
VX_ERROR_OPTIMIZED_AWAYThis is a reference to a virtual tensor that cannot be accessed by the application.
VX_ERROR_INVALID_REFERENCEThe tensor reference is not actually an tensor reference.
VX_ERROR_INVALID_PARAMETERSAn other parameter is incorrect.

◆ vxQueryTensor()

VX_API_ENTRY vx_status VX_API_CALL vxQueryTensor ( vx_tensor  tensor,
vx_enum  attribute,
void *  ptr,
vx_size  size 
)

Retrieves various attributes of a tensor data.

Parameters
[in]tensorThe reference to the tensor data to query.
[in]attributeThe attribute to query. Use a vx_tensor_attribute_e.
[out]ptrThe location at which to store the resulting value.
[in]sizeThe size of the container to which ptr points.
Returns
A vx_status_e enumeration.
Return values
VX_SUCCESSNo errors.
VX_ERROR_INVALID_REFERENCEIf data is not a vx_tensor.
VX_ERROR_INVALID_PARAMETERSIf any of the other parameters are incorrect.

◆ vxSetTensorAttribute()

VX_API_ENTRY vx_status VX_API_CALL vxSetTensorAttribute ( vx_tensor  tensor,
vx_enum  attribute,
const void *  ptr,
vx_size  size 
)

Sets attributes of a tensor object.

Parameters
[in]tensorThe tensor object to set.
[in]attributeThe attribute to modify. Use a vx_tensor_attribute_e enumeration.
[in]ptrThe pointer to the value to which to set the attribute.
[in]sizeThe size of the data pointed to by ptr.
Returns
A vx_status_e enumeration.
Return values
VX_SUCCESSNo errors.
VX_ERROR_INVALID_REFERENCEIf data is not a vx_tensor.
VX_ERROR_INVALID_PARAMETERSIf any of the other parameters are incorrect.

◆ vxReleaseTensor()

VX_API_ENTRY vx_status VX_API_CALL vxReleaseTensor ( vx_tensor tensor)

Releases a reference to a tensor data object. The object may not be garbage collected until its total reference count is zero.

Parameters
[in]tensorThe pointer to the tensor data to release.
Postcondition
After returning from this function the reference is zeroed.
Returns
A vx_status_e enumeration.
Return values
VX_SUCCESSNo errors; all other values indicate failure
*An error occurred. See vx_status_e.

◆ tivxMapTensorPatch()

VX_API_ENTRY vx_status VX_API_CALL tivxMapTensorPatch ( vx_tensor  tensor,
vx_size  number_of_dims,
const vx_size view_start,
const vx_size view_end,
vx_map_id map_id,
vx_size stride,
void **  ptr,
vx_enum  usage,
vx_enum  mem_type 
)

Allows the application to get direct access to a patch of tensor object.

Parameters
[in]tensorThe reference to the tensor object that is the source or the destination for direct access.
[in]number_of_dimsThe number of dimensions. Must be same as tensor number_of_dims.
[in]view_startArray of patch start points in each dimension. This is optional parameter and will be zero when NULL.
[in]view_endArray of patch end points in each dimension. This is optional parameter and will be dims[] of tensor when NULL.
[out]map_idThe address of a vx_map_id variable where the function returns a map identifier.
[out]strideAn array of stride in all dimensions in bytes. The stride value at index 0 must be size of the tensor data element type.
[out]ptrThe address of a pointer that the function sets to the address where the requested data can be accessed. The returned (*ptr) address is only valid between the call to the function and the corresponding call to tivxUnmapTensorPatch.
[in]usageThis declares the access mode for the tensor patch, using the vx_accessor_e enumeration.
  • VX_READ_ONLY: after the function call, the content of the memory location pointed by (*ptr) contains the tensor patch data. Writing into this memory location is forbidden and its behavior is undefined.
  • VX_READ_AND_WRITE : after the function call, the content of the memory location pointed by (*ptr) contains the tensor patch data; writing into this memory is allowed only for the location of items and will result in a modification of the affected items in the tensor object once the range is unmapped. Writing into a gap between items (when (*stride) > item size in bytes) is forbidden and its behavior is undefined.
  • VX_WRITE_ONLY: after the function call, the memory location pointed by (*ptr) contains undefined data; writing each item of the range is required prior to unmapping. Items not written by the application before unmap will become undefined after unmap, even if they were well defined before map. Like for VX_READ_AND_WRITE, writing into a gap between items is forbidden and its behavior is undefined.
[in]mem_typeA vx_memory_type_e enumeration that specifies the type of the memory where the tensor patch is requested to be mapped.
Returns
A vx_status_e enumeration.
Return values
VX_ERROR_OPTIMIZED_AWAYThis is a reference to a virtual tensor that cannot be accessed by the application.
VX_ERROR_INVALID_REFERENCEThe tensor reference is not actually an tensor reference.
VX_ERROR_INVALID_PARAMETERSAn other parameter is incorrect.
VX_ERROR_NO_MEMORYInternal memory allocation failed.
Postcondition
tivxUnmapTensorPatch with same (*map_id) value.

◆ tivxUnmapTensorPatch()

VX_API_ENTRY vx_status VX_API_CALL tivxUnmapTensorPatch ( vx_tensor  tensor,
vx_map_id  map_id 
)

Unmap and commit potential changes to a tensor object patch that were previously mapped. Unmapping a tensor patch invalidates the memory location from which the patch could be accessed by the application. Accessing this memory location after the unmap function completes has an undefined behavior.

Parameters
[in]tensorThe reference to the tensor object to unmap.
[out]map_idThe unique map identifier that was returned by tivxMapTensorPatch .
Returns
A vx_status_e enumeration.
Return values
VX_ERROR_INVALID_REFERENCEThe tensor reference is not actually a tensor reference.
VX_ERROR_INVALID_PARAMETERSAn other parameter is incorrect.
Precondition
tivxMapTensorPatch with same map_id value