【发布时间】:2018-06-07 15:24:37
【问题描述】:
我对 Metal 计算非常陌生,并且正在尝试围绕线程和组的概念来思考。问题是大多数(如果不是全部)示例都使用 2d 纹理作为示例,这完全不是我想要做的。我正在尝试创建一个计算函数,该函数在一个缓冲区中接收 2 个点和几个浮点数并计算 4 个点并将它们放入另一个缓冲区中,因此:
|--------Buffer1------| |-------Buffer2-----------|
f(point1, point2, [floats])=point1, point2, point3, point4
f is a function essentially involving some linear algebra with some multiplication
and addition. The most costly part being a sqrt operation used to normalize
the vector between point1 and point2. No branches in code.
我大致知道如何编写内核函数,但我不知道如何为它分配线程和线程组,因为我不知道如何计算这种情况下可能的最佳数量。
【问题讨论】:
-
大多数情况下,您不需要关心线程组。只需使用 Apple 在其Calculating Threadgroup and Grid Sizes 文章中显示的算法即可。对于您的情况,您需要处理一维缓冲区,只需将示例中的“texture.height”视为 1。
标签: objective-c swift xcode metal