AI Engine
API supports accumulating variable number of vectors multiplied by coefficients –
aie::accumulate
. Following picture shows an
example of weighted accumulation on four vectors:
Figure 1. Vector Arithmetic Operations
The following code shows an example of aie::accumulate
:
/*template<unsigned Lanes, AccumOrOp Acc, Vector VecCoeff, Vector VecData, Vector... NextVecData>
aie::accumulate(const Acc & acc,
const VecCoeff & coeff,
unsigned coeff_start,
const VecData & data,
const NextVecData &... next_data)
*/
aie::vector<int16,16> coe;
aie::vector<int16,16> vdata,vnext1,vnext2,vnext3,vnext4;
//acc[i]=coe[0]*vdata[i]+coe[1]*vnext1[i]+coe[2]*vnext2[i]+coe[3]*vnext3[i]
auto acc=aie::accumulate<16>(coe,2,vdata,vnext1,vnext2,vnext3);//coeff_start=2
acc=aie::accumulate<16>(acc,coe,2,vdata,vnext4);//coeff_start=2
Note: All data vectors should have the same type
and size.