Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

About Loop Unrolling

Hi everyone,

I am wondering if setting a unroll factor that is not multiple of loop count is OK in Altera OpenCL?

For example:# pragma unroll 10

for( int i = 0; i < n; i++){

...

}

Here n is either a number not divisible by 10 (ex: 128) or not known at compilation time (ex: a variable passed in from host). I know this can be done on CPU or GPU but I am wondering if this will generate incorrect result or cause performance issues on FPGA.

Thanks!

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    No, this will work. Depending on whether the iterations are independent or not, you may get performance increase because essentially FPGA hardware of the loop will be replicated 10 times.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you for the reply!

    So basically during the last unrolled iteration, only the reminder (in my example 128%10 = 8) number of the FPGA datapath will be used and the rest (again in my example 10 - 8 = 2) of the datapath will be bypassed right?

    --- Quote Start ---

    No, this will work. Depending on whether the iterations are independent or not, you may get performance increase because essentially FPGA hardware of the loop will be replicated 10 times.

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Thank you for the reply!

    So basically during the last unrolled iteration, only the reminder (in my example 128%10 = 8) number of the FPGA datapath will be used and the rest (again in my example 10 - 8 = 2) of the datapath will be bypassed right?

    --- Quote End ---

    Yes, this is correct.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Yes, this is correct.

    --- Quote End ---

    Thank you!