gpt4 book ai didi

multithreading - Metal - 线程和线程组

转载 作者:行者123 更新时间:2023-12-04 22:57:25 28 4
gpt4 key购买 nike

我在学习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
  • 对于line 1 ,这3个整数代表什么?我的猜测是分配要在进程中使用的线程数,但哪个是哪个?
  • line 1 和有什么区别和“第 2 行”?我的猜测再次是线程和线程组之间的不同。但我不确定根本区别是什么以及何时使用什么。
  • 最佳答案

    在将工作项网格分派(dispatch)到计算内核时,您有责任将网格划分为称为线程组的子集,每个子​​集的线程总数(宽度 * 高度 * 深度)小于 maxTotalThreadsPerThreadgroup。对应的计算管道状态。
    threadsPerThreadgroup size 表示网格每个子集的“形状”(即每个网格维度中的线程数)。 threadgroupsPerGrid参数表示有多少线程组组成整个网格。与您的代码一样,它通常是纹理的尺寸除以您选择的线程组大小的尺寸。

    一个性能说明:每个计算管道状态都有一个 threadExecutionWidth指示线程组的多少线程将由 GPU 一起调度和执行的值。因此,最佳线程组大小将始终是 threadExecutionWidth 的倍数。 .在开发过程中,像您目前所做的那样仅发送一个小方形网格是完全可以接受的。

    关于multithreading - Metal - 线程和线程组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39662431/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com