va_tensorπ
#include <va_tensor.h>
-
struct
va_tensor
π A tensor is an array with a variable number of dimensions.
Public Members
-
va_tensor_type
type
π The type of the tensor.
-
int
num_dimensions
π The number of dimensions in the tensor.
-
int64_t *
dimensions
π Pointer to an array that holds tensor dimensions.
If the tensor is allocated using va_tensor_alloc(), dimensions will be stored right after the header.
-
va_refcount
ref_count
π The number of references to this tensor structure.
-
void *
data
π Pointer to the first data element.
-
void (*
destroy
)(struct va_tensor*)π Destructor function.
Depending on how the tensor was originally allocated, it also needs to be deallocated differently. If destroy is non-null, va_tensor_free() will use it instead of va_tensor_destroy(), which is the default.
-
va_tensor_type
Typedefs
-
typedef struct va_tensor
va_tensor
A tensor is an array with a variable number of dimensions.
Enums
-
enum
va_tensor_type
π Supported tensor types.
Values:
-
enumerator
va_invalid_tensor_type
π Invalid tensor type.
-
enumerator
va_float_tensor_type
π 32-bit floating point.
-
enumerator
va_uint8_tensor_type
π 8-bit unsigned integer.
-
enumerator
va_int8_tensor_type
π 8-bit signed integer.
-
enumerator
va_uint16_tensor_type
π 16-bit unsigned integer.
-
enumerator
va_int16_tensor_type
π 16-bit signed integer.
-
enumerator
va_int32_tensor_type
π 32-bit signed integer.
-
enumerator
va_int64_tensor_type
π 64-bit signed integer.
-
enumerator
va_string_tensor_type
π String type.
NOTE! This type is currently not supported!
-
enumerator
va_bool_tensor_type
π 8-bit boolean.
-
enumerator
va_float16_tensor_type
π IEEE754 half-precision 16-bit floating-point format.
This format has a sign bit, 5 exponent bits, and 10 mantissa bits.
-
enumerator
va_double_tensor_type
π 64-bit floating point.
-
enumerator
va_uint32_tensor_type
π 32-bit unsigned integer.
-
enumerator
va_uint64_tensor_type
π 64-bit unsigned integer.
-
enumerator
va_fcomplex_tensor_type
π 2 x 32-bit complex type.
-
enumerator
va_dcomplex_tensor_type
π 2 x 64-bit complex type.
-
enumerator
va_bfloat16_tensor_type
π IEEE754 single-precision floating-point number truncated to 16 bits.
This format is not an IEEE standard. It has a sign bit, 8 exponent bits, and 7 mantissa bits. NOTE! This type is currently not supported!
-
enumerator
Functions
-
static inline size_t
va_tensor_element_bytes
(va_tensor_type type)π Returns the number of bytes occupied by a single element of the given type.
-
va_tensor *
va_tensor_alloc_empty
(va_tensor_type type, int num_dimensions)π Allocates an empty tensor structure with no data.
va_tensor* t = va_tensor_alloc_empty(va_float_tensor_type, 3); t->dimensions[0] = 3; t->dimensions[1] = 640; t->dimensions[2] = 480; t->data = pointer_to_tensor_data; t->destroy = &my_destructor_function;
-
va_tensor *
va_tensor_alloc
(va_tensor_type type, int num_dimensions, const int64_t *dimensions)π Allocates a tensor with uninitialized data.
-
va_tensor *
va_tensor_calloc
(va_tensor_type type, int num_dimensions, const int64_t *dimensions)π Allocates a tensor with data initialized to zero.
-
va_tensor *
va_tensor_clone
(const va_tensor *tensor)π Creates a deep copy of tensor.
Returns the clone or NULL if memory allocation fails.
-
void
va_tensor_copy_data
(const void *source, va_tensor *target)π Copies raw data from a buffer pointed to by source to the data buffer of target tensor.
-
va_tensor *
va_tensor_typed_copy
(const va_tensor *tensor, va_tensor_type type)π Allocates a new tensor that is the same size as tensor and has the same shape.
The contents will be uninitialized. Returns NULL if memory allocation fails.
-
void
va_tensor_clear
(va_tensor *tensor)π Sets the data to zeros.
Does not change the shape of the tensor.
-
void
va_tensor_free
(va_tensor *tensor)π Releases the memory allocated by tensor.
If there is a custom destructor function, it will be used. If not, va_tensor_destroy() will be called.
-
void
va_tensor_destroy
(va_tensor *tensor)π Releases the memory allocated by tensor and
tensor->data
using shm_free().This is the default destructor function that will be run if
tensor->destroy
is NULL.
-
int64_t
va_tensor_bytes
(const va_tensor *tensor)π Returns the total number of bytes required for the tensorβs data array.
-
int64_t
va_tensor_number_of_elements
(const va_tensor *tensor)π Returns the total number elements in a tensor.
-
void *
va_tensor_element
(const va_tensor *tensor, const int64_t *indices)π Returns a pointer to an element in the tensor.
The element is identified by a list of indices whose length must match
tensor->num_dimensions
.// RGB color planes as a tensor. int64_t dims[] = {3, 640, 480}; va_tensor* t = va_tensor_alloc(va_float_tensor_type, 3, dims); int64_t green_start_idx[] = {1, 0, 0}; float* first_green = va_tensor_element(t, green_start_idx); int64_t blue_end_idx[] = {2, 639, 479}; float* last_blue = va_tensor_element(t, blue_end_idx);
-
const char *
va_tensor_type_name
(va_tensor_type type)π Returns a human-readable name for the given type.