我想知道为什么我不能MPSMatrix
成功初始化?对象方法 initWith 只返回一个 nil(这意味着初始化不成功)。我的代码如下所示,我想创建一个MPSMatrix
命名的 matrixA 但只得到一个 nil 。
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
id<MTLCommandBuffer> mpsBuffer = commandQueue.commandBuffer;
float arrayA[5*6] =
{1,1,1,1,1,1,
2,2,2,2,2,2,
3,3,3,3,3,3,
4,4,4,4,4,4,
5,5,5,5,5,5};
float arrayB[6*5] =
{1,1,1,1,1,
2,2,2,2,2,
3,3,3,3,3,
4,4,4,4,4,
5,5,5,5,5,
6,6,6,6,6};
float arrayC[5*5] = {0};
id<MTLBuffer> bufferA = [device newBufferWithBytes:arrayA length:5*6*4 options:MTLResourceCPUCacheModeDefaultCache];
id<MTLBuffer> bufferB = [device newBufferWithBytes:arrayB length:6*5*4 options:MTLResourceCPUCacheModeDefaultCache];
id<MTLBuffer> bufferC = [device newBufferWithBytes:arrayC length:5*5*4 options:MTLResourceCPUCacheModeDefaultCache];
MPSMatrixDescriptor * descA = [MPSMatrixDescriptor matrixDescriptorWithDimensions:5 columns:6 rowBytes:6*4 dataType:MPSDataTypeFloat32];
MPSMatrixDescriptor * descB = [MPSMatrixDescriptor matrixDescriptorWithDimensions:6 columns:5 rowBytes:5*4 dataType:MPSDataTypeFloat32];
MPSMatrixDescriptor * descC = [MPSMatrixDescriptor matrixDescriptorWithDimensions:5 columns:5 rowBytes:5*4 dataType:MPSDataTypeFloat32];
MPSMatrix * matrixA = [[MPSMatrix alloc] initWithBuffer:bufferA descriptor:descA];
MPSMatrix * matrixB = [[MPSMatrix alloc] initWithBuffer:bufferB descriptor:descB];
MPSMatrix * matrixC = [[MPSMatrix alloc] initWithBuffer:bufferC descriptor:descC];