Data Comparison - 2022.1 English

AI Engine Kernel Coding Best Practices Guide (UG1079)

Document ID
UG1079
Release Date
2022-05-25
Version
2022.1 English

AI Engine API provides vector comparison operations, including:

  • aie::eq
  • aie::neq
  • aie::le
  • aie::lt
  • aie::ge
  • aie::gt

The vector comparison operations compare two vectors element by element or compare one scalar with one vector, and return a special type aie::mask. Each bit of aie::mask corresponds to one elementary comparison result.

aie::vector<int32,16> v1,v2;
aie::mask<16> msk_lt=aie::lt(v1,v2);
msk_lt.set(0);//set bit 0 to be true
aie::vector<int32,16> v_s=aie::select(v1,v2,msk_lt);

The following APIs compare all the elements of the two input vectors and return bool value true or false.

aie::equal
Returns whether all the elements of the two input vectors are equal. The vectors must have the same type and size.
aie::not_equal
Returns whether some elements in the two input vectors are not equal. The vectors must have the same type and size.

The following APIs are provided to choose the max or min value of two vectors (or one scalar and one vector) element by element. The type of the scalar and vectors must be same.

  • aie::max
  • aie::min
aie::vector<int32,16> vc=aie::max(v1,v2); //compare each element of v1,v2, set it to vc