Metal - Threads和ThreadGroups

soo*_*oon 4 multithreading metal

我正在学习Metal并尝试理解以下几行:

let threadGroupCount = MTLSizeMake(8, 8, 1) ///line 1
let threadGroups = MTLSizeMake(drawable.texture.width / threadGroupCount.width, drawable.texture.height / threadGroupCount.height, 1) ///line 2

command_encoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount) ///line 3
Run Code Online (Sandbox Code Playgroud)
  1. 对于line 1,3个整数代表什么?我的猜测是分配在进程中使用的线程数,但哪个是哪个?

  2. line 1和'第2行' 之间有什么不同?我再次猜测线程和线程组之间的差异.但我不确定什么是根本区别以及何时使用什么.

war*_*enm 8

在将工作项网格分派给计算内核时,您有责任将网格划分为称为线程组的子集,每个子集的线程总数(宽度*高度*深度)小于maxTotalThreadsPerThreadgroup对应的线程数.计算管道状态.

threadsPerThreadgroup大小表示网格(即线程在每个网格维度数目)的每个子集的"形状".该threadgroupsPerGrid参数指示构成整个网格的线程组的数量.与在代码中一样,纹理的尺寸通常除以您选择的线程组大小的尺寸.

一个性能注释:每个计算管道状态都有一个threadExecutionWidth值,指示线程组将由GPU一起调度和执行多少线程.因此,最佳线程组大小将始终是倍数threadExecutionWidth.在开发过程中,只需按照您目前的要求调度一个小方格,这是完全可以接受的.