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.

struct va_tensor *sourceπŸ”—

Pointer to a source tensor if data is shared.

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.

Defines

VA_TENSOR_DATA_ALIGNπŸ”—
VA_TENSOR_HEADER_SIZEπŸ”—

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!

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.