Accumulation of ap_float<> Using ap_float_acc<> Helper Class - 2024.2 English - UG1399

Vitis High-Level Synthesis User Guide (UG1399)

Document ID
UG1399
Release Date
2024-11-13
Version
2024.2 English

The helper class ap_float_acc<> is provided to perform an accumulation using an ap_fixed<> integer underlying datatype to enable II=1 for the accumulation loop. The pseudo-code of the class declaration is shown below.

template <...>
class ap_float_acc< ap_float<W, E>, ap_fixed<WFX, IFX> > {
   ap_float<W, E> accumulate(const ap_float<W, E> &value, bool last);
}

The first template argument defines the input data type ap_float<W,E> of the values to be accumulated.

The second template argument defines the underlying datatype ap_fixed<WFX, IFX> of the internal accumulator which performs the actual accumulation.

The member function accumulate(value,last) is used to accumulate the input "value" into its internal accumulator, the input "last" is used to clear the internal accumulator after the last accumulation. The return value is the accumulator value.

using apf_t = ap_float<18, 5>;               // using is a C++ syntax
using acc_datatype_t = ap_fixed<32, 16>;

... my_function(...) {
   ap_float_acc<apf_t, acc_datatype_t> acc;  // instance of accumulator class

   apf_t res;
   for (unsigned int i = 0; i < n; i++) {
      apf_t value = ...;                     // value to accumulate
      res=acc.accumulate( /*input:ap_float*/ value, /*last:bool*/ i == n-1);
   }
}