Forum Discussion

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

Pragma Unroll with variable loop bound

Is it compulsory for the loop bound to be constant for unrolling?

Would the below kernel generate 50 times hw replication? What will happen if host sets the k = 60?

__kernel

__attribute__((task))

void test_multiplier(global char *restrict in, global char *restrict weights, global int *restrict out, int k) {

int output = 0;

#pragma unroll 50

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

output += in * weights;

}

1 Reply

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

    --- Quote Start ---

    Is it compulsory for the loop bound to be constant for unrolling?

    --- Quote End ---

    No. However, for minimum area overhead and maximum performance, it is best if the loop bound is known at compile-time and is divisible by the unroll factor.

    --- Quote Start ---

    Would the below kernel generate 50 times hw replication? What will happen if host sets the k = 60?

    --- Quote End ---

    The compiler will create a pipeline that can process 50 iteration per clock by using more FPGA resources. If you set k = 60, then the pipeline will work for two clocks + pipeline latency; nothing will go wrong, just the pipeline utilization will be low in the last clock.

    ...