IMPORTANT!: This is a compiler hint which the compiler may ignore.

Loop unrolling is the first optimization technique available in SDAccel. The purpose of the loop unroll optimization is to expose concurrency to the compiler. This newly exposed concurrency reduces latency and improves performance, but also consumes more FPGA fabric resources.

The opencl_unroll_hint attribute is part of the OpenCL Language Specification, and specifies that loops (for, while, do) can be unrolled by the OpenCL compiler. See "Unrolling Loops" in SDAccel Environment Optimization Guide (UG1207) for more information.

The opencl_unroll_hint attribute qualifier must appear immediately before the loop to be affected. You can use this attribute to specify full unrolling of the loop, partial unrolling by a specified amount, or to disable unrolling of the loop.


Place the attribute in the OpenCL source before the loop definition:

  • n is an optional loop unrolling factor and must be a positive integer, or compile time constant expression. An unroll factor of 1 disables unrolling.
    TIP: If n is not specified, the compiler automatically determines the unrolling factor for the loop.

Example 1

The following example unrolls the for loop by a factor of 2. This results in two parallel loop iterations instead of four sequential iterations for the compute unit to complete the operation.
for(int i = 0; i < LENGTH; i++) {
bufc[i] = bufa[i] * bufb[i];
Conceptually the compiler transforms the loop above to the code below:
for(int i = 0; i < LENGTH; i+=2) {
bufc[i] = bufa[i] * bufb[i];
bufc[i+1] = bufa[i+1] * bufb[i+1];

See Also