title: How Metal distribute the image block to each thread group?
body: <p><a href="https://i.stack.imgur.com/hgZpnm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hgZpnm.jpg" alt="enter image description here"></a>
   <a href="https://i.stack.imgur.com/kmfxMm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kmfxMm.jpg" alt="enter image description here"></a></p>
  
  <p>For example, if I want to do a grayscale transformation, I need to set up my threadsPerGroup and thread group in the following way.</p>
  
  <pre><code>NSUInteger maxTotalThreadsPerThreadgroup = [self.computePipelineState maxTotalThreadsPerThreadgroup];
  MTLSize threadgroupCounts = MTLSizeMake(threadExecutionWidth * 2, threadExecutionWidth * 2, 1);
  MTLSize threadsPerThreadGroup = MTLSizeMake([self.texutre width] / threadgroupCounts.width + 1,
  [self.texutre height] / threadgroupCounts.height + 1,
  1);
  </code></pre>
  
  <p>I know the image will be chopped into different blocks and each one will be processed by one thread group. But it seems in the kernel, we will just read the 2d texture, and then output the processed texture.</p>
  
  <p>But the question is that how the image is chopped into different 2d texture? How do we know if each block of image get assigned to a thread to process? Is this done by Metal itself? Or we need to manually assign each block to each threadgroup by using the <strong>gid</strong>?</p>