OpenCL local_work_size NULL

gpgpu, opencl

Solution

This depends on how your kernel is written. Often times to get the best performance your kernels need to make assumptions based on the local work size. For example in convolution you want to use the maximum amount of local memory you can to prevent extra reads back to global memory. You will want to handle as many threads as you can based on the incoming kernel sizes and how much local memory your device has. Configuring your local work size based on incoming parameters such as the kernel size can be the difference in major speed ups not just small differences. This is one reason why a language such as Renderscript Compute will never be able to provide performance close to optimized OpenCL/Cuda that allow for the developer to be aware of the hardware they are running on.

Also you are not guessing about the size. Well you certainly can make general assumptions but you can achieve better performance by looking at the architecture you are running (check AMD/NVIDIA/Intel guides on each device) and optimizing for them. You may change that at runtime by having tweaks in your code to modify your OpenCL kernel at runtime (since it is just a string) or you could have multiple kernels and select the best one at runtime.

That said using `NULL` for the workgroup is a great way to not worry about optimization and to just test out acceleration on the GPU with little effort. You will almost certainly get much better performance if you are aware of the hardware, make better choices, and write your kernels with knowledge of the size of the local workgroup.

Problem

When enqueueing an OpenCL kernel, `local_work_size` can be set to `NULL`, in which case the OpenCL implementation will determine how to break the global work-items into appropriate work-group instances. Automatically calculating the `local_work_size` seems like a great feature (better than guessing a multiple of 64). Does OpenCL's work group size choice tend to be optimal? Are there cases where it would be better to manually specify `local_work_size`?

Original source