Previous | Next --- Slide 9 of 57
Back to Lecture Thumbnails

What does it mean that uniform keyword is for "optimization"? How does it allow the program to run faster / in parallel?


@yimmyz From what I understood in lecture, the uniform keyword is for values that are the same for all program instances in the gang. This means that the compiler is free to actually share one instance of such variables across all the program instances instead of making a new variable for each of them, using up less memory and making each of the program instances do less work. It is optional though since semantically each program instance should still have access to its own variable, it's just that we know more about them so we can do more for the sake of speed.


We aren't denom and sign uniform variables? Is it because they change value?


@c0d3r In fact, they are -- look at the "uniform" keyword before their declarations.


@yimmyz In addition to what TomoA has said if i and term were not written with a uniform keyword, then it would mean that the compiler would have to emit code that would have to deal with the possibility of the loop instances following different control paths for each program instance.

Also, adding the uniform keyword means that it is more possible for the compiler to carry out loop unrolling as the compiler would understand your code code better. Loop unrolling is an optimization that reduces the number of iterations of a loop at the cost of increasing the code size. See for details about loop unrolling.

Also see This is where I got the information from.