| AI Engine API User Guide (AIE-API) 2026.1

Loading...
Searching...
No Matches
Vector and Accumulator Conversions
Basic Types

## Overview

Vectors and accumulators of any given element type and size can be reinterpreted as a different element type.

The total size in bits will stay the same after the conversion, so the number of elements may change depending on the size ratio between the old and new element types.

aie::vector<int16, 32> v;
aie::vector<int32, 16> v2;
aie::vector<cint16, 16> v3;
v2 = v.cast_to<int32>();
v3 = aie::vector_cast<cint16>(v);
aie::vector_cast
auto vector_cast(const Vec &v)
Reinterpret a vector using a different element type.
Definition aie.hpp:834
aie::vector::cast_to
auto cast_to() const
Reinterprets the current vector as a vector of the given type.
Definition vector.hpp:215
aie::vector
Type for vector registers.
Definition vector.hpp:75
int32
int32_t int32
Definition types.hpp:22

Vectors can be converted into accumulators. Their values can be shifted into a larger magnitude to implement fixed point precision schemes (this does not apply to floating point accumulators).

aie::vector<int16, 16> v;
aie::accum<acc32, 16> acc;
acc.from_vector(v, shift);
aie::accum::from_vector
void from_vector(const vector< T, Elems > &v, int shift=0)
Updates the contents of the accumulator using the values in the given vector after applying the reque...
Definition accum.hpp:474
aie::accum
Type for vector accumulators.
Definition accum.hpp:49

Conversely, accumulators can be converted into vectors. Their values can be shifted down before rounding and saturation is applied (this does not apply to floating point accumulators).

aie::accum<acc32, 16> acc;
aie::vector<int16, 16> v;
v = acc.to_vector<int16>(shift);
aie::accum::to_vector
vector< T, Elems > to_vector(int shift=0) const
Applies shift-round-saturate to the elements of the accumulator and stores the result into a vector o...
Definition accum.hpp:392
int16
int16_t int16
Definition types.hpp:21

## Functions
template<AccumElemBaseType AccumTag, VectorOrOp Vec>
accum< AccumTag, Vec::size()> | aie::from_vector (const Vec &v, int shift=0)
| Returns the values of the passed vector in an accumulator of the requested type after applying the requested upshift operation.
template<VectorOrOp Vec, typename T2 = Utils::get_prev_integer_type_t<typename Vec::value_type>> requires (!detail::is_floating_point_v<Vec>)
auto | aie::pack (const Vec &v) -> vector< T2, Vec::size()>
| Returns a conversion of the passed vector to the next smaller integer datatype, with the same number of elements.
template<typename TR, typename T> requires (AccumOrOp<T> || MmulOrOp<T>)
vector< TR, T::size()> | aie::to_vector (const T &acc, int shift=0)
| Returns the values of the passed accumulator in a vector of the requested type.
template<VectorOrOp Vec, typename T2 = Utils::get_next_integer_type_t<typename Vec::value_type>> requires (!detail::is_floating_point_v<Vec>)
auto | aie::unpack (const Vec &v) -> vector< T2, Vec::size()>
| Returns a conversion of the passed vector to the next larger integer datatype, with the same number of elements.
template<ElemBaseType DstT, Accum Acc> requires (arch::is(arch::Gen2))
auto | aie::vector_cast (const Acc &acc)
| Reinterpret an accumulator as a vector.
template<ElemBaseType DstT, Vector Vec>
auto | aie::vector_cast (const Vec &v)
| Reinterpret a vector using a different element type.

## Function Documentation

## ◆ from_vector()

template<AccumElemBaseType AccumTag, VectorOrOp Vec>

accum< AccumTag, Vec::size()> aie::from_vector | ( | const Vec & | v,
|  | int | shift = 0 )

Returns the values of the passed vector in an accumulator of the requested type after applying the requested upshift operation.

Parameters

  v | Input vector. The type must meet aie::VectorOrOp.
  shift | Optional upshift in bits to be applied to output accumulator. This parameter is ignored for floating-point types.

Template Parameters

  AccumTag | Accumulator tag that specifies returned accumulator type. The class must be compatible with the vector type (real/complex).

## ◆ pack()

template<VectorOrOp Vec, typename T2 = Utils::get_prev_integer_type_t<typename Vec::value_type>>
requires (!detail::is_floating_point_v<Vec>)

auto aie::pack | ( | const Vec & | v | ) | ->vector< T2, Vec::size()>

Returns a conversion of the passed vector to the next smaller integer datatype, with the same number of elements.

Parameters

  v | Input vector. The type must meet aie::VectorOrOp

Template Parameters

  T2 | Element type for the returned vector. Can only select between int8/uint8 on AIE1.

## ◆ to_vector()

template<typename TR, typename T>
requires (AccumOrOp<T> || MmulOrOp<T>)

vector< TR, T::size()> aie::to_vector | ( | const T & | acc,
|  | int | shift = 0 )

Returns the values of the passed accumulator in a vector of the requested type.

The values can be shifted down before rounding and saturation are applied (does not apply to floating point accumulators).

Note
  On AIE-ML/XDNA1 shift values of -4, -3, and -2 are unsafe, as they will only produce correct result if truncation is selected or saturation against 0 is required.

Parameters

  acc | Input accumulator. The type must meet aie::AccumOrOp or aie::MmulOrOp.
  shift | Optional downshift in bits to be applied to output data. This parameter is ignored for floating-point types.

Template Parameters

  TR | Element type for the returned vector.

## ◆ unpack()

template<VectorOrOp Vec, typename T2 = Utils::get_next_integer_type_t<typename Vec::value_type>>
requires (!detail::is_floating_point_v<Vec>)

auto aie::unpack | ( | const Vec & | v | ) | ->vector< T2, Vec::size()>

Returns a conversion of the passed vector to the next larger integer datatype, with the same number of elements.

Parameters

  v | Input vector. The type must meet aie::VectorOrOp

## ◆ vector_cast() [1/2]

template<ElemBaseType DstT, Accum Acc>
requires (arch::is(arch::Gen2))

auto aie::vector_cast | ( | const Acc & | acc | ) |

Reinterpret an accumulator as a vector.

The returned vector has the same size in bits as the input accumulator.

Template Parameters

  DstT | Element type for the returned vector.

Parameters

  acc | Input accumulator.

## ◆ vector_cast() [2/2]

template<ElemBaseType DstT, Vector Vec>

auto aie::vector_cast | ( | const Vec & | v | ) |

Reinterpret a vector using a different element type.

The returned vector has the same size in bits as the input vector.

Template Parameters

  DstT | Element type for the returned vector.

Parameters

  v | Input vector.