Tensor

Tensor

Classes

struct va_tensor

Macros

#define VA_TENSOR_DATA_ALIGN 16
#define VA_TENSOR_HEADER_SIZE((sizeof(va_tensor)+ VA_TENSOR_DATA_ALIGN - 1)& -VA_TENSOR_DATA_ALIGN)

Typedefs

typedef struct va_tensor va_tensor

Enumerations

enum va_tensor_type

Functions

va_tensor* va_tensor_alloc_empty(va_tensor_type type, int num_dimensions)
va_tensor* va_tensor_alloc(va_tensor_type type, int num_dimensions, const int64_t* dimensions)
va_tensor* va_tensor_calloc(va_tensor_type type, int num_dimensions, const int64_t* dimensions)
va_tensor* va_tensor_clone(const va_tensor* tensor)
void va_tensor_copy_data(const void* source, va_tensor* target)
va_tensor* va_tensor_typed_copy(const va_tensor* tensor, va_tensor_type type)
void va_tensor_clear(va_tensor* tensor)
void va_tensor_free(va_tensor* tensor)
void va_tensor_destroy(va_tensor* tensor)
int64_t va_tensor_bytes(const va_tensor* tensor)
int64_t va_tensor_number_of_elements(const va_tensor* tensor)
void* va_tensor_element(const va_tensor* tensor, const int64_t* indices)
const char* va_tensor_type_name(va_tensor_type type)

Typedef Documentation

typedef struct va_tensor va_tensor

A tensor is an array with a variable number of dimensions.

Enumeration Type Documentation

Supported tensor types.

Enumerator
va_invalid_tensor_type

Invalid tensor type.

va_float_tensor_type

32-bit floating point.

va_uint8_tensor_type

8-bit unsigned integer.

va_int8_tensor_type

8-bit signed integer.

va_uint16_tensor_type

16-bit unsigned integer.

va_int16_tensor_type

16-bit signed integer.

va_int32_tensor_type

32-bit signed integer.

va_int64_tensor_type

64-bit signed integer.

va_string_tensor_type

String type. NOTE! This type is currently not supported!

va_bool_tensor_type

8-bit boolean.

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.

va_double_tensor_type

64-bit floating point.

va_uint32_tensor_type

32-bit unsigned integer.

va_uint64_tensor_type

64-bit unsigned integer.

va_fcomplex_tensor_type

2 x 32-bit complex type.

va_dcomplex_tensor_type

2 x 64-bit complex type.

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!

Function Documentation

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_alloc_empty(va_tensor_type type, int num_dimensions )

Allocates an empty tensor structure with no data.

t->dimensions[0] = 3;
t->dimensions[1] = 640;
t->dimensions[2] = 480;
t->data = pointer_to_tensor_data;
t->destroy = &my_destructor_function;
int64_t va_tensor_bytes(const va_tensor* tensor)

Returns the total number of bytes required for the tensor's data array.

va_tensor* va_tensor_calloc(va_tensor_type type, int num_dimensions, const int64_t* dimensions )

Allocates a tensor with data initialized to zero.

void va_tensor_clear(va_tensor* tensor)

Sets the data to zeros. Does not change the shape of the tensor.

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.

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.

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};
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);
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.

int64_t va_tensor_number_of_elements(const va_tensor* tensor)

Returns the total number elements in a tensor.

const char* va_tensor_type_name(va_tensor_type type)

Returns a human-readable name for the given type.

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.