Can a conditional be embedded in a for loop in the kernel?
If so how is it done?
Section 5.1.1.2 Control Flow Instructions of the CUDA Programming Guide Version 2.1 lead me to believe I could use “normal” C flow control in a kernel. But when I try to nest a conditional within a for loop execution stops the first time the conditional is true in any thread.
In more detail:
I have an array of independent frames of data which share the same processing.
I process one frame in each thread using a for loop to cycle through all elements of the frame.
The current element processing depends on the previous value of the element.
With-in this loop there is a conditional.
If the element exceeds a limit, it is reset back to a starting value.
Each thread, ( or frame ), reaches the limit independently of the others.
The first frame to reach the limit causes execution to cease with the message:
cutilCheckMsg() CUTIL CUDA error: Kernel execution failed in file <filename.cu>, line 476 : unspecified launch failure.
If I move the conditional to after the for loop, thus checking at the end of the frame processing rather than after each elements processing, it works. The values increase, each at its own rate. When one exceeds the limit it is reset.
Note: the kernel is launched multiple times. The data is in global memory and processing picks up where it left off. It takes multiple launches before any frame reaches the limit.
Thanks for any help you can offer.
[codebox] const unsigned int tid = blockIdx.x * blockDim.x + threadIdx.x;
Â
for ( int i = 0; i < N_FRAME; i++ )Â {
Â
  Data[ tid * N_DATA + ACCUMULATOR_OFFSET ] += Data[ tid * N_DATA + INCREMENT_OFFSET ];
Â
   // *** Conditional In Loop ***
   if ( Data[ tid * N_DATA + ACCUMULATOR_OFFSET ] >= Data[ tid * N_DATA + LIMIT_OFFSET ] ) {
       Data[ tid * N_DATA + ACCUMULATOR_OFFSET ] -= 1024.00f;
   }
 }
Â
 // *** Conditional After Loop ***
 if ( Data[ tid * N_DATA + ACCUMULATOR_OFFSET ] >= Data[ tid * N_DATA + LIMIT_OFFSET ] ) {
     Data[ tid * N_DATA + ACCUMULATOR_OFFSET ] -= 1024.00f;
 }[/codebox]