Previous | Next --- Slide 7 of 60
Back to Lecture Thumbnails
khans

programCount doesn't actually have to divide N - a few threads would simply have more 1 loop iteration if it doesn't.

aperiwal

Wouldn't that lead to a possible out-of-bound access for the arrays x and result ?

thunder

Agree with @aperiwal. Here is an example of this. If N is 6 and programCount is 4, for the instance with the index of 3 during the second loop in the outer for loop, i is 4 (less than 6) and it can execute into the loop. Thus we can get 7 for idx and since there are only 6 element in the array x, the line that loads x[idx] to value as well as the line after that will encounter the out-of-bound access. And therefore, the assumption is needed for the code.

pdp

I think ISPC will have some sort of a masking operation to mask some indices if it is out of bounds (just like AVX intrinsics). Or we could define a boolean vector and specify our logic if it exceeds the bounds of the array.

rsvaidya

Keyword uniform before a variable represents a single value that is shared across the gang thus reducing the storage space required. A more important benefit is that it can enable the compiler to generate substantially better code for control flow; when a test condition for a control flow decision is based on a uniform quantity, the compiler can be immediately aware that all of the running program instances will follow the same path at that point, saving the overhead of needing to deal with control flow divergence and mask management. Complete article

sampathchanda

@rsvaidya, thanks for sharing the link. In the uniform data section of the link, the keyword varying is mentioned. Till now, I was under the assumption that, there can be only two types of variables - uniform/non-uniform (which are not indicated by the keyword uniform).

Then what could be the possible difference between variables that are defined with the keyword varying and those just defined without either of uniform or varying ? Is there any difference at all ?

Vincent

Another possible solution is that we can check the programIndex before the loop and make some limitations to specify our logic. But I'm not sure whether ISPC will check invalid index for us.