Previous | Next --- Slide 11 of 47
Back to Lecture Thumbnails
xiaowend

Since read-modify-write operation may be not atomic. If two program instances try to modify sum simultaneously, the sum may be incorrect. So one way to solve it is to create partial sum for each program instance. "partial" in each instance can only be modified by one instance so that correctness can be guaranteed.

miko

It is also significant to note that one should only return uniform variables, something that each program instance has in common with one another.

xs33

Question: Can someone please tell me how reduceAdd() works conceptually?

kayvonf

The input to reduceAdd is of type per-instance float. The output of reduceAdd is of type uniform float.

The semantics of uniform float sum = reduceAdd(partial) above are as follows:

You can think about reduceAdd running once per gang, not once per program instance. reduceAdd accepts as input the individual values of partial for each instance in the gang, computes their sum, and then returns a single value as a result, which is stored into the uniform value sum.

Note that this is a form of inter-instance communication. ISPC provides special language built-in functions like reduceAdd for this purpose.