Previous | Next --- Slide 2 of 47
Back to Lecture Thumbnails
haiyuem

This is a tricky question because the answer can also be "both": each "instance" of the program is run serially but the "instances" are run parallelly. (Not sure if "instance" is the correct wording here)

pmp

Could you change one of those for-loops to be a foreach-loop? That way ISPC launches program instances within this function. In that case, would the loops actually be executed in parallel within this function?

gpu

^ I am curious about this as well. When exactly does ISPC-compiled code spawn the multiple program instances and assign each of them some data on which to operate? My initial understanding was that this all occurred when foreach was called; however, based on this example and the next slide, it seems these program instances are launched when ispc_sinx is called.

l-henken

^ The foreach construct seems to a leaky abstraction to me and I am not sure if that is my misinterpretation or what. Without the foreach, it seems that the instances are spawned upon entry into the ISPC function and that each instance will execute the first instruction (abstraction with SIMD implementation). Yet with the foreach construct, it seems that the instances will be spawned and begin execution inside the body of foreach as opposed to the entry into the ISPC function.

kayvonf

@l-henken. Good comments.

But there is a consistent semantics to foreach. (To other students: the code above does not use ISPC's foreach construct. I am referring to that construct in this comment, not to the code above.) ISPC program instances are launched at the call to ispc_sinx(). In general we think of expressions in the body of the ISPC function as being carried out by all program instances. But remember, expressions on uniform variables need only happen once per gang, not once per instance. You can think of foreach as a per-gang concept, not a per instance concept. The semantics of foreach are that is defines an iteration space for the entire gang, and ISPC is responsible for determining which iterations get done by which program instances. (That assignment is an ISPC implementation detail, and is not defined by the language itself.)

Yes, you can't talk about the meaning of foreach without reasoning at the level of a gang, but I wouldn't call that leaky. There's just semantics at the level of a program instances and at the level of a gang.

jessicaaa

According to the professor, the "uniform" in the for loop here is a compile time directive. It means that for all program instances, the value of this variable will be the same. But it doesn't mean they're doing same maths or using the same index, as every program instance turns i into a unique index.

Please log in to leave a comment.