0
$\begingroup$

Does anybody know if using very small local sizes in compute shaders will hurt performance?

eg. If I do this in a shader:

layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

Will it be slower than if I use larger sizes (eg. x=8, y=8)?

If size 1 is bad for performance then what's the recommended size? Is it a rectangle based on the value returned by aglGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE...)?

I've read many, many web pages today and the whole issue of "threading" in OpenGL compute shaders is about as clear as mud.

$\endgroup$
3
  • $\begingroup$ Won't you get an answer faster by benchmarking on your own ? $\endgroup$ May 3 at 11:45
  • $\begingroup$ I can't benchmark on many devices. $\endgroup$ May 3 at 19:46
  • $\begingroup$ You should explain that in your post. It makes a different question. $\endgroup$ May 3 at 20:09

1 Answer 1

2
$\begingroup$

Your workgroup size should be a multiple of 32 (Nvidia) or 64 (AMD).

The reason is, that on the GPU the work units are grouped to a warp(Nvidia) or a wave (AMD) with the size of 32 or 64. Each unit does the same arithmetic operation within a workgroup. So when define a workgroup with 1 * 1 * 1=1 units, the other 31(Nvidia) or 63(AMD) are blocked. So your performance will drop (it will only drop in case you are using more warps or waves than your GPU has, because then they are in a kind of waiting queue and will be executed when free warps/waves are available).

$\endgroup$
6
  • $\begingroup$ I'll accept the answer but it raises several more questions, eg. Does glGet(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS...) tell me the optimal size? $\endgroup$ May 3 at 20:10
  • $\begingroup$ No it does not. It tells you the maximum number of invocations within a workgroup. So it is the maximum value local_size_x * local_size_y * local_size_z can get. $\endgroup$
    – Thomas
    May 4 at 4:39
  • 1
    $\begingroup$ To find out the perfect size is very tricky... It depends on the shader you have. Keep in mind, that invocations within the same workgroup do the same arithmetic operations. So when using conditional statements and some invocations go to the 'if' case and other to the 'else' case is called Branching, which should be avoided. Because the execution of the workgroup would take as long as going to both ('if' and 'else') cases $\endgroup$
    – Thomas
    May 4 at 4:47
  • 1
    $\begingroup$ The branching problem is called "divergence" :-) $\endgroup$ May 5 at 9:57
  • $\begingroup$ @ChiftiSaidi thanks! Still learned something new =) $\endgroup$
    – Thomas
    May 5 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.