Skip to content

blaize::vx

Namespaces

Name
blaize::vx::details

Classes

Name
class blaize::vx::basic_shape
struct blaize::vx::IsVxType
class blaize::vx::Scales
Stores the scale factors for a tensor.
class blaize::vx::Unique
Wrap a vx_ object (e.g. vx_context) with an object that automatically calls vxReleaseReference on scope exit.
class blaize::vx::VxOrder
Indicates that the following dimensions are in VX order rather than numpy/ONNX order.

Types

Name
enum class vx_enum DataType
enum class int VxDimension { X = -1, Y = -2, Z = -3, W = -4}
Access a dimension in Vx order independent of how many dimensions it has.
enum class int OnnxDimension { N = -4, C = -3, H = -2, W = -1}
Access a dimension in Onnx order independent of how many dimensions it has.
using basic_shape< vx_int32 > Shape
The instantiation of the basic_shape template for integer types.
using basic_shape< vx_float32 > FloatShape
The instantiation of the basic_shape template for float types.
using Unique< vx_graph > Graph
using Unique< vx_kernel > Kernel
using Unique< vx_image > Image
using Unique< vx_scalar > Scalar
using Unique< vx_array > Array
using Unique< vx_matrix > Matrix
using Unique< vx_threshold > Threshold
using Unique< vx_pyramid > Pyramid
using Unique< vx_lut > LUT
using Unique< vx_convolution > Convolution
using Unique< vx_distribution > Distribution
using Unique< vx_remap > Remap
using Unique< vx_node > Node
using Unique< vx_context > Context
using Unique< vx_delay > Delay
using Unique< vx_object_array > ObjectArray
using Unique< vx_parameter > Parameter
using Unique< vx_reference > Reference
using Unique< vx_target > Target
using Unique< vx_tensor > Tensor

Functions

