首页 > 解决方案 > 函数(depthwiseConvolution):在 lM[0] 的索引 0 处缺少 threadgroupMemory 绑定

问题描述

我正在尝试在 MacOS 上使用 Metal Performance Shaders 执行一个简单的 DepthwiseConvolution 内核,但遇到了问题。首先,我用适当的大小初始化一个MPSImage(称为debugInputImage),并填充了一些数字,比如1.0。然后我创建我的卷积核:

convolution_depthwise_0 = MPSCNNConvolution(device: device, 
    weights: datasource_depthwise_0)

具有以下描述符datasource_depthwise_0的实例在哪里:MPSCNNConvolutionDataSource

func descriptor() -> MPSCNNConvolutionDescriptor {
    var desc = MPSCNNDepthWiseConvolutionDescriptor(kernelWidth: 3,
        kernelHeight: 3,
        inputFeatureChannels: 32,
        outputFeatureChannels: 32)
    return desc
}

这就是我初始化输入图像的方式:

let imageDescriptor = MPSImageDescriptor(channelFormat: .float16, 
    width: 256, height: 256, featureChannels: 32)

debugInputImage = MPSImage(device: device, 
    imageDescriptor: imageDescriptor)

var arrayOfOnes = Array(repeating: Float(1.0), 
    count: imageDescriptor.width * imageDescriptor.height 
        * imageDescriptor.featureChannels)


let arrayOfOnes16 = toFloat16(&arrayOfOnes, size: arrayOfOnes.count)

debugInputImage.writeBytes(arrayOfOnes16, 
    dataLayout: MPSDataLayout.HeightxWidthxFeatureChannels, imageIndex: 0)

当我运行所有这些时:

let commandBuffer = commandQueue.makeCommandBuffer()!
let outImage = convolution_depthwise_0.encode(commandBuffer: commandBuffer, 
    sourceImage: debugInputImage)

并得到这个错误(在这一行let outImage = convolution_depthwise_0.encode(...):

validateComputeFunctionArguments:860: failed assertion `Compute 
Function(depthwiseConvolution): missing threadgroupMemory binding 
at index 0 for lM[0].'

对于常规卷积,一切都很好,只有 Depthwise 我遇到了这个问题。

该错误的原因可能是什么?

系统:MacOS 10.14、XCode 10.1 beta 3

只有 MPSCNNDepthWiseConvolutionDescriptor 不起作用。我对 MPSCNNConvolutionDescriptor 没有任何问题。我在 iOS 上也没有问题,只有 Mac OS。

标签: metalmetal-performance-shaders

解决方案


推荐阅读