opencl_unroll_hint
Description
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.
Theopencl_unroll_hint
attribute is part of the OpenCL Language Specification, and specifies that loops (for
,while
,do
) can be unrolled by the OpenCL compiler.SeeUnrolling Loopsfor more information.
Theopencl_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.
Syntax
Place the attribute in the OpenCL source before the loop definition:
__attribute__((opencl_unroll_hint(n)))
- nis 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 nis not specified, the compiler automatically determines the unrolling factor for the loop.
Example 1
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.
__attribute__((opencl_unroll_hint(2))) for(int i = 0; i < LENGTH; i++) { bufc[i] = bufa[i] * bufb[i]; }
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
- SDAccel Environment Optimization Guide(UG1207)
- https://www.khronos.org/
- The OpenCL C Specification