The following code segment shows how to use a runtime parameter to generate a sum or difference of the cascade input and an input vector.
template<unsigned nelems, unsigned burst_count>
void sumdiff(
const int8 mode, // runtime parameter: 0: add; otherwise subtract
input_stream<acc48> *icstrm, // input vector via accumulator cascade
input_stream<int32> *istrm, // input vector via plio stream
adf::output_buffer<int32, adf::extents<burst_count * nelems>> &out // output sum or difference
) {
// initialize iterator
auto optr = aie::begin_vector<nelems>(out);
// avoid if-else whenever possible in innermost loops as they will be executed on the scalar processor
if (mode == 0) { // perform addition
for (auto i = 0u; i < burst_count; i++) {
auto v1 = readincr_v<nelems>(icstrm); // get input from previous accumulator
auto v2 = readincr_v<nelems>(istrm); // get input from plio
auto acc = aie::add(v1, v2); // perform addition
auto result = acc.template to_vector<int32>(); // copy accumulator to vector
*optr++ = result; // write to output buffer
} // end for (auto i = 0u; i < burst_count; i++)
} else { // perform subtraction
for (auto i = 0u; i < burst_count; i++) {
auto v1 = readincr_v<nelems>(icstrm); // get input from previous accumulator
auto v2 = readincr_v<nelems>(istrm); // get input from plio
auto acc = aie::sub(v1, v2); // perform subtraction
auto result = acc.template to_vector<int32>(); // copy accumulator to vector
*optr++ = result; // write to output buffer
} // end for (auto i = 0u; i < burst_count; i++)
} // end if-e,se (mode == 0)
} // end sumdiff()
Declare the input RTP as const int8 mode in the function argument list. Within the code, a simple if statement selects whether a sum or difference is output.