Search Unity

Question Is there a way to know the number of kernels that a GPU has?

Discussion in 'General Graphics' started by laurentlavigne, Sep 13, 2022.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    That's for tuning the number of kernels in ComputeShader.Dispatch.
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    675
    First I thought you are asking for the number of #pragma kernel lines in a compute shader.
    Then I thought, you are asking for the thread group size of a kernel as it's defined in the shader.
    But, now I'm thinking, you would like to know what the best thread group size is to choose.

    I'm not aware that there is a way to query that with any API. The usual recommendation is to use a power-of-two size between 64 and 256. If you don't use group-shared memory, it's usually better to use a smaller number. If you do use group-shared memory, it's usually better to use a bigger number. But it depends on the shader, so you have to experiment.

    This has already been answered many times before:
    https://forum.unity.com/threads/compute-shader-thread-dispatching.953000/
    https://gpuopen.com/learn/optimizing-gpu-occupancy-resource-usage-large-thread-groups/
    https://stackoverflow.com/questions...-size-and-number-of-workgro/10098063#10098063
    https://www.intel.com/content/www/u.../work-group-size-recommendations-summary.html
    https://www.reddit.com/r/vulkan/comments/u3i6we/what_does_the_local_workgroup_size_in_compute/
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Oh thanks, I was afraid of using too many threads with 64 on Xe but that seems to be the sweet spot.