AI Engine API User Guide (AIE) 2023.2
Loading...
Searching...
No Matches
Basic Type Initialization

Vector Initialization

On construction, the contents of a vector are undefined.

Type for vector registers.
Definition vector.hpp:107

The simplest way of initializing a vector is from another vector of the same type and size.

Or as the result of an operation.

auto add(const Vec1 &v1, const Vec2 &v2) -> aie_dm_resource_remove_t< Vec1 >
Returns a vector with the element-wise addition of the two input vectors.
Definition aie.hpp:3070

A vector can also be read from memory using the aie::load_v operation or iterators. See Memory for more details.

aie::vector<int16, 16> v = aie::load_v<16>(ptr);

Sections of a vector can be modified independently. It can be done in a per-element basis.

for (unsigned i = 0; i < v.size(); ++i)
v[i] = i; // i-th element is updated
static constexpr unsigned size()
Returns the number of elements in the vector.
Definition vector.hpp:136

Or by writing subvectors.

v.insert(0, v1); // This updates elements 0-7
v.insert(1, v2); // This updates elements 8-15
vector & insert(unsigned idx, const vector< T, ElemsIn > &v)
Updates the contents of a region of the vector.
Definition vector.hpp:392

Vectors can also be concatenated into a larger vector.

auto concat(const Acc &acc, const Accums &...accums) -> accum< typename Acc::value_type, Acc::size() *(1+sizeof...(Accums))>
Concatenate the contents of all input accumulators into a larger accumulator.
Definition aie.hpp:1079

Accumulator Initialization

Accumulators support all the aforementioned vector operations but the individual element update.

Initialization by Stream Read

Both vectors and accumulators can also be read from ADF abstractions such as windows and streams. See Interoperability with Adaptive Data Flow (ADF) Graph Abstractions for more details.

aie::vector<int16, 8> v = readincr_v<8>(input_stream);
aie::accum<acc48, 8> acc = readincr_v<8>(input_cascade);
Type for vector accumulators.
Definition accum.hpp:84

Mask Initialization

Masks are usually initialized as a result of a comparison using vectors:

Type for vector element masks.
Definition mask.hpp:61
mask< Vec1::size()> lt(const Vec1 &v1, const Vec2 &v2)
Compares the elements of the two input vectors and returns a mask that says what elements from the fi...
Definition aie.hpp:1237

In addition, it is possible to initialize a mask using a constant value. For example:

auto m1 = aie::mask<64>::from_uint64(0xaaaabbbbccccddddULL);
auto m2 = aie::mask<64>::from_uint32(0xaaaabbbb, 0xccccdddd);
auto m3 = aie::mask<16>::from_uint32(0b1010'1010'1011'1011);
static constexpr mask< Elems > from_uint64(uint64_t w, T &&... words)
Construct from unsigned (64b) words.
Definition mask.hpp:214
static constexpr mask< Elems > from_uint32(unsigned w, T &&... words)
Construct from unsigned (32b) words.
Definition mask.hpp:194
Tip:
You can use the standard C/C++ macros for fixed-sized integers instead of the integer suffix. In the definition of m1 it would look like UINT64_C(0xaaaabbbbccccdddd).