<p>Your workgroup size should be a multiple of 32 (Nvidia) or 64 (AMD).</p>
<p>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).</p>

CC BY-SA 4.0
2023-05-03T20:10:04.303Z
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?
Chifti Saidi
CC BY-SA 4.0
2023-05-04T04:39:22.857Z
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.
Thomas
CC BY-SA 4.0
2023-05-04T04:47:34.537Z
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
Thomas
CC BY-SA 4.0
2023-05-05T09:57:07.750Z
The branching problem is called "divergence" :-)
Chifti Saidi
CC BY-SA 4.0
2023-05-05T10:17:48.507Z
@ChiftiSaidi thanks! Still learned something new =)
Thomas
CC BY-SA 4.0
2023-05-12T15:17:11.053Z
@ChiftiSaidi If your hardware supports it (specifcally if it supports `GL_KHR_shader_subgroup`), you can at least ask it for the size of a subgroup (`GL_SUBGROUP_SIZE_KHR`), which is GL terminology for the above mentioned warps/wavefronts. This is normally a good hint for the *minimum* size you probably want (for the reasons explained in the answer). Still, as the answer says, the actualy size largely depends on your algorithm and in some scenarios even going below the warp size can help performance (if most of your threads would idle around anyway).
Christian Rau
CC BY-SA 4.0
2024-12-06T13:29:40.203Z
Also in case of Nvidia the workgroup size should be at least 64, as most of their architectures support 64 warps per multiprocessor(a block of cores), but only 32 workgroups: https://xmartlabs.github.io/cuda-calculator/
user369070
CC BY-SA 4.0
2023-05-02T20:12:43.547Z
2023-05-03T09:47:34.353Z
2023-05-03T09:47:34.353Z
Thomas
<p>Does anybody know if using very small local sizes in compute shaders will hurt performance?</p>
<p>eg. If I do this in a shader:</p>
<pre><code>layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
</code></pre>
<p>Will it be slower than if I use larger sizes (eg. x=8, y=8)?</p>
<p>If size 1 is bad for performance then what's the recommended size? Is it a rectangle based on the value returned by <strong>aglGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE...)</strong>?</p>
<p>I've read many, many web pages today and the whole issue of &quot;threading&quot; in OpenGL compute shaders is about as clear as mud.</p>

CC BY-SA 4.0
2023-05-03T19:46:06.167Z
I can't benchmark on many devices.
Chifti Saidi
<opengl><compute-shader><optimisation>
OpenGL compute local size vs. performance
Chifti Saidi
# OpenGL compute local size vs. performance

(Asked by: username_0 on 2023-05-02)

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.

**Tags:** opengl, compute-shader, optimisation

> **Comments:**
> **username_0**: I can't benchmark on many devices.  

---

## 1 answers

### Answer by username_1 on 2023-05-02. Score: 2 | Accepted answer

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).

> **Comments:**
> **username_0**: 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?  
> **username_1**: 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.  
> **username_1**: 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  
> **username_0**: The branching problem is called "divergence" :-)  
> **username_1**: @username_0 thanks! Still learned something new =)  
> **username_2**: @username_0 If your hardware supports it (specifcally if it supports `GL_KHR_shader_subgroup`), you can at least ask it for the size of a subgroup (`GL_SUBGROUP_SIZE_KHR`), which is GL terminology for the above mentioned warps/wavefronts. This is normally a good hint for the *minimum* size you probably want (for the reasons explained in the answer). Still, as the answer says, the actualy size largely depends on your algorithm and in some scenarios even going below the warp size can help performance (if most of your threads would idle around anyway).  
> **username_3**: Also in case of Nvidia the workgroup size should be at least 64, as most of their architectures support 64 warps per multiprocessor(a block of cores), but only 32 workgroups: https://xmartlabs.github.io/cuda-calculator/  

---