Name
template <typename T >
std::string
to_string(const basic_shape< T > & shape)
Format the shape as a string in (n, c, h, w) format.
template <typename T >
std::ostream &
operator<<(std::ostream & s, const basic_shape< T > & shape)
bool AreEquivalent(const Shape & left, const Shape & right)
Determine if two shapes are equivalent, that is that all dimensions are the same, and any missing dimensions in one tensor are 1 in the other. \detail For example: assert(AreEquivalent(vx::Shape(1, 2, 3, 4), vx::Shape(2, 3, 4)); assert(!AreEquivalent(vx::Shape(2, 2, 3, 4), vx::Shape(2, 3, 4));.
size_t ComputeSize(const Shape & shape)
Return the product of all dimensions, for a tensor shape this can be used to determine the total number of elements in the tensor.
Shape GetShape(vx_tensor t)
Get the shape of the tensor. \detail If the tensor is an invalid reference then a default constructed Shape is returned.
std::uint32_t GetElementSize(DataType format)
Get the element bytes per pixel of the given data format. \detail If the format is not a valid VX_TYPE_ enumeration then 1 is returned.
DataType GetDataType(vx_tensor t)
Get the data format of the tensor. \detail If the tensor is an invalid reference then VX_TYPE_INVALID is returned.
Scales GetScales(vx_tensor t)
Get the scales of the tensor. \detail If the tensor is an invalid reference then a default constructed Scales is returned.
Tensor CreateTensor(vx_context ctx, const Shape & shape, DataType data_type, const Scales & scales =Scales{}, const std::string & from_file =std::string{})
Create a Tensor of given shape and format. \detail Optionally also set the tensor scale factor, and initialise the tensor with data from a binary file.
Tensor CreateVirtualTensor(vx_graph graph, const Shape & shape, DataType data_type, const Scales & scales =Scales{})
Create a Virtual Tensor of given shape and format. \detail Optionally also set the tensor scale factor.
Tensor CreateTensorFromView(vx_tensor parent, const Shape & start, const Shape & end)
Create an ROI of a Tensor from start to end positions.
template <typename T >
vx_status
ReadTensor(vx_tensor t, std::vector< T > & buffer)
Read the entire contents of a tensor (or roi) into a vector.
template <typename T >
vx_status
WriteTensor(vx_tensor t, const std::vector< T > & buffer)
Write to the entire contents of a tensor (or roi) from a vector.
template <typename Ref >
vx_reference
ToReference(Ref ref)
Convert a vx object such as vx_tensor into a vx_reference. \detail Whilst a reinterpret_cast can be used for this purpose, this function is safer because it will not allow non vx types to be cast. Additionally it accepts Unique objects.
template <typename Ref >
vx_reference
ToReference(const Unique< Ref > & ref)
vx_reference ToReference< vx_reference >(vx_reference ref)
template <typename VxType >
Unique< VxType >
Own(VxType r)
Create a deduced Unique<> object that owns the given reference.
template <typename VxType >
Unique< VxType >
RetainAndOwn(VxType r)
Create a deduced Unique<> object that retains and then owns the given reference. \detail This can be useful when an optional reference is given to a function and the given ref is not owned by the current scope.
template <typename Ref >
vx_context
GetContext(const Ref & r)
Retrieves the context from any reference from within a context.
template <typename T >
std::string
GetReferenceName(const T & ref)
Retrieves the reference name.
void EnableLogging(vx_context c, bool verbose =false)
Enables openvx logging to stdout.

Attributes

Name
constexpr auto int8
constexpr auto uint8
constexpr auto float8
constexpr auto int16
constexpr auto uint16
constexpr auto float16
constexpr auto bfloat16
constexpr auto int32
constexpr auto uint32
constexpr auto float32
constexpr auto int64
constexpr auto uint64
constexpr auto float64
constexpr auto vxorder
constexpr auto N
constexpr auto C
constexpr auto H
constexpr auto W

Types Documentation

enum DataType

Enumerator Value Description
invalid VX_TYPE_INVALID
int8 VX_TYPE_INT8
uint8 VX_TYPE_UINT8
float8 VX_TYPE_FLOAT8
int16 VX_TYPE_INT16
uint16 VX_TYPE_UINT16
float16 VX_TYPE_FLOAT16
bfloat16 VX_TYPE_BFLOAT16
int32 VX_TYPE_INT32
uint32 VX_TYPE_UINT32
float32 VX_TYPE_FLOAT32
int64 VX_TYPE_INT64
uint64 VX_TYPE_UINT64
float64 VX_TYPE_FLOAT64

enum VxDimension

Enumerator Value Description
X -1
Y -2
Z -3
W -4

Access a dimension in Vx order independent of how many dimensions it has.

enum OnnxDimension

Enumerator Value Description
N -4
C -3
H -2
W -1

Access a dimension in Onnx order independent of how many dimensions it has.

using Shape

using Shape =  basic_shape<vx_int32>;

The instantiation of the basic_shape template for integer types.

using FloatShape

using FloatShape =  basic_shape<vx_float32>;

The instantiation of the basic_shape template for float types.

using Graph

using Graph =  Unique<vx_graph>;

using Kernel

using Kernel =  Unique<vx_kernel>;

using Image

using Image =  Unique<vx_image>;

using Scalar

using Scalar =  Unique<vx_scalar>;

using Array

using Array =  Unique<vx_array>;

using Matrix

using Matrix =  Unique<vx_matrix>;

using Threshold

using Threshold =  Unique<vx_threshold>;

using Pyramid

using Pyramid =  Unique<vx_pyramid>;

using LUT

using LUT =  Unique<vx_lut>;

using Convolution

using Convolution =  Unique<vx_convolution>;

using Distribution

using Distribution =  Unique<vx_distribution>;

using Remap

using Remap =  Unique<vx_remap>;

using Node

using Node =  Unique<vx_node>;

using Context

using Context =  Unique<vx_context>;

using Delay

using Delay =  Unique<vx_delay>;

using ObjectArray

using ObjectArray =  Unique<vx_object_array>;

using Parameter

using Parameter =  Unique<vx_parameter>;

using Reference

using Reference =  Unique<vx_reference>;

using Target

using Target =  Unique<vx_target>;

using Tensor

using Tensor =  Unique<vx_tensor>;

Functions Documentation

function to_string

template <typename T >
std::string to_string(
    const basic_shape< T > & shape
)

Format the shape as a string in (n, c, h, w) format.

function operator<<

template <typename T >
std::ostream & operator<<(
    std::ostream & s,
    const basic_shape< T > & shape
)

function AreEquivalent

inline bool AreEquivalent(
    const Shape & left,
    const Shape & right
)

Determine if two shapes are equivalent, that is that all dimensions are the same, and any missing dimensions in one tensor are 1 in the other. \detail For example: assert(AreEquivalent(vx::Shape(1, 2, 3, 4), vx::Shape(2, 3, 4)); assert(!AreEquivalent(vx::Shape(2, 2, 3, 4), vx::Shape(2, 3, 4));.

function ComputeSize

inline size_t ComputeSize(
    const Shape & shape
)

Return the product of all dimensions, for a tensor shape this can be used to determine the total number of elements in the tensor.

function GetShape

inline Shape GetShape(
    vx_tensor t
)

Get the shape of the tensor. \detail If the tensor is an invalid reference then a default constructed Shape is returned.

function GetElementSize

inline std::uint32_t GetElementSize(
    DataType format
)

Get the element bytes per pixel of the given data format. \detail If the format is not a valid VX_TYPE_ enumeration then 1 is returned.

function GetDataType

inline DataType GetDataType(
    vx_tensor t
)

Get the data format of the tensor. \detail If the tensor is an invalid reference then VX_TYPE_INVALID is returned.

function GetScales

inline Scales GetScales(
    vx_tensor t
)

Get the scales of the tensor. \detail If the tensor is an invalid reference then a default constructed Scales is returned.

function CreateTensor

inline Tensor CreateTensor(
    vx_context ctx,
    const Shape & shape,
    DataType data_type,
    const Scales & scales =Scales{},
    const std::string & from_file =std::string{}
)

Create a Tensor of given shape and format. \detail Optionally also set the tensor scale factor, and initialise the tensor with data from a binary file.

Parameters:

  • ctx The reference to the context.
  • shape Shape of tensor to create.
  • format The element format, one of the VX_TYPE_ constants.
  • scales Scales instance indicating the scale factor of the tensor (for integer types only).
  • from_file Path to a binary file that is used to initialise the tensor. This file must be at least as large as ComputeSize(shape) * bytes-per-element.

Return: A Tensor that owns the vx_tensor on success. If the function fails then an error object is returned which can be queried for its status code. ```cpp

auto tensor = vx::CreateTensor(ctx, {3, 480, 640}, vx::int8, {0.0125}, "initdata.bin"); if (!tensor) { return tensor.get_status(); } vx_uint32 ndims = 0; vxQueryTensor(*tensor, VX_TENSOR_NUM_OF_DIMS, &ndims, sizeof(ndims));

### function CreateVirtualTensor

```cpp
inline Tensor CreateVirtualTensor(
    vx_graph graph,
    const Shape & shape,
    DataType data_type,
    const Scales & scales =Scales{}
)

Create a Virtual Tensor of given shape and format. \detail Optionally also set the tensor scale factor.

Parameters:

  • graph The graph that will use the virtual tensor.
  • shape Shape of tensor to create.
  • format The element format, one of the VX_TYPE_ constants.
  • scales Scales instance indicating the scale factor of the tensor (for integer types only). ```cpp

auto tensor = vx::VirtualTensor(graph, {3, 480, 640}, VX_TYPE_INT8, {0.0125});

### function CreateTensorFromView

```cpp
inline Tensor CreateTensorFromView(
    vx_tensor parent,
    const Shape & start,
    const Shape & end
)

Create an ROI of a Tensor from start to end positions.

Parameters:

  • tensor The parent tensor from which the roi will be derived
  • start Start position of the Shape of tensor to create, in the coordinates of the parent tensor
  • end End position of the Shape of tensor to create, in the coordinates of the parent tensor. The end is not included in the ROI ```cpp

auto tensor = vx::VirtualTensor(graph, {3, 480, 640}, VX_TYPE_INT8, {0.0125}); auto green_channel = vx::TensorROI(tensor, {1, 0, 0}, {2, 480, 640}, ); assert(GetShape(green_channel) == Shape(1, 480, 640));

### function ReadTensor

```cpp
template <typename T >
vx_status ReadTensor(
    vx_tensor t,
    std::vector< T > & buffer
)

Read the entire contents of a tensor (or roi) into a vector.

Parameters:

  • t The tensor to read from.
  • buffer A vector to receive the read elements. ```cpp

auto t = vx::Tensor(ctx, {3, 200, 300}, VX_TYPE_BFLOAT16); if (!t) { ... } const auto shape = vx::GetShape(t); const auto write = std::vector(ComputeSize(shape), 0x8000); if (vx::WriteTensor(t, write) != VX_SUCCESS) { ... } auto read_back = std::vector(); if (vx::ReadTensor(t, read_back) != VX_SUCCESS) { ... } assert(write == read_back);

The element size of the tensor must match the element size of the vector. The vector will be resized to be the correct length, it need not be resized before the call. 


### function WriteTensor

```cpp
template <typename T >
vx_status WriteTensor(
    vx_tensor t,
    const std::vector< T > & buffer
)

Write to the entire contents of a tensor (or roi) from a vector.

Parameters:

  • t The tensor to write to.
  • buffer A vector containing the data to write. ```cpp

auto t = vx::Tensor(ctx, {3, 200, 300}, VX_TYPE_BFLOAT16); if (!t) { ... } const auto shape = vx::GetShape(t); const auto write = std::vector(ComputeSize(shape), 0x8000); if (vx::WriteTensor(t, write) != VX_SUCCESS) { ... } auto read_back = std::vector(); if (vx::ReadTensor(t, read_back) != VX_SUCCESS) { ... } assert(write == read_back);

The element size of the tensor must match the element size of the vector. The vector must me of the correct length, that is that : buffer.size() == ComputeSize(GetShape(t))


### function ToReference

```cpp
template <typename Ref >
vx_reference ToReference(
    Ref ref
)

Convert a vx object such as vx_tensor into a vx_reference. \detail Whilst a reinterpret_cast can be used for this purpose, this function is safer because it will not allow non vx types to be cast. Additionally it accepts Unique objects.

function ToReference

template <typename Ref >
vx_reference ToReference(
    const Unique< Ref > & ref
)

function ToReference< vx_reference >

inline vx_reference ToReference< vx_reference >(
    vx_reference ref
)

function Own

template <typename VxType >
Unique< VxType > Own(
    VxType r
)

Create a deduced Unique<> object that owns the given reference.

Parameters:

  • r The reference to be owned by the Unique<> object. ```cpp

auto context = vx::Own(vxCreateContext());

### function RetainAndOwn

```cpp
template <typename VxType >
Unique< VxType > RetainAndOwn(
    VxType r
)

Create a deduced Unique<> object that retains and then owns the given reference. \detail This can be useful when an optional reference is given to a function and the given ref is not owned by the current scope.

Parameters:

  • r The reference to be retained and owned by the Unique<> object. ```cpp

Graph CreateGraph(vx_context ctx, vx_tensor t = nullptr) { auto graph = vx::Own(vxCreateGraph(ctx)); auto t0 = t ? vx::RetainAndOwn(t) : vx::CreateTensor(ctx, {16, 2}, vx::int8};; ... // at scope exit the object managed by t0 is released, but because we used // RetainAndOwn then the callers reference will not be destroyed if t was // given. return graph; }

### function GetContext

```cpp
template <typename Ref >
vx_context GetContext(
    const Ref & r
)

Retrieves the context from any reference from within a context.

Parameters:

  • reference The reference from which to extract the context.

Return: The overall context that created the particular reference.

function GetReferenceName

template <typename T >
std::string GetReferenceName(
    const T & ref
)

Retrieves the reference name.

Parameters:

  • ref The reference from which to extract the name.

Return: The name of the reference as set by vxSetReferenceName, or an empty string if the reference is not valid..

function EnableLogging

inline void EnableLogging(
    vx_context c,
    bool verbose =false
)

Enables openvx logging to stdout.

Parameters:

  • context The reference to the context.
  • verbose If true then all calls are logged, if false then some noisy functions are skipped. Specifically any info log messages resulting from vxRelease, vxQuery, and vxGetContext and vxGetStatus calls..

This installs a simple log callback (using vxRegisterLogCallback) which outputs to stdout.

Attributes Documentation

variable int8

constexpr auto int8 = DataType::int8;

variable uint8

constexpr auto uint8 = DataType::uint8;

variable float8

constexpr auto float8 = DataType::float8;

variable int16

constexpr auto int16 = DataType::int16;

variable uint16

constexpr auto uint16 = DataType::uint16;

variable float16

constexpr auto float16 = DataType::float16;

variable bfloat16

constexpr auto bfloat16 = DataType::bfloat16;

variable int32

constexpr auto int32 = DataType::int32;

variable uint32

constexpr auto uint32 = DataType::uint32;

variable float32

constexpr auto float32 = DataType::float32;

variable int64

constexpr auto int64 = DataType::int64;

variable uint64

constexpr auto uint64 = DataType::uint64;

variable float64

constexpr auto float64 = DataType::float64;

variable vxorder

constexpr auto vxorder = VxOrder{};

variable N

constexpr auto N = OnnxDimension::N;

variable C

constexpr auto C = OnnxDimension::C;

variable H

constexpr auto H = OnnxDimension::H;

variable W

constexpr auto W = OnnxDimension::W;

Updated on 2023-11-29 at 18:22:22 +0000