Intel® High Level Synthesis Compiler Pro Edition: Reference Manual

ID 683349
Date 10/02/2023

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

Document Table of Contents
Give Feedback

6.4. Loop Unrolling (unroll Pragma)

The Intel® HLS Compiler supports the unroll pragma for unrolling multiple copies of a loop.

Example code:

#pragma unroll <N>
for (int i = 0; i < M; ++i) {
    // Some useful work

In this example, <N> specifies the unroll factor, that is, the number of copies of the loop that the HLS compiler generates. If you do not specify an unroll factor, the HLS compiler unrolls the loop fully when the number of loop iterations is known at compile time.

As an example of the kind of code the compiler generates when unrolling a loop, consider the following code snippet where you specify an unroll factor of 3:
hls_register float data[N];

#pragma unroll 3
for (int i = 0; i < N; i++)
    data[i] = function(i, a);
Unrolling the loop with an unroll factor of 3 results in the compiler transforming the code snippet into something like the following code:
hls_register float data[N];

for (int i = 0; i < N; i += 3)
    data[i + 0] = function(i + 0, a);
    if (i + 1 < N)
        data[i + 1] = function(i + 1, a);
    if (i + 2 < N)
        data[i + 2] = function(i + 2, a);

You can find the unroll status of each loop in the high level design report (report.html).