【问题标题】:Metal: No matching function for call to 'threadgroup_barrier' in the kernel or Use of undeclared identifier 'mem_threadgroup'Metal:没有匹配函数调用内核中的“threadgroup_barrier”或使用未声明的标识符“mem_threadgroup”
【发布时间】:2014-12-08 16:52:10
【问题描述】:

我正在编写一个使用 Apple 的 Metal 进行科学计算的计算函数(又名内核)。

在内核中,我使用threadgroup 内存空间。 (据我了解,它类似于 OpenCL 中的 local 内存空间 - 如果我错了,请纠正我。) 为了同步一些内存读/写操作,我需要放置threadgroup_barrier(mem_threadgroup)。但是,屏障命令不断产生错误:

Use of undeclared identifier 'mem_threadgroup.' 

即使我删除函数调用 (threadgroup_barrier()) 的参数,我也会收到错误:

No matching function for call to 'threadgroup_barrier' in the kernel.

我在内核中包含了头文件“metal_stdlib”。我在这里想念什么?我需要使用另一个标题来使用屏障吗?

我们将不胜感激。

这里是代码摘要:

#include <metal_stdlib>
using namespace metal;

kernel void myKernel(device float2 *args [[buffer(0)]],
                    uint2 bidx [[threadgroup_position_in_grid]],
                    uint2 tidx [[thread_position_in_threadgroup]])
{
    // memory space shared by thread groups
    threadgroup float2 tile[32][32+1];

    ...

    for (uint k = 0; k < params.depth; k++)
    {
       ... // operations with tile (threadgroup memory space)

       threadgroup_barrier(mem_threadgroup);

       ... // more operations with tile

       threadgroup_barrier(mem_threadgroup);
    }
}

【问题讨论】:

    标签: objective-c c opencl gpgpu metal


    【解决方案1】:

    [感谢帮助找到解决方法的同事。] 由于 mem_flags 是一个枚举类,我需要范围解析运算符 (mem_flags::)。所以,屏障的正确用法是

    threadgroup_barrier(mem_flags::mem_threadgroup)
    

    此修复消除了错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多