Intel® High Level Synthesis Compiler Pro Edition: Reference Manual

ID 683349
Date 12/13/2021
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

3.3.1. Templated Functions

Using a templated function as an HLS component differs from using the templated function as an HLS task.

Templated Functions as an HLS Component

When you create a template function, you must declare the instantiation of the function to synthesize into hardware.

For example, a templated multadd function might be useful in a system.
template <typename T, int MULT>
T multadd (T a, T b) {
  return MULT * (a + b);
}
To synthesize a version of this function into a component, you must declare the instantiation that you want to synthesize:
template component int multadd<int, 5>(int a, int b);

This declaration combined with the earlier template definition marks the int variant with MULT=5 of the multiadd function to be generated into a component. This component can now be invoked from the testbench.

Templated Functions as an HLS Task

If you want to use the function as a task in a system of tasks, use the ihc::launch and ihc::collect calls as shown in the following example:

component void foo () {
  int a, b;
  ihc::launch<multadd<int, 5>> (a, b);
  int res = ihc::collect<multadd<int, 5>>();
}